Pluto.jl icon indicating copy to clipboard operation
Pluto.jl copied to clipboard

LaTeX equation labeling in markdown

Open dojt opened this issue 3 years ago • 14 comments

There seems to be a problem with equation labeling:

md"""
```math
\begin{equation}\label{blahbel}
\partial^2 \approx 7
\end{equation}
```
"""

runs correctly the first time it is run, but if you press shift-enter a second time, it gives an error in the LaTeX code. The error goes away when you change the label, so it seems to come from LaTeX complaining about "multiply defined labels" or whatnot. image

dojt avatar Nov 15 '20 11:11 dojt

Check if similar to #488

DhruvaSambrani avatar Nov 15 '20 11:11 DhruvaSambrani

In addition to label change, error also goes away when the page is refreshed.

Same thing appears to happen if you do actually use the label twice on the page

image

Seems related to MathJax processing, not #488 (which is caused by pre-processing the MathJax with text{}). MathJax has already seen that label so complains multiply defined. Something related to this?: http://docs.mathjax.org/en/latest/web/typeset.html#updating-previously-typeset-content

zmoon avatar Nov 16 '20 12:11 zmoon

Even if this is fixed, would the \label feature be useful? How do you reference to a labeled equation?

fonsp avatar Nov 16 '20 16:11 fonsp

It could be useful in a notebook with a lot of text and equations.

You use \ref or \eqref,

though the numbering doesn't seem to be working

image

Edit: Seems that the referencing only works properly if the displayed equation numbers are enabled this way: http://docs.mathjax.org/en/latest/input/tex/eqnumbers.html (has another warning about dynamic page modification at the bottom)

zmoon avatar Nov 16 '20 16:11 zmoon

But how do you use \ref? Can MathJax generate clickable links inside the svg?

fonsp avatar Nov 17 '20 19:11 fonsp

It might still be a good idea to call typesetClear https://github.com/fonsp/Pluto.jl/issues/678#issuecomment-727957475

fonsp avatar Nov 17 '20 19:11 fonsp

But how do you use \ref? Can MathJax generate clickable links inside the svg?

Yes, blue clickable jump links that take you to the equation. I put an example of usage in <details> of my previous comment (In equation $\ref{label}$...), though the jumping/numbering doesn't currently work with equation numbering not enabled. I can confirm it does work properly (in a simple MathJax test page) with svg output if equation numbering is enabled though.

zmoon avatar Nov 17 '20 20:11 zmoon

it would be great to be able to cross-reference equations in a notebook, I hope this issue can be solved

CarloLucibello avatar Jun 30 '21 12:06 CarloLucibello

http://docs.mathjax.org/en/latest/web/typeset.html#tex-reset looks useful

fonsp avatar Jul 01 '21 23:07 fonsp

A workaround was provided in this discussion https://discourse.julialang.org/t/pluto-how-to-number-equations-in-latex-mode/59900/9

CarloLucibello avatar Jul 10 '21 10:07 CarloLucibello

@CarloLucibello Thanks for linking the post. Just clarifying that the solution in the discourse post uses KaTeX (and it has been very shallowly tested) so it can't be directly applied to deal with equation numbering/labelling in mathjax using the standard latex synthax from @md_str

disberd avatar Jul 10 '21 11:07 disberd

AFAICT now Pluto uses MathJax, has the status of this issue changed somehow?

doppioandante avatar Oct 12 '21 22:10 doppioandante

Pluto always used MathJax from what I remember (and the issue is/was related to that). The latest comment on Katex was just for the workaround in the link above (which creates a custom function for rendering latex equations that skips markdown/mathjax and use katex directly

disberd avatar Oct 13 '21 09:10 disberd

Experimentem isto: $$ \begin{align} \tag{1.1} V_{sphere} = \frac{4}{3}\pi r^3 \end{align} $$

rlaunemacedo avatar Mar 08 '22 11:03 rlaunemacedo