CERN Accelerating science

This website is no longer maintained. Its content may be obsolete. Please visit for current CERN information.

next up previous
Next: For hackers only: Up: LaTeXeAn Overview Previous: Generalized parboxes and

Manipulating Boxed Material

Material can be typeset once and then stored inside a named box, so that its contents can be retrieved later. LaTeX offers the following commands for dealing with this situation.

\newsavebox{cmd}                  &  declare box   
\sbox{cmd}{text}                 &  fill box      
\savebox{cmd}[width][pos]{text}&  fill box      
\usebox{cmd}                      &  use contents  [1mm]
& fill box text \end{lrbox}

Note that the environment lrbox is an addition in LaTeXe. cmd should be a box register previously allocated with newsavebox. The environment lrbox will save text in this box for later use with usebox. Leading and trailing spaces are ignored. Thus, lrbox is basically the environment form of sbox. You can make good use of this environment if you want to save the body of some environment in a box for further processing. For example, the following code defines the environment fminipage that works like a minipage but surrounds its body with a frame. Note the use of the optional argument for controlling the width of the boxed minipage, and the fact that verbatim material can be used inside. To be able to do the arithmetic operations you will also need to have the calc package loaded.

    [1][\linewidth]% default width is \linewidth

  In this environment verbatim text like 
  \verb=\fminibox= can be used.


Janne Saarela
Wed May 17 14:38:58 METDST 1995