Add support to parse unit string of \SI command (closes #4296).

This commit is contained in:
Marc Schreiber 2018-03-18 04:59:20 +01:00 committed by John MacFarlane
parent 14cc82bcc7
commit 155a2ac039
2 changed files with 50 additions and 1 deletions

View file

@ -666,7 +666,7 @@ dosiunitx = do
skipopts
value <- tok
valueprefix <- option "" $ bracketed tok
unit <- tok
unit <- inlineCommand' <|> tok
let emptyOr160 "" = ""
emptyOr160 _ = "\160"
return . mconcat $ [valueprefix,
@ -675,6 +675,12 @@ dosiunitx = do
emptyOr160 unit,
unit]
-- siunitx's \square command
dosquare :: PandocMonad m => LP m Inlines
dosquare = do
unit <- inlineCommand' <|> tok
return . mconcat $ [unit, "\178"]
lit :: String -> LP m Inlines
lit = pure . str
@ -1468,6 +1474,13 @@ inlineCommands = M.union inlineLanguageCommands $ M.fromList
, ("acsp", doAcronymPlural "abbrv")
-- siuntix
, ("SI", dosiunitx)
-- units of siuntix
, ("celsius", lit "°C")
, ("degreeCelsius", lit "°C")
, ("gram", lit "g")
, ("meter", lit "m")
, ("milli", lit "m")
, ("square", dosquare)
-- hyphenat
, ("bshyp", lit "\\\173")
, ("fshyp", lit "/\173")

View file

@ -19,3 +19,39 @@
^D
[Para [Str "{}\160{}\160{}"]]
```
```
% pandoc -f latex -t native
\SI{30}{\milli\meter}
^D
[Para [Str "30\160mm"]]
```
```
% pandoc -f latex -t native
\SI{6}{\gram}
^D
[Para [Str "6\160g"]]
```
```
% pandoc -f latex -t native
\SI{25}{\square\meter}
^D
[Para [Str "25\160m\178"]]
```
```
% pandoc -f latex -t native
\SI{18.2}{\degreeCelsius}
^D
[Para [Str "18.2\160\176C"]]
```
```
% pandoc -f latex -t native
\SI{18.2}{\celsius}
^D
[Para [Str "18.2\160\176C"]]
```