Skip to content

LaTeX: brackets alone as scripts, bars in text, \vert and \bigm| - #32

Merged
simonebortolin merged 6 commits into
mainfrom
claude/latex-bars-brackets
Nov 11, 2026
Merged

simonebortolin merged 6 commits into
mainfrom
claude/latex-bars-brackets

Conversation

@simonebortolin

@simonebortolin simonebortolin commented Nov 11, 2026 •

Copy link
Copy Markdown
Owner

On main. The stack it was part of (#22, #23, #29) is merged. Continued by #35.

These four bugs were found while working on #29 and were already there before it:

LaTeX Before Now
x_{[} written x_[, which reads back as x_([) written x_{[}, reads back the same
x_(, x^{)} 𝑥_((()┤), 𝑥^(()\)) 𝑥_\(, 𝑥^\)
\text{a|b} "a|b", written back with a backslash in it "a|b"
a\vert b throws: not valid UnicodeMath 𝑎|𝑏
|a \bigm| b| |𝑎|𝑏|: the \bigm bar was paired with the first bar |(𝑎|𝑏)|
  • Reader
    • A bracket alone as a script is escaped: a closing bracket, or an opening one that does not close. Word's x^(a+b), where the brackets close, is still read as a group.
    • A closing bracket alone in a group, as in {)}, is escaped too.
    • \) and \] would end the LaTeX, so escaped closing brackets are held as noncharacters until the end, as the escapes of \text already are.
    • Bars inside \text and the like are left alone.
    • \vert is |, which is then paired or escaped like any other bar.
    • \bigm| outside brackets becomes {|}, a bar alone. Between brackets it stays the separator, so \{x \bigm| x>0\} still reads as {𝑥│𝑥>0}.
  • Writer
    • It braces a script that is a single bracket.
    • It writes {|} for a bar alone between brackets, which would otherwise read back as their separator: \{x {|} x>0\} did not read back the same.
  • Tests: 11 new cases in ReadsSlashesAndBarsAsLaTeX. 6950/6950 pass on net10.0 and net8.0, after merging main.

🤖 Generated with Claude Code

https://claude.ai/code/session_01SyVio98rJkziNnwWW9T1Mn

… a default and empty macro bodies

\DeclareMathOperator{\name}{text} (and \DeclareMathOperator\name, starred or not) defines
\name as \operatorname{text} (\operatorname*{text}); a macro of \newcommand{\f}[n][default]
takes its first argument optional, [given] or the default, as \newenvironment does; an
empty body (\newcommand{\e}{}, \def\e{}) expands to nothing, not to an empty group. The
latex2mathml macro cases that were not expanded now are, but for
newcommand-optional-default, where latex2mathml takes the group after a macro whose one
argument is optional as that argument: LaTeX gives it its default.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SyVio98rJkziNnwWW9T1Mn
…ts alone in a group

Two bars with nothing between them (||, | |) are bars alone, but for two such pairs
around something, a norm (||x||) as UnicodeMath reads it; one bar alone between
brackets with an empty side holds the placeholder there ({|} is {⬚│⬚}, as \middle| is);
the pairs of bars between \left and \right are grouped, which UnicodeMath would otherwise
close at \right (├(x|a|b┤)); {|}, the ordinary bar of TeX, is a bar alone, and the
writer writes so a bar alone before other bars that the reader would pair it with. A
bracket that a group opens and does not close (\phantom{(}, \mathstrut) is escaped,
where UnicodeMath closed it with an empty fence. An mrow between bars or brackets that
are text has no default intent (no absolute value of bars alone). The latex2mathml
cases spaces, middle and mathstrut now write LaTeX that reads back.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SyVio98rJkziNnwWW9T1Mn
…and \bigm| as LaTeX means them

- A bracket alone as a script: x_( and x^{)} are escaped, where UnicodeMath read the opening of what follows or lost
  the bracket (\) and \] would end the LaTeX: the closing brackets are held as noncharacters until the end); a
  script in brackets that close, Word's x^(a+b), is left as it is. The writer braces a script that is a bracket
  (x_{[}, not x_[).
- The bars of \text are text, not escaped (\text{a|b}).
- \vert outside angles is the bar |, which EscapeOddBars pairs or escapes (a\vert b threw).
- \bigm| outside brackets is a relation, {|}, a bar alone that no other bar pairs with (|a \bigm| b|).
- The writer writes {|} for a bar alone between brackets, which the reader would read as their separator.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SyVio98rJkziNnwWW9T1Mn
@simonebortolin
simonebortolin changed the base branch from claude/latex-write-back to main November 11, 2026 00:13
@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Pre-release removed now that this PR is closed.

@simonebortolin
simonebortolin added this pull request to stack #36 November 11, 2026 00:18
@simonebortolin
simonebortolin merged commit 469db54 into main Nov 11, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants