Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question

1 Answer 1

up vote 6 down vote accepted

You're short some expansion inside \wbox:

enter image description here

\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}
share|improve this answer
2  
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.