From a03160fb0d9c9790e23f6c75368bfa39281b76a8 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Thu, 10 Sep 2020 13:07:31 -0700 Subject: LaTeX reader: support parenthesized uncertainties in siunitx. --- src/Text/Pandoc/Readers/LaTeX/SIunitx.hs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src/Text') diff --git a/src/Text/Pandoc/Readers/LaTeX/SIunitx.hs b/src/Text/Pandoc/Readers/LaTeX/SIunitx.hs index 052a9d82e..9a14c9a3e 100644 --- a/src/Text/Pandoc/Readers/LaTeX/SIunitx.hs +++ b/src/Text/Pandoc/Readers/LaTeX/SIunitx.hs @@ -70,10 +70,22 @@ parseNumPart = parseX <|> parseSpace where - parseDecimalNum = - str . T.pack <$> many1 (satisfy (\c -> isDigit c || c == '.')) + parseDecimalNum = do + basenum <- T.pack <$> many1 (satisfy (\c -> isDigit c || c == '.')) + uncertainty <- option mempty $ T.pack <$> parseParens + if T.null uncertainty + then return $ str basenum + else return $ str $ basenum <> "\xa0\xb1\xa0" <> + case T.break (=='.') basenum of + (_,ys) + | T.length ys <= 1 -> uncertainty + | otherwise -> "0." <> + T.replicate (T.length ys - 1 - T.length uncertainty) "0" + <> uncertainty parseComma = str "." <$ char ',' parsePlusMinus = str "\xa0\xb1\xa0" <$ try (string "+-") + parseParens = + char '(' *> many1 (satisfy (\c -> isDigit c || c == '.')) <* char ')' parseI = str "i" <$ char 'i' parseX = str "\xa0\xd7\xa0" <$ char 'x' parseExp = (\n -> str ("\xa0\xd7\xa0" <> "10") <> superscript n) -- cgit v1.2.3