-
-
Notifications
You must be signed in to change notification settings - Fork 80
TeX reader: handle \boldsymbol based on content style #281
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -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 | ||||||
| _ -> 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) | ||||||
|
||||||
| -- Uppercase Greek letters (Α-Ω, excluding lowercase range) | |
| -- Uppercase Greek letters (Α-Ω) |
| 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" ] | ||
| ] |
There was a problem hiding this comment.
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.