LaTeX reader siunitx: add leading 0 to numbers starting with .

This commit is contained in:
John MacFarlane 2021-05-20 09:11:26 -07:00
parent 183ce58477
commit 5dc917da3e
3 changed files with 14 additions and 5 deletions

View file

@ -83,8 +83,11 @@ parseNumPart =
parseExp, parseSpace :: Parser Text () Inlines
parseDecimalNum = try $ do
pref <- option mempty $ (mempty <$ char '+') <|> ("\x2212" <$ char '-')
basenum <- (pref <>) . T.pack
<$> many1 (satisfy (\c -> isDigit c || c == '.'))
basenum' <- many1 (satisfy (\c -> isDigit c || c == '.'))
let basenum = pref <> T.pack
(case basenum' of
'.':_ -> '0':basenum'
_ -> basenum')
uncertainty <- option mempty $ T.pack <$> parseParens
if T.null uncertainty
then return $ str basenum

View file

@ -9,13 +9,10 @@
\SI{12.3(60)}{\m}
\SI{10.0 \pm 3.3}{\ms}
\SI{10.0 +- 3.3}{\ms}
^D
<p>23 ± 2 m</p>
<p>125 ± 12 m</p>
<p>0.135 ± 0.021 m</p>
<p>12.3 ± 6 m</p>
<p>10.0 ± 3.3 ms</p>
<p>10.0 ± 3.3 ms</p>
```

9
test/command/6658.md Normal file
View file

@ -0,0 +1,9 @@
```
pandoc -f latex
\SI{10.0 +- 3.3}{\ms}
\num{.3e45}
^D
<p>10.0 ± 3.3 ms</p>
<p>0.3 × 10<sup>45</sup></p>
```