expandUntil :: Expander -> TeXParser Token -> TeXParser [Token]
expandUntil expand stop =
  untilRec []
  where
    untilRec :: [Token] -> TeXParser [Token]
    untilRec revList =
      ((expand (lookAhead stop) >> (return $ reverse revList)) <|>
       (assignment expand >> untilRec revList) <|>
       (expand (categoryToken BeginGroup) >> beginGroup >> untilRec revList) <|>
       (expand (categoryToken EndGroup) >> endGroup >> untilRec revList) <|>
       (expand anyToken >>= (\tok -> untilRec (tok:revList))))
expandUntil :: Expander -> TeXParser Token -> TeXParser [Token]
expandUntil expand stop =
  untilRec []
  where
    untilRec :: [Token] -> TeXParser [Token]
    untilRec revList =
      ((expand (lookAhead stop) >> (return $ reverse revList)) <|>
       (assignment expand >> untilRec revList) <|>
       (expand (categoryToken BeginGroup) >> beginGroup >> untilRec revList) <|>
       (expand (categoryToken EndGroup) >> endGroup >> untilRec revList) <|>
       (expand anyToken >>= (\tok -> untilRec (tok:revList))))
expandUntil expand stop =
  untilRec []
  where
    untilRec :: [Token] -> TeXParser [Token]
    untilRec revList =
      ((expand (lookAhead stop) >> (return $ reverse revList)) <|>
       (assignment expand >> untilRec revList) <|>
       (expand (categoryToken BeginGroup) >> beginGroup >> untilRec revList) <|>
       (expand (categoryToken EndGroup) >> endGroup >> untilRec revList) <|>
       (expand anyToken >>= (\tok -> untilRec (tok:revList))))