# Prevent macro expansion within setbox

Following code is the quintessence of a problem i'm facing:

\documentclass{minimal}

\newbox\boxa
\newbox\boxb
\newbox\boxc
\parindent=0pt

\begin{document}

\setbox\boxc\hbox{Hello World!}

\def\foobar{MIST}

\setbox\boxa=\hbox{\foobar\space A}

\def\foobar{MOST}
\setbox\boxb=\hbox{\foobar\space B}

\setbox\boxc=\hbox{\unhbox\boxc\space \unhbox\boxa\space \unhbox\boxb.}

\unhbox\boxc
\end{document}


with the desired output being

Hello World! MOST A MOST B.


but i only get

Hello World! MIST A MOST B.


Is it technically possible to get the desired output by doing magic on \setbox\boxa only?

• no............. – user4686 Nov 29 '18 at 9:01
• only way is to define all kinds of boxes you need, and when defining \boxc use some conditional to \unhbox only those you want at that spot. but macros are expanded when the box is build and there is no undoing that or doing it again. – user4686 Nov 29 '18 at 9:04
• you can get what you need by saving macros, not by saving boxes. A box contains typeset text there is no tex control structure in a box at all – David Carlisle Nov 29 '18 at 9:44
• @DavidCarlisle i cannot measure the size of macro contents, can i? – Lupino Nov 29 '18 at 9:58
• macro contents do not have a size, they are just a list of tokens but at any point you can typeset them to a box and measure the result – David Carlisle Nov 29 '18 at 10:54