Reasons for saving a box?
Box usage isn't (normally) related to fragility. Boxes (and glue) are the fundamental typesetting constructs that TeX uses. All of TeX's typesetting is done by positioning boxes. Saving a box (as opposed to saving a command) means that you are saving a fragment of typeset text rather than saving a list of tokens to be executed. As mentioned in comments there are many reasons for wanting to do that. It might be to measure the width of some typeset construct, it might be that executing the commands is very costly in terms of execution time and you want to re-set copies of the same result multiple times, or it may just be that you want to pass a typeset fragment to another command (such as \fbox
where it is more convenient to first set the contents into a box rather than directly as a command argument (perhaps because the contents involve verbatim material.)
i've used it to save and reuse a small graphic to replace the amsthm
proof "tombstone":
\newsavebox{\QEDbox}
\savebox{\QEDbox}{%
\raisebox{-3pt}{\includegraphics[scale=.7]{proofpicture}}}
\renewcommand{\qedsymbol}{\usebox{\QEDbox}}
relevant quote from the texbook (p.329):
It's much faster to copy a box than to build it up from scratch.
I can't name all of the situations to use a savebox
but one particular case that I've found it very useful is for aligning subfigures
The idea is to save the largest image into a box, which you can then measure to help with the \vfill
in the other subfigure
s. This allows the caption
and the images to remain aligned as you wish.
\documentclass{article}
\usepackage{tikz}
\usepackage{subcaption}
\newsavebox{\tempbox}
\begin{document}
% store the bigger of the pictures in a vbox
\sbox{\tempbox}{%
\begin{tikzpicture}
\draw circle (1.25cm) {};
\end{tikzpicture}%
}
\begin{figure}
\begin{subfigure}[t]{0.3\textwidth}
\centering
% use the save box
\usebox{\tempbox}
\caption{Biggest (using a savebox)}
\end{subfigure}%
\begin{subfigure}[t]{0.3\textwidth}
\centering
% for the other figures, you can use \vfill as follows
\vbox to\ht\tempbox{
\begin{tikzpicture}
\draw circle (.5cm) {};
\end{tikzpicture}%
\vfill
}
\caption{Top justified}
\end{subfigure}%
\begin{subfigure}[t]{0.3\textwidth}
\centering
% vertically centered
\vbox to\ht\tempbox{
\vfill
\begin{tikzpicture}
\draw circle (.5cm) {};
\end{tikzpicture}%
\vfill
}
\caption{Vertically centered}
\end{subfigure}%
\end{figure}
\end{document}