Skip to content

Conversation

@cesaryuan
Copy link

@cesaryuan cesaryuan commented Jan 17, 2026

Summary

  • Fix \boldsymbol and \bm commands to apply the correct bold style based on the content's default style
  • Apply TextBoldItalic for content that is normally italic (latin letters, lowercase greek)
  • Apply TextBold for content that is normally upright (uppercase greek letters, numbers)

Previously, \boldsymbol always applied TextBold regardless of the content, which was incorrect. In LaTeX, \boldsymbol{x} should produce bold italic x, while \boldsymbol{\Gamma} should produce bold upright Gamma.

Test plan

  • Added test case test/reader/tex/boldsymbol.test
  • Verified: \boldsymbol{x} → TextBoldItalic
  • Verified: \boldsymbol{\Gamma} → TextBold
  • Verified: \boldsymbol{\alpha} → TextBoldItalic
  • Verified: \bm{y} → TextBoldItalic

Close #280

This is the effect of applying the modified texmath:

image

Previously \boldsymbol always applied TextBold. Now it applies
TextBoldItalic for content that is normally italic (latin letters,
lowercase greek) and TextBold for content that is normally upright
(uppercase greek, numbers).
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes the handling of \boldsymbol and \bm commands in the TeX reader to apply bold styling based on the default style of the content. Previously, these commands always applied TextBold regardless of content type, which was incorrect for content that should be italic in math mode (like Latin letters and lowercase Greek letters).

Changes:

  • Apply TextBoldItalic for content normally rendered italic (Latin letters, lowercase Greek letters, operators)
  • Apply TextBold for content normally rendered upright (uppercase Greek letters, numbers)
  • Move \boldsymbol and \bm handling from the styleOps map to special-case logic in the styled function

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
test/reader/tex/boldsymbol.test New test file verifying correct bold styling for mixed content including lowercase Greek (α), Latin letters (b, D), uppercase Greek (Γ), operators (+, =, ÷), demonstrating both TextBoldItalic and TextBold applications
src/Text/TeXMath/Readers/TeX/Commands.hs Removed \boldsymbol and \bm from styleOps map with explanatory comment noting special handling in TeX.hs
src/Text/TeXMath/Readers/TeX.hs Added special handling for \boldsymbol and \bm in the styled function, implemented applyBoldsymbol function with content-aware styling logic, and added isDefaultUpright helper to identify uppercase Greek letters and digits

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

-- This includes uppercase Greek letters.
isDefaultUpright :: Char -> Bool
isDefaultUpright c =
-- Uppercase Greek letters (Α-Ω, excluding lowercase range)
Copy link

Copilot AI Jan 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment "excluding lowercase range" is misleading. The range \x0391 to \x03A9 naturally doesn't include lowercase Greek letters (which start at \x03B1), so nothing is being actively excluded. Consider revising to: "Uppercase Greek letters (U+0391 to U+03A9)" or simply "Uppercase Greek letters (Α-Ω)".

Suggested change
-- Uppercase Greek letters (Α-Ω, excluding lowercase range)
-- Uppercase Greek letters (Α-Ω)

Copilot uses AI. Check for mistakes.
EStyled TextNormal xs -> EStyled TextBold xs
EStyled TextItalic xs -> EStyled TextBoldItalic xs
EStyled TextBold xs -> EStyled TextBold xs
EStyled TextBoldItalic xs -> EStyled TextBoldItalic xs
Copy link

Copilot AI Jan 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The catch-all case wraps unhandled expression types (like ESub, ESuper, EFraction, etc.) entirely in TextBoldItalic, rather than recursively applying the bold style to their components. For example, \boldsymbol{x^2} would wrap the entire superscript expression instead of applying bold to both the base and exponent separately. Consider adding explicit handling for compound expressions if the current behavior doesn't match LaTeX semantics.

Suggested change
EStyled TextBoldItalic xs -> EStyled TextBoldItalic xs
EStyled TextBoldItalic xs -> EStyled TextBoldItalic xs
ESub base sub -> ESub (applyBoldsymbol base) (applyBoldsymbol sub)
ESuper base sup -> ESuper (applyBoldsymbol base) (applyBoldsymbol sup)
EFraction num den -> EFraction (applyBoldsymbol num) (applyBoldsymbol den)

Copilot uses AI. Check for mistakes.
@jgm jgm closed this in d997ae9 Jan 17, 2026
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.

Should \boldsymbol be the style for bold italic?

1 participant