git.iko.soy/typeable/pandoc
on master help sign in
LaTeX reader: Fix parsing of `+-` in siunitx numbers.

See #6658.

commita366bd6abccd18a49f0033de850ddd53830cc5ed authorJohn MacFarlane <jgm@berkeley.edu> dateThu 20 May 2021, 09:03 (5 years ago) parent8437a4a
2 files changed+11−5
src/Text/Pandoc/Readers/LaTeX/SIunitx.hs+7−4 test/command/6620.md+4−1
src/Text/Pandoc/Readers/LaTeX/SIunitx.hs+7−4
@@ -45,9 +45,7 @@ doSI tok = do
4545 unit]
4646
4747doSInum :: PandocMonad m => LP m Inlines
48−doSInum = skipopts *> (tonum . untokenize . map convertPM <$> braced)
49− where convertPM (Tok pos (CtrlSeq "pm") _) = Tok pos Word "\xb1\xa0"
50− convertPM t = t
48+doSInum = skipopts *> (tonum . untokenize <$> braced)
5149
5250tonum :: Text -> Inlines
5351tonum value =
@@ -74,12 +72,16 @@ parseNumPart =
7472 parseDecimalNum <|>
7573 parseComma <|>
7674 parsePlusMinus <|>
75+ parsePM <|>
7776 parseI <|>
7877 parseExp <|>
7978 parseX <|>
8079 parseSpace
8180 where
82− parseDecimalNum = do
81+ parseDecimalNum, parsePlusMinus, parsePM,
82+ parseComma, parseI, parseX,
83+ parseExp, parseSpace :: Parser Text () Inlines
84+ parseDecimalNum = try $ do
8385 pref <- option mempty $ (mempty <$ char '+') <|> ("\x2212" <$ char '-')
8486 basenum <- (pref <>) . T.pack
8587 <$> many1 (satisfy (\c -> isDigit c || c == '.'))
@@ -100,6 +102,7 @@ parseNumPart =
100102 | otherwise -> "." <> t
101103 parseComma = str "." <$ char ','
102104 parsePlusMinus = str "\xa0\xb1\xa0" <$ try (string "+-")
105+ parsePM = str "\xa0\xb1\xa0" <$ try (string "\\pm")
103106 parseParens =
104107 char '(' *> many1 (satisfy (\c -> isDigit c || c == '.')) <* char ')'
105108 parseI = str "i" <$ char 'i'
test/command/6620.md+4−1
@@ -9,10 +9,13 @@
99\SI{12.3(60)}{\m}
1010
1111\SI{10.0 \pm 3.3}{\ms}
12+
13+\SI{10.0 +- 3.3}{\ms}
1214^D
1315<p>23 ± 2 m</p>
1416<p>125 ± 12 m</p>
1517<p>0.135 ± 0.021 m</p>
1618<p>12.3 ± 6 m</p>
17−<p>10.0 ± 3.3 ms</p>
19+<p>10.0 ± 3.3 ms</p>
20+<p>10.0 ± 3.3 ms</p>
1821```