@@ -45,10 +45,16 @@ function chemical_arrows(rn::ModelingToolkit.ReactionSystem;
45
45
eol = double_linebreak ? " \\\\\\\\\n " : " \\\\\n "
46
46
47
47
mathjax && (str *= " \\ require{mhchem}\n " )
48
-
49
-
50
48
backwards_reaction = false
51
49
rxs = ModelingToolkit. equations (rn)
50
+ @variables t
51
+
52
+ # this should replace A(t) with A in equations however, currently substituter rewrites
53
+ # things like x/y as inv(y)*x^1 which looks worse... for now we leave a stub that can
54
+ # be updated when substitution preserves expressions better.
55
+ # subber = ModelingToolkit.substituter([s(t) => s() for s in states(rn)])
56
+ subber = x -> x
57
+
52
58
for (i, r) in enumerate (rxs)
53
59
if backwards_reaction
54
60
backwards_reaction = false
@@ -57,7 +63,7 @@ function chemical_arrows(rn::ModelingToolkit.ReactionSystem;
57
63
str *= " \\ ce{ "
58
64
59
65
# ## Expand functions to maths expressions
60
- rate = r. rate isa Operation ? Expr (r. rate) : r. rate
66
+ rate = r. rate isa Operation ? Expr (subber ( r. rate) ) : r. rate
61
67
expand && (rate = recursive_clean! (rate))
62
68
expand && (rate = recursive_clean! (rate))
63
69
@@ -72,7 +78,7 @@ function chemical_arrows(rn::ModelingToolkit.ReactionSystem;
72
78
poststr = mathjax ? " ]" : " \$ ]"
73
79
if i + 1 <= length (rxs) && issetequal (r. products,rxs[i+ 1 ]. substrates) && issetequal (r. substrates,rxs[i+ 1 ]. products)
74
80
# ## Bi-directional arrows
75
- rate_backwards = Expr (rxs[i+ 1 ]. rate)
81
+ rate_backwards = rxs[i + 1 ] . rate isa Operation ? Expr (subber ( rxs[i+ 1 ]. rate)) : rxs[i + 1 ] . rate
76
82
expand && (rate_backwards = recursive_clean! (rate_backwards))
77
83
expand && (rate_backwards = recursive_clean! (rate_backwards))
78
84
str *= " &<=>"
0 commit comments