Skip to content

Commit

Permalink
Parse TeX \mathbf as both bold and upright.
Browse files Browse the repository at this point in the history
Closes #236.
  • Loading branch information
jgm committed Apr 10, 2024
1 parent a95c52f commit 64e1cbf
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/Text/TeXMath/Readers/TeX/Commands.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ styleOps :: M.Map Text ([Exp] -> Exp)
styleOps = M.fromList
[ ("\\mathrm", EStyled TextNormal)
, ("\\mathup", EStyled TextNormal)
, ("\\mathbf", EStyled TextBold)
, ("\\mathbf", EStyled TextNormal . (:[]) . EStyled TextBold)
, ("\\boldsymbol", EStyled TextBold)
, ("\\bm", EStyled TextBold)
, ("\\symbf", EStyled TextBold)
Expand Down
3 changes: 3 additions & 0 deletions src/Text/TeXMath/Writers/TeX.hs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@ writeExp (EText ttype s) = do
case map (fixSpace . escapeLaTeX) (T.unpack s) of
[] -> return ()
xs -> tell $ txtcmd (Grouped xs)
writeExp (EStyled TextNormal [EStyled TextBold es]) = do
tell [ControlSeq "\\mathbf"]
tellGroup $ mapM_ writeExp $ everywhere (mkT (fromUnicode TextBold)) es
writeExp (EStyled ttype es) = do
txtcmd <- (flip S.getLaTeXTextCommand ttype) <$> asks mathEnv
tell [ControlSeq txtcmd]
Expand Down
17 changes: 10 additions & 7 deletions test/reader/tex/22.test
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,16 @@
]
, [ [ EText TextMonospace "mathbf" ]
, [ EStyled
TextBold
[ EIdentifier "A"
, EIdentifier "B"
, EIdentifier "C"
, EIdentifier "a"
, EIdentifier "b"
, EIdentifier "c"
TextNormal
[ EStyled
TextBold
[ EIdentifier "A"
, EIdentifier "B"
, EIdentifier "C"
, EIdentifier "a"
, EIdentifier "b"
, EIdentifier "c"
]
]
]
]
Expand Down
8 changes: 5 additions & 3 deletions test/reader/tex/binomial_coefficient.test
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
\mathbf{C}(n,k) = \mathbf{C}_k^n = {}_n\mathbf{C}_k = \binom{n}{k} = \frac{n!}{k!\,(n -k)!}

>>> native
[ EStyled TextBold [ EIdentifier "C" ]
[ EStyled TextNormal [ EStyled TextBold [ EIdentifier "C" ] ]
, EDelimited
"("
")"
Expand All @@ -12,12 +12,14 @@
]
, ESymbol Rel "="
, ESubsup
(EStyled TextBold [ EIdentifier "C" ])
(EStyled TextNormal [ EStyled TextBold [ EIdentifier "C" ] ])
(EIdentifier "k")
(EIdentifier "n")
, ESymbol Rel "="
, ESub (EGrouped []) (EIdentifier "n")
, ESub (EStyled TextBold [ EIdentifier "C" ]) (EIdentifier "k")
, ESub
(EStyled TextNormal [ EStyled TextBold [ EIdentifier "C" ] ])
(EIdentifier "k")
, ESymbol Rel "="
, EDelimited
"("
Expand Down
4 changes: 4 additions & 0 deletions test/regression/236a.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<<< tex
\mathbf{A}
>>> typst
upright(bold(A))
4 changes: 4 additions & 0 deletions test/regression/236b.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<<< tex
\mathbf{A}
>>> tex
\mathbf{A}

0 comments on commit 64e1cbf

Please sign in to comment.