newenvironment :: HandleTeXIO m => MacroDefinitionMode -> LexerT m [Token]
newenvironment defMode = do
  name <- grouped tokens <?> "environment name"
  context <- latexMacroContext
  startCode <- grouped tokensNoExpand <?> "environment start code"
  endCode <- grouped tokensNoExpand <?> "environment end code"
  modifyState $ registerMacroEnv defMode
    (name, MacroEnv name context startCode endCode)
  return []

-- Parse a LaTeX2e macro context definition and
-- convert it to an xparse-style ArgSpec.
newenvironment :: HandleTeXIO m => MacroDefinitionMode -> LexerT m [Token]
newenvironment defMode = do
  name <- grouped tokens <?> "environment name"
  context <- latexMacroContext
  startCode <- grouped tokensNoExpand <?> "environment start code"
  endCode <- grouped tokensNoExpand <?> "environment end code"
  modifyState $ registerMacroEnv defMode
    (name, MacroEnv name context startCode endCode)
  return []

-- Parse a LaTeX2e macro context definition and
-- convert it to an xparse-style ArgSpec.
newenvironment defMode = do
  name <- grouped tokens <?> "environment name"
  context <- latexMacroContext
  startCode <- grouped tokensNoExpand <?> "environment start code"
  endCode <- grouped tokensNoExpand <?> "environment end code"
  modifyState $ registerMacroEnv defMode
    (name, MacroEnv name context startCode endCode)
  return []

-- Parse a LaTeX2e macro context definition and
-- convert it to an xparse-style ArgSpec.