% next word parser, based on http://tex.stackexchange.com/a/11925/15107 \makeatletter \def\consumenextword#1{% \begingroup \let\@cmd#1% \def\@selectedword{}% \consumenextword@ } \def\consumenextword@{% \futurelet\ntoken\consumenextword@@ } \def\consumenextword@@{% \ifcase 0% \ifx\ntoken\@sptoken 0\else \ifcat a\ntoken 1\else \ifcat 0\ntoken 2\fi% test of token is catcode "other" \fi\fi \relax \expandafter\consumenextword@end \or \expandafter\consumenextword@add \else \expandafter\consumenextword@checknum \fi } % Checks if token is a number (ASCII 48-57) \def\consumenextword@checknum#1{% \ifcase 0% \ifnum`#1>47 \ifnum`#1<58 1\fi\fi \relax \def\next{\consumenextword@end#1}% \else \def\next{\consumenextword@add{#1}}% \fi \next } \def\consumenextword@add#1{% \edef\@selectedword{\@selectedword#1}% \consumenextword@ } \def\consumenextword@end{% \@cmd\@selectedword% \endgroup% } \makeatother