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

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

Post Reply