Manipulate unbalanced lists of tokens in LaTeX