git.iko.soy/typeable/pandoc
on master help sign in
Better handle complex \def macros as raw latex.
commit6aef1bd228e7cb3369056bf47151787cc58c11d3 authorJohn MacFarlane <jgm@berkeley.edu> dateSun 13 Aug 2017, 12:45 (9 years ago) parent425b731
1 file changed+11−9
src/Text/Pandoc/Readers/LaTeX.hs+11−9
src/Text/Pandoc/Readers/LaTeX.hs+11−9
@@ -1075,7 +1075,7 @@ inlineCommand' = try $ do
10751075 let names = ordNub [name', name] -- check non-starred as fallback
10761076 let raw = do
10771077 guard $ isInlineCommand name || not (isBlockCommand name)
1078− rawcommand <- getRawCommand (cmd <> star)
1078+ rawcommand <- getRawCommand name (cmd <> star)
10791079 (guardEnabled Ext_raw_tex >> return (rawInline "latex" rawcommand))
10801080 <|> ignore rawcommand
10811081 lookupListDefault raw names inlineCommands
@@ -1421,20 +1421,22 @@ rawInlineOr :: PandocMonad m => Text -> LP m Inlines -> LP m Inlines
14211421rawInlineOr name' fallback = do
14221422 parseRaw <- extensionEnabled Ext_raw_tex <$> getOption readerExtensions
14231423 if parseRaw
1424− then rawInline "latex" <$> getRawCommand name'
1424+ then rawInline "latex" <$> getRawCommand name' ("\\" <> name')
14251425 else fallback
14261426
1427−getRawCommand :: PandocMonad m => Text -> LP m String
1428−getRawCommand txt = do
1427+getRawCommand :: PandocMonad m => Text -> Text -> LP m String
1428+getRawCommand name txt = do
14291429 (_, rawargs) <- withRaw $
1430− case txt of
1431− "\\write" -> do
1430+ case name of
1431+ "write" -> do
14321432 void $ satisfyTok isWordTok -- digits
14331433 void braced
1434− "\\titleformat" -> do
1434+ "titleformat" -> do
14351435 void braced
14361436 skipopts
14371437 void $ count 4 braced
1438+ "def" -> do
1439+ void $ manyTill anyTok braced
14381440 _ -> do
14391441 skipangles
14401442 skipopts
@@ -1759,7 +1761,7 @@ blockCommand = try $ do
17591761 let names = ordNub [name', name]
17601762 let rawDefiniteBlock = do
17611763 guard $ isBlockCommand name
1762− rawBlock "latex" <$> getRawCommand (txt <> star)
1764+ rawBlock "latex" <$> getRawCommand name (txt <> star)
17631765 -- heuristic: if it could be either block or inline, we
17641766 -- treat it if block if we have a sequence of block
17651767 -- commands followed by a newline. But we stop if we
@@ -1771,7 +1773,7 @@ blockCommand = try $ do
17711773 guard $ "start" `T.isPrefixOf` n
17721774 let rawMaybeBlock = try $ do
17731775 guard $ not $ isInlineCommand name
1774− curr <- rawBlock "latex" <$> getRawCommand (txt <> star)
1776+ curr <- rawBlock "latex" <$> getRawCommand name (txt <> star)
17751777 rest <- many $ notFollowedBy startCommand *> blockCommand
17761778 lookAhead $ blankline <|> startCommand
17771779 return $ curr <> mconcat rest