git.iko.soy/typeable/pandoc
on master help sign in
LaTeX reader: Support squared, cubed, tothe in siunitx.
529eb69John MacFarlane
src/Text/Pandoc/Readers/LaTeX/SIunitx.hs+22−12
@@ -21,7 +21,7 @@ dosiunitx tok = do
21 skipopts
21 skipopts
22 value <- tok
22 value <- tok
23 valueprefix <- option "" $ bracketed tok
23 valueprefix <- option "" $ bracketed tok
24− unit <- rawUnit tok
24+ unit <- grouped (siUnit tok) <|> tok
25 return . mconcat $ [valueprefix,
25 return . mconcat $ [valueprefix,
26 emptyOr160 valueprefix,
26 emptyOr160 valueprefix,
27 value,
27 value,
@@ -36,7 +36,7 @@ doSIrange tok = do
36 startvalueprefix <- option "" $ bracketed tok
36 startvalueprefix <- option "" $ bracketed tok
37 stopvalue <- tok
37 stopvalue <- tok
38 stopvalueprefix <- option "" $ bracketed tok
38 stopvalueprefix <- option "" $ bracketed tok
39− unit <- rawUnit tok
39+ unit <- grouped (siUnit tok) <|> tok
40 return . mconcat $ [startvalueprefix,
40 return . mconcat $ [startvalueprefix,
41 emptyOr160 startvalueprefix,
41 emptyOr160 startvalueprefix,
42 startvalue,
42 startvalue,
@@ -49,23 +49,33 @@ doSIrange tok = do
49 emptyOr160 unit,
49 emptyOr160 unit,
50 unit]
50 unit]
51
51
52−rawUnit :: PandocMonad m => LP m Inlines -> LP m Inlines
53−rawUnit tok = grouped (mconcat <$> many1 (siUnit tok)) <|> siUnit tok <|> tok
54−
55emptyOr160 :: Inlines -> Inlines
52emptyOr160 :: Inlines -> Inlines
56emptyOr160 x = if x == mempty then x else str "\160"
53emptyOr160 x = if x == mempty then x else str "\160"
57
54
58siUnit :: PandocMonad m => LP m Inlines -> LP m Inlines
55siUnit :: PandocMonad m => LP m Inlines -> LP m Inlines
59siUnit tok = do
56siUnit tok = do
60 Tok _ (CtrlSeq name) _ <- anyControlSeq
57 Tok _ (CtrlSeq name) _ <- anyControlSeq
58+ case name of
61− if name == "square"
59+ "square" -> do
62− then do
60+ unit <- siUnit tok
61+ return $ unit <> superscript "2"
62+ "cubic" -> do
63− unit <- rawUnit tok
63+ unit <- siUnit tok
64− return $ unit <> "\178"
64+ return $ unit <> superscript "3"
65− else
65+ "raisetothe" -> do
66+ n <- tok
67+ unit <- siUnit tok
68+ return $ unit <> superscript n
69+ _ ->
66 case M.lookup name siUnitMap of
70 case M.lookup name siUnitMap of
67− Just il -> return il
71+ Just il ->
72+ option il $
73+ choice
74+ [ (il <> superscript "2") <$ controlSeq "squared"
75+ , (il <> superscript "3") <$ controlSeq "cubed"
76+ , (\n -> il <> superscript n) <$> (controlSeq "tothe" *> tok)
77+ ]
68− Nothing -> mzero
78+ Nothing -> tok
69
79
70siUnitMap :: M.Map Text Inlines
80siUnitMap :: M.Map Text Inlines
71siUnitMap = M.fromList
81siUnitMap = M.fromList
test/command/3587.md+41−10
@@ -13,13 +13,6 @@
13```
13```
14
14
15
15
16−```
17−% pandoc -f latex -t native
18−\SI[round-precision=2]{\{\}}[\{\}]{\{\}}
19−^D
20−[Para [Str "{}\160{}\160{}"]]
21−```
22−
23```
16```
24% pandoc -f latex -t native
17% pandoc -f latex -t native
25\SI{30}{\milli\meter}
18\SI{30}{\milli\meter}
@@ -38,7 +31,7 @@
38% pandoc -f latex -t native
31% pandoc -f latex -t native
39\SI{25}{\square\meter}
32\SI{25}{\square\meter}
40^D
33^D
41−[Para [Str "25\160m\178"]]
34+[Para [Str "25\160m",Superscript [Str "2"]]]
42```
35```
43
36
44```
37```
@@ -87,15 +80,53 @@
87[Para [Str "4.5\160\176C\8211\&97367265.5\160\176C"]]
80[Para [Str "4.5\160\176C\8211\&97367265.5\160\176C"]]
88```
81```
89
82
90−## Squared units
83+## Squared, cubed etc. units
91
84
92```
85```
93% pandoc -f latex -t native
86% pandoc -f latex -t native
94\SIrange{10}{20}{\square\meter}
87\SIrange{10}{20}{\square\meter}
95^D
88^D
96−[Para [Str "10\160m\178\8211\&20\160m\178"]]
89+[Para [Str "10\160m",Superscript [Str "2"],Str "\8211\&20\160m",Superscript [Str "2"]]]
97```
90```
98
91
92+```
93+% pandoc -f latex -t native
94+\SIrange{10}{20}{\cubic\meter}
95+^D
96+[Para [Str "10\160m",Superscript [Str "3"],Str "\8211\&20\160m",Superscript [Str "3"]]]
97+```
98+
99+```
100+% pandoc -f latex -t native
101+\SIrange{10}{20}{\raisetothe{4}\meter}
102+^D
103+[Para [Str "10\160m",Superscript [Str "4"],Str "\8211\&20\160m",Superscript [Str "4"]]]
104+```
105+
106+
107+```
108+% pandoc -f latex -t native
109+\SIrange{10}{20}{\meter\squared}
110+^D
111+[Para [Str "10\160m",Superscript [Str "2"],Str "\8211\&20\160m",Superscript [Str "2"]]]
112+```
113+
114+```
115+% pandoc -f latex -t native
116+\SIrange{10}{20}{\meter\cubed}
117+^D
118+[Para [Str "10\160m",Superscript [Str "3"],Str "\8211\&20\160m",Superscript [Str "3"]]]
119+```
120+
121+```
122+% pandoc -f latex -t native
123+\SIrange{10}{20}{\meter\tothe{4}}
124+^D
125+[Para [Str "10\160m",Superscript [Str "4"],Str "\8211\&20\160m",Superscript [Str "4"]]]
126+```
127+
128+
129+
99## Ignore round precision
130## Ignore round precision
100
131
101`round-precision` option appears to be ignored by `\SI` as of 7c6dbd37e, so
132`round-precision` option appears to be ignored by `\SI` as of 7c6dbd37e, so