-
Notifications
You must be signed in to change notification settings - Fork 332
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
referencing equations inside $$ \begin{align}
environment
#2275
Comments
Hello there, if you work with only HTML and PDF, I have the following (probably temporary) workaround:
If you render this, the HTML should produce references to all 3 tagged equations without issue. If you render PDF, note that the I do not expect this to remain permanently usable, but for now it should work. EDIT: I think some interesting background into how raw LaTeX is written in .qmd can be found here |
Are there any workaround for MS word documents? |
The workaround that uses
The difference is that |
update Aug 2024 In a reply on this thread, I suggested adding tldr; For LaTeX users wanting complex math in both html and PDF using the same Quarto file: 1) Add a mathjax.html file and add to your top yaml (instructions below) to turn-on equation numbering and only use LaTeX equation environments (not
will not render equation numbers in html. You could add Here is how to turn on numbering with the MathJax v3+ file that Quarto is using. Create this file: mathjax.html
For MathJax v2.7, the config uses For a Quarto book, the top yaml in
Do not add
Now this LaTeX code shows your autonumbers in both html and pdf output.
Something to keep in mind is that the Quarto equation numbering (meaning
If you only need to render to both html and PDF, then I would say never use I tested with Quarto docx format and RMarkdown officerdown::rdocx_document format and both showed the same behavior. I don't know how Pandoc is doing the markdown to Word XML (I assume) conversion but seems like the non-recognizing LaTeX equation environments is at a low level. But I also didn't search for a "equation to image" option, which would allow Pandoc to create the equation imagew via LaTeX and bypass the Word Equation engine. I don't know if that is a thing, but that is how I would solve equations in Word docs created with Quarto/RMarkdown. A note re
|
Note I tried a mathjax.html file with both ways of turning on numbering, and it still worked. So this file may be a more robust way to turn on numbering since it will work with more versions of MathJax (I think).
But weirdly with the MathJax file that RStudio Rmd files loads (v2.7 from 2017), the line up of the equations numbers changes. How do you know what version of MathJax that a js file is? Paste the url in the browser and look at the top of the js file. The info on the version of MathJax will be there. In Jan 2023, here is the MathJax js file that Quarto is using by default:
You can change the MathJax version being used like so. Adding this html-math-method code will break numbering! At least it did for me in Aug 2024. This is for example's sake to show how to change the mathjax url. Don't add the
|
@eeholmes Thank you so much for the mathjax config scripts and the detailed explanations. One question: the Mathjax 3.2 doc pages use |
Just landed on this thread, and here is a proposal using the
This works with default settings with correct labels in both PDF and HTML ( and I guess word!) and does not require any MathJax hacking. Useful thing is that
will display referenced equations on hover in HTML (and PDF, depending on your PDF reader), which is handy with long technical content. |
It should be noted that using
will render using Instead of two equations with two labels mathjax counts them as one. Why is this relevant? If one starts with the following latex file
and converts it to markdown via |
My solution is correct for just a single label for all aligned equations in a single display. I tend not to need more than one label, mainly because I avoid more than three equations in a single display, and then I can always say the first / second / third / etc. equation/expression/ etc. in XYZ. Labelling more than 1 equation in a single align display in the current quarto version seems impossible without the Mathjax hacks in previous responses. But with those, many nice goodies that quarto provides and guarantees on the outputs between formats may be lost. |
I tried to follow to the letter the instructions by @eeholmes but what I get in my HTML output is this: To be precise here is what I did:
Perhaps I am misunderstanding @eeholmes instructions, I apologize in advance for my total ignorance (in particular regarding the discussion around the version of Mathjack). I appreciate the help because I teach and I need to label equations in a long derivation ALL the time and I just switched from Bookdown (where I could do that) to Quarto and bumped into this issue. |
@mtartari Look at this repo https://github.com/nmfs-opensci/test-equations. You might be missing the |
@Scott-Akenhead Yes it works if you don't have |
Ok, I figured out the problem. This bit in the yaml is breaking things:
The top yaml should be
@Scott-Akenhead Something changed with Quarto since my Jan 20, 2023 answer. Now to get |
I don't think we intentionally changed anything! If you folks can come up with a minimal document where the behavior changed, we will be able to more easily help. |
@cscheid Sorry we didn't get to meet up at Posit conf! So close... I am moving my various notes from this issue and another into a repo to chip away at the issues for LaTeX users. Also will provide me a place to send LaTeX users for examples.
I don't think it is any Quarto bug per se. My goal is to figure out what needs to be done to get proper amsmath LaTeX syntax working in Quarto books. nmfs-opensci/quarto-amsmath#2. I realize that Quarto syntax for equation numbering is working, but that is causing too many issues for LaTeX users who are trying to get their amsmath code working. So rather than try to create a new equation syntax, I'd like to figure how to get amsmath syntax working. It is pretty close. Most things work fine. It is just the section numbering that I don't know how to fix. |
On behalf of all of us using Quarto to collaborate on science papers: An encompassing, over-the-horizon, goal might be: Submit a paper in Quarto directly to a science journal. |
@cscheid I added this comment to the issue I am working on. nmfs-opensci/quarto-amsmath#2 (comment) Maybe it will explain the problem better? Quarto is essentially circumventing the MathJax javascript libraries way of handling and figuring out equation numbering in our complicated equations. Recreating the MathJax library behavior would not be good. It's really complicated and took years of work to make complicated amsmath equations look right with numbers in the right places in html. The solution is not too hard. I have done it before. It uses the MathJax tagformat extension. Solution is here. But it involves adding |
This might be harder said than done. I have to spend some time investigating to say for sure, but I believe some amount of the processing for MathJax happens after Lua filters are done (some of it is done by Pandoc, and some of it is done by Quarto post-processors). At the point where the document is at a state that you want it to be, there might not be any Quarto extension entry points. |
@cscheid Here is the repo showing where I am at. I am quite close to a 'proof of concept'. If I can just figure out how to id the https://github.com/nmfs-opensci/chapnum-equations |
Is it possible to read some proper documentation on how to handle referencing in equations? There are a lot of suggestions in this thread but I can't really understand which would be the right one. |
Bug description
I am struggling to label multiple equations placed within
$$ \begin{align} ... \end{align} $$
.This works flawlessly...
...but neither of these work:
I tried various other versions of Quarto and/or LaTeX syntax, but couldn't achieve the desired results: To have multiple numbered (and cross-referenceable) equations placed within an align-block.
Any suggestions would be greatly appreciated! And, it would be nice to have such an example included in the Equations sections of the Technical Writing documentation here.
Software:
(1db809b8, 2022-05-16) for macOS
Checklist
The text was updated successfully, but these errors were encountered: