aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorschrieveslaach <schrieveslaach@online.de>2017-04-22 21:57:21 +0200
committerJohn MacFarlane <jgm@berkeley.edu>2017-04-22 21:57:21 +0200
commit020dc63e23226789cb2e3b7957bc70d6e938fab1 (patch)
treecb009eb865f22f9944db0f4c2e53d2eab6bba51a
parentb68135d34dfc0e53ca0aa5db4be3f4a2359001f4 (diff)
downloadpandoc-020dc63e23226789cb2e3b7957bc70d6e938fab1.tar.gz
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} ```
-rw-r--r--src/Text/Pandoc/Readers/LaTeX.hs17
-rw-r--r--test/command/3587.md21
2 files changed, 38 insertions, 0 deletions
diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs
index e85002ba3..f3c94dacb 100644
--- a/src/Text/Pandoc/Readers/LaTeX.hs
+++ b/src/Text/Pandoc/Readers/LaTeX.hs
@@ -668,6 +668,8 @@ inlineCommands = M.fromList $
, ("nocite", mempty <$ (citation "nocite" NormalCitation False >>=
addMeta "nocite"))
, ("hypertarget", braced >> tok)
+ -- siuntix
+ , ("SI", dosiunitx)
] ++ map ignoreInlines
-- these commands will be ignored unless --parse-raw is specified,
-- in which case they will appear as raw latex blocks:
@@ -726,6 +728,21 @@ dolstinline = do
doLHSverb :: PandocMonad m => LP m Inlines
doLHSverb = codeWith ("",["haskell"],[]) <$> manyTill (satisfy (/='\n')) (char '|')
+-- converts e.g. \SI{1}[\$]{} to "$ 1" or \SI{1}{\euro} to "1 €"
+dosiunitx :: PandocMonad m => LP m Inlines
+dosiunitx = do
+ skipopts
+ value <- tok
+ valueprefix <- option "" $ char '[' >> (mconcat <$> manyTill tok (char ']'))
+ unit <- tok
+ let emptyOr160 "" = ""
+ emptyOr160 _ = "\160"
+ return . mconcat $ [valueprefix,
+ emptyOr160 valueprefix,
+ value,
+ emptyOr160 unit,
+ unit]
+
lit :: String -> LP m Inlines
lit = pure . str
diff --git a/test/command/3587.md b/test/command/3587.md
new file mode 100644
index 000000000..addb6c582
--- /dev/null
+++ b/test/command/3587.md
@@ -0,0 +1,21 @@
+```
+% pandoc -f latex -t native
+\SI[round-precision=2]{1}{m} is equal to \SI{1000}{mm}
+^D
+[Para [Str "1\160m",Space,Str "is",Space,Str "equal",Space,Str "to",Space,Str "1000\160mm"]]
+```
+
+```
+% pandoc -f latex -t native
+\SI[round-precision=2]{1}[\$]{} is equal to \SI{0.938094}{\euro}
+^D
+[Para [Str "$\160\&1",Space,Str "is",Space,Str "equal",Space,Str "to",Space,Str "0.938094\160\8364"]]
+```
+
+
+```
+% pandoc -f latex -t native
+\SI[round-precision=2]{\{\}}[\{\}]{\{\}}
+^D
+[Para [Str "{}\160{}\160{}"]]
+```