GeneralWhy \newsavebox, \usebox, \savebox instead of \newcommand?

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
dl3fo3
Posts: 10
Joined: Mon Jan 05, 2009 4:35 pm

Why \newsavebox, \usebox, \savebox instead of \newcommand?

Post by dl3fo3 »

Why use \newsavebox, \usebox, \savebox when \newcommand seems to do the job too?

\newsavebox, \usebox, and \savebox :

Code: Select all

% Create the holders we will need for our work
\newlength{\mytitleheight}
\newsavebox{\mytitletext}
% Create the reference text for measures
\savebox{\mytitletext}{%
  \Large\bfseries This is our title%
}
\settoheight{\mytitleheight}{\usebox{\mytitletext}}
% Now creates the actual object in our document
\framebox[\textwidth][l]{%
  \rule{5em}{\mytitleheight}%
  \hspace{2mm}%
  \usebox{\mytitletext}%
}

Doing the same with \newcommand:

Code: Select all

\newlength{\mahtitleheight}
\newcommand{\mahtitletext}{%
  \Large\bfseries This is ahr title%
}
\settoheight{\mahtitleheight}{\mahtitletext}
\framebox[\textwidth][l]{%
  \rule{5em}{\mahtitleheight}%
  \hspace{2mm}%
  \mahtitletext%
}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Post Reply