diff options
author | John MacFarlane <jgm@berkeley.edu> | 2019-09-02 21:03:05 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2019-09-02 21:03:05 -0700 |
commit | 6b286a1d74dd145d08565aaf85e2273ac9e7cef0 (patch) | |
tree | f10ba74265b6d830e8db051a5926c9dbb3f4e14f | |
parent | d79242796b5bfa24788d30b239de3b15c0ed326c (diff) | |
download | pandoc-6b286a1d74dd145d08565aaf85e2273ac9e7cef0.tar.gz |
LaTeX reader: don't try to parse includes if raw_tex is set.
When the `raw_tex` extension is set, we just carry through
`\usepackage`, `\input`, etc. verbatim as raw LaTeX.
Closes #5673.
-rw-r--r-- | src/Text/Pandoc/Readers/LaTeX.hs | 18 | ||||
-rw-r--r-- | test/command/3530.md | 7 |
2 files changed, 15 insertions, 10 deletions
diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs index 76a48a364..18bfebabb 100644 --- a/src/Text/Pandoc/Readers/LaTeX.hs +++ b/src/Text/Pandoc/Readers/LaTeX.hs @@ -1152,7 +1152,7 @@ inlineCommands = M.union inlineLanguageCommands $ M.fromList -- babel , ("foreignlanguage", foreignlanguage) -- include - , ("input", include "input") + , ("input", rawInlineOr "input" $ include "input") -- soul package , ("ul", underlineSpan <$> tok) -- ulem package @@ -1468,6 +1468,14 @@ paragraph = do then return mempty else return $ para x +rawBlockOr :: PandocMonad m => Text -> LP m Blocks -> LP m Blocks +rawBlockOr name fallback = do + -- if raw_tex allowed, don't process + parseRaw <- extensionEnabled Ext_raw_tex <$> getOption readerExtensions + if parseRaw + then rawBlock "latex" <$> getRawCommand name ("\\" <> name) + else fallback + include :: (PandocMonad m, Monoid a) => Text -> LP m a include name = do skipMany opt @@ -1838,10 +1846,10 @@ blockCommands = M.fromList , ("hyphenblockquote", braced >>= blockquote False . Just . untokenize) , ("hyphenblockcquote", braced >>= blockquote True . Just . untokenize) -- include - , ("include", include "include") - , ("input", include "input") - , ("subfile", include "subfile") - , ("usepackage", include "usepackage") + , ("include", rawBlockOr "include" $ include "include") + , ("input", rawBlockOr "input" $ include "input") + , ("subfile", rawBlockOr "subfile" $ include "subfile") + , ("usepackage", rawBlockOr "usepackage" $ include "usepackage") -- preamble , ("PackageError", mempty <$ (braced >> braced >> braced)) -- epigraph package diff --git a/test/command/3530.md b/test/command/3530.md index 66393c856..178b36ff0 100644 --- a/test/command/3530.md +++ b/test/command/3530.md @@ -14,9 +14,6 @@ \subfile{command/sub-file-chapter-1} \subfile{command/sub-file-chapter-2} ^D -[Header 1 ("chapter-1",[],[]) [Str "Chapter",Space,Str "1"] -,Para [Str "This",Space,Str "is",Space,Str "Chapter",Space,Str "1,",Space,Str "provided",Space,Str "in",Space,Str "a",Space,Str "sub",Space,Str "file."] -,Header 1 ("chapter-2",[],[]) [Str "Chapter",Space,Str "2"] -,Para [Str "This",Space,Str "is",Space,Str "Chapter",Space,Str "2,",Space,Str "provided",Space,Str "in",Space,Str "a",Space,Str "second",Space,Str "sub",Space,Str "file."]] - +[RawBlock (Format "latex") "\\subfile{command/sub-file-chapter-1}" +,RawBlock (Format "latex") "\\subfile{command/sub-file-chapter-2}"] ``` |