Skip to content
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

Rendering of math blocks in generated notebooks doesn't display tech #182

Closed
ChrisRackauckas opened this issue Feb 26, 2019 · 10 comments
Closed

Comments

@ChrisRackauckas
Copy link
Member

Example: https://github.com/JuliaDiffEq/DiffEqTutorials.jl/blob/master/notebook/introduction/ode_introduction.ipynb . Jupyter seems to treat that as a markdown block.

@mpastell
Copy link
Collaborator

This is due to Jupyter using different markdown variant than Weave. In this case the easiest fix is to use $$ for math blocks instead of ````math .

You could also use pandoc2* formats instead of md2* if you need a closer match between weave output and notebooks.

@ChrisRackauckas
Copy link
Member Author

So the fix is on my end to change to using pandoc2* commands? I can go ahead with that, but wanted to double check before editing all of the jmds.

@mpastell
Copy link
Collaborator

Can't you can use $$ in both md2html and notebook output? i.e does the below work?

$$\frac{dx}{dt} &= \sigma (y - x)\\
\frac{dy}{dt} &= x (\rho - z) -y\\
\frac{dz}{dt} &= xy - \beta z$$

I personally prefer to use md2* formats so I don't need to use pandoc (you may encounter some new bugs), but if you need features from pandoc that julia markdown doesn't have then it's best to switch the format.

@mpastell
Copy link
Collaborator

There seems to be a problem with Weave writer adding \begin{align} to math blocks (see: #142) . Probably that wasn't the best design choice as it makes the documents incompatible with Jupyter now...

I think it might be to remove that feature, but it will break documents that rely on that...

@ChrisRackauckas
Copy link
Member Author

For the notebooks to render correctly, they need to be like:

$$
\begin{align}
\frac{dx}{dt} &= \sigma (y - x)\\
\frac{dy}{dt} &= x (\rho - z) -y\\
\frac{dz}{dt} &= xy - \beta z
\end{align}
$$

Note the newline before the $$. This isn't compatible with the other formats, since we cannot write align in there since it will double up, but also because of the newline handling on the $$ breaks the other formats IIRC. I think you should just leave it up to the user to handle the align command.

@mpastell
Copy link
Collaborator

I'll remove the align from output for now. I also think I should be able to extend the Julia markdown parser to handle $$ with newlines, but it may take some time.

FYI: math rendering without the newlines before and after $$ works in Jupyterlab.

@mpastell
Copy link
Collaborator

I just remembered why align is added by default: it seemed like the best option to output math that works in both Mathjax and Latex.

@ChrisRackauckas do you have a good suggestion how to ouput math in Latex instead of using aligned? by default (=after removing current weave output formatting) this markdown:

$$\begin{align} \frac{dx}{dt} &= \sigma (y - x)\\\ \frac{dy}{dt} &= x (\rho - z) -y\\\ \frac{dz}{dt} &= xy - \beta z \end{align}$$

becomes the following in tex:

$$\begin{align}
\frac{dx}{dt} &= \sigma (y - x)\\
\frac{dy}{dt} &= x (\rho - z) -y\\
\frac{dz}{dt} &= xy - \beta z
\end{align}$$

Which then gives the following error when running xelatex:

! Package amsmath Error: Erroneous nesting of equation structures;
(amsmath)                trying to recover with `aligned'.

I'm having a hard time coming up with a good fix that would work well.

@ChrisRackauckas
Copy link
Member Author

I'm not sure, I think it needs to not output the $$ when it sees aligns.

@mpastell
Copy link
Collaborator

mpastell commented Feb 27, 2019

This is probably the best option, to check for align, equation etc. I will not probably remember all that people want to use, but new special cases will be easy to add.

@mpastell
Copy link
Collaborator

I ended up extending the markdown parser so that this now also works with Weave:

$$
\begin{align}
\frac{dx}{dt} &= \sigma (y - x)\\
\frac{dy}{dt} &= x (\rho - z) -y\\
\frac{dz}{dt} &= xy - \beta z
\end{align}
$$

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants