| 1 |
% \iffalse |
| 2 |
%% |
| 3 |
%% File: desclist.dtx Copyright (C) 2002--2004 by Alexander I. Rozhenko |
| 4 |
%% |
| 5 |
%<package>\NeedsTeXFormat{LaTeX2e} |
| 6 |
%<package>\ProvidesPackage{desclist} |
| 7 |
%<package> [2004/11/23 v1.1 Desclist Package (NCC)] |
| 8 |
% |
| 9 |
% \changes{v1.0}{2002/01/09}{This version was uploaded to CTAN} |
| 10 |
% \changes{v1.1}{2004/11/21}{Desclist suffix was enclosed in braces} |
| 11 |
% \changes{v1.1}{2004/11/23}{Documentation was prepared} |
| 12 |
% |
| 13 |
%<*driver> |
| 14 |
\let\makeindex\relax |
| 15 |
\documentclass{ltxdoc} |
| 16 |
\usepackage{desclist} |
| 17 |
\GetFileInfo{desclist.sty} |
| 18 |
\begin{document} |
| 19 |
\title{The \textsf{desclist} package\thanks{This file |
| 20 |
has version number \fileversion, last |
| 21 |
revised \filedate.}} |
| 22 |
\author{Alexander I. Rozhenko\\[email protected]} |
| 23 |
\date{\filedate} |
| 24 |
\maketitle |
| 25 |
\DocInput{desclist.dtx} |
| 26 |
\end{document} |
| 27 |
%</driver> |
| 28 |
% \fi |
| 29 |
% The package implements the |desclist| environment and redefines |
| 30 |
% the |description| environment to provide an optional parameter |
| 31 |
% as a prototype for calculation the hang indent of the list. |
| 32 |
% |
| 33 |
% \tableofcontents |
| 34 |
% |
| 35 |
% \section{User Interface} |
| 36 |
% |
| 37 |
% \DescribeMacro{desclist} |
| 38 |
% The |desclist| environment is similar to the |description| |
| 39 |
% environment but adds more control for typesetting list labels. |
| 40 |
% The usage: |
| 41 |
% \begin{quote} |
| 42 |
% |\begin{desclist}|\marg{prefix}\marg{suffix}\oarg{prototype}\\ |
| 43 |
% |\item|\oarg{label} \meta{text}\\ |
| 44 |
% \ldots\\ |
| 45 |
% |\end{desclist}| |
| 46 |
% \end{quote} |
| 47 |
% The \meta{prefix} is inserted before the label and the suffix |
| 48 |
% is inserted after the label. The optional \meta{prototype} parameter |
| 49 |
% specifies a prototype for calculation the minimum width of a list label |
| 50 |
% and for calculation the hang indent of a list text. |
| 51 |
% If this parameter is omitted, the standard hang indent value is used |
| 52 |
% and the minimum width of list labels is equal to zero. |
| 53 |
% |
| 54 |
% A list label is generated in the |\item|\oarg{label} command |
| 55 |
% as follows: |
| 56 |
% \begin{quote} |
| 57 |
% \meta{prefix}\meta{label}\marg{suffix}|\hfil| |
| 58 |
% \end{quote} |
| 59 |
% Therefore, you can finish the \meta{label} with a command having a parameter |
| 60 |
% to replace a suffix with something else. The |\hfil| command at the end of |
| 61 |
% label adds necessary horizontal space if the label width is less than the |
| 62 |
% minimum width of list label. Using a \meta{prototype} together with the |
| 63 |
% |\hfill| command in \meta{prefix} and/or \meta{suffix} |
| 64 |
% parameters, you can align left, align right, or center narrow list labels. |
| 65 |
% |
| 66 |
% The following example shows the benefits of the |desclist| environment: |
| 67 |
% \begin{desclist}{\sf}{ \rm\hfill---}[Mark] |
| 68 |
% \newcommand*\Skip[1]{} |
| 69 |
% \item[M] an item with a narrow label; |
| 70 |
% \item[MM] an item with a narrow label; |
| 71 |
% \item[Mark] an item with a normal label; |
| 72 |
% \item[Long mark] an item with too wide label; and |
| 73 |
% \item[A mark without dash.\Skip] Here we skip the desclist suffix. |
| 74 |
% \end{desclist} |
| 75 |
% It was prepared as follows: |
| 76 |
% \begin{quote} |
| 77 |
% |\begin{desclist}{\sf}{ \rm\hfill---}[Mark]|\\ |
| 78 |
% |\newcommand*\Skip[1]{}|\\ |
| 79 |
% |\item[M] an item with a narrow label;|\\ |
| 80 |
% |\item[MM] an item with a narrow label;|\\ |
| 81 |
% |\item[Mark] an item with a normal label;|\\ |
| 82 |
% |\item[Long mark] an item with too wide label; and|\\ |
| 83 |
% |\item[A mark without dash.\Skip] Here we skip|\\ |
| 84 |
% |the desclist suffix.|\\ |
| 85 |
% |\end{desclist}| |
| 86 |
% \end{quote} |
| 87 |
% |
| 88 |
% \DescribeMacro{description} |
| 89 |
% The package also redefines the |description| environment to allow |
| 90 |
% an optional parameter. In fact, the new implementation of |description| |
| 91 |
% is equivalent to |
| 92 |
% \begin{quote} |
| 93 |
% |\begin{desclist}{\normalfont\bfseries}{}|\oarg{prototype}\\ |
| 94 |
% \ldots\\ |
| 95 |
% |\end{desclist}| |
| 96 |
% \end{quote} |
| 97 |
% \StopEventually{} |
| 98 |
% |
| 99 |
% \section{The Implementation} |
| 100 |
% \begin{macro}{desclist} |
| 101 |
% The definition of the |desclist| environment is quite simple. |
| 102 |
% If an optional parameter is omitted, pass an empty one |
| 103 |
% to the internal command. |
| 104 |
% \begin{macrocode} |
| 105 |
%<*package> |
| 106 |
\newenvironment*{desclist}[2]{% |
| 107 |
\@ifnextchar[{\NCC@dlist{#1}{#2}}{\NCC@dlist{#1}{#2}[]}% |
| 108 |
}{% |
| 109 |
\endlist |
| 110 |
} |
| 111 |
% \end{macrocode} |
| 112 |
% \end{macro} |
| 113 |
% |
| 114 |
% \begin{macro}{\NCC@dlist} |
| 115 |
% The internal definition of the |desclist| is based on the |\list|: |
| 116 |
% \begin{macrocode} |
| 117 |
\def\NCC@dlist#1#2[#3]{% |
| 118 |
\list{}{% |
| 119 |
% \end{macrocode} |
| 120 |
% Specify just the same list parameters as in the |description| |
| 121 |
% if the optional parameter is empty: |
| 122 |
% \begin{macrocode} |
| 123 |
\def\@tempa{#3}\ifx\@tempa\@empty |
| 124 |
\labelwidth\z@ \itemindent-\leftmargin |
| 125 |
% \end{macrocode} |
| 126 |
% In other case, use the prototype to calculate the label width |
| 127 |
% and margins: |
| 128 |
% \begin{macrocode} |
| 129 |
\else |
| 130 |
\settowidth\leftmargin{#1#3{#2}}% |
| 131 |
\advance\leftmargin\labelsep |
| 132 |
\labelwidth=\leftmargin |
| 133 |
\itemindent\z@ |
| 134 |
\fi |
| 135 |
% \end{macrocode} |
| 136 |
% Finally, define the |\makelabel| command adding the desclist |
| 137 |
% prefix and suffix and finishing it with |\hfil| to allow left |
| 138 |
% alignment for narrow labels. The suffix is enclosed in braces, |
| 139 |
% to allow a trick with ignoring it in the label mark if necessary |
| 140 |
% (see the example above): |
| 141 |
% \begin{macrocode} |
| 142 |
\def\makelabel##1{\hspace\labelsep #1##1{#2}\hfil}% |
| 143 |
}% |
| 144 |
} |
| 145 |
% \end{macrocode} |
| 146 |
% \end{macro} |
| 147 |
% |
| 148 |
% \begin{macro}{description} |
| 149 |
% Now we redefine the |description| environment. We do not test |
| 150 |
% is it defined or not. |
| 151 |
% \begin{macrocode} |
| 152 |
\def\description{\desclist{\normalfont\bfseries}{}} |
| 153 |
\let\enddescription=\enddesclist |
| 154 |
%</package> |
| 155 |
% \end{macrocode} |
| 156 |
% \end{macro} |
| 157 |
\endinput |