Skip to content

Commit

Permalink
BUG: LaTeX pretty-print omits parentheses around negative literals.
Browse files Browse the repository at this point in the history
  • Loading branch information
epatters committed Dec 14, 2018
1 parent 0660527 commit f208551
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/algebra/Tree.jl
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,11 @@ function show_latex_formula(io::IO, bool::Bool; kw...)
end

function show_latex_formula(io::IO, num::Number; kw...)
if isinf(num)
show_latex_formula(io, num > 0 ? :Inf : Formula(:-, :Inf))
if num < 0
# Treat negative literals as compound expressions.
show_latex_formula(io, Formula(:-, abs(num)); kw...)
else
print(io, num)
print(io, isinf(num) ? "\\infty" : num)
end
end

Expand Down
1 change: 1 addition & 0 deletions test/algebra/Tree.jl
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ sexpr(form::Formula) = sprint(show_sexpr, form)
@test latex(Formula((:-, (:+, :x, :y)))) == "- \\left(x + y\\right)"
@test_skip latex(Formula((:+, :x, (:-, :y)))) == "x + \\left(- y\\right)"
@test latex(Formula((:factorial, (:*, :m, :n)))) == "\\left(m n\\right) !"
@test latex(Formula(:^, -1, :n)) == "\\left(- 1\\right)^{n}"

# S-expression pretty-print.
@test sexpr(Formula(:f)) == "(:f)"
Expand Down

0 comments on commit f208551

Please sign in to comment.