Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion src/Text/TeXMath/Readers/TeX.hs
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,40 @@ styled c = do
return $ case x of
EGrouped xs -> f xs
_ -> f [x]
Nothing -> mzero
Nothing
| c == "\\boldsymbol" || c == "\\bm" -> do
x <- texSymbol <|> inbraces <|> texChar
return $ applyBoldsymbol x
| otherwise -> mzero

-- | Apply \boldsymbol style: use TextBoldItalic for content that is
-- normally italic (latin letters, lowercase greek), and TextBold for
-- content that is normally upright (uppercase greek, numbers).
applyBoldsymbol :: Exp -> Exp
applyBoldsymbol e =
case e of
EGrouped xs -> EGrouped (map applyBoldsymbol xs)
EIdentifier t
| T.all isDefaultUpright t -> EStyled TextBold [e]
| otherwise -> EStyled TextBoldItalic [e]
ENumber _ -> EStyled TextBold [e]
ESymbol _ t
| T.all isDefaultUpright t -> EStyled TextBold [e]
| otherwise -> EStyled TextBoldItalic [e]
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.
_ -> EStyled TextBoldItalic [e]

-- | Returns True if a character is normally rendered upright in math mode.
-- 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.
(c >= '\x0391' && c <= '\x03A9') ||
-- Also handle digits
(c >= '0' && c <= '9')

colored :: Text -> TP Exp
colored "\\color" = do
Expand Down
3 changes: 1 addition & 2 deletions src/Text/TeXMath/Readers/TeX/Commands.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,12 @@ import Data.Text (Text)
import Data.Ratio ((%))

-- Note: cal and scr are treated the same way, as unicode is lacking such two different sets for those.
-- Note: \boldsymbol and \bm are handled specially in TeX.hs (styled function).
styleOps :: M.Map Text ([Exp] -> Exp)
styleOps = M.fromList
[ ("\\mathrm", EStyled TextNormal)
, ("\\mathup", EStyled TextNormal)
, ("\\mathbf", EStyled TextNormal . (:[]) . EStyled TextBold)
, ("\\boldsymbol", EStyled TextBold)
, ("\\bm", EStyled TextBold)
, ("\\symbf", EStyled TextBold)
, ("\\mathbold", EStyled TextBold)
, ("\\pmb", EStyled TextBold)
Expand Down
17 changes: 17 additions & 0 deletions test/reader/tex/boldsymbol.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<<< tex
\boldsymbol{\alpha + b = \Gamma \div D} + \bm{y}


>>> native
[ EGrouped
[ EStyled TextBoldItalic [ EIdentifier "\945" ]
, EStyled TextBoldItalic [ ESymbol Ord "+" ]
, EStyled TextBoldItalic [ EIdentifier "b" ]
, EStyled TextBoldItalic [ ESymbol Rel "=" ]
, EStyled TextBold [ EIdentifier "\915" ]
, EStyled TextBoldItalic [ ESymbol Ord "\247" ]
, EStyled TextBoldItalic [ EIdentifier "D" ]
]
, ESymbol Bin "+"
, EStyled TextBoldItalic [ EIdentifier "y" ]
]
Loading