git.iko.soy/typeable/pandoc
on master help sign in
Minimal support for SIRange in LaTeX reader (#6418)

Add support for `\SIRange{firstnumber}{secondnumber}{unit}` provided by siunitx. An en-dash is used instead of localized "to".

commit1b8f1611983706f81cc33db4c4fe0ce379973c65 authorEmerson Harkin <emerson.f.harkin@gmail.com> dateThu 23 Jul 2020, 19:47 (6 years ago) parentc37a56e
2 files changed+83
src/Text/Pandoc/Readers/LaTeX.hs+24 test/command/3587.md+59
src/Text/Pandoc/Readers/LaTeX.hs+24
@@ -259,6 +259,29 @@ dosiunitx = do
259259 emptyOr160 unit,
260260 unit]
261261
262+-- converts e.g. \SIRange{100}{200}{\ms} to "100 ms--200 ms"
263+doSIRange :: PandocMonad m => LP m Inlines
264+doSIRange = do
265+ skipopts
266+ startvalue <- tok
267+ startvalueprefix <- option "" $ bracketed tok
268+ stopvalue <- tok
269+ stopvalueprefix <- option "" $ bracketed tok
270+ unit <- grouped (mconcat <$> many1 siUnit) <|> siUnit <|> tok
271+ let emptyOr160 "" = ""
272+ emptyOr160 _ = "\160"
273+ return . mconcat $ [startvalueprefix,
274+ emptyOr160 startvalueprefix,
275+ startvalue,
276+ emptyOr160 unit,
277+ unit,
278+ "\8211", -- An en-dash
279+ stopvalueprefix,
280+ emptyOr160 stopvalueprefix,
281+ stopvalue,
282+ emptyOr160 unit,
283+ unit]
284+
262285siUnit :: PandocMonad m => LP m Inlines
263286siUnit = do
264287 Tok _ (CtrlSeq name) _ <- anyControlSeq
@@ -1075,6 +1098,7 @@ inlineCommands = M.union inlineLanguageCommands $ M.fromList
10751098 , ("acsp", doAcronymPlural "abbrv")
10761099 -- siuntix
10771100 , ("SI", dosiunitx)
1101+ , ("SIRange", doSIRange)
10781102 -- hyphenat
10791103 , ("bshyp", lit "\\\173")
10801104 , ("fshyp", lit "/\173")
test/command/3587.md+59
@@ -55,3 +55,62 @@
5555[Para [Str "18.2\160\176C"]]
5656```
5757
58+# SIRange tests
59+
60+## Integer range with simple common units
61+
62+```
63+% pandoc -f latex -t native
64+\SIRange{10}{20}{\gram}
65+^D
66+[Para [Str "10\160g\8211\&20\160g"]]
67+```
68+```
69+% pandoc -f latex -t native
70+\SIRange{35}{9}{\milli\meter}
71+^D
72+[Para [Str "35\160mm\8211\&9\160mm"]]
73+```
74+```
75+% pandoc -f latex -t native
76+\SIRange{4}{97367265}{\celsius}
77+^D
78+[Para [Str "4\160\176C\8211\&97367265\160\176C"]]
79+```
80+
81+## Decimal range with simple units
82+
83+```
84+% pandoc -f latex -t native
85+\SIRange{4.5}{97367265.5}{\celsius}
86+^D
87+[Para [Str "4.5\160\176C\8211\&97367265.5\160\176C"]]
88+```
89+
90+## Squared units
91+
92+```
93+% pandoc -f latex -t native
94+\SIRange{10}{20}{\square\meter}
95+^D
96+[Para [Str "10\160m\178\8211\&20\160m\178"]]
97+```
98+
99+## Ignore round precision
100+
101+`round-precision` option appears to be ignored by `\SI` as of 7c6dbd37e, so
102+`\SIRange` will ignore it as well.
103+
104+```
105+% pandoc -f latex -t native
106+\SIRange[round-precision=2]{10}{20}{\gram}
107+^D
108+[Para [Str "10\160g\8211\&20\160g"]]
109+```
110+```
111+% pandoc -f latex -t native
112+\SIRange[round-precision=2]{10.0}{20.25}{\gram}
113+^D
114+[Para [Str "10.0\160g\8211\&20.25\160g"]]
115+```
116+