fix(katex): convert aligned→align when \tag is present#3847
Merged
Conversation
KaTeX's aligned/gathered environments treat the entire block as one equation and only permit a single \tag per block (parse error "Multiple \tag"), while align/gather support \tag on every row natively. Instead of stripping \tag commands (which loses equation numbers), convert aligned→align, gathered→gather, and alignedat→alignat when \tag is detected in the math source. Plain aligned blocks without \tag are left unchanged so they keep their un-numbered behaviour. 6 new unit tests + 1 updated e2e test (99 total, all pass).
0562163 to
2bafd91
Compare
esengine
approved these changes
Jun 11, 2026
esengine
left a comment
Owner
There was a problem hiding this comment.
Nice fix — converting to align/gather/alignat instead of stripping \tag keeps the equation numbers, and gating on \tag presence means plain aligned blocks keep their semantics. The e2e tests actually rendering through KaTeX (including the boxed nesting) is exactly the verification this needed. Thanks!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
KaTeX
saligned/gatheredenvironments treat the entire block as one equation and only permit a single\tagper block (parse error "Multiple \tag"). When LLMs emit\tag{...}insidealigned` — as in:KaTeX throws
KaTeX parse error: Multiple \tag, whichrehype-katexrenders as
<span class="katex-error" style="color:#cc0000">—showing red error text in the web UI.
Fix
Instead of stripping
\tagcommands (which loses equation numbers),convert the environments when
\tagis present:\begin{aligned}→\begin{align}\begin{gathered}→\begin{gather}\begin{alignedat}{N}→\begin{alignat}{N}KaTeX's
align/gather/alignatsupport\tagon every rownatively. Plain
alignedblocks without\tagare left unchangedso they keep their un-numbered behaviour. The conversion is only
applied when
\tagis detected in the math source.Files changed
desktop/frontend/src/components/latexNormalize.ts— aligned→alignconversion when
\tagis presentdesktop/frontend/src/__tests__/math-golden.test.ts— 6 new unittests + 1 updated e2e test
Testing
All 99 golden tests pass (
npx tsx src/__tests__/math-golden.test.ts).