---------- Builtin macros: LaTeX3 (xparse) macro definitions

-- Parse and register an xparse macro definition.
declareDocumentCommand :: HandleTeXIO m => MacroDefinitionMode -> LexerT m [Token]
declareDocumentCommand defMode = do
  (CtrlSeq name active) <- optGrouped ctrlseqNoExpand <?> "macro name"
  context <- argspec <?> "macro argspec"
  body <- grouped tokensNoExpand
  let key = (name, active)
  modifyState $ registerMacroCmd defMode
    (key, MacroCmdUser key context body)
  return []

-- Parse and register an xparse environment definition.
declareDocumentCommand :: HandleTeXIO m => MacroDefinitionMode -> LexerT m [Token]
declareDocumentCommand defMode = do
  (CtrlSeq name active) <- optGrouped ctrlseqNoExpand <?> "macro name"
  context <- argspec <?> "macro argspec"
  body <- grouped tokensNoExpand
  let key = (name, active)
  modifyState $ registerMacroCmd defMode
    (key, MacroCmdUser key context body)
  return []

-- Parse and register an xparse environment definition.
declareDocumentCommand defMode = do
  (CtrlSeq name active) <- optGrouped ctrlseqNoExpand <?> "macro name"
  context <- argspec <?> "macro argspec"
  body <- grouped tokensNoExpand
  let key = (name, active)
  modifyState $ registerMacroCmd defMode
    (key, MacroCmdUser key context body)
  return []

-- Parse and register an xparse environment definition.