Skip to content

Commit 2e3ee5b

Browse files
committed
Fix latexification of Functions.
1 parent 2ff6db1 commit 2e3ee5b

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

src/latexify_recipes.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
prettify_expr(expr) = expr
2-
prettify_expr(f::Function) = Base.isoperator(nameof(f)) ? nameof(f) : f
2+
prettify_expr(f::Function) = nameof(f)
33
prettify_expr(expr::Expr) = Expr(expr.head, prettify_expr.(expr.args)...)
44

55
@latexrecipe function f(eqs::Vector{ModelingToolkit.Equation})

test/latexify.jl

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,38 +26,52 @@ 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-
@test latexify(eqs) == raw"""\begin{align}
29+
30+
# Latexify.@generate_test latexify(eqs)
31+
@test latexify(eqs) == replace(
32+
raw"\begin{align}
3033
\frac{dx(t)}{dt} =& \frac{\sigma \left( y\left( t \right) - x\left( t \right) \right) \frac{d\left(x\left( t \right) - y\left( t \right)\right)}{dt}}{\frac{dz(t)}{dt}} \\
3134
0 =& \frac{\sigma x\left( t \right) \left( \rho - z\left( t \right) \right)}{10} - y\left( t \right) \\
3235
\frac{dz(t)}{dt} =& x\left( t \right) \left( y\left( t \right) \right)^{\frac{2}{3}} - \beta z\left( t \right)
3336
\end{align}
34-
"""
35-
@parameters t p[1:3]
36-
@variables u[1:3](t)
37-
@derivatives D'~t
37+
", "\r\n"=>"\n")
3838

39+
@variables u[1:3](t)
40+
@parameters p[1:3]
3941
eqs = [D(u[1]) ~ p[3]*(u[2]-u[1]),
4042
0 ~ p[2]*p[3]*u[1]*(p[1]-u[1])/10-u[2],
4143
D(u[3]) ~ u[1]*u[2]^(2//3) - p[3]*u[3]]
4244

43-
@test latexify(eqs) ==
45+
@test latexify(eqs) == replace(
4446
raw"\begin{align}
4547
\frac{du{_1}(t)}{dt} =& p{_3} \left( \mathrm{u{_2}}\left( t \right) - \mathrm{u{_1}}\left( t \right) \right) \\
4648
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) \\
4749
\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)
4850
\end{align}
49-
"
51+
", "\r\n"=>"\n")
5052

5153
eqs = [D(u[1]) ~ p[3]*(u[2]-u[1]),
5254
D(u[2]) ~ p[2]*p[3]*u[1]*(p[1]-u[1])/10-u[2],
5355
D(u[3]) ~ u[1]*u[2]^(2//3) - p[3]*u[3]]
5456

5557
sys = ODESystem(eqs)
5658

57-
@test latexify(eqs) ==
59+
@test latexify(eqs) == replace(
5860
raw"\begin{align}
5961
\frac{du{_1}(t)}{dt} =& p{_3} \left( \mathrm{u{_2}}\left( t \right) - \mathrm{u{_1}}\left( t \right) \right) \\
6062
\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) \\
6163
\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)
6264
\end{align}
63-
"
65+
", "\r\n"=>"\n")
66+
67+
68+
@parameters t
69+
@variables x(t)
70+
@derivatives D'~t
71+
eqs = [D(x) ~ (1+cos(t))/(1+2*x)]
72+
73+
@test latexify(eqs) == replace(
74+
raw"\begin{align}
75+
\frac{dx(t)}{dt} =& \frac{1 + \cos\left( t \right)}{1 + 2 x\left( t \right)}
76+
\end{align}
77+
", "\r\n"=>"\n")

0 commit comments

Comments
 (0)