aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2017-08-13 12:45:04 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2017-08-13 12:45:04 -0700
commit6aef1bd228e7cb3369056bf47151787cc58c11d3 (patch)
tree48a7ec54beb2f4eaa7b531946c0689229b2e418b
parent425b731050f48739749cd99c29c15aa011dbcabb (diff)
downloadpandoc-6aef1bd228e7cb3369056bf47151787cc58c11d3.tar.gz
Better handle complex \def macros as raw latex.
-rw-r--r--src/Text/Pandoc/Readers/LaTeX.hs20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs
index 0edfc498d..986547f42 100644
--- a/src/Text/Pandoc/Readers/LaTeX.hs
+++ b/src/Text/Pandoc/Readers/LaTeX.hs
@@ -1075,7 +1075,7 @@ inlineCommand' = try $ do
let names = ordNub [name', name] -- check non-starred as fallback
let raw = do
guard $ isInlineCommand name || not (isBlockCommand name)
- rawcommand <- getRawCommand (cmd <> star)
+ rawcommand <- getRawCommand name (cmd <> star)
(guardEnabled Ext_raw_tex >> return (rawInline "latex" rawcommand))
<|> ignore rawcommand
lookupListDefault raw names inlineCommands
@@ -1421,20 +1421,22 @@ rawInlineOr :: PandocMonad m => Text -> LP m Inlines -> LP m Inlines
rawInlineOr name' fallback = do
parseRaw <- extensionEnabled Ext_raw_tex <$> getOption readerExtensions
if parseRaw
- then rawInline "latex" <$> getRawCommand name'
+ then rawInline "latex" <$> getRawCommand name' ("\\" <> name')
else fallback
-getRawCommand :: PandocMonad m => Text -> LP m String
-getRawCommand txt = do
+getRawCommand :: PandocMonad m => Text -> Text -> LP m String
+getRawCommand name txt = do
(_, rawargs) <- withRaw $
- case txt of
- "\\write" -> do
+ case name of
+ "write" -> do
void $ satisfyTok isWordTok -- digits
void braced
- "\\titleformat" -> do
+ "titleformat" -> do
void braced
skipopts
void $ count 4 braced
+ "def" -> do
+ void $ manyTill anyTok braced
_ -> do
skipangles
skipopts
@@ -1759,7 +1761,7 @@ blockCommand = try $ do
let names = ordNub [name', name]
let rawDefiniteBlock = do
guard $ isBlockCommand name
- rawBlock "latex" <$> getRawCommand (txt <> star)
+ rawBlock "latex" <$> getRawCommand name (txt <> star)
-- heuristic: if it could be either block or inline, we
-- treat it if block if we have a sequence of block
-- commands followed by a newline. But we stop if we
@@ -1771,7 +1773,7 @@ blockCommand = try $ do
guard $ "start" `T.isPrefixOf` n
let rawMaybeBlock = try $ do
guard $ not $ isInlineCommand name
- curr <- rawBlock "latex" <$> getRawCommand (txt <> star)
+ curr <- rawBlock "latex" <$> getRawCommand name (txt <> star)
rest <- many $ notFollowedBy startCommand *> blockCommand
lookAhead $ blankline <|> startCommand
return $ curr <> mconcat rest