From 623ce89e0eb08d1878b4a006d32a7c2986b3494a Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Thu, 10 Sep 2020 14:48:35 -0700 Subject: Improved uncertainty handling in slunitx. --- src/Text/Pandoc/Readers/LaTeX/SIunitx.hs | 17 +++++++++++------ test/command/6620.md | 3 +++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/Text/Pandoc/Readers/LaTeX/SIunitx.hs b/src/Text/Pandoc/Readers/LaTeX/SIunitx.hs index 9a14c9a3e..49a6d7301 100644 --- a/src/Text/Pandoc/Readers/LaTeX/SIunitx.hs +++ b/src/Text/Pandoc/Readers/LaTeX/SIunitx.hs @@ -76,12 +76,17 @@ parseNumPart = 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 + let (_,ys) = T.break (=='.') basenum + in case (T.length ys - 1, T.length uncertainty) of + (0,_) -> uncertainty + (x,y) + | x > y -> "0." <> T.replicate (x - y) "0" <> + T.dropWhileEnd (=='0') uncertainty + | otherwise -> T.take (y - x) uncertainty <> + case T.dropWhileEnd (=='0') + (T.drop (y - x) uncertainty) of + t | T.null t -> mempty + | otherwise -> "." <> t parseComma = str "." <$ char ',' parsePlusMinus = str "\xa0\xb1\xa0" <$ try (string "+-") parseParens = diff --git a/test/command/6620.md b/test/command/6620.md index 4b4fe2a01..314200d30 100644 --- a/test/command/6620.md +++ b/test/command/6620.md @@ -5,8 +5,11 @@ \SI{125(12)}{\m} \SI{0.135(21)}{\m} + +\SI{12.3(60)}{\m} ^D

23 ± 2 m

125 ± 12 m

0.135 ± 0.021 m

+

12.3 ± 6 m

``` -- cgit v1.2.3