git.iko.soy/typeable/pandoc
on master help sign in
Fix #4499: add mbox and hbox handling to LaTeX reader (#5586)
f6c92c7Vasily Alferov
src/Text/Pandoc/Readers/LaTeX.hs+11−1
@@ -29,7 +29,7 @@ import Prelude
29import Control.Applicative (many, optional, (<|>))
29import Control.Applicative (many, optional, (<|>))
30import Control.Monad
30import Control.Monad
31import Control.Monad.Except (throwError)
31import Control.Monad.Except (throwError)
32−import Data.Char (isDigit, isLetter, toLower, toUpper)
32+import Data.Char (isDigit, isLetter, toLower, toUpper, chr)
33import Data.Default
33import Data.Default
34import Data.List (intercalate, isPrefixOf)
34import Data.List (intercalate, isPrefixOf)
35import qualified Data.Map as M
35import qualified Data.Map as M
@@ -893,6 +893,8 @@ inlineCommands = M.union inlineLanguageCommands $ M.fromList
893 , ("cref", rawInlineOr "cref" $ doref "ref") -- from cleveref.sty
893 , ("cref", rawInlineOr "cref" $ doref "ref") -- from cleveref.sty
894 , ("vref", rawInlineOr "vref" $ doref "ref+page") -- from varioref.sty
894 , ("vref", rawInlineOr "vref" $ doref "ref+page") -- from varioref.sty
895 , ("eqref", rawInlineOr "eqref" $ doref "eqref") -- from amsmath.sty
895 , ("eqref", rawInlineOr "eqref" $ doref "eqref") -- from amsmath.sty
896+ , ("mbox", rawInlineOr "mbox" $ processHBox <$> tok)
897+ , ("hbox", rawInlineOr "hbox" $ processHBox <$> tok)
896 , ("lettrine", optional opt >> extractSpaces (spanWith ("",["lettrine"],[])) <$> tok)
898 , ("lettrine", optional opt >> extractSpaces (spanWith ("",["lettrine"],[])) <$> tok)
897 , ("(", mathInline . toksToString <$> manyTill anyTok (controlSeq ")"))
899 , ("(", mathInline . toksToString <$> manyTill anyTok (controlSeq ")"))
898 , ("[", mathDisplay . toksToString <$> manyTill anyTok (controlSeq "]"))
900 , ("[", mathDisplay . toksToString <$> manyTill anyTok (controlSeq "]"))
@@ -1287,6 +1289,14 @@ rawInlineOr name' fallback = do
1287 then rawInline "latex" <$> getRawCommand name' ("\\" <> name')
1289 then rawInline "latex" <$> getRawCommand name' ("\\" <> name')
1288 else fallback
1290 else fallback
1289
1291
1292+processHBox :: Inlines -> Inlines
1293+processHBox = walk convert
1294+ where
1295+ convert Space = Str [chr 160] -- non-breakable space
1296+ convert SoftBreak = Str [chr 160] -- non-breakable space
1297+ convert LineBreak = Str ""
1298+ convert x = x
1299+
1290getRawCommand :: PandocMonad m => Text -> Text -> LP m String
1300getRawCommand :: PandocMonad m => Text -> Text -> LP m String
1291getRawCommand name txt = do
1301getRawCommand name txt = do
1292 (_, rawargs) <- withRaw $
1302 (_, rawargs) <- withRaw $
test/command/4499.mdnew file+87
@@ -0,0 +1,87 @@
1+```
2+% pandoc -f latex -t html
3+\mbox{abc def} ghi
4+^D
5+<p>abc def ghi</p>
6+```
7+
8+```
9+% pandoc -f latex+raw_tex -t native
10+\mbox{abc def}
11+^D
12+[Para [RawInline (Format "latex") "\\mbox{abc def}"]]
13+```
14+
15+```
16+% pandoc -f latex -t html
17+abc \mbox{\textit{def ghi} jkl} mno
18+^D
19+<p>abc <em>def ghi</em> jkl mno</p>
20+```
21+
22+```
23+% pandoc -f latex -t html
24+abc \mbox{def \\ ghi} jkl
25+^D
26+<p>abc defghi jkl</p>
27+```
28+
29+```
30+% pandoc -f latex -t html
31+abc \mbox{def
32+ghi}
33+^D
34+<p>abc def ghi</p>
35+```
36+
37+```
38+% pandoc -f latex -t html
39+abc \mbox{def \textit{ghi \\ jkl}
40+mno} pqr
41+^D
42+<p>abc def <em>ghijkl</em> mno pqr</p>
43+```
44+
45+```
46+% pandoc -f latex -t html
47+\hbox{abc def} ghi
48+^D
49+<p>abc def ghi</p>
50+```
51+
52+```
53+% pandoc -f latex+raw_tex -t native
54+\hbox{abc def}
55+^D
56+[Para [RawInline (Format "latex") "\\hbox{abc def}"]]
57+```
58+
59+```
60+% pandoc -f latex -t html
61+abc \hbox{\textit{def ghi} jkl} mno
62+^D
63+<p>abc <em>def ghi</em> jkl mno</p>
64+```
65+
66+```
67+% pandoc -f latex -t html
68+abc \hbox{def \\ ghi} jkl
69+^D
70+<p>abc defghi jkl</p>
71+```
72+
73+```
74+% pandoc -f latex -t html
75+abc \hbox{def
76+ghi}
77+^D
78+<p>abc def ghi</p>
79+```
80+
81+```
82+% pandoc -f latex -t html
83+abc \hbox{def \textit{ghi \\ jkl}
84+mno} pqr
85+^D
86+<p>abc def <em>ghijkl</em> mno pqr</p>
87+```