Skip to content

Commit

Permalink
Merge pull request #4 from rdeits/latex-escape
Browse files Browse the repository at this point in the history
escape # character from gensym() symbols
  • Loading branch information
dpsanders authored Jan 30, 2017
2 parents 58a4724 + 1887984 commit ebfe75d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/TreeView.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
7 changes: 7 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit ebfe75d

Please sign in to comment.