latexMacroContext :: Monad m => LexerT m ArgSpec
latexMacroContext = do
  numArgs <- option 0 (bracketed singleDigit)
  let open = mkOther '['
      close = mkOther ']'
  optArg <- optionMaybe (balanced open close)
  let context = case optArg of
        Just d -> OptionalGroup open close (Just d) :
                  replicate (numArgs-1) Mandatory
        Nothing -> replicate numArgs Mandatory
  return context

-------------------- Handle LaTeX environments (named groups)

-- Start TeX group and try to expand user-defined environment definitions.
latexMacroContext :: Monad m => LexerT m ArgSpec
latexMacroContext = do
  numArgs <- option 0 (bracketed singleDigit)
  let open = mkOther '['
      close = mkOther ']'
  optArg <- optionMaybe (balanced open close)
  let context = case optArg of
        Just d -> OptionalGroup open close (Just d) :
                  replicate (numArgs-1) Mandatory
        Nothing -> replicate numArgs Mandatory
  return context

-------------------- Handle LaTeX environments (named groups)

-- Start TeX group and try to expand user-defined environment definitions.
latexMacroContext = do
  numArgs <- option 0 (bracketed singleDigit)
  let open = mkOther '['
      close = mkOther ']'
  optArg <- optionMaybe (balanced open close)
  let context = case optArg of
        Just d -> OptionalGroup open close (Just d) :
                  replicate (numArgs-1) Mandatory
        Nothing -> replicate numArgs Mandatory
  return context

-------------------- Handle LaTeX environments (named groups)

-- Start TeX group and try to expand user-defined environment definitions.