git.iko.soy/typeable/pandoc
on master help sign in
LaTeX reader: allow hspace and vspace to count as raw block or inline.

Previously we would refuse to parse anything as raw inline if it was in the blockCommands list. Now we allow exceptions if they're listed under ignoreInlines in inlineCommands. This should make it easier e.g. to include an \hspace between two side-by-side raw LaTeX tables.

commit7d0082aa0b631592f38fc9436a3d0dd5426653cf authorJohn MacFarlane <jgm@berkeley.edu> dateSat 25 Feb 2017, 12:40 (10 years ago) parentf1cf827
2 files changed+61−3
src/Text/Pandoc/Readers/LaTeX.hs+5−3 test/command/hspace.md+56
src/Text/Pandoc/Readers/LaTeX.hs+5−3
@@ -445,7 +445,6 @@ inlineCommand :: PandocMonad m => LP m Inlines
445445inlineCommand = try $ do
446446 (name, raw') <- withRaw anyControlSeq
447447 guard $ name /= "begin" && name /= "end"
448− guard $ not $ isBlockCommand name
449448 exts <- getOption readerExtensions
450449 star <- option "" (string "*")
451450 let name' = name ++ star
@@ -461,7 +460,7 @@ inlineCommand = try $ do
461460 else ignore rawcommand
462461 (lookupListDefault mzero [name',name] inlineCommands <*
463462 optional (try (string "{}")))
464− <|> raw
463+ <|> (guard (not (isBlockCommand name)) >> raw)
465464
466465unlessParseRaw :: PandocMonad m => LP m ()
467466unlessParseRaw = getOption readerExtensions >>=
@@ -648,7 +647,10 @@ inlineCommands = M.fromList $
648647 ] ++ map ignoreInlines
649648 -- these commands will be ignored unless --parse-raw is specified,
650649 -- in which case they will appear as raw latex blocks:
651− [ "index" ]
650+ [ "index"
651+ , "hspace"
652+ , "vspace"
653+ ]
652654
653655mkImage :: PandocMonad m => [(String, String)] -> String -> LP m Inlines
654656mkImage options src = do
test/command/hspace.mdnew file+56
@@ -0,0 +1,56 @@
1+`\hspace` and `\vspace` should count as both block and inline.
2+
3+Here they need to be inline:
4+```
5+% pandoc -f markdown+raw_tex -t native
6+\begin{figure}
7+\includegraphics{lalune.jpg}
8+\caption{lalune \hspace{2em} \vspace{1em} bloo}
9+\end{figure}
10+^D
11+[RawBlock (Format "latex") "\\begin{figure}\n\\includegraphics{lalune.jpg}\n\\caption{lalune \\hspace{2em} \\vspace{1em} bloo}\n\\end{figure}"]
12+```
13+
14+Here block:
15+```
16+% pandoc -f markdown+raw_tex -t native
17+\begin{tabular}[t]{cc|c}
18+\(P\) & \(Q\) & \(P\wedge Q\)\\
19+\hline
20+T & T &\\
21+T & F &\\
22+F & T &\\
23+F & F &\\
24+\end{tabular}
25+\hspace{1em}
26+\begin{tabular}[t]{cc|c}
27+\(P\) & \(Q\) & \(P\vee Q\)\\
28+\hline
29+T & T &\\
30+T & F &\\
31+F & T &\\
32+F & F &\\
33+\end{tabular}
34+^D
35+[RawBlock (Format "latex") "\\begin{tabular}[t]{cc|c}\n\\(P\\) & \\(Q\\) & \\(P\\wedge Q\\)\\\\\n\\hline\nT & T &\\\\\nT & F &\\\\\nF & T &\\\\\nF & F &\\\\\n\\end{tabular}\\hspace{1em}\\begin{tabular}[t]{cc|c}\n\\(P\\) & \\(Q\\) & \\(P\\vee Q\\)\\\\\n\\hline\nT & T &\\\\\nT & F &\\\\\nF & T &\\\\\nF & F &\\\\\n\\end{tabular}"]
36+```
37+
38+```
39+% pandoc -f markdown+raw_tex -t native
40+hi\hspace{1em}there
41+^D
42+[Para [Str "hi",RawInline (Format "tex") "\\hspace{1em}",Str "there"]]
43+```
44+
45+```
46+% pandoc -f markdown+raw_tex -t native
47+hi
48+
49+\hspace{1em}
50+
51+there
52+^D
53+[Para [Str "hi"]
54+,RawBlock (Format "latex") "\\hspace{1em}"
55+,Para [Str "there"]]
56+```