# A macro that passes each word of its argument to another macro as an argument (again)

I know that this is a duplicate to A macro that passes each word of its argument to another macro as an argument?, that's why I kept the title, but I didn't manage to get the right result when the argument that contained the words is given also as a macro.

See the code below:

\documentclass{minimal}%
\begin{document}

\def\somefigures{1 2 3 4 5 6 7 8 9}
\def\wbox#1{\boxw#1 \empty}
\def\boxw#1 #2{\fbox{#1}\ \ifx #2\empty\else\expandafter\boxw\fi #2}

\wbox{1 2 3 4 5 6 7 8 9}\bigskip

\wbox{\somefigures}

\end{document}

-

You're short some expansion inside \wbox:

\documentclass{article}%
\begin{document}

\def\somefigures{1 2 3 4 5 6 7 8 9}
\def\wbox#1{\expandafter\boxw#1 \empty}% expanded #1 first
\def\boxw#1 #2{\fbox{#1}\ \ifx #2\empty\else\expandafter\boxw\fi #2}

\wbox{1 2 3 4 5 6 7 8 9}\bigskip

\wbox{\somefigures}

\end{document}

-
Assuming that there is no issue with the expansion of tokens, of course: don't try \wbox{\textbf} for example. – Joseph Wright May 16 '12 at 14:07
It worked. What if I want something like \wbox{\textbf{\somefigures}} (following what @JosephWright said)? – digital-Ink May 16 '12 at 14:27
@digital-Ink Use \textbf{\wbox{\somefigures}} – egreg May 16 '12 at 14:55