From 734b4c26a990a334b2bbe352ba34257ebb2a6fcd Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Mon, 16 Nov 2020 14:07:31 -0800 Subject: 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. --- src/Text/Pandoc/Readers/LaTeX/SIunitx.hs | 6 ++++-- test/command/siunitx-negative-numbers.md | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 test/command/siunitx-negative-numbers.md 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 +

33.3 m

+

5

+

-33.3 m

+

-33

+``` -- cgit v1.2.3