You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When #201 is merged, direct parsing of latex amsmath environments will be supported 😄
Currently, though it will not do anything with any environments containing \label{name}.
It would be good to parse these in a way that they can be referenced correctly by e.g. {eq}`name`
Reacted by Philip Austin, Sylvain Girard, fleimgruber, Fan Jiang, Ian Hawke, Bernard Knaepen, Pawel Chilinski, HolKo, Juan Luis Cano Rodríguez, Jesse Perla and 88 more
I use amsmath environment and equation labeling via \label{name} a lot so I'm definitely interested in this 😀. Here are some observations that I would like to share.
In Latex, if an environment line align contains several equations, each of them is numbered by default. For example,
\begin{align}
a&=1 \label{eq1} \\
b&=2 \label{eq2}
\end{align}
This is the first label: \ref{eq1}. This is the second label: \ref{eq2}.
is rendered as:
If I add this align environment in a myst markdown file, it gets rendered like this when processed through jupyter-books:
So only the environment as a whole is numbered, not the individual equations. I am new to JB but if I understand well, this is how sphynx behaves and I have not found info (yet) on how to get the numbering as in the regular Latex output.
For parsing the labels, this is where it can be tricky. In Latex, a label can be added to each equation in multiline environments and these may be used separately in \ref{} statements, like in the example above. In JB, if only the whole environment is numbered, this cannot work well, even if there is only one label as it can reference the second equation for example.
To be able to use amsmath environments and labels in my jupyter notebooks, I currently use the following workaround:
Use on label per environment
Place the label directly under the \begin{statement}
Using a python script, I then parse the myst markdown files and change all amsmath environments to myst directives with proper labels. Here is an example:
The python script also changes in the markdown file all the statement like \ref{mylabel} to roles like {eq}mylabel. This allows to have proper referencing of the equations in the final html output. But it won't solve the multiline/multi labels issue as only one label is allowed in this strategy. Using directives, it's not clear to me how to get multiple labels either.
I wonder if there are some news about this problem.
Being able to write several labels in a single align, and then refer to any line of this align is crucial in math.
Thanks for your answer.
Best,
To do this "properly" you really need access to a latex parser.
I have not seen any python libraries able to do this at present.
Happy for anyone to let me know of any?
I've added the help wanted label, just to make it clearer that I do not have the time to do this.
I'm sure one of you smart people can; as I've already said, you first need to parse the latex to identify/extract the labels (maybe use https://github.com/alvinwan/TexSoup),
then you need to work how to represent these in the AST
Activity
chrisjsewell commentedon Aug 11, 2020
If you would like to see this feature implemented leave a 👍 reaction on the comment above (see https://executablebooks.org/en/latest/feature-vote/)
bknaepen commentedon Nov 1, 2020
I use amsmath environment and equation labeling via \label{name} a lot so I'm definitely interested in this 😀. Here are some observations that I would like to share.
In Latex, if an environment line
aligncontains several equations, each of them is numbered by default. For example,is rendered as:
If I add this
alignenvironment in a myst markdown file, it gets rendered like this when processed through jupyter-books:So only the environment as a whole is numbered, not the individual equations. I am new to JB but if I understand well, this is how sphynx behaves and I have not found info (yet) on how to get the numbering as in the regular Latex output.
For parsing the labels, this is where it can be tricky. In Latex, a label can be added to each equation in multiline environments and these may be used separately in \ref{} statements, like in the example above. In JB, if only the whole environment is numbered, this cannot work well, even if there is only one label as it can reference the second equation for example.
To be able to use amsmath environments and labels in my jupyter notebooks, I currently use the following workaround:
Using a python script, I then parse the myst markdown files and change all amsmath environments to myst directives with proper labels. Here is an example:
becomes
The python script also changes in the markdown file all the statement like \ref{mylabel} to roles like {eq}
mylabel. This allows to have proper referencing of the equations in the final html output. But it won't solve the multiline/multi labels issue as only one label is allowed in this strategy. Using directives, it's not clear to me how to get multiple labels either.a7p commentedon Jun 29, 2021
This issue has a lot of votes, but lacks the enhancement-label, hence it's not in that list.
joachimlebovits commentedon Oct 6, 2023
Hi,
I wonder if there are some news about this problem.
Being able to write several labels in a single align, and then refer to any line of this align is crucial in math.
Thanks for your answer.
Best,
gao-hongnan commentedon Dec 1, 2023
Any updates...? I also concur that it is an important feature.
chrisjsewell commentedon Dec 1, 2023
To do this "properly" you really need access to a latex parser.
I have not seen any python libraries able to do this at present.
Happy for anyone to let me know of any?
i2000s commentedon May 30, 2024
So, any updates?
chipbrock commentedon Aug 16, 2024
Any action on this? It's a real issue for me as I convert all of my work from Rmarkdown to Jupyter-book. Thanks
chrisjsewell commentedon Aug 16, 2024
I've added the
help wantedlabel, just to make it clearer that I do not have the time to do this.I'm sure one of you smart people can; as I've already said, you first need to parse the latex to identify/extract the labels (maybe use https://github.com/alvinwan/TexSoup),
then you need to work how to represent these in the AST