-
-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parse error when defining reaction network in Jupyter notebook #595
Comments
Yup, Katex and Mathjax are incompatible in how they handle the chemical notation package (mhchem). We currently output Latex that works with the latter as it should work with Documenter and Pluto. It doesn't work with Jupyter which uses Katex. If anyone knows how to add a path for detecting Latexify is being called within a Jupyter environment we can try to hardcode different Latex output in that case, but I don't know how to do this. |
Would it be possible to add an option to |
@TorkelE there is an option, Catalyst.jl/src/latexify_recipes.jl Lines 101 to 118 in b47dd03
Maybe when Catalyst is initialized we can detect if it is running within Jupyter somehow, and then set Catalyst.jl/src/latexify_recipes.jl Lines 1 to 6 in b47dd03
(The default would be Then we could modify Catalyst.jl/src/latexify_recipes.jl Line 102 in b47dd03
so that the That should make it automatic if there is a way to detect we're running within Jupyter. |
Ahh, this is even worse than I imagined. @jonathanfischer97 this is the same issue you posted on Discourse right? https://discourse.julialang.org/t/testing-whether-a-function-is-executing-in-a-jupyter-notebook/222 As I said there, Latex display kinds works in Jupyter for me, but that was in the web-browser interface, which I guess uses Mathjax. It seems VS Code uses an entirely different display stack, I guess Katex-based, and so it doesn't work at all. You'd need to somehow extend VSCode's Jupyter install to load the mhchem Katex extension, and then we'd need to add code here to output Katex-compatible Latex if we detect we are running in Jupyter within VSCode. Unfortunately, it seems Microsoft is not interested in adding this compatibility themselves: |
Alternatively, we could try to detect if we are in Jupyter here and write a non-mhchem Latex path. @TorkelE I'd be fine with dropping mhchem for everything and just using the extensible Latex reaction arrows with over and under bars instead of mhchem. mhchem was just what Latexify has always used, but it is kinda a pain on the web... |
If that would sort out all these issues, it would probably be worth going down that route. If the old one still looks distinctly better (but the new one is not bad) we could try adding it ins as an option. I am happy to look at it sometime in the future. I feel we might be compiling several Latexify stuff (there's also SciML/ModelingToolkit.jl#2069), would make sense to deal with them in one go. |
Correct! Thank you for being so on top of it, as a relative noobie I'm sorry I don't have more to contribute as far as ideas. But I'd also be in favor of dropping mhchem as its expensive to compile within Overleaf for what it's worth |
Sounds good. I think dropping mhchem is probably the best option if both Katex and Mathjax support some extensible arrow type. If we are just going to run into the same issue with a basic set of forward, backward, and reversible extensible arrows then it won't gain us much. |
@jonathanfischer97 should hopefully be fixed in v13 (hoping to release it next week). |
Fantastic, many thanks to both you Professor Isaacson and Mr. Loman. Big fan of you both |
Hello, I'm running the Catalyst tutorial through an interactive Jupyter session (in VS Code) and I'm getting a similar error upon defining the example reaction. I'm using Catalyst v13.5.1 and Julia v1.10.4. Is there an existing workaround by any chance?
|
Hi, sorry for the delayed reply; I was traveling last week. Can you show us the output of running the following codes?
That would help in figuring out your issue. |
I appreciate your reply! The outputs are below. Also, I'm not sure if this is relevant, but my Jupyter session is hosted on a remote machine, and I connect to it via SSH within VSCode. The outputs are from the same session. Output of
Output of
Output of
|
I can't seem to reproduce this locally. Can you try making a new notebook and running the following code (which creates a new, blank environment and just installs Catalyst)? using Pkg
Pkg.activate(; temp = true)
Pkg.add("Catalyst")
using Catalyst
rn = @reaction_network begin
α, S + I --> 2I
β, I --> R
end Do you still have the issue? Do you have the Julia and Jupyter extensions installed? If this example fails can you run those |
If that still fails for you I will try installing via a remote Linux server to see if I have the problem there (but it will take some time to do, so would be helpful if you can check my example first). |
I appreciate your help but I wouldn't want to take up too much of your time. I can work around this issue. I wanted to use a remote Jupyter session since it allows me to keep it alive indefinitely and reconnect as needed, but I'll manage with a remote REPL. |
Just to confirm, you don't see this issue with a non-remote session? |
The remote server is command line only so I'm unable to run an interactive shell locally there. At least I don't know how to do so, so I can't test it. |
OK, one last thing. Are you using a Jupyter session in a web browser or the builtin VSCode Jupyter Notebook viewer / extension? The latter works remotely for me too (though I have only been able to test via connecting from Mac to Mac and not on Linux). You shouldn't need to install IJulia in any way if using the VSCode Jupyter extension to view your notebook within VSCode (remotely or locally). |
I'm using the Jupyter extension for VSCode. I start the jupyter session within Julia on the remote server, then I start VSCode locally, and I connect to the remote session via the "Jupyter: Create Interactive Window" option. |
I see. I haven't ever used that workflow -- I usually just use VSCode's builtin remote-ssh extension to connect to a server and open notebooks on it. In that workflow I'm not seeing any issues. |
Yes, that makes sense, thank you. The only reason I did it this way is because it's the only method I know to keep the remote session alive, even if I disconnect for a couple of days. I'll explore if there's a way to achieve this directly through VSCode. If not, it's not a dealbreaker. It's good to know there are similar workflows where Catalyst works well. |
Thinking about this some, what is probably happening is that the logic in Catalyst to detect if the notebook is being displayed in VSCode vs Jupyter is not correctly detecting that displaying is being done in VSCode. They require separate Latex codegen as VSCode uses Katex and Jupyter Mathjax, and only in the later could we get mhchem to work for reaction display. |
Unfortunately, I don’t know how to better detect who is rendering the notebook, or if there is a way to instead detect Mathjax vs Katex as the renderer. |
Running Julia 1.8.5 within VSCode Jupyter notebook, and always receive this parse error when defining a new reaction network. Anybody know what's going on?
The text was updated successfully, but these errors were encountered: