---------- Builtin macros: LaTeX2e macro definitions

-- Parse and register a LaTeX2e macro definition.
newcommand :: Monad m => MacroDefinitionMode -> LexerT m [Token]
newcommand defMode = do
  optional (char '*' Other) -- ignore 'long' property
  (CtrlSeq name active) <- optGrouped ctrlseqNoExpand <?> "macro name"
  context <- latexMacroContext
  body <- grouped tokensNoExpand <|> count 1 singleToken
  let key = (name, active)
  modifyState $ registerMacroCmd defMode
    (key, MacroCmdUser key context body)
  return []

-- Parse and register a LaTeX2e environment definition.
newcommand :: Monad m => MacroDefinitionMode -> LexerT m [Token]
newcommand defMode = do
  optional (char '*' Other) -- ignore 'long' property
  (CtrlSeq name active) <- optGrouped ctrlseqNoExpand <?> "macro name"
  context <- latexMacroContext
  body <- grouped tokensNoExpand <|> count 1 singleToken
  let key = (name, active)
  modifyState $ registerMacroCmd defMode
    (key, MacroCmdUser key context body)
  return []

-- Parse and register a LaTeX2e environment definition.
newcommand defMode = do
  optional (char '*' Other) -- ignore 'long' property
  (CtrlSeq name active) <- optGrouped ctrlseqNoExpand <?> "macro name"
  context <- latexMacroContext
  body <- grouped tokensNoExpand <|> count 1 singleToken
  let key = (name, active)
  modifyState $ registerMacroCmd defMode
    (key, MacroCmdUser key context body)
  return []

-- Parse and register a LaTeX2e environment definition.