I need to count number of words in a macro defined as follow:

\def\columnNames{MATRIX, METHODA, METHODB}

I manually set number of words as follow:


I need an automatic way to find number of words in a macro. The list is separated with commas ",".

I have found several solutions (1,2,...). However, I was not able to adapt to my situation.

1 Answer 1


The 'word count' element here is not important: all you require is a method to find the 'length' of a comma-separated list. That's relatively easy to do, but as expl3 provides a pre-defined solution I'd use that approach

\cs_new_eq:NN \commalistlength \clist_count:N

\def\columnNames{MATRIX, METHODA, METHODB}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .