Skip to content

Commit

Permalink
fix latexify on complex expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
mxhbl committed Aug 25, 2024
1 parent 7097212 commit 9cba874
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/latexify_recipes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,9 @@ function _toexpr(O)
end
end

if isempty(numer) || !isone(abs(m.coeff))
if !isreal(m.coeff)
numer_expr = Expr(:call, :*, m.coeff, numer...)
elseif isempty(numer) || !isone(abs(m.coeff))
numer_expr = Expr(:call, :*, abs(m.coeff), numer...)
else
numer_expr = length(numer) > 1 ? Expr(:call, :*, numer...) : numer[1]
Expand All @@ -181,7 +183,7 @@ function _toexpr(O)
frac_expr = Expr(:call, :/, numer_expr, denom_expr)
end

if m.coeff < 0
if isreal(m.coeff) && m.coeff < 0
return Expr(:call, :-, frac_expr)
else
return frac_expr
Expand Down
1 change: 1 addition & 0 deletions test/latexify.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Dy = Differential(y)
@test_reference "latexify_refs/complex1.txt" latexify(x^2-y^2+2im*x*y)
@test_reference "latexify_refs/complex2.txt" latexify(3im*x)
@test_reference "latexify_refs/complex3.txt" latexify(1 - x + (1+2x)*im; imaginary_unit="\\mathbb{i}")
@test_reference "latexify_refs/complex4.txt" latexify(im * Symbolics.Term(sqrt, [2]))

@test_reference "latexify_refs/indices1.txt" latexify(h[10,10])
@test_reference "latexify_refs/indices2.txt" latexify(h[10,10], index=:bracket)
3 changes: 3 additions & 0 deletions test/latexify_refs/complex4.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
\begin{equation}
\mathit{i} \sqrt{2}
\end{equation}

0 comments on commit 9cba874

Please sign in to comment.