Improved uncertainty handling in slunitx.

This commit is contained in:
John MacFarlane 2020-09-10 14:48:35 -07:00
parent a03160fb0d
commit 623ce89e0e
2 changed files with 14 additions and 6 deletions

View file

@ -76,12 +76,17 @@ parseNumPart =
if T.null uncertainty if T.null uncertainty
then return $ str basenum then return $ str basenum
else return $ str $ basenum <> "\xa0\xb1\xa0" <> else return $ str $ basenum <> "\xa0\xb1\xa0" <>
case T.break (=='.') basenum of let (_,ys) = T.break (=='.') basenum
(_,ys) in case (T.length ys - 1, T.length uncertainty) of
| T.length ys <= 1 -> uncertainty (0,_) -> uncertainty
| otherwise -> "0." <> (x,y)
T.replicate (T.length ys - 1 - T.length uncertainty) "0" | x > y -> "0." <> T.replicate (x - y) "0" <>
<> uncertainty 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 ',' parseComma = str "." <$ char ','
parsePlusMinus = str "\xa0\xb1\xa0" <$ try (string "+-") parsePlusMinus = str "\xa0\xb1\xa0" <$ try (string "+-")
parseParens = parseParens =

View file

@ -5,8 +5,11 @@
\SI{125(12)}{\m} \SI{125(12)}{\m}
\SI{0.135(21)}{\m} \SI{0.135(21)}{\m}
\SI{12.3(60)}{\m}
^D ^D
<p>23 ± 2 m</p> <p>23 ± 2 m</p>
<p>125 ± 12 m</p> <p>125 ± 12 m</p>
<p>0.135 ± 0.021 m</p> <p>0.135 ± 0.021 m</p>
<p>12.3 ± 6 m</p>
``` ```