Commit 39f8c1c
feat(preview): canonicalize single-line $$x$$ alone-on-line to block math
User-observed bug: pasting \`$$ E = mc^2 $$\` (compact, single line)
rendered as inline display math — no \`.katex-display\` node, so the
Math-align toggle had nothing to act on. The user reasonably thought
the toggle was broken when actually the input never crossed the
block-math threshold.
Fix
---
Extend canonicalizeBlockMath's rewriteMath to detect "alone on its
own line" — preceded by start-of-input / \`\n\` (allowing trailing
spaces) AND followed by \`\n\` / end-of-input. When that holds, the
single-line \`$$x$$\` is rewritten to canonical block form
(\`\n\n$$\nx\n$$\n\n\`) just like the existing multi-line and
\`\\begin{env}\` cases.
Mid-line \`text $$x$$ text\` is left alone — that's legitimate inline
display usage. The new condition only kicks in when the user clearly
meant "this fragment is a math block."
Two new unit tests pin the new behavior (alone-on-line + start-of-input)
and the existing mid-line test was clarified. 130 / 130 tests pass.
Combined with the existing \`\\[ \\]\` → \`$$ $$\` translation in
normalize-latex-delimiters, compact LLM shapes like
\`\\[E = mc^2\\]\` on a single line now also become block math.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>1 parent d7991b0 commit 39f8c1c
2 files changed
Lines changed: 43 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | | - | |
60 | | - | |
61 | | - | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
62 | 63 | | |
63 | 64 | | |
64 | 65 | | |
65 | 66 | | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
66 | 87 | | |
67 | 88 | | |
68 | 89 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
104 | 104 | | |
105 | 105 | | |
106 | 106 | | |
107 | | - | |
| 107 | + | |
108 | 108 | | |
109 | 109 | | |
110 | | - | |
111 | | - | |
112 | | - | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
113 | 128 | | |
114 | 129 | | |
115 | 130 | | |
| |||
0 commit comments