# CERN Accelerating science

This website is no longer maintained. Its content may be obsolete. Please visit http://home.cern/ for current CERN information.

Next: Font commands---an overview Up: LaTeXeAn Overview Previous: Manipulating Boxed Material

## For hackers only: several optional arguments

What if we want to define a command or environment with, eg. two optional arguments? Suppose we want a list where we are able to specify not only the width of the label, but also whether the list should be dense'' or not, ie. we want a syntax like:

\begin{Description}[<margin>][<style>]

In this case we use a trick (and the packages calc and ifthen) and introduce a multiple-step definition. The example also shows how one can parameterize the various typographic parameters for the list so that they can be controlled more easily (eg. the alignment of the label, its font, and the width of the margin).

\newcommand{\Descriptionlabel}[1]{%
\mbox{\Descriptionfont #1}\hfil}

\newcommand\Descriptionfont{\itshape}
\newcommand\Descriptionmargin{}

\newenvironment{Description}[1][\kern\leftmargin]
{\renewcommand\Descriptionmargin{#1}\xdescription}
{\endlist}

\newcommand{\xdescription}[1][normal]{%
\list{}{\settowidth{\labelwidth}%
{\mbox{\Descriptionfont\Descriptionmargin}}%
\setlength{\itemindent}{0pt}%
\setlength{\leftmargin}{\labelwidth+\labelsep}%
\let\makelabel\Descriptionlabel
\ifthenelse{\equal{#1}{compact}}%
{\setlength{\itemsep}{0pt}%
\setlength{\topsep}{.5\topsep}}{}%
}}

[] #1 <1543>>

[normal] #} #1compact

Text before text before text before text before
\begin{Description}
\item[First] This is the first item in the list.
\item[Veryyy long] This is a veryyy long item.
\item[] This is an empty item.
\end{Description}

\begin{Description}[Veryyy long]
...
\end{Description}

\begin{Description}[Veryyy long][compact]
...
\end{Description}

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