Skip to content

add equation numbering and cross-references - #78

Closed
jackhogan wants to merge 1 commit into
mainfrom
equation_numbering
Closed

jackhogan wants to merge 1 commit into
mainfrom
equation_numbering

Conversation

@jackhogan

Copy link
Copy Markdown

Support adding an id to a display equation so that it gets numbered and can be cited with e.g. [@eq-lossfunc], which renders as "Equation 1". This gives papers and other technical documents the same treatment for equations that figures and tables already have.

What changes

  • eq joins sec, fig and tbl as a built-in reference type, with the words "Equation" and "Equations".
  • A display-math block with an id (div.math.display in MDHTML) registers as a caption-kind target. [@eq-lossfunc] resolves to "Equation 1", [-@eq-lossfunc] to "1", and groups work as they do for figures.
  • The HTML exporter numbers id-bearing display equations in document order and appends \tag{n} on its own line to the equation's TeX, which KaTeX and MathJax render as the equation number. md2gfm does the same in the source. mdhtml2typst emits #set math.equation(numbering: "(1)") when any equation has an id, labels each one, and opts unlabelled equations out of numbering.
  • Display math without an id is left untouched by every exporter.
  • Parser fix: an attribute list on the closing line of display math, \]{#eq-lossfunc} or $${#eq-lossfunc}, now closes the block and attaches to it, as attributes on a fence line do. Before, the closer was not recognised and the block swallowed the rest of the document without a warning. The IAL-below form continues to work; both parse identically.

@jph00

jph00 commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

Thanks @jackhogan . If you look at the diff, you'll see that there's some wild string-mangling going on in python, in _equation(). Since mdhtml is meant to be a markdown API, the presence of that code told me something was wrong...

So I looked into it, and there were a lot of things wrong in mdhtml that you inherited here! One was that md2gfm promised byte-identical results, which is the opposite of how it's meant to work, so it ignored all our machinery. Secondly, our underlying Document model still wasn't good enough to work with cleanly.

I've now fixed both of those issues, and recreated your feature on top of it. Thanks for the PR! :D

@jph00 jph00 closed this Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants