LaTeX reader: support parenthesized uncertainties in siunitx.

This commit is contained in:
John MacFarlane 2020-09-10 13:07:31 -07:00
parent 9423b4b7d9
commit a03160fb0d
2 changed files with 26 additions and 2 deletions

View file

@ -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)

12
test/command/6620.md Normal file
View file

@ -0,0 +1,12 @@
```
% pandoc -f latex
\SI{23(2)}{\m}
\SI{125(12)}{\m}
\SI{0.135(21)}{\m}
^D
<p>23 ± 2 m</p>
<p>125 ± 12 m</p>
<p>0.135 ± 0.021 m</p>
```