diff --git a/src/TreeView.jl b/src/TreeView.jl index ad424f5..6b7c1e9 100644 --- a/src/TreeView.jl +++ b/src/TreeView.jl @@ -13,11 +13,15 @@ end add_numbered_vertex!(g) = (add_vertex!(g); top = nv(g)) # returns the number of the new vertex +# latex treats # as a special character, so we have to escape it. See: +# https://github.com/sisl/TikzGraphs.jl/issues/12 +latex_escape(s::String) = replace(s, "#", "\\#") + "Convert the current node into a label" function label(sym) sym == :(^) && return "\\textasciicircum" # TikzGraphs chokes on ^ - return string("\\texttt{", sym, "}") + return latex_escape(string("\\texttt{", sym, "}")) end diff --git a/test/runtests.jl b/test/runtests.jl index 6985c73..335d7c3 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -17,3 +17,10 @@ using Base.Test t = @tree x^2 + y^2 @test length(t.labels) == 7 end + +@testset "latex special characters" begin + # Test for issues with the characters present in julia's generated symbols + expr = Expr(Symbol("##271")) + t = walk_tree(expr) + @test t.labels[1] == "\\texttt{\\#\\#271}" +end