[Tex/LaTex] Reasons for saving a box

boxesmacros

I've been reading through a number of answers that use \newsavebox to save the contents of a box. As far as I can tell it's a workaround for fragility of some kind. Is that right? If not, what is the point of saving a box?

Best Answer

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.)

Related Question