Skip to content

Commit

Permalink
COSMETIC: Greek alphabet in LaTeX pretty-printing of formulas.
Browse files Browse the repository at this point in the history
  • Loading branch information
epatters committed Dec 14, 2018
1 parent 34cbccb commit 0660527
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/algebra/Tree.jl
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,13 @@ function show_latex_formula(io::IO, num::Number; kw...)
end

function show_latex_formula(io::IO, sym::Symbol; kw...)
print(io, get(latex_symbol_table, sym) do
length(string(sym)) == 1 ? sym : "\\mathrm{$sym}"
end)
if sym in latex_symbol_aliases
print(io, "\\", sym)
else
print(io, get(latex_symbol_table, sym) do
length(string(sym)) == 1 ? sym : "\\mathrm{$sym}"
end)
end
end

# Show non-terminal nodes as LaTeX.
Expand Down Expand Up @@ -404,12 +408,16 @@ const latex_command_table = Dict{Symbol,String}(
)
const latex_symbol_table = Dict{Symbol,String}(
:Inf => "\\infty",
:pi => "\\pi",
:sin => "\\sin", :cos => "\\cos", :tan => "\\tan",
:exp => "\\exp", :log => "\\log",
:Int => "\\mathbb{Z}", :Integer => "\\mathbb{Z}",
:Signed => "\\mmathbb{Z}", :Unsigned => "\\mathbb{N}",
:Real => "\\mathbb{R}", :Complex => "\\mathbb{C}",
)
const latex_symbol_aliases = Set{Symbol}([
:alpha, :beta, :gamma, :Gamma, :delta, :Delta, :epsilon, :varepsilon,
:zeta, :eta, :theta, :vartheta, :Theta, :iota, :kappa, :lambda, :Lambda,
:mu, :nu, :xi, :Xi, :pi, :Pi, :rho, :varrho, :sigma, :Sigma, :tau,
:upsilon, :Upsilon, :phi, :varphi, :Phi, :chi, :psi, :Psi, :omega, :Omega,
:exp, :log, :sin, :cos, :tan,
])

end
1 change: 1 addition & 0 deletions test/algebra/Tree.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ sexpr(form::Formula) = sprint(show_sexpr, form)
@test latex(Formula(:cos, :x)) == "\\cos\\left(x\\right)"
@test latex(Formula(:+, :x, :y)) == "x + y"
@test latex(Formula(:+, :x, :y, :z)) == "x + y + z"
@test latex(Formula(:+, :alpha, :beta)) == "\\alpha + \\beta"
@test latex(Formula(:-, :x, :y)) == "x - y"
@test latex(Formula(:-, :x)) == "- x"
@test latex(Formula(:*, :x, :y)) == "x y"
Expand Down

0 comments on commit 0660527

Please sign in to comment.