Anybody know why this error occurs when trying to define a Catalyst @reaction_network in Jupyter Notebooks?

Jupyter might not like the Latex? Open an issue and we can try and figure out what’s going on here. @stevengj do you know if Jupyter just isn’t fine with us adding package require statements in the generated Tex?

1 Like

I don’t think it supports using packages — it’s using a very limited LaTeX renderer (KaTeX) that is mainly just for rendering math. See e.g. this discussion and jupyterlab#11701.

(However, you can add packages when you generate `.tex` via `nbconvert. This doesn’t help with rendering interactively, though.)

1 Like

With the latest Catalyst and IJulia versions this example

using Catalyst
rn = @reaction_network begin
    k, A --> B
    k2, A+C --> D
    end k k2

displays the Latex reactions in Jupyter for me, but with the reaction rates printed within dollar signs. I don’t get the reported error.

More generally though, I’ve found it very challenging to maintain working and consistent Latex display across Documenter, Jupyter, and Pluto. At the moment we seem to have output from Catalyst such that Documenter and Pluto work, but Jupyter seems to need a bit different tex to properly use the mhchem package.

It seems like the Katex mhchem version with the Jupyter associated with the latest IJulia doesn’t actually conform to the mhchem manual. Catalyst generates:

\begin{align*}
\require{mhchem}
\ce{ A &->[$k$] B}\\
\ce{ A + C &->[$k2$] D}
\end{align*}

but Jupyter does not correctly handle the dollar signs. This is the documented notation to get math above/below the arrows per the manual for both the current Mathjax and Katex versions: Manual for: mhchem for MathJax, mhchem for KaTeX, but it seems like an extra set of dollars is being implicitly added somewhere.