Skip to content

Commit 8f6f959

Browse files
committed
prepare for dropping (t) in latex rxs
1 parent 269abc3 commit 8f6f959

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/latexify_recipes.jl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,18 @@ function chemical_arrows(rn::ModelingToolkit.ReactionSystem;
4646

4747
mathjax && (str *= "\\require{mhchem}\n")
4848

49+
println(kwargs)
4950

5051
backwards_reaction = false
5152
rxs = ModelingToolkit.equations(rn)
53+
@variables t
54+
55+
# this should replace A(t) with A in equations however, currently substituter rewrites
56+
# things like x/y as inv(y)*x^1 which looks worse... for now we leave a stub that can
57+
# be updated when substitution preserves expressions better.
58+
# subber = ModelingToolkit.substituter([s(t) => s() for s in states(rn)])
59+
subber = x -> x
60+
5261
for (i, r) in enumerate(rxs)
5362
if backwards_reaction
5463
backwards_reaction = false
@@ -57,7 +66,7 @@ function chemical_arrows(rn::ModelingToolkit.ReactionSystem;
5766
str *= "\\ce{ "
5867

5968
### Expand functions to maths expressions
60-
rate = r.rate isa Operation ? Expr(r.rate) : r.rate
69+
rate = r.rate isa Operation ? Expr(subber(r.rate)) : r.rate
6170
expand && (rate = recursive_clean!(rate))
6271
expand && (rate = recursive_clean!(rate))
6372

@@ -72,7 +81,7 @@ function chemical_arrows(rn::ModelingToolkit.ReactionSystem;
7281
poststr = mathjax ? "]" : "\$]"
7382
if i + 1 <= length(rxs) && issetequal(r.products,rxs[i+1].substrates) && issetequal(r.substrates,rxs[i+1].products)
7483
### Bi-directional arrows
75-
rate_backwards = Expr(rxs[i+1].rate)
84+
rate_backwards = rxs[i+1].rate isa Operation ? Expr(subber(rxs[i+1].rate)) : rxs[i+1].rate
7685
expand && (rate_backwards = recursive_clean!(rate_backwards))
7786
expand && (rate_backwards = recursive_clean!(rate_backwards))
7887
str *= " &<=>"

0 commit comments

Comments
 (0)