{{ message }}
Repository navigation
fix(muya): keep a wide equation from scrolling under its own tag (#4339) - #5540
Merged
Merged
Conversation
1 task done
KaTeX positions `\tag` absolutely at the right edge of `.katex-html`, a block as wide as whatever holds it, so a formula wider than the column was drawn underneath the tag rather than beside it — the overlap reported in #4339 and still open upstream as KaTeX/KaTeX#1983. Size that box to the formula and float the tag instead: the tag then follows the formula inside the scrollable extent, and `min-width: 100%` keeps it at the right margin whenever the formula fits, which is the numbered-equation look. Same-line display math (#4935) is covered by the same rules — its popup shrinks to fit the formula, so the tag sat over the tail of even a short one. The one deliberate cost: a formula that fits is now centred in the space left of its tag, half the tag's width off the box centre. Centring the formula and flowing the tag after it cannot both hold, and the overlap is the bug. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Jocs
force-pushed
the
fix/math-tag-overlap-4339
branch
from
September 24, 2026 01:44
deeb8b6 to
ee5fc57
Compare
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.

Fixes the overlap half of #4339: an equation with
\tag{…}that is wider than the editor column is drawn underneath its own tag.Reproduced
The reporter's formula in a math block, in a column narrower than the formula (a 520px viewport reproduces their screenshot exactly): on
developthe tag(A.13)is painted overn^4(V_m − V_K)— 186px of overlap, measured as the last.base's right edge against the tag's left. With this change the overlap is 0 and the tag is reached by scrolling.The scrollbar half of the report — a horizontal scrollbar under short inline formulas at any Max width percentage — was #5034 and is already fixed by #5466;
inline-math-editor-width-5034.spec.tscovers it. (The comment's$\int k dx=kx+C $no longer parses as math at all: pandoc'stex_math_dollarsforbids a space before the closing$, adopted in #5449.)Mechanism
KaTeX renders a tagged display equation as
with
.katex-html { display: block; position: relative }and.tag { position: absolute; right: 0 }..katex-htmlis a block, so it is as wide as the box around it, never as wide as the formula: the tag is pinned to the column's right edge while thewhite-space: nowrapformula overflows straight past it. Open upstream as KaTeX/KaTeX#1983.The fix sizes that box to the formula and puts the tag in the flow:
width: max-content— the float lands after the formula, inside the scrollable extent.min-width: 100%— the float goes to the column's right margin, the numbered-equation look.Both properties are needed. Floating the tag alone leaves the box at column width, so the float has nowhere to go and drops to a second line (measured: block height 72 → 112px, overlap 186 → 205px).
width: max-contentalone keeps the tag absolute, which just moves the overlap from mid-formula to its last 51px.Scoped with
:has(> .tag)so untagged equations — nearly all of them — keep their current box.:has()is already used in this stylesheet. muya never passesleqno/fleqnto KaTeX, so the left-tag variant cannot occur.Two things this also fixes
$$…$$inside a paragraph, feat(muya): support same-line display math #4935). Its popup shrinks to fit the formula, so its right edge is the formula's — the tag sat over the tail of even a short formula (23px overlap fora+b=c \tag{1}).The deliberate cost
A formula that fits is now centred in the space left of its tag, i.e. half the tag's width (~25px for
(A.13), ~21px for(1)) left of the box centre. Exact centring and a tag that flows after the formula cannot both hold — this is the trade-off named in the upstream thread — and the overlap is the actual bug. Untagged equations are untouched, which is what the third spec asserts.Test plan
packages/muya/e2e/tests/blocks/math-tag-overflow-4339.spec.ts, six cases: a block wider than the column, a block that fits, the active block's floating preview, an untagged block, and same-line display math both wider and narrower than the column. Four of the six fail ondevelopand pass with the rules.pnpm -C packages/muya/e2e exec playwright test --project=chromium tests/blocks/math-tag-overflow-4339.spec.ts— 6 passed; 4 fail with the CSS revertedinline-math-align,inline-math-editor-width-5034,inline-math-overflow-4339,math-error-nowrap-4100,inline/same-line-display-math,inline/tex-math-dollars— unchangedpnpm -C packages/muya exec stylelint "src/**/*.css"— same 7 findings as ondevelop, none in the new rulespnpm run build:unpack, Electron): the rules ship in the bundled renderer CSS; a tagged formula wider than the 700px column scrolls with no overlap, one that fits keeps its tag flush at the right margintyping/math-and-diagrams.spec.ts— one pre-existing local failure ("clicking the rendered inline KaTeX activates the source for editing"), identical with and without this change🤖 Generated with Claude Code