git.iko.soy/typeable/pandoc
on master help sign in
Fixed latex macro parsing.

Now latex macro definitions are preserved when output is latex, and applied when it is another format, as originally intended. Partially addresses #730. \providecommand is still not supported. For this we need changes to texmath.

commit8c55023d188bb159b5309d817ba6d834a69e7b9c authorJohn MacFarlane <fiddlosopher@gmail.com> dateMon 28 Jan 2013, 10:50 (14 years ago) parentcc17c79
3 files changed+6−6
src/Text/Pandoc/Parsing.hs+4−4 src/Text/Pandoc/Readers/LaTeX.hs+1−1 src/Text/Pandoc/Readers/Markdown.hs+1−1
src/Text/Pandoc/Parsing.hs+4−4
@@ -148,7 +148,7 @@ where
148148
149149import Text.Pandoc.Definition
150150import Text.Pandoc.Options
151−import Text.Pandoc.Builder (Blocks, Inlines)
151+import Text.Pandoc.Builder (Blocks, Inlines, rawBlock)
152152import qualified Text.Pandoc.UTF8 as UTF8 (putStrLn)
153153import Text.Parsec
154154import Text.Parsec.Pos (newPos)
@@ -1007,7 +1007,7 @@ nested p = do
10071007--
10081008
10091009-- | Parse a \newcommand or \renewcommand macro definition.
1010−macro :: Parser [Char] ParserState Block
1010+macro :: Parser [Char] ParserState Blocks
10111011macro = do
10121012 apply <- getOption readerApplyMacros
10131013 inp <- getInput
@@ -1018,8 +1018,8 @@ macro = do
10181018 then do
10191019 updateState $ \st ->
10201020 st { stateMacros = ms ++ stateMacros st }
1021− return Null
1022− else return $ RawBlock "latex" def'
1021+ return mempty
1022+ else return $ rawBlock "latex" def'
10231023
10241024-- | Apply current macros to string.
10251025applyMacros' :: String -> Parser [Char] ParserState String
src/Text/Pandoc/Readers/LaTeX.hs+1−1
@@ -204,7 +204,7 @@ block :: LP Blocks
204204block = (mempty <$ comment)
205205 <|> (mempty <$ ((spaceChar <|> newline) *> spaces))
206206 <|> environment
207− <|> mempty <$ macro
207+ <|> macro
208208 <|> blockCommand
209209 <|> paragraph
210210 <|> grouped block
src/Text/Pandoc/Readers/Markdown.hs+1−1
@@ -355,7 +355,7 @@ parseBlocks = mconcat <$> manyTill block eof
355355
356356block :: MarkdownParser (F Blocks)
357357block = choice [ codeBlockFenced
358− , guardEnabled Ext_latex_macros *> (mempty <$ macro)
358+ , guardEnabled Ext_latex_macros *> (macro >>= return . return)
359359 , header
360360 , lhsCodeBlock
361361 , rawTeXBlock