Skip to content

Commit

Permalink
Merge pull request #589 from SciML/latexify_update
Browse files Browse the repository at this point in the history
Add `form` option to latexify
  • Loading branch information
TorkelE authored Feb 7, 2023
2 parents ade10f8 + 2d8cef0 commit b47dd03
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/latexify_recipes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,17 @@ function chemical_arrows(rn::ReactionSystem; expand = true,
return latexstr
end

@latexrecipe function f(sys::ReactionSystem)
# Set default option values.
env --> :chem
cdot --> false

return sys
@latexrecipe function f(rs::ReactionSystem; form = :reactions)
if form == :reactions # Returns chemical reaction network code.
cdot --> false
env --> :chem
return rs
elseif form == :ode # Returns ODE system code.
return convert(ODESystem, rs)
elseif form == :sde # Returns SDE system code.
return convert(SDESystem, rs)
end
error("Unrecognised form argument given: $form. This should be either reactions (default), :ode, or :sde.")
end

function Latexify.infer_output(env, rs::ReactionSystem, args...)
Expand Down
17 changes: 17 additions & 0 deletions test/latexify.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

### Fetch required packages and reaction networks ###
using Catalyst, Latexify
include("test_networks.jl")

############################
### CURRENTLY NOT ACITVE ###
Expand Down Expand Up @@ -122,3 +123,19 @@ raw"\begin{align*}
\ce{ Y &->[$Y k$] \varnothing}
\end{align*}
", "\r\n"=>"\n")

# Tests the `form` option
for rn in reaction_networks_standard
@test latexify(rn)==latexify(rn; form=:reactions)
#@test latexify(convert(ODESystem,rn)) == latexify(rn; form=:ode) # Slight difference due to some latexify weirdity. Both displays fine though
end

rn = @reaction_network begin
(p,d), 0 <--> X
(kB,kD), 2X <--> X2
end
@test latexify(rn; form=:ode) == raw"$\begin{align}
\frac{\mathrm{d} X\left( t \right)}{\mathrm{d}t} =& p - \left( X\left( t \right) \right)^{2} kB - d X\left( t \right) + 2 kD \mathrm{X2}\left( t \right) \\
\frac{\mathrm{d} \mathrm{X2}\left( t \right)}{\mathrm{d}t} =& \frac{1}{2} \left( X\left( t \right) \right)^{2} kB - kD \mathrm{X2}\left( t \right)
\end{align}
$"

0 comments on commit b47dd03

Please sign in to comment.