Glue inline math to hugging punctuation so it can't orphan-wrap#215
Merged
Conversation
KaTeX renders inline math inside a display:inline-block box — an atomic inline the browser can soft-wrap on both sides. That let a period written right after a formula ($x$.) or a bracket written right before one (($x$) flow onto its own line, away from the formula it belongs to. Wrap each inline formula together with the whitespace-free run hugging it on either side in a white-space:nowrap span. This lands on both render paths via shared glue primitives (takeLeadingGlue/takeTrailingGlue): the string renderer (renderMathContentToHtml, rebuilt around a typed-segment model) and the markdown pipeline (a new rehype-math-nowrap plugin run after rehype-katex). CSS rounds it out: hyphens:none in math prose, a p:has(.katex) carve-out that backs WebKit off text-wrap:pretty (which mishandles the atomic nowrap spans), and a hanging-indent gutter so wrapped list lines align under the text. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
KaTeX renders inline math inside a
display:inline-blockbox — an atomic inline the browser can soft-wrap on either side. That let a period written right after a formula ($x$.) or a bracket written right before one (($x$) flow onto its own line, away from the formula it belongs to.This wraps each inline formula together with the whitespace-free run hugging it on either side in a
white-space:nowrapspan, on both render paths via shared glue primitives (takeLeadingGlue/takeTrailingGlue):renderMathContentToHtmlrebuilt around a typed-segment model (TextSegment | InlineMathSegment | DisplayMathSegment) plus a glue pass.rehype-math-nowrapplugin appended afterrehype-katexin both the shared<Markdown>pipeline and the headless validator.CSS rounds it out:
hyphens: nonein math prose, ap:has(.katex)carve-out that backs WebKit offtext-wrap: pretty(which mishandles the atomic nowrap spans), and a hanging-indent gutter so wrapped list lines align under the text rather than the marker.Covered by new vitest specs for the glue primitives, both render paths (including escaping, shared-text gluing, and the previously-untested
inlineBlockToMathSource), and idempotency.🤖 Generated with Claude Code