LaTeX reader: Fix parsing of +- in siunitx numbers.

See #6658.
This commit is contained in:
John MacFarlane
2021-05-20 09:03:29 -07:00
parent 8437a4a002
commit a366bd6abc
2 changed files with 11 additions and 5 deletions
+7 -4
View File
@@ -45,9 +45,7 @@ doSI tok = do
unit]
doSInum :: PandocMonad m => LP m Inlines
doSInum = skipopts *> (tonum . untokenize . map convertPM <$> braced)
where convertPM (Tok pos (CtrlSeq "pm") _) = Tok pos Word "\xb1\xa0"
convertPM t = t
doSInum = skipopts *> (tonum . untokenize <$> braced)
tonum :: Text -> Inlines
tonum value =
@@ -74,12 +72,16 @@ parseNumPart =
parseDecimalNum <|>
parseComma <|>
parsePlusMinus <|>
parsePM <|>
parseI <|>
parseExp <|>
parseX <|>
parseSpace
where
parseDecimalNum = do
parseDecimalNum, parsePlusMinus, parsePM,
parseComma, parseI, parseX,
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 == '.'))
@@ -100,6 +102,7 @@ parseNumPart =
| otherwise -> "." <> t
parseComma = str "." <$ char ','
parsePlusMinus = str "\xa0\xb1\xa0" <$ try (string "+-")
parsePM = str "\xa0\xb1\xa0" <$ try (string "\\pm")
parseParens =
char '(' *> many1 (satisfy (\c -> isDigit c || c == '.')) <* char ')'
parseI = str "i" <$ char 'i'
+4 -1
View File
@@ -9,10 +9,13 @@
\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>
<p>10.0 ± 3.3 ms</p>
```