fix(desktop): correct pipe handling for array column specs and kets#4320
Open
lightfront wants to merge 1 commit into
Open
fix(desktop): correct pipe handling for array column specs and kets#4320lightfront wants to merge 1 commit into
lightfront wants to merge 1 commit into
Conversation
Two distinct bugs in latexNormalize.ts | handling that surfaced as
broken math rendering in the chat:
1. Array column specs corrupted
\begin{array}{c|c} was rewritten to \begin{array}{c\vert c},
causing KaTeX "Unknown column alignment: \vert" parse errors. In
LaTeX, the | inside an array/tabular preamble means "draw a
vertical rule" between columns and must not become \vert.
Fix: COLUMN_SPEC_ENVS lists environments whose first {...} arg is
a column spec. When \begin{<env>} is found, the spec brace group
is copied verbatim (no | or % rewriting). Pipes outside the spec
still convert to \vert normally.
2. Ket delimiters in GFM tables render as double bars
In Markdown tables, | is the column delimiter, so an LLM writes
kets as \|uud\rangle to avoid breaking the table. But \| in KaTeX
is the "parallel-to" symbol (U+2225) the heavy double bar used for
norms, not the single bar (U+2223) kets use. The result: kets
rendered with double bars instead of single bars.
Fix: fixKetPipes() converts \| to \vert when it is a ket opener
(\|...\rangle) or bra closer (\langle...\|), while preserving
matched \|...\| norm pairs. Disambiguation is by forward scan to
the next \| or \rangle, with a backward scan for unmatched
\langle to catch bra closers.
Tests: 121 passed, 0 failed (was 109; +12 new golden tests covering
column-spec preservation, ket/bra conversion, norm preservation, and
end-to-end KaTeX render of all three cases through the full pipeline).
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.
What this fixes
Two distinct bugs in
latexNormalize.tspipe (|) handling that surface as broken math rendering in the chat. Both are edge cases of the existing|→\vertrule that PR #3666 established.1. Array column specs corrupted — KaTeX parse error
\begin{array}{c|c}was rewritten to\begin{array}{c\vert c}, causing:In LaTeX, the
|inside an array/tabular column specification means "draw a vertical rule" between columns. It must not be rewritten to\vert.Fix:
COLUMN_SPEC_ENVSlists environments whose first{...}argument is a column spec (array,tabular,tabularx,longtable,subarray). When\begin{<env>}is encountered, the column-spec brace group is copied verbatim — no|or%rewriting. Pipes outside the spec still convert to\vertnormally.2. Ket delimiters in GFM tables render as double bars
In Markdown tables,
|is the column delimiter. To write a ket|ψ⟩inside a table cell, the|must be escaped as\|— otherwise the table breaks. But\|in LaTeX/KaTeX is the parallel-to symbol (‖, U+2225), the heavy double bar used for norms, not the light single bar (∣, U+2223) that kets use. The result:|uud⟩rendered as‖uud⟩.Fix:
fixKetPipes()converts\|→\vertwhen it is:\|...\rangle(unpaired, ends in\rangle)\langle...\|(unpaired, starts with\langle)While preserving norms: matched
\|...\|pairs keep the double bar. Disambiguation is by forward scan to the next\|or\rangle, with a backward scan for unmatched\langleto catch bra closers at the end of an expression.|uud\rangle\vert(single bar ∣)\langle\psi|\vert(single bar ∣)\langle x | y \rangle\vert(single bar ∣)|x||(double bar ‖)Testing
normalizeMath→remark-math→rehype-katexpipelineRelationship to other PRs
Related to #3666 (inline math rendering hardening) — that PR established the math pre-pass infrastructure and the
|→\vertrule. This PR fixes two edge cases of that rule. Independent of #3750 (\slashed) and #4216 (Young diagrams).