aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2020-11-16 14:07:31 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2020-11-16 14:08:29 -0800
commit734b4c26a990a334b2bbe352ba34257ebb2a6fcd (patch)
treecd06aa1f189192713d486355496337b304f71b68
parentdcf99f29e0c439c893fb4fd0df0931b482e35c6b (diff)
downloadpandoc-734b4c26a990a334b2bbe352ba34257ebb2a6fcd.tar.gz
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.
-rw-r--r--src/Text/Pandoc/Readers/LaTeX/SIunitx.hs6
-rw-r--r--test/command/siunitx-negative-numbers.md15
2 files changed, 19 insertions, 2 deletions
diff --git a/src/Text/Pandoc/Readers/LaTeX/SIunitx.hs b/src/Text/Pandoc/Readers/LaTeX/SIunitx.hs
index 436330d85..d16dec580 100644
--- a/src/Text/Pandoc/Readers/LaTeX/SIunitx.hs
+++ b/src/Text/Pandoc/Readers/LaTeX/SIunitx.hs
@@ -58,7 +58,7 @@ doSInumlist = do
text ", & " <> last xs
parseNum :: Parser Text () Inlines
-parseNum = mconcat <$> many parseNumPart
+parseNum = (mconcat <$> many parseNumPart) <* eof
parseNumPart :: Parser Text () Inlines
parseNumPart =
@@ -71,7 +71,9 @@ parseNumPart =
parseSpace
where
parseDecimalNum = do
- basenum <- T.pack <$> many1 (satisfy (\c -> isDigit c || c == '.'))
+ pref <- option mempty $ (mempty <$ char '+') <|> ("-" <$ char '-')
+ basenum <- (pref <>) . T.pack
+ <$> many1 (satisfy (\c -> isDigit c || c == '.'))
uncertainty <- option mempty $ T.pack <$> parseParens
if T.null uncertainty
then return $ str basenum
diff --git a/test/command/siunitx-negative-numbers.md b/test/command/siunitx-negative-numbers.md
new file mode 100644
index 000000000..56cdbe31d
--- /dev/null
+++ b/test/command/siunitx-negative-numbers.md
@@ -0,0 +1,15 @@
+```
+% pandoc -f latex
+\SI{+33.3}{\m}
+
+\num{+5}
+
+\SI{-33.3}{\m}
+
+\num{-33}
+^D
+<p>33.3 m</p>
+<p>5</p>
+<p>-33.3 m</p>
+<p>-33</p>
+```