Skip to content

fix: \bm and \boldsymbol keep a letter's italic shape - #3117

Open
shupphar wants to merge 1 commit into
arnog:masterfrom
shupphar:fix-bold-italic
Open

shupphar wants to merge 1 commit into
arnog:masterfrom
shupphar:fix-bold-italic

Conversation

@shupphar

Copy link
Copy Markdown

The 0.100 changelog says that \boldsymbol and \bm "preserve the style of the characters, so they remain italic if they were italic before", while \mathbf renders upright. In practice, \bm{x} and \boldsymbol{x} are drawn as an upright bold x (class ML__mathbf) and serialized as \mathbf{x}, so a field round-trips \bm{x}^\top \mathbf{W} \bm{x} to \mathbf{x}^{\top}\mathbf{Wx}.

Cause. \mathbf sets the normal variant plus the bold variant style. \bm and \boldsymbol set only the bold variant style. That difference survives in the atom's style, but both the atom's createBox() and Box defaulted a missing variant to normal before MathMode.getFont() ran, so the two looked identical there. getFont() also only auto-italicized a letter that had no variant style at all.

Fix.

  • Rendering. Box and createBox() no longer fill in the variant. getFont() treats a missing variant as normal itself. For a bold with no variant, it applies the same letter shape as for a regular letter: under tex a Latin letter or a lowercase Greek letter becomes italic (Math-BoldItalic, ML__mathbfit), while uppercase Greek and digits stay upright.
  • Serialization. emitBoldRun() splits a bold run by how its weight is spelt:
    • An upright bold, where a variant was set, is \mathbf when it is letters and digits, as before.
    • A bold with the automatic shape is \bm, the fallback MathLive already uses, unless it is only digits.
    • A bold italic variant (\mathbfit) carries its own weight, so \mathbfit{x} is no longer written \mathbf{\mathbfit{x}}.

Tests. A BOLD ITALIC block in test/latex.test.ts covers the round trips above, and checks that \bm{x} and \boldsymbol{x} draw with ML__mathbfit, while \mathbf{x} and \bm{\Gamma} don't. The existing suites pass unchanged.

Suggested changelog line: \bm{x} and \boldsymbol{x} are drawn bold italic, as in TeX, and serialized as \bm{x} rather than the upright \mathbf{x}.

🤖 Generated with Claude Code

The changelog of 0.100 says `\boldsymbol` and `\bm` "preserve the style of the
characters, so they remain italic if they were italic before", while `\mathbf`
is upright. They didn't: `\bm{x}` was drawn as an upright bold x, and written
back as `\mathbf{x}`.

`\mathbf` sets the 'normal' variant; `\bm` and `\boldsymbol` set only the
bold weight, so the difference was in the atom's style, but the box and the
atom's createBox defaulted every missing variant to 'normal' before
MathMode.getFont() saw it. They no longer do: getFont() treats a missing
variant as 'normal' itself and, for a bold with no variant, applies the letter
shape it applies to a regular letter (italic for a Latin letter in 'tex', so
the Math-BoldItalic font).

When writing LaTeX, a bold run is split by how its weight is spelt: an upright
bold (a variant was set) is `\mathbf` when it is letters and digits, as
before; a bold with the automatic shape is `\bm`, unless it is only digits,
which are upright either way; a bold italic variant (`\mathbfit`) carries its
own weight, so `\mathbfit{x}` is no longer written `\mathbf{\mathbfit{x}}`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant