aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikolay Yakimov <root@livid.pp.ru>2015-03-21 22:39:07 +0300
committerNikolay Yakimov <root@livid.pp.ru>2015-03-30 05:37:00 +0300
commitf3e8274d0425b3bf7a2459a2d88af585b491507f (patch)
tree91ec28f8ec2b3b63114ec2f442cc4fe04a45caf5
parent34c6ff1f602cefa6c68af096a69bd1483e613606 (diff)
downloadpandoc-f3e8274d0425b3bf7a2459a2d88af585b491507f.tar.gz
LaTeX Reader: check for block-level newcommand aliases in blockCommand
-rw-r--r--src/Text/Pandoc/Readers/LaTeX.hs16
-rw-r--r--tests/latex-reader.latex19
-rw-r--r--tests/latex-reader.native6
3 files changed, 37 insertions, 4 deletions
diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs
index a517f9566..4d50ec4ed 100644
--- a/src/Text/Pandoc/Readers/LaTeX.hs
+++ b/src/Text/Pandoc/Readers/LaTeX.hs
@@ -239,17 +239,28 @@ block = (mempty <$ comment)
blocks :: LP Blocks
blocks = mconcat <$> many block
+getRawCommand :: String -> LP String
+getRawCommand name' = do
+ rawargs <- withRaw (skipopts *> option "" dimenarg *> many braced)
+ return $ '\\' : name' ++ snd rawargs
+
blockCommand :: LP Blocks
blockCommand = try $ do
name <- anyControlSeq
guard $ name /= "begin" && name /= "end"
star <- option "" (string "*" <* optional sp)
let name' = name ++ star
+ let raw = do
+ rawcommand <- getRawCommand name'
+ transformed <- applyMacros' rawcommand
+ if transformed /= rawcommand
+ then parseFromString blocks transformed
+ else mzero
case M.lookup name' blockCommands of
Just p -> p
Nothing -> case M.lookup name blockCommands of
Just p -> p
- Nothing -> mzero
+ Nothing -> raw
inBrackets :: Inlines -> Inlines
inBrackets x = (str "[") <> x <> (str "]")
@@ -385,8 +396,7 @@ inlineCommand = try $ do
star <- option "" (string "*")
let name' = name ++ star
let raw = do
- rawargs <- withRaw (skipopts *> option "" dimenarg *> many braced)
- let rawcommand = '\\' : name ++ star ++ snd rawargs
+ rawcommand <- getRawCommand name'
transformed <- applyMacros' rawcommand
if transformed /= rawcommand
then parseFromString inlines transformed
diff --git a/tests/latex-reader.latex b/tests/latex-reader.latex
index 2ebdfed99..0e5983d6a 100644
--- a/tests/latex-reader.latex
+++ b/tests/latex-reader.latex
@@ -845,4 +845,23 @@ indented.
\$ \% \& \# \_ \{ \}
+\section{Block newcommands}
+
+See e.g. issues #1866, #1835
+
+\newcommand{\FIG}[3]{
+ \begin{figure}[h!]
+ \centering
+ \includegraphics[width=#2\columnwidth,angle=0]{#1}
+ \caption{#3}
+ \label{fig:#1}
+ \end{figure}
+}
+
+\newcommand{\separator}{\vspace{4em}}
+
+\separator
+
+\FIG{lalune.jpg}{0.5}{Test caption}
+
\end{document}
diff --git a/tests/latex-reader.native b/tests/latex-reader.native
index abc4b05a7..2cc6508de 100644
--- a/tests/latex-reader.native
+++ b/tests/latex-reader.native
@@ -372,4 +372,8 @@ Pandoc (Meta {unMeta = fromList [("author",MetaList [MetaInlines [Str "John",Spa
[[Para [Str "And",Space,Str "in",Space,Str "list",Space,Str "items.",Note [Para [Str "In",Space,Str "list."]]]]]
,Para [Str "This",Space,Str "paragraph",Space,Str "should",Space,Str "not",Space,Str "be",Space,Str "part",Space,Str "of",Space,Str "the",Space,Str "note,",Space,Str "as",Space,Str "it",Space,Str "is",Space,Str "not",Space,Str "indented."]
,Header 1 ("escaped-characters",[],[]) [Str "Escaped",Space,Str "characters"]
-,Para [Str "$",Space,Str "%",Space,Str "&",Space,Str "#",Space,Str "_",Space,Str "{",Space,Str "}"]]
+,Para [Str "$",Space,Str "%",Space,Str "&",Space,Str "#",Space,Str "_",Space,Str "{",Space,Str "}"]
+,Header 1 ("block-newcommands",[],[]) [Str "Block",Space,Str "newcommands"]
+,Para [Str "See",Space,Str "e.g.",Space,Str "issues",Space,Str "#1866,",Space,Str "#1835"]
+,RawBlock (Format "latex") "\\vspace{4em}"
+,Para [RawInline (Format "latex") "\\centering",Image [Str "Test",Space,Str "caption",Span ("",[],[("data-label","fig:lalune.jpg")]) []] ("lalune.jpg","fig:")]]