I'm trying to make a function that takes an argument and returns the number of words in the argument, once it is expanded.
Something along the lines of \wordcount{Some text goes here with \macros{abc} goes here.}
, that expands to an arabic numeral counting the words.
It doesn't have to be too advanced, or completely perfect, I was just planning to count the number of spaces and add one. But what I'm struggling with is finding a way to fully expand that argument before counting the words. There are a couple of questions on here about fully expanding an argument, but they mostly mention \expandafter, which in my experience doesn't seem to work if there are multiple levels of macros.
What is the best way to fully expand an argument to a function, so that I can count the number of spaces in it. Or is there a better way to achieve this for this use case?
\expandafter\wordcount\expandafter{\expanded{..........}}
will fully expand the argument\expandafter\wordcount\expanded{{..........}}
works too and is a bit shorter.