@@ -1824,7 +1824,7 @@ letmacro = do
18241824 Tok _ (CtrlSeq name) _ <- anyControlSeq
18251825 optional $ symbol '='
18261826 spaces
1827− contents <- braced <|> ((:[]) <$> (anyControlSeq <|> singleChar))
1827+ contents <- macroContents
18281828 return (name, Macro ExpandWhenDefined 0 Nothing contents)
18291829
18301830defmacro :: PandocMonad m => LP m (Text, Macro)
@@ -1832,7 +1832,9 @@ defmacro = try $ do
18321832 controlSeq "def"
18331833 Tok _ (CtrlSeq name) _ <- anyControlSeq
18341834 numargs <- option 0 $ argSeq 1
1835− contents <- withVerbatimMode braced
1835+ -- we use withVerbatimMode, because macros are to be expanded
1836+ -- at point of use, not point of definition
1837+ contents <- withVerbatimMode macroContents
18361838 return (name, Macro ExpandWhenUsed numargs Nothing contents)
18371839
18381840-- Note: we don't yet support fancy things like #1.#2
@@ -1846,6 +1848,9 @@ isArgTok :: Tok -> Bool
18461848isArgTok (Tok _ (Arg _) _) = True
18471849isArgTok _ = False
18481850
1851+macroContents :: PandocMonad m => LP m [Tok]
1852+macroContents = braced <|> ((:[]) <$> (anyControlSeq <|> singleChar))
1853+
18491854newcommand :: PandocMonad m => LP m (Text, Macro)
18501855newcommand = do
18511856 pos <- getPosition
@@ -1861,9 +1866,7 @@ newcommand = do
18611866 spaces
18621867 optarg <- option Nothing $ Just <$> try bracketedToks
18631868 spaces
1864− contents <- withVerbatimMode braced
1865− -- we use withVerbatimMode, because macros are to be expanded
1866− -- at point of use, not point of definition
1869+ contents <- withVerbatimMode macroContents
18671870 when (mtype == "newcommand") $ do
18681871 macros <- sMacros <$> getState
18691872 case M.lookup name macros of
@@ -1885,9 +1888,9 @@ newenvironment = do
18851888 spaces
18861889 optarg <- option Nothing $ Just <$> try bracketedToks
18871890 spaces
1888− startcontents <- withVerbatimMode braced
1891+ startcontents <- withVerbatimMode macroContents
18891892 spaces
1890− endcontents <- withVerbatimMode braced
1893+ endcontents <- withVerbatimMode macroContents
18911894 when (mtype == "newenvironment") $ do
18921895 macros <- sMacros <$> getState
18931896 case M.lookup name macros of