|
2 | 2 | # Set default option values.
|
3 | 3 | env --> :align
|
4 | 4 |
|
5 |
| - # Convert both the left and right hand side to expressions of basic types |
| 5 | + # Convert both the left and right hand side to expressions of basic types |
6 | 6 | # that latexify can deal with.
|
7 | 7 |
|
8 | 8 | rhs = getfield.(eqs, :rhs)
|
|
21 | 21 |
|
22 | 22 | return lhs, rhs
|
23 | 23 | end
|
| 24 | + |
| 25 | +@latexrecipe function f(eqs::Vector{ModelingToolkit.DiffEq}; iv=:t) |
| 26 | + # Set default option values. |
| 27 | + env --> :align |
| 28 | + |
| 29 | + # Convert both the left and right hand side to expressions of basic types |
| 30 | + # that latexify can deal with. |
| 31 | + |
| 32 | + rhs = getfield.(eqs, :rhs) |
| 33 | + rhs = convert.(Expr, rhs) |
| 34 | + rhs = [postwalk(x -> x isa ModelingToolkit.Constant ? x.value : x, eq) for eq in rhs] |
| 35 | + rhs = [postwalk(x -> x isa Expr && length(x.args) == 1 ? x.args[1] : x, eq) for eq in rhs] |
| 36 | + 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] |
| 37 | + 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] |
| 38 | + |
| 39 | + var = getfield.(getfield.(eqs, :x),:name) |
| 40 | + ns = getfield.(eqs, :n) |
| 41 | + lhs = [ns[i] == 1 ? Latexify.LaTeXString("\\frac{d$(Latexify.latexraw(var[i]))}{d$iv}") : LaTeXString("\\frac{d^{$(ns[i])}$(Latexify.latexraw(var[i]))}{d$iv^{$(ns[i])}}") for i in 1:length(var)] |
| 42 | + return lhs, rhs |
| 43 | +end |
| 44 | + |
| 45 | +@latexrecipe function f(sys::ModelingToolkit.ODESystem; iv=:t) |
| 46 | + return latexify(sys.eqs; iv=iv) |
| 47 | +end |
0 commit comments