git.iko.soy/typeable/pandoc
on master help sign in
Add siunitx Support (#3588)
020dc63schrieveslaach
src/Text/Pandoc/Readers/LaTeX.hs+17
@@ -668,6 +668,8 @@ inlineCommands = M.fromList $
668 , ("nocite", mempty <$ (citation "nocite" NormalCitation False >>=
668 , ("nocite", mempty <$ (citation "nocite" NormalCitation False >>=
669 addMeta "nocite"))
669 addMeta "nocite"))
670 , ("hypertarget", braced >> tok)
670 , ("hypertarget", braced >> tok)
671+ -- siuntix
672+ , ("SI", dosiunitx)
671 ] ++ map ignoreInlines
673 ] ++ map ignoreInlines
672 -- these commands will be ignored unless --parse-raw is specified,
674 -- these commands will be ignored unless --parse-raw is specified,
673 -- in which case they will appear as raw latex blocks:
675 -- in which case they will appear as raw latex blocks:
@@ -726,6 +728,21 @@ dolstinline = do
726doLHSverb :: PandocMonad m => LP m Inlines
728doLHSverb :: PandocMonad m => LP m Inlines
727doLHSverb = codeWith ("",["haskell"],[]) <$> manyTill (satisfy (/='\n')) (char '|')
729doLHSverb = codeWith ("",["haskell"],[]) <$> manyTill (satisfy (/='\n')) (char '|')
728
730
731+-- converts e.g. \SI{1}[\$]{} to "$ 1" or \SI{1}{\euro} to "1 €"
732+dosiunitx :: PandocMonad m => LP m Inlines
733+dosiunitx = do
734+ skipopts
735+ value <- tok
736+ valueprefix <- option "" $ char '[' >> (mconcat <$> manyTill tok (char ']'))
737+ unit <- tok
738+ let emptyOr160 "" = ""
739+ emptyOr160 _ = "\160"
740+ return . mconcat $ [valueprefix,
741+ emptyOr160 valueprefix,
742+ value,
743+ emptyOr160 unit,
744+ unit]
745+
729lit :: String -> LP m Inlines
746lit :: String -> LP m Inlines
730lit = pure . str
747lit = pure . str
731
748
test/command/3587.mdnew file+21
@@ -0,0 +1,21 @@
1+```
2+% pandoc -f latex -t native
3+\SI[round-precision=2]{1}{m} is equal to \SI{1000}{mm}
4+^D
5+[Para [Str "1\160m",Space,Str "is",Space,Str "equal",Space,Str "to",Space,Str "1000\160mm"]]
6+```
7+
8+```
9+% pandoc -f latex -t native
10+\SI[round-precision=2]{1}[\$]{} is equal to \SI{0.938094}{\euro}
11+^D
12+[Para [Str "$\160\&1",Space,Str "is",Space,Str "equal",Space,Str "to",Space,Str "0.938094\160\8364"]]
13+```
14+
15+
16+```
17+% pandoc -f latex -t native
18+\SI[round-precision=2]{\{\}}[\{\}]{\{\}}
19+^D
20+[Para [Str "{}\160{}\160{}"]]
21+```