-
Notifications
You must be signed in to change notification settings - Fork 330
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
enhancement: add MathJax equation numbering for math environments in html #4136
Comments
Thanks for the feedback! I think what you're saying makes sense. We need to check how these interact with our crossref systems, but I'll take a look at that as we're overhauling crossrefs internals in any case. |
Hi @cscheid Feel free to reach out to me for any feedback on the math side of the crossref system. I am heavily invested in the LateX-Quarto interface (with quarto_titlepage and other mathy templates). I have years of experience in complex math in the Rmd ecosystem. Did this heavily in bookdown but since migrated to Quarto. As an applied mathematician, I am familiar with how those who do complex math would expect math cross-referencing to work. Re the MathJax options I am guessing it is probably better to set math options in the metadata rather than hard-coding anything in header.
For example adding section numbers to equations numbers is common but the MathJax setting to add section numbers to equation numbers is complex. Note in LaTeX it's Re, cross-referencing in math equations In the spirit of not re-inventing the wheel, LaTeX (which MathJax and ilk know) already has a system for complex math (latex math environments) and how to cross-ref. Anyone who puts this kind of math in their documents knows and uses the LaTeX/AMS syntax for math equations. The I think it is key to have have LaTeX/AMS users give feedback in order not to get "painted in a corner" by doing a math cross-ref system that will not allow the core cross-ref syntax that every math user will want. Like, numbering of sub-equations in a math environment and the different ways one does that in the LaTeX/AMS syntax (there really only 2). Even if your first system can't do that in the beginning, I bet there are ways to design things so that that will be a doable update in the future versus having to rebuild the whole system from the ground up. BTW, currently Quarto works for fine for complex math and equation cross-refs. I just have to be careful to never use Cheers! |
I will do, and thank you for the long, thoughtful followup. |
Adding a couple more notes (more for myself). MathJax fully supports amsmath so if you are having trouble with your cross-refs showing up, double check that your amsmath syntax is correct. Note if you happen to land on this thread and you are working with RMarkdown, be aware that in May 2023, RMarkdown still uses MathJax 2.7 (from 2017!) and the configuration syntax for that is completely different than MathJax 3+. Scroll all the way to the bottom to see how to use a different version of MathJax. Just numbers 1 to infinityExample mathjax1.html (to include in header for html output)
Example qmd
If you want your
Add section numbers to your equation numbersIf by chance you landed here while searching for how to do this for PDF output, all you do is add If you need your equations numbered by section, so like 1.2 and 3.1. Then you need to follow this awful mathjax.html file Then after each section Your mathjax.html file
Here is an example qmd file:
Ack I need PDF output too, and now it complains about Help for RMarkdown usersQuarto users ignore this: This is for the poor Rmd folks who might land on this thread in desperation. As of May 2023, the default MathJax js file that getting imported for Rmd is MathJax 2.7. You need to use a more recent version of MathJax to get proper support for equation numbering and cross-refs. Use this in your yaml:
with the mathjax.html files above depending on what you need. |
Thank you so much for sharing, @eeholmes ! The newer mathjax also supports changing equation numbers to custom tags, and My addition here to the wish list for quarto crossref (@cscheid :-)): a mechanism for \tagging. For equations, one could keep LaTeX syntax, that is what presumably most users of such a feature already are familiar with. |
Here is a first version of the filter: |
See also #2275 |
Thanks @ute your extension is great, I've been searching around for something that allows equation numbering to work out-of-the-box.
with
thus allowing usage of Markdown $$ syntax when that's all I need. But for more complex numbering I can still use LaTeX syntax via a math environment. The only drawback is we don't have a filter for For anyone just finding this thread, you only need to include the mathjax1.html file (in the header) to enable to ams labelling, and then use Ute's nice Para function (see the filter mathjax3eqno.lua). In my writing I'd like to be able to use Markdown format most of the time, but fallback on LaTeX/MathJax for things that Markdown cannot do (like number some lines in an align, but not others). While I wait for Quarto to get its act together and support numbering of equations in a more complete way. Is there any sign that Quarto will be updated to allow for richer equation numbering? I'll be checking back to see if you have any success with making it compatible with Quarto books (or if Quarto fixes it all before then). |
@dhodge180 , there are two problems with books, due to the fact that chapters are rendered kind of independently: a. mathjax does not know the chapter number, and uses chapter sections as prefix for equation numbers, b. cross-references between chapters cannot be resolved by mathjax Problem a. could be fixed with tweaking mathjax, but b. amounts to rewriting the crossreferencing mechanism (which also would solve a). I believe the quarto team will come up with a solution soon-ish. I also need this equation numbering in a book right now, and currently work around by setting latex tags manually. This works with mathjax. |
Thanks! I've had a play with your code to see if I can help with a. but I'm not good enough with Lua I don't think. I can't work out yet why the For the meantime for a book I think you're saying the answer is probably to use (display) |
@dhodge180, I have updated my extension with a workaround for books. It is still not possible to cross reference between chapters, but it works within a chapter now. You have to provide the chapter number manually with the first equation, then all equation numbers im that chapter are prefixed with chapter number. |
By default, MathJax does not have equation numbers when the LaTeX math environments are used. This:
produces this:
instead of this (with numbers)
The reason is that the default behavior for MathJax is to not show the equation numbers. This causes endless confusion for those who use the math environment, which is used for more complex math.
It'd be great if Quarto turned on equation numbering in math environments by default so that html and PDF output behaves the same. All that is needed is to have this script in the header if the equation engine is mathjax:
Obviously you can turn this on manually with
with mathjax.html having the script above but most users spend hours and hours trying to debug lack of numbers until they stumble upon the right solution. What is worse, is that the solution depends on the MathJax version. The above is the method for the version being used by Quarto (by default).
I don't think there is any reason to have the numbering turned off. Anyone using the LaTeX math environment is likely to be a LaTeX user and we have a standard methods for selectively turning off numbers on an equation if that were wanted.
The text was updated successfully, but these errors were encountered: