Closed hturner closed 1 month ago
Numbering and cross-referencing equations are definitely trickier than other elements. It shouldn't be too hard to support MathJax. I need to do more research on KaTeX (the last two links in your post are missing; did you mean https://github.com/KaTeX/KaTeX/issues/2003?).
Yes, that's the one. I'll check and update my links.
After fully reading https://github.com/KaTeX/KaTeX/issues/2003, I feel hopeful to number and cross-reference equations with KaTeX.
It should be simple enough to configure MathJax for litedown by default. I'll do that next week. Thanks for the suggestion and guidance!
Phew, all done. Add a \label{eq:*}
(and optionally a \tag{}
) to an equation, and then use @eq:*
or @eqn:*
to cross-reference it. Both MathJax and KaTeX should work out of the box. No extra config is required.
Honestly speaking, I don't feel comfortable with my hacks since I don't think the way that I scan labels and tags is not robust: https://github.com/yihui/misc.js/blob/main/js/render-katex.js but that's my best effort for now, given all the constraints from KaTeX. I'll post to https://github.com/KaTeX/KaTeX/issues/2003 and seek feedback when I have more time.
Something like the Quarto behaviour could be nice.
Actually litedown's cross-reference mechanism is more general than Quarto's. Anything can be numbered and cross-referenced in {litedown}, although the number of built-in cross-referenceable elements is small (section/figure/table/equation). I just spent a little more time on documenting it: https://yihui.github.io/litedown/#sec:cross-references
(this is the link to latest dev version of the book, not intended to be shared widely, so I put the URL in code)
As far as I can tell, the only way to cross-reference auto-numbered equations with litedown is via MathJax:
that we can save in a file, say
header.html
. Alternatively create amathjax-config.js
file with the configuration.header.html
:Equation $\ref{eq:sample}$
, where$\ref{eq:sample}$
will be replace by the equation number hyperlinked to an anchor on the equation.Unfortunately this is not possibly with KaTeX (there is a longstanding issue on missing support for \label and \ref).
It would help those looking to cross-reference equations if litedown:
Is numbering/cross-referencing of Markdown equations on the roadmap? Something like the Quarto behaviour could be nice.