git.iko.soy/typeable/pandoc
on master help sign in
Add siunitx Support (#3588)

For example: ```latex \SI[round-precision=2]{1}{m} is equal to \SI{1000}{mm}. \SI[round-precision=2]{1}[\$]{} is equal to \SI{0.938094}{\euro} ```

commit020dc63e23226789cb2e3b7957bc70d6e938fab1 authorschrieveslaach <schrieveslaach@online.de> dateSat 22 Apr 2017, 21:57 (10 years ago) parentb68135d
2 files changed+38
src/Text/Pandoc/Readers/LaTeX.hs+17 test/command/3587.md+21
src/Text/Pandoc/Readers/LaTeX.hs+17
@@ -668,6 +668,8 @@ inlineCommands = M.fromList $
668668 , ("nocite", mempty <$ (citation "nocite" NormalCitation False >>=
669669 addMeta "nocite"))
670670 , ("hypertarget", braced >> tok)
671+ -- siuntix
672+ , ("SI", dosiunitx)
671673 ] ++ map ignoreInlines
672674 -- these commands will be ignored unless --parse-raw is specified,
673675 -- in which case they will appear as raw latex blocks:
@@ -726,6 +728,21 @@ dolstinline = do
726728doLHSverb :: PandocMonad m => LP m Inlines
727729doLHSverb = codeWith ("",["haskell"],[]) <$> manyTill (satisfy (/='\n')) (char '|')
728730
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+
729746lit :: String -> LP m Inlines
730747lit = pure . str
731748
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+```