@@ -389,13 +389,10 @@ doMacros = do
389389 expanded <- sExpanded <$> getState
390390 verbatimMode <- sVerbatimMode <$> getState
391391 unless (expanded || verbatimMode) $ do
392− mbNewInp <- getInput >>= doMacros' 1
393− case mbNewInp of
394− Nothing -> return ()
395− Just inp -> setInput inp
392+ getInput >>= doMacros' 1 >>= setInput
396393 updateState $ \st -> st{ sExpanded = True }
397394
398−doMacros' :: PandocMonad m => Int -> [Tok] -> LP m (Maybe [Tok])
395+doMacros' :: PandocMonad m => Int -> [Tok] -> LP m [Tok]
399396doMacros' n inp = do
400397 case inp of
401398 Tok spos (CtrlSeq "begin") _ : Tok _ Symbol "{" :
@@ -405,10 +402,11 @@ doMacros' n inp = do
405402 Tok _ Word name : Tok _ Symbol "}" : ts
406403 -> handleMacros n spos ("end" <> name) ts
407404 Tok _ (CtrlSeq "expandafter") _ : t : ts
408− -> (fmap (combineTok t)) <$> doMacros' n ts
405+ -> combineTok t <$> doMacros' n ts
409406 Tok spos (CtrlSeq name) _ : ts
410407 -> handleMacros n spos name ts
411− _ -> return Nothing
408+ _ -> return inp
409+ <|> return inp
412410
413411 where
414412 combineTok (Tok spos (CtrlSeq name) x) (Tok _ Word w : ts)
@@ -454,7 +452,7 @@ doMacros' n inp = do
454452 $ throwError $ PandocMacroLoop (T.unpack name)
455453 macros <- sMacros <$> getState
456454 case M.lookup name macros of
457− Nothing -> return Nothing
455+ Nothing -> mzero
458456 Just (Macro expansionPoint argspecs optarg newtoks) -> do
459457 let getargs' = do
460458 args <- case optarg of
@@ -475,9 +473,8 @@ doMacros' n inp = do
475473 -- expand #1 etc.)
476474 let result = foldr (addTok False args spos) rest newtoks
477475 case expansionPoint of
478− ExpandWhenUsed ->
479− maybe (Just result) Just <$> doMacros' (n' + 1) result
480− ExpandWhenDefined -> return $ Just result
476+ ExpandWhenUsed -> doMacros' (n' + 1) result
477+ ExpandWhenDefined -> return result
481478
482479setpos :: SourcePos -> Tok -> Tok
483480setpos spos (Tok _ tt txt) = Tok spos tt txt