diff options
author | John MacFarlane <jgm@berkeley.edu> | 2017-10-30 10:59:52 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2017-10-30 10:59:52 -0700 |
commit | 601a28fd3610f74a9353450bf3031eba4d94e73f (patch) | |
tree | 292138034a76db111aa555ea1551e0b5dc4c310b /src/Text | |
parent | 562e92954cc07be68b3aee765aa68ccce243948b (diff) | |
download | pandoc-601a28fd3610f74a9353450bf3031eba4d94e73f.tar.gz |
Allow body of macro definition to be unbraced.
e.g.
\newcommand\arrow\to
See #4007.
Diffstat (limited to 'src/Text')
-rw-r--r-- | src/Text/Pandoc/Readers/LaTeX.hs | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs index d6a3de2f1..0664a94aa 100644 --- a/src/Text/Pandoc/Readers/LaTeX.hs +++ b/src/Text/Pandoc/Readers/LaTeX.hs @@ -1824,7 +1824,7 @@ letmacro = do Tok _ (CtrlSeq name) _ <- anyControlSeq optional $ symbol '=' spaces - contents <- braced <|> ((:[]) <$> (anyControlSeq <|> singleChar)) + contents <- macroContents return (name, Macro ExpandWhenDefined 0 Nothing contents) defmacro :: PandocMonad m => LP m (Text, Macro) @@ -1832,7 +1832,9 @@ defmacro = try $ do controlSeq "def" Tok _ (CtrlSeq name) _ <- anyControlSeq numargs <- option 0 $ argSeq 1 - contents <- withVerbatimMode braced + -- we use withVerbatimMode, because macros are to be expanded + -- at point of use, not point of definition + contents <- withVerbatimMode macroContents return (name, Macro ExpandWhenUsed numargs Nothing contents) -- Note: we don't yet support fancy things like #1.#2 @@ -1846,6 +1848,9 @@ isArgTok :: Tok -> Bool isArgTok (Tok _ (Arg _) _) = True isArgTok _ = False +macroContents :: PandocMonad m => LP m [Tok] +macroContents = braced <|> ((:[]) <$> (anyControlSeq <|> singleChar)) + newcommand :: PandocMonad m => LP m (Text, Macro) newcommand = do pos <- getPosition @@ -1861,9 +1866,7 @@ newcommand = do spaces optarg <- option Nothing $ Just <$> try bracketedToks spaces - contents <- withVerbatimMode braced - -- we use withVerbatimMode, because macros are to be expanded - -- at point of use, not point of definition + contents <- withVerbatimMode macroContents when (mtype == "newcommand") $ do macros <- sMacros <$> getState case M.lookup name macros of @@ -1885,9 +1888,9 @@ newenvironment = do spaces optarg <- option Nothing $ Just <$> try bracketedToks spaces - startcontents <- withVerbatimMode braced + startcontents <- withVerbatimMode macroContents spaces - endcontents <- withVerbatimMode braced + endcontents <- withVerbatimMode macroContents when (mtype == "newenvironment") $ do macros <- sMacros <$> getState case M.lookup name macros of |