primitiveMeanings :: HandleTeXIO m => [(Primitive, LexerT m [Token])]
primitiveMeanings =
  [ ("begingroup", [bgroupTok] <$ modifyState (pushGroup NativeGroup))
  , ("endgroup", [egroupTok] <$ modifyState (popGroup NativeGroup))
  , ("bgroup", [bgroupTok] <$ modifyState (pushGroup AnonymousGroup))
  , ("egroup", [egroupTok] <$ modifyState (popGroup AnonymousGroup))
  , ("(", return [mathTok])
  , (")", return [mathTok])
  , ("[", return (replicate 2 mathTok))
  , ("]", return (replicate 2 mathTok))
  , ("begin", beginEnvironment)
  , ("end", endEnvironment)
  , ("catcode", catcode)
  , ("def", def)
  , ("let", letmeaning)
  , ("iftrue", iftrue)
  , ("iffalse", iffalse)
  , ("char", count 1 chr)
  , ("number", numbertoks)
  , ("NewDocumentCommand", declareDocumentCommand MacroNew)
  , ("RenewDocumentCommand", declareDocumentCommand MacroRenew)
  , ("ProvideDocumentCommand", declareDocumentCommand MacroProvide)
  , ("DeclareDocumentCommand", declareDocumentCommand MacroDeclare)
  , ("NewDocumentEnvironment", declareDocumentEnvironment MacroNew)
  , ("RenewDocumentEnvironment", declareDocumentEnvironment MacroRenew)
  , ("ProvideDocumentEnvironment", declareDocumentEnvironment MacroProvide)
  , ("DeclareDocumentEnvironment", declareDocumentEnvironment MacroDeclare)
  , ("IfBooleanTF", xparseif trueTok)
  , ("IfNoValueTF", xparseif noValueTok)
  , ("newcommand", newcommand MacroNew)
  , ("renewcommand", newcommand MacroRenew)
  , ("providecommand", newcommand MacroProvide)
  , ("DeclareRobustCommand", newcommand MacroDeclare)
  , ("newenvironment", newenvironment MacroNew)
  , ("renewenvironment", newenvironment MacroRenew)
  , ("input", readInputFile)
  , ("include", readInputFile)
  , ("year", fmtDate "%Y")
  , ("month", fmtDate "%-m") -- no padding
  , ("day", fmtDate "%-d")   -- no padding
  , ("time", fmtTime)
  , ("meaning", meaning)
  , ("undefined", error "undefined control sequence")
  ]
primitiveMeanings :: HandleTeXIO m => [(Primitive, LexerT m [Token])]
primitiveMeanings =
  [ ("begingroup", [bgroupTok] <$ modifyState (pushGroup NativeGroup))
  , ("endgroup", [egroupTok] <$ modifyState (popGroup NativeGroup))
  , ("bgroup", [bgroupTok] <$ modifyState (pushGroup AnonymousGroup))
  , ("egroup", [egroupTok] <$ modifyState (popGroup AnonymousGroup))
  , ("(", return [mathTok])
  , (")", return [mathTok])
  , ("[", return (replicate 2 mathTok))
  , ("]", return (replicate 2 mathTok))
  , ("begin", beginEnvironment)
  , ("end", endEnvironment)
  , ("catcode", catcode)
  , ("def", def)
  , ("let", letmeaning)
  , ("iftrue", iftrue)
  , ("iffalse", iffalse)
  , ("char", count 1 chr)
  , ("number", numbertoks)
  , ("NewDocumentCommand", declareDocumentCommand MacroNew)
  , ("RenewDocumentCommand", declareDocumentCommand MacroRenew)
  , ("ProvideDocumentCommand", declareDocumentCommand MacroProvide)
  , ("DeclareDocumentCommand", declareDocumentCommand MacroDeclare)
  , ("NewDocumentEnvironment", declareDocumentEnvironment MacroNew)
  , ("RenewDocumentEnvironment", declareDocumentEnvironment MacroRenew)
  , ("ProvideDocumentEnvironment", declareDocumentEnvironment MacroProvide)
  , ("DeclareDocumentEnvironment", declareDocumentEnvironment MacroDeclare)
  , ("IfBooleanTF", xparseif trueTok)
  , ("IfNoValueTF", xparseif noValueTok)
  , ("newcommand", newcommand MacroNew)
  , ("renewcommand", newcommand MacroRenew)
  , ("providecommand", newcommand MacroProvide)
  , ("DeclareRobustCommand", newcommand MacroDeclare)
  , ("newenvironment", newenvironment MacroNew)
  , ("renewenvironment", newenvironment MacroRenew)
  , ("input", readInputFile)
  , ("include", readInputFile)
  , ("year", fmtDate "%Y")
  , ("month", fmtDate "%-m") -- no padding
  , ("day", fmtDate "%-d")   -- no padding
  , ("time", fmtTime)
  , ("meaning", meaning)
  , ("undefined", error "undefined control sequence")
  ]
primitiveMeanings =
  [ ("begingroup", [bgroupTok] <$ modifyState (pushGroup NativeGroup))
  , ("endgroup", [egroupTok] <$ modifyState (popGroup NativeGroup))
  , ("bgroup", [bgroupTok] <$ modifyState (pushGroup AnonymousGroup))
  , ("egroup", [egroupTok] <$ modifyState (popGroup AnonymousGroup))
  , ("(", return [mathTok])
  , (")", return [mathTok])
  , ("[", return (replicate 2 mathTok))
  , ("]", return (replicate 2 mathTok))
  , ("begin", beginEnvironment)
  , ("end", endEnvironment)
  , ("catcode", catcode)
  , ("def", def)
  , ("let", letmeaning)
  , ("iftrue", iftrue)
  , ("iffalse", iffalse)
  , ("char", count 1 chr)
  , ("number", numbertoks)
  , ("NewDocumentCommand", declareDocumentCommand MacroNew)
  , ("RenewDocumentCommand", declareDocumentCommand MacroRenew)
  , ("ProvideDocumentCommand", declareDocumentCommand MacroProvide)
  , ("DeclareDocumentCommand", declareDocumentCommand MacroDeclare)
  , ("NewDocumentEnvironment", declareDocumentEnvironment MacroNew)
  , ("RenewDocumentEnvironment", declareDocumentEnvironment MacroRenew)
  , ("ProvideDocumentEnvironment", declareDocumentEnvironment MacroProvide)
  , ("DeclareDocumentEnvironment", declareDocumentEnvironment MacroDeclare)
  , ("IfBooleanTF", xparseif trueTok)
  , ("IfNoValueTF", xparseif noValueTok)
  , ("newcommand", newcommand MacroNew)
  , ("renewcommand", newcommand MacroRenew)
  , ("providecommand", newcommand MacroProvide)
  , ("DeclareRobustCommand", newcommand MacroDeclare)
  , ("newenvironment", newenvironment MacroNew)
  , ("renewenvironment", newenvironment MacroRenew)
  , ("input", readInputFile)
  , ("include", readInputFile)
  , ("year", fmtDate "%Y")
  , ("month", fmtDate "%-m") -- no padding
  , ("day", fmtDate "%-d")   -- no padding
  , ("time", fmtTime)
  , ("meaning", meaning)
  , ("undefined", error "undefined control sequence")
  ]