Skip to content

Commit ebfe75d

Browse files
authored
Merge pull request #4 from rdeits/latex-escape
escape # character from gensym() symbols
2 parents 58a4724 + 1887984 commit ebfe75d

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/TreeView.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,15 @@ end
1313

1414
add_numbered_vertex!(g) = (add_vertex!(g); top = nv(g)) # returns the number of the new vertex
1515

16+
# latex treats # as a special character, so we have to escape it. See:
17+
# https://github.com/sisl/TikzGraphs.jl/issues/12
18+
latex_escape(s::String) = replace(s, "#", "\\#")
19+
1620
"Convert the current node into a label"
1721
function label(sym)
1822
sym == :(^) && return "\\textasciicircum" # TikzGraphs chokes on ^
1923

20-
return string("\\texttt{", sym, "}")
24+
return latex_escape(string("\\texttt{", sym, "}"))
2125
end
2226

2327

test/runtests.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,10 @@ using Base.Test
1717
t = @tree x^2 + y^2
1818
@test length(t.labels) == 7
1919
end
20+
21+
@testset "latex special characters" begin
22+
# Test for issues with the characters present in julia's generated symbols
23+
expr = Expr(Symbol("##271"))
24+
t = walk_tree(expr)
25+
@test t.labels[1] == "\\texttt{\\#\\#271}"
26+
end

0 commit comments

Comments
 (0)