git.iko.soy/typeable/pandoc
on master help sign in
LaTeX reader: Fix negative numbers in siunitx commands.

The commit a157e1a broke negative numbers, e.g. `\SI{-33}{\celcius}` or `\num{-3}`. This fixes the regression.

commit734b4c26a990a334b2bbe352ba34257ebb2a6fcd authorJohn MacFarlane <jgm@berkeley.edu> dateMon 16 Nov 2020, 14:07 (6 years ago) parentdcf99f2
2 files changed+19−2
src/Text/Pandoc/Readers/LaTeX/SIunitx.hs+4−2 test/command/siunitx-negative-numbers.md+15
src/Text/Pandoc/Readers/LaTeX/SIunitx.hs+4−2
@@ -58,7 +58,7 @@ doSInumlist = do
5858 text ", & " <> last xs
5959
6060parseNum :: Parser Text () Inlines
61−parseNum = mconcat <$> many parseNumPart
61+parseNum = (mconcat <$> many parseNumPart) <* eof
6262
6363parseNumPart :: Parser Text () Inlines
6464parseNumPart =
@@ -71,7 +71,9 @@ parseNumPart =
7171 parseSpace
7272 where
7373 parseDecimalNum = do
74− basenum <- T.pack <$> many1 (satisfy (\c -> isDigit c || c == '.'))
74+ pref <- option mempty $ (mempty <$ char '+') <|> ("-" <$ char '-')
75+ basenum <- (pref <>) . T.pack
76+ <$> many1 (satisfy (\c -> isDigit c || c == '.'))
7577 uncertainty <- option mempty $ T.pack <$> parseParens
7678 if T.null uncertainty
7779 then return $ str basenum
test/command/siunitx-negative-numbers.mdnew file+15
@@ -0,0 +1,15 @@
1+```
2+% pandoc -f latex
3+\SI{+33.3}{\m}
4+
5+\num{+5}
6+
7+\SI{-33.3}{\m}
8+
9+\num{-33}
10+^D
11+<p>33.3 m</p>
12+<p>5</p>
13+<p>-33.3 m</p>
14+<p>-33</p>
15+```