@@ -45,10 +45,16 @@ function chemical_arrows(rn::ModelingToolkit.ReactionSystem;
4545 eol = double_linebreak ? " \\\\\\\\\n " : " \\\\\n "
4646
4747 mathjax && (str *= " \\ require{mhchem}\n " )
48-
49-
5048 backwards_reaction = false
5149 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+
5258 for (i, r) in enumerate (rxs)
5359 if backwards_reaction
5460 backwards_reaction = false
@@ -57,7 +63,7 @@ function chemical_arrows(rn::ModelingToolkit.ReactionSystem;
5763 str *= " \\ ce{ "
5864
5965 # ## 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
6167 expand && (rate = recursive_clean! (rate))
6268 expand && (rate = recursive_clean! (rate))
6369
@@ -72,7 +78,7 @@ function chemical_arrows(rn::ModelingToolkit.ReactionSystem;
7278 poststr = mathjax ? " ]" : " \$ ]"
7379 if i + 1 <= length (rxs) && issetequal (r. products,rxs[i+ 1 ]. substrates) && issetequal (r. substrates,rxs[i+ 1 ]. products)
7480 # ## 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
7682 expand && (rate_backwards = recursive_clean! (rate_backwards))
7783 expand && (rate_backwards = recursive_clean! (rate_backwards))
7884 str *= " &<=>"
0 commit comments