git.iko.soy/typeable/pandoc
on master help sign in
Fix #4499: add mbox and hbox handling to LaTeX reader (#5586)

When `+raw_tex` is enabled, these are passed through literally. Otherwise, they are handled in a way that emulates LaTeX's behavior.

commitf6c92c7523a4070f13fbf193ef80ad7ac63f6693 authorVasily Alferov <ya-ikmik2012@yandex.ru> dateSun 14 Jul 2019, 02:55 (7 years ago) parent7bc9eab
2 files changed+98−1
src/Text/Pandoc/Readers/LaTeX.hs+11−1 test/command/4499.md+87
src/Text/Pandoc/Readers/LaTeX.hs+11−1
@@ -29,7 +29,7 @@ import Prelude
2929import Control.Applicative (many, optional, (<|>))
3030import Control.Monad
3131import Control.Monad.Except (throwError)
32−import Data.Char (isDigit, isLetter, toLower, toUpper)
32+import Data.Char (isDigit, isLetter, toLower, toUpper, chr)
3333import Data.Default
3434import Data.List (intercalate, isPrefixOf)
3535import qualified Data.Map as M
@@ -893,6 +893,8 @@ inlineCommands = M.union inlineLanguageCommands $ M.fromList
893893 , ("cref", rawInlineOr "cref" $ doref "ref") -- from cleveref.sty
894894 , ("vref", rawInlineOr "vref" $ doref "ref+page") -- from varioref.sty
895895 , ("eqref", rawInlineOr "eqref" $ doref "eqref") -- from amsmath.sty
896+ , ("mbox", rawInlineOr "mbox" $ processHBox <$> tok)
897+ , ("hbox", rawInlineOr "hbox" $ processHBox <$> tok)
896898 , ("lettrine", optional opt >> extractSpaces (spanWith ("",["lettrine"],[])) <$> tok)
897899 , ("(", mathInline . toksToString <$> manyTill anyTok (controlSeq ")"))
898900 , ("[", mathDisplay . toksToString <$> manyTill anyTok (controlSeq "]"))
@@ -1287,6 +1289,14 @@ rawInlineOr name' fallback = do
12871289 then rawInline "latex" <$> getRawCommand name' ("\\" <> name')
12881290 else fallback
12891291
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+
12901300getRawCommand :: PandocMonad m => Text -> Text -> LP m String
12911301getRawCommand name txt = do
12921302 (_, 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+```