@@ -4,6 +4,7 @@ module Text.Pandoc.Readers.LaTeX.SIunitx
5 , doSIrange
5 , doSIrange
@@ -18,6 +19,7 @@ import qualified Data.Map as M
18import Data.Char (isDigit)
19import Data.Char (isDigit)
19import Data.Text (Text)
20import Data.Text (Text)
20import qualified Data.Text as T
21import qualified Data.Text as T
22+import Data.List (intersperse)
22dosi :: PandocMonad m => LP m Inlines -> LP m Inlines
24dosi :: PandocMonad m => LP m Inlines -> LP m Inlines
23dosi tok = grouped (siUnit tok) <|> siUnit tok
25dosi tok = grouped (siUnit tok) <|> siUnit tok
@@ -36,12 +38,24 @@ doSI tok = do
38doSInum :: PandocMonad m => LP m Inlines
40doSInum :: PandocMonad m => LP m Inlines
41− value <- untokenize <$> braced
41+doSInum = skipopts *> (tonum . untokenize <$> braced)
43+tonum :: Text -> Inlines
42 case runParser parseNum () "" value of
45 case runParser parseNum () "" value of
43− Left _ -> return $ text value
46+ Left _ -> text value
44− Right num -> return num
47+ Right num -> num
49+doSInumlist :: PandocMonad m => LP m Inlines
52+ xs <- map tonum . T.splitOn ";" . untokenize <$> braced
57+ mconcat (intersperse (str "," <> space) (init xs)) <>
58+ text ", & " <> last xs
46parseNum :: Parser Text () Inlines
60parseNum :: Parser Text () Inlines
47parseNum = mconcat <$> many parseNumPart
61parseNum = mconcat <$> many parseNumPart
@@ -78,14 +92,16 @@ doSIang = do
78 _ -> return mempty
92 _ -> return mempty
80-- converts e.g. \SIrange{100}{200}{\ms} to "100 ms--200 ms"
94-- converts e.g. \SIrange{100}{200}{\ms} to "100 ms--200 ms"
81−doSIrange :: PandocMonad m => LP m Inlines -> LP m Inlines
95+doSIrange :: PandocMonad m => Bool -> LP m Inlines -> LP m Inlines
82−doSIrange tok = do
96+doSIrange includeUnits tok = do
84 startvalue <- doSInum
98 startvalue <- doSInum
85 startvalueprefix <- option "" $ bracketed tok
99 startvalueprefix <- option "" $ bracketed tok
86 stopvalue <- doSInum
100 stopvalue <- doSInum
87 stopvalueprefix <- option "" $ bracketed tok
101 stopvalueprefix <- option "" $ bracketed tok
102+ unit <- if includeUnits
88− unit <- dosi tok
103+ then dosi tok
89 return . mconcat $ [startvalueprefix,
105 return . mconcat $ [startvalueprefix,
90 emptyOr160 startvalueprefix,
106 emptyOr160 startvalueprefix,
91 startvalue,
107 startvalue,