| 1 |
% \iffalse meta-comment |
| 2 |
% |
| 3 |
% Copyright (C) 2008 by |
| 4 |
% Antoine Lejay <Antoine dot Lejay at iecn dot u-nancy dot fr> |
| 5 |
% |
| 6 |
% Based on ltxref.dtx of the Latex Kernel (Copyright the LaTeX 3 project). |
| 7 |
% |
| 8 |
% This work may be distributed and/or modified under the |
| 9 |
% conditions of the LaTeX Project Public License, either |
| 10 |
% version 1.3c of this license or (at your option) any later |
| 11 |
% version. The latest version of this license is in |
| 12 |
% http://www.latex-project.org/lppl.txt |
| 13 |
% and version 1.3c or later is part of all distributions of |
| 14 |
% LaTeX version 2005/12/01 or later. |
| 15 |
% |
| 16 |
% This work has the LPPL maintenance status `maintained.' |
| 17 |
% |
| 18 |
% The current maintainer of this work is Antoine Lejay. |
| 19 |
% |
| 20 |
% This work consists of the source file constants.dtx |
| 21 |
% and the derived files constants.ins, |
| 22 |
% constants.sty, |
| 23 |
% constants.pdf, |
| 24 |
% \fi |
| 25 |
% \iffalse |
| 26 |
%<*driver> |
| 27 |
\documentclass[a4paper]{ltxdoc} |
| 28 |
\EnableCrossrefs |
| 29 |
\CodelineIndex |
| 30 |
\RecordChanges |
| 31 |
%\OnlyDescription |
| 32 |
\usepackage[latin1]{inputenc} |
| 33 |
\usepackage[T1]{fontenc} |
| 34 |
\usepackage[english]{babel} |
| 35 |
\usepackage{fancyvrb} |
| 36 |
%\usepackage[dvipdfm]{hyperref} |
| 37 |
\usepackage{hyperref} |
| 38 |
\usepackage{constants} |
| 39 |
\hypersetup{ |
| 40 |
pdftitle={The constants package}, |
| 41 |
pdfauthor={Antoine Lejay} |
| 42 |
} |
| 43 |
\newcommand{\parenthezises}[1]{(\arabic{#1})} |
| 44 |
\newconstantfamily{example1}{ |
| 45 |
symbol=K, |
| 46 |
format=\parenthezises, |
| 47 |
reset={section} |
| 48 |
} |
| 49 |
\newcommand{\family}{$\langle$\textsl{family}$\rangle$} |
| 50 |
\newcommand{\cstpage}{$\langle$\textsl{page}$\rangle$} |
| 51 |
\newcommand{\cstlabel}{$\langle$\textsl{label}$\rangle$} |
| 52 |
\newcommand{\cstnumber}{$\langle$\textsl{number}$\rangle$} |
| 53 |
|
| 54 |
\begin{document} |
| 55 |
\DocInput{\jobname.dtx} |
| 56 |
\PrintIndex |
| 57 |
\PrintChanges |
| 58 |
\end{document} |
| 59 |
%</driver> |
| 60 |
% |
| 61 |
% \fi |
| 62 |
% |
| 63 |
% \CheckSum{0} |
| 64 |
% |
| 65 |
% \CharacterTable |
| 66 |
% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z |
| 67 |
% Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z |
| 68 |
% Digits \0\1\2\3\4\5\6\7\8\9 |
| 69 |
% Exclamation \! Double quote \" Hash (number) \# |
| 70 |
% Dollar \$ Percent \% Ampersand \& |
| 71 |
% Acute accent \' Left paren \( Right paren \) |
| 72 |
% Asterisk \* Plus \+ Comma \, |
| 73 |
% Minus \- Point \. Solidus \/ |
| 74 |
% Colon \: Semicolon \; Less than \< |
| 75 |
% Equals \= Greater than \> Question mark \? |
| 76 |
% Commercial at \@ Left bracket \[ Backslash \\ |
| 77 |
% Right bracket \] Circumflex \^ Underscore \_ |
| 78 |
% Grave accent \` Left brace \{ Vertical bar \| |
| 79 |
% Right brace \} Tilde \~} |
| 80 |
% |
| 81 |
%\changes{1.0}{2008/03/25}{First released} |
| 82 |
% |
| 83 |
%\GetFileInfo{\jobname.sty} |
| 84 |
%\DoNotIndex{\@auxout,\@@end,\@empty,\@latex@warning,\@latex@warning@no@line} |
| 85 |
%\DoNotIndex{\@mainaux,\@namedef,\@nameuse,\AtEndDocument,\begingroup,\endgroup} |
| 86 |
%\DoNotIndex{\csname,\endcsname,\expandafter,\elseif,\def,\closeout,\if,\fi} |
| 87 |
%\DoNotIndex{\gdef,\global,\if@filesw,\if@tempswa,\ifx,\immediate,\input} |
| 88 |
%\DoNotIndex{\makeatletter,\NeedsTeXFormat,\newcommand,\newcounter,\jobname} |
| 89 |
%\DoNotIndex{\setcounter,\nfss@text,\null,\RequirePackage,\reset@font} |
| 90 |
%\DoNotIndex{\textbf,\textrm,\textsuperscript,\thepage,\z@,\stepcounter} |
| 91 |
%\DoNotIndex{\space,\string,\relax,\clearpage,\deadcycles,\else,\long,\let} |
| 92 |
%\DoNotIndex{\PackageError,\PackageInfo,\protect,\protected@edef,\protected@write} |
| 93 |
%\DoNotIndex{\ProvidesPackage,\@bsphack,\@esphack,\@gobbletwo,\@ifundefined} |
| 94 |
%\DoNotIndex{\@tempswfalse,\@testdef,\bfseries} |
| 95 |
%\MakeShortVerb{\|} |
| 96 |
% |
| 97 |
% \title{\texttt{\filename},\\ a package for automatic numbering\\ of constants% |
| 98 |
% \thanks{This file describes version \fileversion, last revised |
| 99 |
% \filedate.}} |
| 100 |
% \author{Antoine Lejay} |
| 101 |
% \date{Released \filedate} |
| 102 |
% |
| 103 |
% \maketitle |
| 104 |
% |
| 105 |
% \begin{abstract} |
| 106 |
% This set of macros aims to provide a way to number automatically |
| 107 |
% constants in a mathematical proof |
| 108 |
% with a system for labelling/referencing. In addition, |
| 109 |
% several families of constants (with different symbols) may be defined. |
| 110 |
% \end{abstract} |
| 111 |
% |
| 112 |
%\begin{multicols}{2} |
| 113 |
% \footnotesize |
| 114 |
% \tableofcontents |
| 115 |
%\end{multicols} |
| 116 |
% \section{Introduction} |
| 117 |
% |
| 118 |
% Some domains of mathematics such as the theory of (partial) |
| 119 |
% differential equations heavily rely on inequalities, and many |
| 120 |
% proofs are done by writing down a long sequence of inequalities |
| 121 |
% involving constants that may change from line to line. |
| 122 |
% Thus, a standard redaction trick consists in starting a proof |
| 123 |
% by the statement |
| 124 |
% \begin{quote} |
| 125 |
% Let $C$ denotes a constants that varies |
| 126 |
% from line to line. |
| 127 |
% \end{quote} |
| 128 |
% However, it is sometimes necessary |
| 129 |
% to get more informations about the involved constants. |
| 130 |
% Thus, either one has to finds different symbols, to the risk of |
| 131 |
% introduce some confusions in the notations, or to labels the |
| 132 |
% constants. Of course, manual labelling is not that easy, |
| 133 |
% especially at the early stages of redaction. |
| 134 |
% |
| 135 |
% The aim of this package is then to provide an automatic |
| 136 |
% way to incrementally label the constants with numbers. |
| 137 |
% In addition, it offers the possibility to |
| 138 |
% label the constants with a mechanism similar to |
| 139 |
% |\label| and |\ref|. Finally, it is possible to |
| 140 |
% define several families of constants with different |
| 141 |
% rules for printing. |
| 142 |
% |
| 143 |
% \paragraph{Dependencies: } this package uses the |keyval| |
| 144 |
% package of the \emph{graphic bundle} (which is in every standard distribution). |
| 145 |
% |
| 146 |
% \section{Basic usage} |
| 147 |
% |
| 148 |
% \DescribeMacro{\C} |
| 149 |
% The most basic usage of this package consists in calling |
| 150 |
% the macro |\C| in math mode, that prints $C_1$ for the first time, $C_2$ |
| 151 |
% for the second time, ... |
| 152 |
% |
| 153 |
% \DescribeMacro{\Cl} |
| 154 |
% The macro |\Cl| is similar to |\C| except that it takes |
| 155 |
% a mandatory argument which is a label's name, for |
| 156 |
% example |\Cl{cst-1}|. The number of the constant which |
| 157 |
% is then printed is recorded and written in the |.aux| file. |
| 158 |
% Note that |\label{cst-1}| does not interact with |
| 159 |
% and |\Cl{cst-1}|, that is |
| 160 |
% the labels for constants are treated in a specific way |
| 161 |
% and can be only accessed through the command |\Cr| below. |
| 162 |
% |
| 163 |
% \DescribeMacro{\Cr} |
| 164 |
% The macro |\Cr| takes a mandatory argument which |
| 165 |
% shall be the name of a label defined by |\Cl|. |
| 166 |
% As for standard labels in \LaTeX, if |\Cr| calls |
| 167 |
% a label that have not yet been defined are, then |
| 168 |
% the result is replaced by ``\textrm{C\textsuperscript{st}\textbf{??}}''. |
| 169 |
% A message is written at the end of the compilation to indicate |
| 170 |
% the need of a second compilation to get all the references right. |
| 171 |
% |
| 172 |
% \DescribeMacro{\pagerefconstant} |
| 173 |
% This macros takes the label of a constant as a mandatory |
| 174 |
% argument and returns the page were the constant is. |
| 175 |
% |
| 176 |
% \DescribeMacro{\resetconstant} |
| 177 |
% This macros resets the counter of constants, so that the |
| 178 |
% next call to |\C| will print again $C_1$. |
| 179 |
% |
| 180 |
% \section{Family of constants} |
| 181 |
% |
| 182 |
% What if one whishes to use two families of |
| 183 |
% constants $\C[example1]$, $\C[example1]$, ... and $\C$, $\C$, ... |
| 184 |
% in the same document, and that the $K_{(i)}$'s are reseted |
| 185 |
% at each new section? A possibility consists then in defining |
| 186 |
% a new family of constant using the following code in the preamble. |
| 187 |
% \begin{verbatim} |
| 188 |
%\newcommand{\parenthezises}[1]{(\arabic{#1})} |
| 189 |
%\newconstantfamily{example1}{ |
| 190 |
% symbol=K, |
| 191 |
% format=\parenthezises, |
| 192 |
% reset={section} |
| 193 |
%} |
| 194 |
% \end{verbatim} |
| 195 |
% |
| 196 |
% \subsection{Defining a family} |
| 197 |
% |
| 198 |
% \DescribeMacro{\newconstantfamily} |
| 199 |
% The macro |\newconstantfamily| allows one to define a new |
| 200 |
% family of constants. Its first argument is the name of the |
| 201 |
% family, while the second argument uses the key-value principle. |
| 202 |
% |
| 203 |
% The key |symbol| is for the symbol that is used. |
| 204 |
% The key |format| shall takes as argument a command |
| 205 |
% with one argument that can be applied to a counter |
| 206 |
% (such as |\alph|, |\roman|, ...), or any user-defined command |
| 207 |
% such a |\parenthezises| above. |
| 208 |
% The key |reset| takes the name of a counter and thus |
| 209 |
% the counter for this family of constants is reseted |
| 210 |
% each time the corresponding counter is stepped by one. |
| 211 |
% Note that several |reset| key may be used (technically, |
| 212 |
% it adds the name of the counter to a list of counters to be reseted |
| 213 |
% each time a given counter is stepped). |
| 214 |
% Here, possible names are |section|, |subsection|, |equation|, ... |
| 215 |
% |
| 216 |
% By default, there is one family which is defined, whose |
| 217 |
% name is |normal|. |
| 218 |
% |
| 219 |
% If a key is missing, then the corresponding standard values are used |
| 220 |
% (that is |symbol=C|, |format=\arabic| and no |reset| key). |
| 221 |
% |
| 222 |
% \DescribeMacro{\renewconstantfamily} |
| 223 |
% If |\newconstantfamily| is called upon a family name that |
| 224 |
% has been already defined, then the compilers stops and |
| 225 |
% returns an error message. The |\renewconstantfamily| |
| 226 |
% (still to be used in the preamble) |
| 227 |
% allows one to override the behavior of a family |
| 228 |
% without getting an arror message. Using |normal| as |
| 229 |
% a family name, one can get replace the standard behavior |
| 230 |
% of |\C|. |
| 231 |
% |
| 232 |
% \subsection{Using a family} |
| 233 |
% |
| 234 |
% \DescribeMacro{\C} |
| 235 |
% \DescribeMacro{\Cl} |
| 236 |
% \DescribeMacro{\Cr} |
| 237 |
% \DescribeMacro{\pagerefconstant} |
| 238 |
% Using a family is simple: it is sufficient to |
| 239 |
% call |\C| and |\Cl| with an optional argument |
| 240 |
% which is the family name (if the name is incorrect, |
| 241 |
% an error message is printed), that is |
| 242 |
% |\C[example1]| and |\Cl[example1]{cst-2}| |
| 243 |
% to get $\C[example1]$ and~$\Cl[example1]{cst-2}$. |
| 244 |
% For |\Cr|, there is no need to call the family, |
| 245 |
% as it is stored with the family name. Thus, |
| 246 |
% |\Cr{cst-2}| will print $\Cr{cst-2}$. The macro |
| 247 |
% |\pagerefconstant| also do not need any reference |
| 248 |
% to a family name. |
| 249 |
% |
| 250 |
% \DescribeMacro{\resetconstant} |
| 251 |
% The command |\resetconstant| also accepts the family |
| 252 |
% name as an optional argument. |
| 253 |
% |
| 254 |
% |
| 255 |
% \iffalse |
| 256 |
%<*package> |
| 257 |
% \fi |
| 258 |
% \section{The code} |
| 259 |
% \label{sec-1} |
| 260 |
% |
| 261 |
% The mechanism of labelling constants is similar |
| 262 |
% to the mechanism used by the standard \LaTeX\ |
| 263 |
% |\label| and |\ref| mechanism (see the files |source2e.pdf|, |
| 264 |
% |latex.ltx| and |ltxref.dtx|), excepted that |
| 265 |
% the family of the constant is taken into |
| 266 |
% account. |
| 267 |
% |
| 268 |
% This works the following way: |
| 269 |
% \begin{enumerate} |
| 270 |
% \item The |aux| file is read first. If a line of type |
| 271 |
% \begin{quote} |
| 272 |
% |\newlabelconstant{|\cstlabel|}{{|\cstnumber|}{|\cstpage|}{|\family|}}| |
| 273 |
% \end{quote} |
| 274 |
% is found, then a new macro |\cstr@|\cstlabel\ is created. This |
| 275 |
% macro shall expand into |
| 276 |
% \begin{quote} |
| 277 |
% |{{|\cstnumber|}{|\cstpage|}{|\family|}}| |
| 278 |
% \end{quote} |
| 279 |
% where \cstnumber\ is the number of the constant, |
| 280 |
% \cstpage\ is the page were it appears and \family\ is its family name. |
| 281 |
% |
| 282 |
% \item When a reference \cstlabel\ to a constant is found (call |
| 283 |
% of |\Cr{|\cstlabel|}|), then |
| 284 |
% \TeX\ determines if |\cstr@|\cstlabel\ is already defined. |
| 285 |
% If not, then it prints a symbol for unknown constants and send |
| 286 |
% a warning message. |
| 287 |
% |
| 288 |
% \item When a label to a constant is defined (call of |
| 289 |
% |\Cr[\family]{|\cstlabel|}|), then \TeX\ writes into the |
| 290 |
% |aux| file the corresponding |\newlabelconstant| line. |
| 291 |
% |
| 292 |
% \item At the end of the document, the |aux| file is read |
| 293 |
% once to determined wether or not there the source file has |
| 294 |
% to be compiled or not. |
| 295 |
% \end{enumerate} |
| 296 |
% |
| 297 |
% |
| 298 |
% \subsection{Initialization} |
| 299 |
% |
| 300 |
% The initializaton call the package |keyval|. |
| 301 |
% |
| 302 |
% \begin{macrocode} |
| 303 |
\NeedsTeXFormat{LaTeX2e} |
| 304 |
\ProvidesPackage{constants}% |
| 305 |
[2008/03/25 v.1 Labeling and numbering constants] |
| 306 |
\PackageInfo{constants} |
| 307 |
{This package aims to label et number constants in a mathematical proof.} |
| 308 |
\RequirePackage{keyval} |
| 309 |
% \end{macrocode} |
| 310 |
% |
| 311 |
% \subsection{Macros associated to constants} |
| 312 |
% |
| 313 |
% When a family \family\ of constants is defined, several macros are |
| 314 |
% created, that are |\cst@family@|\family, to check the existence |
| 315 |
% of a family, |\cst@format@|\family, that takes a counter name as argument, |
| 316 |
% and |\cst@symbol@|\family, that expand into the symbol of the constant. |
| 317 |
% In addition, a counter |cst@counter@|\family\ is created. |
| 318 |
% |
| 319 |
% \subsection{Macros for testing existence of families} |
| 320 |
% |
| 321 |
% \DescribeMacro{\@if@constant@exists} |
| 322 |
% When a new family \family\ is defined, a macro |
| 323 |
% |\cst@family@|\family\ is defined, that expands to nothing. |
| 324 |
% |
| 325 |
% \begin{macrocode} |
| 326 |
\def\@if@constant@exists#1#2#3{\@ifundefined{cst@family@#1}{#3}{#2}} |
| 327 |
% \end{macrocode} |
| 328 |
% |
| 329 |
% \subsection{The family of constants \emph{normal}} |
| 330 |
% |
| 331 |
% The normal family is the family by default. The corresponding |
| 332 |
% macros are then defined. |
| 333 |
% |
| 334 |
% \begin{macrocode} |
| 335 |
\global\@namedef{cst@family@normal}{} |
| 336 |
\newcounter{cst@counter@normal} |
| 337 |
\def\cst@format@normal#1{\arabic{#1}} |
| 338 |
\def\cst@symbol@normal{C} |
| 339 |
% \end{macrocode} |
| 340 |
% |
| 341 |
% \subsection{Definition of families} |
| 342 |
% |
| 343 |
% \DescribeMacro{\newconstantfamily} |
| 344 |
% The macro |\newconstantfamily| defines the macros and counter |
| 345 |
% associated to a family. |
| 346 |
% \begin{macrocode} |
| 347 |
\newcommand{\newconstantfamily}[2]{ |
| 348 |
\@if@constant@exists{#1}{% |
| 349 |
\PackageError{constants}{The family of constants '#1' already exists}{% |
| 350 |
Use \protect\renewconstantfamily\space to override}}% |
| 351 |
{% |
| 352 |
\expandafter\def\csname cst@family@#1\endcsname{} |
| 353 |
\expandafter\def\csname cst@format@#1\endcsname{\cst@format@normal} |
| 354 |
\expandafter\def\csname cst@symbol@#1\endcsname{\cst@symbol@normal} |
| 355 |
\expandafter\newcounter{cst@counter@#1} |
| 356 |
\define@key{constants}{format}% |
| 357 |
{\expandafter\def\csname cst@format@#1\endcsname{##1}} |
| 358 |
\define@key{constants}{symbol}% |
| 359 |
{\expandafter\def\csname cst@symbol@#1\endcsname{##1}} |
| 360 |
\define@key{constants}{reset}{\@addtoreset{cst@counter@#1}{##1}} |
| 361 |
\setkeys{constants}{#2} |
| 362 |
}} |
| 363 |
% \end{macrocode} |
| 364 |
% |
| 365 |
% \DescribeMacro{\renewconstantfamily} |
| 366 |
% The |\renewconstantfamily| also redefines the macros associated to |
| 367 |
% constants, but does not re-create the counter. |
| 368 |
% |
| 369 |
% \begin{macrocode} |
| 370 |
\newcommand{\renewconstantfamily}[2]{ |
| 371 |
\@if@constant@exists{#1}{ |
| 372 |
\define@key{constants}{format}{% |
| 373 |
\expandafter\def\csname cst@format@#1\endcsname{##1}} |
| 374 |
\define@key{constants}{symbol}{% |
| 375 |
\expandafter\def\csname cst@symbol@#1\endcsname{##1}} |
| 376 |
\define@key{constants}{reset}{\@addtoreset{cst@counter@#1}{##1}} |
| 377 |
\setkeys{constants}{#2} |
| 378 |
}{% |
| 379 |
\PackageError{constants}{The family of constants '#1' already exists}{% |
| 380 |
Use \protect\renewconstantfamily\space to override}}% |
| 381 |
} |
| 382 |
% \end{macrocode} |
| 383 |
% |
| 384 |
% The macros |\newconstantfamily| and |\renewconstantfamily| |
| 385 |
% can only be called in the preamble. |
| 386 |
% |
| 387 |
% \begin{macrocode} |
| 388 |
\@onlypreamble\newconstantfamily |
| 389 |
\@onlypreamble\renewconstantfamily |
| 390 |
% \end{macrocode} |
| 391 |
% |
| 392 |
% \subsection{Reading constants informations} |
| 393 |
% |
| 394 |
% The following macros aims to read the informations |
| 395 |
% from the macro |\cstr@|\cstlabel\ (See Section~\ref{sec-1}). |
| 396 |
% |
| 397 |
% When constants informations are read from the |aux| file, |
| 398 |
% the format, deduced from the family name \family, |
| 399 |
% is put in |\cst@tmp@format| and the symbol is put |
| 400 |
% in |\cst@tmp@symbol|. By default, these macros expand into |
| 401 |
% |\cst@undefined@format| and |\cst@undefined@symbol|. |
| 402 |
% \begin{macrocode} |
| 403 |
\def\G@refundefinedconstanttrue{% |
| 404 |
\gdef\@refundefinedconstant{% |
| 405 |
\@latex@warning@no@line{% |
| 406 |
There were undefined references to constants}}} |
| 407 |
\let\@refundefinedconstant\relax |
| 408 |
\def\cst@tmp@format{cst@undefined@format} |
| 409 |
\def\cst@tmp@symbol{cst@undefined@symbol} |
| 410 |
% \end{macrocode} |
| 411 |
% |
| 412 |
% \DescribeMacro{\@firstofthree} |
| 413 |
% \DescribeMacro{\@secondofthree} |
| 414 |
% \DescribeMacro{\@thirdofthree} |
| 415 |
% These macros return respectively their first, second and third argument. |
| 416 |
% \begin{macrocode} |
| 417 |
\long\def\@firstofthree#1#2#3{#1} |
| 418 |
\long\def\@secondofthree#1#2#3{#2} |
| 419 |
\long\def\@thirdofthree#1#2#3{#3} |
| 420 |
% \end{macrocode} |
| 421 |
% |
| 422 |
% If a reference to a macro is not defined, then |
| 423 |
% the counter value is not expanded, while a |
| 424 |
% symbol ``\textrm{C\textsuperscript{st}\textbf{??}}'' is returned. |
| 425 |
% \begin{macrocode} |
| 426 |
\def\cst@undefined@format#1{} |
| 427 |
\def\cst@undefined@symbol{% |
| 428 |
\nfss@text{\reset@font\textrm{C\textsuperscript{st}\textbf{??}}}} |
| 429 |
% \end{macrocode} |
| 430 |
% |
| 431 |
% \DescribeMacro{\@setrefconstant} |
| 432 |
% This macro expands into one of the arguments of the constant. |
| 433 |
% The argument |#1| shall be of type |cstr@|\cstlabel, |
| 434 |
% the argument |#2| shall then be |\@firstofthree|, |
| 435 |
% |\@secondofthree| and |\@thirdofthree|. The third argument |
| 436 |
% |#3| expands into |{{|\cstnumber|}{|\cstpage|}{|\family|}}|. |
| 437 |
% If |cstr@|\cstlabel\ is not defined, then the package send |
| 438 |
% a warning and the macro expands to ``\textbf{??}''. |
| 439 |
% \begin{macrocode} |
| 440 |
\def\@setrefconstant#1#2#3{% |
| 441 |
\ifx#1\relax |
| 442 |
\protect\G@refundefinedconstanttrue |
| 443 |
\nfss@text{\reset@font\bfseries ??}% |
| 444 |
\@latex@warning{Reference to constant `#3' on page \thepage \space |
| 445 |
undefined}% |
| 446 |
\else |
| 447 |
\expandafter#2#1\null |
| 448 |
\fi} |
| 449 |
% \end{macrocode} |
| 450 |
% |
| 451 |
% \DescribeMacro{\@setfamconstant} |
| 452 |
% This macro is similar to |\@setrefconstant| but |
| 453 |
% initializes |\cst@tmp@format| and |\cst@tmp@symbol| |
| 454 |
% to |\cst@format@|\family\ and |\cst@fsymbol@|\family. |
| 455 |
% \begin{macrocode} |
| 456 |
\def\@setfamconstant#1#2#3{% |
| 457 |
\ifx#1\relax% |
| 458 |
\def\cst@tmp@format{cst@undefined@format}\null |
| 459 |
\def\cst@tmp@symbol{cst@undefined@symbol}\null |
| 460 |
\else% |
| 461 |
\def\cst@tmp@format{cst@format@\expandafter#2#1}\null |
| 462 |
\def\cst@tmp@symbol{cst@symbol@\expandafter#2#1}\null |
| 463 |
\fi} |
| 464 |
% \end{macrocode} |
| 465 |
% |
| 466 |
% \DescribeMacro{\@setcounterconstant} |
| 467 |
% This macro is similar to |\@setrefconstant| but |
| 468 |
% set the temporary counter |cst@tmp@counter| to |
| 469 |
% the value of \cstnumber. |
| 470 |
% \begin{macrocode} |
| 471 |
\newcounter{cst@tmp@counter} |
| 472 |
\def\@setcounterconstant#1#2#3{% |
| 473 |
\ifx#1\relax |
| 474 |
\protect\G@refundefinedconstanttrue |
| 475 |
\@latex@warning{Reference to constant `#3' on page \thepage \space |
| 476 |
undefined}% |
| 477 |
\else |
| 478 |
\setcounter{cst@tmp@counter}{\expandafter#2#1}\null |
| 479 |
\fi} |
| 480 |
% \end{macrocode} |
| 481 |
% |
| 482 |
% \DescribeMacro{\refconstant} |
| 483 |
% \DescribeMacro{\familyconstant} |
| 484 |
% \DescribeMacro{\counterconstant} |
| 485 |
% These macros are used to call |\@setrefconstant|, |\@setfamconstant| |
| 486 |
% and |\@setcounterconstant|. |
| 487 |
% \begin{macrocode} |
| 488 |
\def\refconstant#1{% |
| 489 |
\expandafter\@setrefconstant\csname cstr@#1\endcsname\@firstofthree{#1}} |
| 490 |
\def\familyconstant#1{% |
| 491 |
\expandafter\@setfamconstant\csname cstr@#1\endcsname\@thirdofthree{#1}} |
| 492 |
\def\counterconstant#1{% |
| 493 |
\expandafter\@setcounterconstant% |
| 494 |
\csname cstr@#1\endcsname\@firstofthree{#1}} |
| 495 |
% \end{macrocode} |
| 496 |
% |
| 497 |
% \subsection{Calling constants} |
| 498 |
% |
| 499 |
% \DescribeMacro{\Cr} |
| 500 |
% The macro is used to call a referenced constant. |
| 501 |
% Using |\counterconstant| and |\familyconstant|, |
| 502 |
% the macros |\cst@tmp@symbols|, |\cst@tmp@format| |
| 503 |
% and the counter |cst@tmp@counter| have been properly initialized. |
| 504 |
% \begin{macrocode} |
| 505 |
\newcommand{\Cr}[1]{% |
| 506 |
\counterconstant{#1}% |
| 507 |
\familyconstant{#1}% |
| 508 |
{\@nameuse{\cst@tmp@symbol}}_{\@nameuse{\cst@tmp@format}{cst@tmp@counter}}} |
| 509 |
% \end{macrocode} |
| 510 |
% |
| 511 |
% \DescribeMacro{\C} |
| 512 |
% This macro checks the existence of a family of constants |
| 513 |
% and then expand to the symbol with the value of the counter. |
| 514 |
% \begin{macrocode} |
| 515 |
\newcommand{\C}[1][normal]{% |
| 516 |
\@if@constant@exists{#1}{% |
| 517 |
\expandafter\refstepcounterconstant{cst@counter@#1}% |
| 518 |
{\@nameuse{cst@symbol@#1}}_{\@nameuse{cst@format@#1}{cst@counter@#1}}}% |
| 519 |
{\PackageError{constants}{Family for constants '#1' not defined}{ |
| 520 |
Check the name or use \protect\newconstantfamily}}% |
| 521 |
} |
| 522 |
% \end{macrocode} |
| 523 |
% \DescribeMacro{\Cl} |
| 524 |
% This macro calls |\C| and then call |\labelconstant| to |
| 525 |
% add the constant label into the |aux| file. |
| 526 |
% \begin{macrocode} |
| 527 |
\newcommand{\Cl}[2][normal]{\C[#1]\labelconstant{#2}{\string #1}} |
| 528 |
% \end{macrocode} |
| 529 |
% |
| 530 |
% \DescribeMacro{\pagerefconstant} |
| 531 |
% This macro is similar to |refconstant| but returns the page number. |
| 532 |
% \begin{macrocode} |
| 533 |
\def\pagerefconstant#1{% |
| 534 |
\expandafter\@setrefconstant\csname cstr@#1\endcsname |
| 535 |
\@secondofthree{#1}} |
| 536 |
% \end{macrocode} |
| 537 |
% |
| 538 |
% \DescribeMacro{\refstepcouterconstant} |
| 539 |
% This macro is used to increment the number of the constants. |
| 540 |
% \begin{macrocode} |
| 541 |
\def\refstepcounterconstant#1{\stepcounter{#1}% |
| 542 |
\protected@edef\@currentlabelconstant |
| 543 |
{\csname p@#1\endcsname\csname the#1\endcsname}% |
| 544 |
} |
| 545 |
% \end{macrocode} |
| 546 |
% |
| 547 |
% |
| 548 |
% \subsection{Writing informations in the \texttt{aux} file} |
| 549 |
% |
| 550 |
% \DescribeMacro{\@newl@belconstant} |
| 551 |
% This macro checks the existence of |#1@#2| (here |
| 552 |
% |cstr| is passed as argument |#1| and \cstlabel\ is passed as |
| 553 |
% argument |#2|). If |#1@#2| has already been defined, then |
| 554 |
% it claims that the label already exists. |
| 555 |
% then it creates this macros that expands into |#3|, which |
| 556 |
% shall then expand into |
| 557 |
% \begin{quote} |
| 558 |
% |{{|\cstnumber|}{|\cstpage|}{|\family|}}| |
| 559 |
% \end{quote} |
| 560 |
% This macro is called by |\newlabelconstant| and is |
| 561 |
% executed only when reading the |aux| file at the beginning |
| 562 |
% of the page processing. In addition, it can only be called |
| 563 |
% in the preamble. |
| 564 |
% \begin{macrocode} |
| 565 |
\def\@newl@belconstant#1#2#3{{% |
| 566 |
\@ifundefined{#1@#2}% |
| 567 |
\relax |
| 568 |
{\gdef \@multiplelabelsconstant {% |
| 569 |
\@latex@warning@no@line{% |
| 570 |
There were multiply-defined labels for constants}}% |
| 571 |
\@latex@warning@no@line{Label for constant `#2' multiply defined}}% |
| 572 |
\global\@namedef{#1@#2}{#3} |
| 573 |
}} |
| 574 |
\def\@currentlabelconstant{} |
| 575 |
\def\newlabelconstant{\@newl@belconstant{cstr}} |
| 576 |
\@onlypreamble\@newl@belconstant |
| 577 |
\let \@multiplelabelsconstant \relax |
| 578 |
% \end{macrocode} |
| 579 |
% |
| 580 |
% \DescribeMacro{\labelconstant} |
| 581 |
% This macro is called when a new label is created and |
| 582 |
% writes the corresponding informations into the |aux| file. |
| 583 |
% \begin{macrocode} |
| 584 |
\def\labelconstant#1#2{\@bsphack |
| 585 |
\protected@write\@auxout{}% |
| 586 |
{\string\newlabelconstant{#1}{{\@currentlabelconstant}{\thepage}{#2}}}% |
| 587 |
\@esphack} |
| 588 |
% \end{macrocode} |
| 589 |
% |
| 590 |
% The following codes corresponds to the final check to determine |
| 591 |
% if a supplementary compilation is needed. |
| 592 |
% |
| 593 |
% \begin{macrocode} |
| 594 |
\AtEndDocument{ |
| 595 |
\clearpage |
| 596 |
\let\@newl@belconstant\@empty |
| 597 |
\begingroup |
| 598 |
\if@filesw |
| 599 |
\immediate\closeout\@mainaux |
| 600 |
\let\@setckpt\@gobbletwo |
| 601 |
\let\@newl@belconstant\@testdef |
| 602 |
\let\@newl@bel\@testdef |
| 603 |
\@tempswafalse |
| 604 |
\makeatletter \input\jobname.aux |
| 605 |
\fi |
| 606 |
\@refundefinedconstant |
| 607 |
\if@filesw |
| 608 |
\ifx \@multiplelabelsconstant \relax |
| 609 |
\if@tempswa |
| 610 |
\@latex@warning@no@line{% |
| 611 |
Label(s) for constants may have changed. |
| 612 |
Rerun to get cross-references right}% |
| 613 |
\fi |
| 614 |
\else |
| 615 |
\@multiplelabelsconstant |
| 616 |
\fi |
| 617 |
\fi |
| 618 |
\endgroup |
| 619 |
\deadcycles\z@\@@end |
| 620 |
} |
| 621 |
% \end{macrocode} |
| 622 |
% |
| 623 |
% \subsection{Reseting constants} |
| 624 |
% |
| 625 |
% The macro |\resetconstant| set the counter |cst@counter@|\family\ to $0$. |
| 626 |
% \DescribeMacro{\resetconstant} |
| 627 |
% \begin{macrocode} |
| 628 |
\newcommand{\resetconstant}[1][normal]{% |
| 629 |
\@if@constant@exists{#1}{% |
| 630 |
\setcounter{cst@counter@#1}{0}}{% |
| 631 |
{\PackageError{constants}{Family for constants '#1' not defined}{% |
| 632 |
Check the name or use \protect\newconstantfamily}}% |
| 633 |
}} |
| 634 |
% \end{macrocode} |
| 635 |
% |
| 636 |
% \iffalse |
| 637 |
%</package> |
| 638 |
% \fi |
| 639 |
% \Finale |
| 640 |
\endinput |