Skip to content

Commit dfbb304

Browse files
Merge pull request #283 from SciML/latexify
fix latexification
2 parents 49dfc25 + 8092448 commit dfbb304

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

src/latexify_recipes.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
@latexrecipe function f(eqs::Vector{ModelingToolkit.Equation}; iv=:t)
22
# Set default option values.
33
env --> :align
4+
cdot --> false
45

56
# Convert both the left and right hand side to expressions of basic types
67
# that latexify can deal with.
@@ -9,15 +10,15 @@
910
rhs = convert.(Expr, rhs)
1011
rhs = [postwalk(x -> x isa ModelingToolkit.Constant ? x.value : x, eq) for eq in rhs]
1112
rhs = [postwalk(x -> x isa Expr && length(x.args) == 1 ? x.args[1] : x, eq) for eq in rhs]
12-
rhs = [postwalk(x -> x isa Expr && x.args[1] == :Differential && length(x.args[2].args) == 2 ? :($(Symbol(:d, x.args[2]))/($(Symbol(:d, x.args[2].args[2])))) : x, eq) for eq in rhs]
13-
rhs = [postwalk(x -> x isa Expr && x.args[1] == :Differential ? "\\frac{d\\left($(Latexify.latexraw(x.args[2]))\\right)}{d$iv}" : x, eq) for eq in rhs]
13+
rhs = [postwalk(x -> x isa Expr && x.args[1] == :derivative && length(x.args[2].args) == 2 ? :($(Symbol(:d, x.args[2]))/($(Symbol(:d, x.args[2].args[2])))) : x, eq) for eq in rhs]
14+
rhs = [postwalk(x -> x isa Expr && x.args[1] == :derivative ? "\\frac{d\\left($(Latexify.latexraw(x.args[2]))\\right)}{d$iv}" : x, eq) for eq in rhs]
1415

1516
lhs = getfield.(eqs, :lhs)
1617
lhs = convert.(Expr, lhs)
1718
lhs = [postwalk(x -> x isa ModelingToolkit.Constant ? x.value : x, eq) for eq in lhs]
1819
lhs = [postwalk(x -> x isa Expr && length(x.args) == 1 ? x.args[1] : x, eq) for eq in lhs]
19-
lhs = [postwalk(x -> x isa Expr && x.args[1] == :Differential && length(x.args[2].args) == 2 ? :($(Symbol(:d, x.args[2]))/($(Symbol(:d, x.args[2].args[2])))) : x, eq) for eq in lhs]
20-
lhs = [postwalk(x -> x isa Expr && x.args[1] == :Differential ? "\\frac{d\\left($(Latexify.latexraw(x.args[2]))\\right)}{d$iv}" : x, eq) for eq in lhs]
20+
lhs = [postwalk(x -> x isa Expr && x.args[1] == :derivative && length(x.args[2].args) == 2 ? :($(Symbol(:d, x.args[2]))/($(Symbol(:d, x.args[2].args[2])))) : x, eq) for eq in lhs]
21+
lhs = [postwalk(x -> x isa Expr && x.args[1] == :derivative ? "\\frac{d\\left($(Latexify.latexraw(x.args[2]))\\right)}{d$iv}" : x, eq) for eq in lhs]
2122

2223
return lhs, rhs
2324
end

test/latexify.jl

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,11 @@ eqs = [D(x) ~ σ*(y-x)*D(x-y)/D(z),
2626
0 ~ σ*x*-z)/10-y,
2727
D(z) ~ x*y^(2//3) - β*z]
2828

29-
3029
@test latexify(eqs) ==
3130
raw"\begin{align}
32-
\mathrm{derivative}\left( \mathrm{x}\left( t \right), t \right) =& \frac{\sigma \cdot \left( \mathrm{y}\left( t \right) - \mathrm{x}\left( t \right) \right) \cdot \mathrm{derivative}\left( \mathrm{x}\left( t \right) - \mathrm{y}\left( t \right), t \right)}{\mathrm{derivative}\left( \mathrm{z}\left( t \right), t \right)} \\
33-
0 =& \frac{\sigma \cdot \mathrm{x}\left( t \right) \cdot \left( \rho - \mathrm{z}\left( t \right) \right)}{10} - \mathrm{y}\left( t \right) \\
34-
\mathrm{derivative}\left( \mathrm{z}\left( t \right), t \right) =& \mathrm{x}\left( t \right) \cdot \left( \mathrm{y}\left( t \right) \right)^{\frac{2}{3}} - \beta \cdot \mathrm{z}\left( t \right)
31+
\frac{dx(t)}{dt} =& \frac{\sigma \left( \mathrm{y}\left( t \right) - \mathrm{x}\left( t \right) \right) \frac{d\left(\mathrm{x}\left( t \right) - \mathrm{y}\left( t \right)\right)}{dt}}{\frac{dz(t)}{dt}} \\
32+
0 =& \frac{\sigma \mathrm{x}\left( t \right) \left( \rho - \mathrm{z}\left( t \right) \right)}{10} - \mathrm{y}\left( t \right) \\
33+
\frac{dz(t)}{dt} =& \mathrm{x}\left( t \right) \left( \mathrm{y}\left( t \right) \right)^{\frac{2}{3}} - \beta \mathrm{z}\left( t \right)
3534
\end{align}
3635
"
3736

@@ -45,9 +44,9 @@ eqs = [D(u[1]) ~ p[3]*(u[2]-u[1]),
4544

4645
@test latexify(eqs) ==
4746
raw"\begin{align}
48-
\mathrm{derivative}\left( \mathrm{u_1}\left( t \right), t \right) =& p_3 \cdot \left( \mathrm{u_2}\left( t \right) - \mathrm{u_1}\left( t \right) \right) \\
49-
0 =& \frac{p_2 \cdot p_3 \cdot \mathrm{u_1}\left( t \right) \cdot \left( p_1 - \mathrm{u_1}\left( t \right) \right)}{10} - \mathrm{u_2}\left( t \right) \\
50-
\mathrm{derivative}\left( \mathrm{u_3}\left( t \right), t \right) =& \mathrm{u_1}\left( t \right) \cdot \left( \mathrm{u_2}\left( t \right) \right)^{\frac{2}{3}} - p_3 \cdot \mathrm{u_3}\left( t \right)
47+
\frac{du_1(t)}{dt} =& p_3 \left( \mathrm{u_2}\left( t \right) - \mathrm{u_1}\left( t \right) \right) \\
48+
0 =& \frac{p_2 p_3 \mathrm{u_1}\left( t \right) \left( p_1 - \mathrm{u_1}\left( t \right) \right)}{10} - \mathrm{u_2}\left( t \right) \\
49+
\frac{du_3(t)}{dt} =& \mathrm{u_1}\left( t \right) \left( \mathrm{u_2}\left( t \right) \right)^{\frac{2}{3}} - p_3 \mathrm{u_3}\left( t \right)
5150
\end{align}
5251
"
5352

@@ -59,16 +58,16 @@ sys = ODESystem(eqs)
5958

6059
@test latexify(sys.eqs) ==
6160
raw"\begin{align}
62-
\frac{du_{1}}{dt} =& p_3 \cdot \left( \mathrm{u_2}\left( t \right) - \mathrm{u_1}\left( t \right) \right) \\
63-
\frac{du_{2}}{dt} =& \frac{p_2 \cdot p_3 \cdot \mathrm{u_1}\left( t \right) \cdot \left( p_1 - \mathrm{u_1}\left( t \right) \right)}{10} - \mathrm{u_2}\left( t \right) \\
64-
\frac{du_{3}}{dt} =& \mathrm{u_1}\left( t \right) \cdot \left( \mathrm{u_2}\left( t \right) \right)^{\frac{2}{3}} - p_3 \cdot \mathrm{u_3}\left( t \right)
61+
\frac{du_1(t)}{dt} =& p_3 \left( \mathrm{u_2}\left( t \right) - \mathrm{u_1}\left( t \right) \right) \\
62+
\frac{du_2(t)}{dt} =& \frac{p_2 p_3 \mathrm{u_1}\left( t \right) \left( p_1 - \mathrm{u_1}\left( t \right) \right)}{10} - \mathrm{u_2}\left( t \right) \\
63+
\frac{du_3(t)}{dt} =& \mathrm{u_1}\left( t \right) \left( \mathrm{u_2}\left( t \right) \right)^{\frac{2}{3}} - p_3 \mathrm{u_3}\left( t \right)
6564
\end{align}
6665
"
6766

6867
@test latexify(sys) ==
6968
raw"$\begin{align}
70-
\frac{du_{1}}{dt} =& p_3 \cdot \left( \mathrm{u_2}\left( t \right) - \mathrm{u_1}\left( t \right) \right) \\
71-
\frac{du_{2}}{dt} =& \frac{p_2 \cdot p_3 \cdot \mathrm{u_1}\left( t \right) \cdot \left( p_1 - \mathrm{u_1}\left( t \right) \right)}{10} - \mathrm{u_2}\left( t \right) \\
72-
\frac{du_{3}}{dt} =& \mathrm{u_1}\left( t \right) \cdot \left( \mathrm{u_2}\left( t \right) \right)^{\frac{2}{3}} - p_3 \cdot \mathrm{u_3}\left( t \right)
69+
\frac{du_1(t)}{dt} =& p_3 \left( \mathrm{u_2}\left( t \right) - \mathrm{u_1}\left( t \right) \right) \\
70+
\frac{du_2(t)}{dt} =& \frac{p_2 p_3 \mathrm{u_1}\left( t \right) \left( p_1 - \mathrm{u_1}\left( t \right) \right)}{10} - \mathrm{u_2}\left( t \right) \\
71+
\frac{du_3(t)}{dt} =& \mathrm{u_1}\left( t \right) \left( \mathrm{u_2}\left( t \right) \right)^{\frac{2}{3}} - p_3 \mathrm{u_3}\left( t \right)
7372
\end{align}
7473
$"

test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ using SafeTestsets, Test
1515
@safetestset "Constraints Test" begin include("constraints.jl") end
1616
@safetestset "PDE Construction Test" begin include("pde.jl") end
1717
@safetestset "Test Big System Usage" begin include("bigsystem.jl") end
18-
#@testset "Latexify recipes Test" begin include("latexify.jl") end
18+
@testset "Latexify recipes Test" begin include("latexify.jl") end
1919
@testset "Distributed Test" begin include("distributed.jl") end

0 commit comments

Comments
 (0)