@@ -1,23 +1,25 @@
1{-# LANGUAGE OverloadedStrings #-}
1{-# LANGUAGE OverloadedStrings #-}
2module Text.Pandoc.Readers.LaTeX.SIunitx
2module Text.Pandoc.Readers.LaTeX.SIunitx
4 , doSIrange
4 , doSIrange
7import Text.Pandoc.Builder
8import Text.Pandoc.Builder
8import Text.Pandoc.Readers.LaTeX.Parsing
9import Text.Pandoc.Readers.LaTeX.Parsing
9import Text.Pandoc.Readers.LaTeX.Types
10import Text.Pandoc.Readers.LaTeX.Types
10import Text.Pandoc.Class
11import Text.Pandoc.Class
11−import Control.Monad (mzero)
12−import Text.Pandoc.Parsing hiding (blankline, many, mathDisplay, mathInline,
12+import Text.Pandoc.Parsing hiding (blankline, mathDisplay, mathInline,
13 optional, space, spaces, withRaw, (<|>))
13 optional, space, spaces, withRaw, (<|>))
14import Control.Applicative ((<|>))
14import Control.Applicative ((<|>))
15import qualified Data.Map as M
15import qualified Data.Map as M
16+import Data.Char (isDigit)
16import Data.Text (Text)
17import Data.Text (Text)
18+import qualified Data.Text as T
18-- converts e.g. \SI{1}[\$]{} to "$ 1" or \SI{1}{\euro} to "1 €"
20-- converts e.g. \SI{1}[\$]{} to "$ 1" or \SI{1}{\euro} to "1 €"
19−dosiunitx :: PandocMonad m => LP m Inlines -> LP m Inlines
21+doSI :: PandocMonad m => LP m Inlines -> LP m Inlines
20−dosiunitx tok = do
22+doSI tok = do
22 value <- tok
24 value <- tok
23 valueprefix <- option "" $ bracketed tok
25 valueprefix <- option "" $ bracketed tok
@@ -28,6 +30,37 @@ dosiunitx tok = do
28 emptyOr160 unit,
30 emptyOr160 unit,
33+doSInum :: PandocMonad m => LP m Inlines
36+ value <- untokenize <$> braced
37+ case runParser parseNum () "" value of
38+ Left _ -> return $ text value
39+ Right num -> return num
41+parseNum :: Parser Text () Inlines
42+parseNum = mconcat <$> many parseNumPart
44+parseNumPart :: Parser Text () Inlines
55+ str . T.pack <$> many1 (satisfy (\c -> isDigit c || c == '.'))
56+ parseComma = str "." <$ char ','
57+ parsePlusMinus = str "\xa0\xb1\xa0" <$ try (string "+-")
58+ parseI = str "i" <$ char 'i'
59+ parseX = str "\xa0\xd7\xa0" <$ char 'x'
60+ parseExp = (\n -> str ("\xa0\xd7\xa0" <> "10") <> superscript n)
61+ <$> (char 'e' *> parseDecimalNum)
62+ parseSpace = mempty <$ skipMany1 (char ' ')
31-- converts e.g. \SIrange{100}{200}{\ms} to "100 ms--200 ms"
64-- converts e.g. \SIrange{100}{200}{\ms} to "100 ms--200 ms"
32doSIrange :: PandocMonad m => LP m Inlines -> LP m Inlines
65doSIrange :: PandocMonad m => LP m Inlines -> LP m Inlines
33doSIrange tok = do
66doSIrange tok = do