summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/constants/constants.dtx
blob: 6d9ac43c26c6f84c64714f234697f25bc0614901 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
% \iffalse meta-comment
%
% Copyright (C) 2008 by
% 	Antoine Lejay <Antoine dot Lejay at iecn dot u-nancy dot fr>
% 
% Based on ltxref.dtx of the Latex Kernel (Copyright the LaTeX 3 project).
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either
% version 1.3c of this license or (at your option) any later
% version. The latest version of this license is in
%    http://www.latex-project.org/lppl.txt
% and version 1.3c or later is part of all distributions of
% LaTeX version 2005/12/01 or later.
%
% This work has the LPPL maintenance status `maintained.'
%
% The current maintainer of this work is Antoine Lejay.
%
% This work consists of the source file constants.dtx
%                 and the derived files constants.ins,
%                                       constants.sty,
%                                       constants.pdf,
% \fi
% \iffalse
%<*driver>
\documentclass[a4paper]{ltxdoc}
\EnableCrossrefs
\CodelineIndex
\RecordChanges
%\OnlyDescription
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{fancyvrb}
%\usepackage[dvipdfm]{hyperref}
\usepackage{hyperref}
\usepackage{constants}
\hypersetup{
  pdftitle={The constants package},
  pdfauthor={Antoine Lejay}
}
\newcommand{\parenthezises}[1]{(\arabic{#1})}
\newconstantfamily{example1}{
	symbol=K,
	format=\parenthezises,
	reset={section}
}
\newcommand{\family}{$\langle$\textsl{family}$\rangle$}
\newcommand{\cstpage}{$\langle$\textsl{page}$\rangle$}
\newcommand{\cstlabel}{$\langle$\textsl{label}$\rangle$}
\newcommand{\cstnumber}{$\langle$\textsl{number}$\rangle$}

\begin{document}
  \DocInput{\jobname.dtx}
\PrintIndex
\PrintChanges
\end{document}
%</driver>
%
% \fi
%
% \CheckSum{0}
%
% \CharacterTable
%  {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
%   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
%   Digits        \0\1\2\3\4\5\6\7\8\9
%   Exclamation   \!     Double quote  \"     Hash (number) \#
%   Dollar        \$     Percent       \%     Ampersand     \&
%   Acute accent  \'     Left paren    \(     Right paren   \)
%   Asterisk      \*     Plus          \+     Comma         \,
%   Minus         \-     Point         \.     Solidus       \/
%   Colon         \:     Semicolon     \;     Less than     \<
%   Equals        \=     Greater than  \>     Question mark \?
%   Commercial at \@     Left bracket  \[     Backslash     \\
%   Right bracket \]     Circumflex    \^     Underscore    \_
%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%   Right brace   \}     Tilde         \~}
%
%\changes{1.0}{2008/03/25}{First released}
%
%\GetFileInfo{\jobname.sty}
%\DoNotIndex{\@auxout,\@@end,\@empty,\@latex@warning,\@latex@warning@no@line}
%\DoNotIndex{\@mainaux,\@namedef,\@nameuse,\AtEndDocument,\begingroup,\endgroup}
%\DoNotIndex{\csname,\endcsname,\expandafter,\elseif,\def,\closeout,\if,\fi}
%\DoNotIndex{\gdef,\global,\if@filesw,\if@tempswa,\ifx,\immediate,\input}
%\DoNotIndex{\makeatletter,\NeedsTeXFormat,\newcommand,\newcounter,\jobname}
%\DoNotIndex{\setcounter,\nfss@text,\null,\RequirePackage,\reset@font}
%\DoNotIndex{\textbf,\textrm,\textsuperscript,\thepage,\z@,\stepcounter}
%\DoNotIndex{\space,\string,\relax,\clearpage,\deadcycles,\else,\long,\let}
%\DoNotIndex{\PackageError,\PackageInfo,\protect,\protected@edef,\protected@write}
%\DoNotIndex{\ProvidesPackage,\@bsphack,\@esphack,\@gobbletwo,\@ifundefined}
%\DoNotIndex{\@tempswfalse,\@testdef,\bfseries}
%\MakeShortVerb{\|}
%
% \title{\texttt{\filename},\\ a package for automatic numbering\\ of constants%
%  \thanks{This file describes version \fileversion, last revised
%    \filedate.}}
% \author{Antoine Lejay}
% \date{Released \filedate}
%
% \maketitle
%
% \begin{abstract}
% This set of macros aims to provide a way to number automatically
% constants in a mathematical proof
% with a system for labelling/referencing. In addition, 
% several families of constants (with different symbols) may be defined.
% \end{abstract}
%
%\begin{multicols}{2}
% \footnotesize
%  \tableofcontents
%\end{multicols}
% \section{Introduction}
%
% Some domains of mathematics such as the theory of (partial)
% differential equations heavily rely on inequalities, and many
% proofs are done by writing down a long sequence of inequalities
% involving constants that may change from line to line. 
% Thus, a standard redaction trick consists in starting a proof
% by the statement 
% \begin{quote}
% Let $C$ denotes a constants that varies 
% from line to line.
% \end{quote}
% However, it is sometimes necessary 
% to get more informations about the involved constants. 
% Thus, either one has to finds different symbols, to the risk of 
% introduce some confusions in the notations, or to labels the 
% constants. Of course, manual labelling is not that easy, 
% especially at the early stages of redaction.  
% 
% The aim of this package is then to provide an automatic
% way to incrementally label the constants with numbers.  
% In addition, it offers the possibility to 
% label the constants with a mechanism similar to 
% |\label| and |\ref|. Finally, it is possible to 
% define several families of constants with different 
% rules for printing. 
%
% \paragraph{Dependencies: } this package uses the |keyval| 
% package of the \emph{graphic bundle} (which is in every standard distribution). 
%
% \section{Basic usage}
%
% \DescribeMacro{\C}
% The most basic usage of this package consists in calling 
% the macro |\C| in math mode, that prints $C_1$ for the first time, $C_2$
% for the second time, ...
%
% \DescribeMacro{\Cl}
% The macro |\Cl| is similar to |\C| except that it takes
% a mandatory argument which is a label's name, for 
% example |\Cl{cst-1}|. The number of the constant which
% is then printed is recorded and written in the |.aux| file. 
% Note that |\label{cst-1}| does not interact with 
% and |\Cl{cst-1}|, that is 
% the labels for constants are treated in a specific way 
% and can be only accessed through the command |\Cr| below.
%
% \DescribeMacro{\Cr}
% The macro |\Cr| takes a mandatory argument which 
% shall be the name of a label defined by |\Cl|. 
% As for standard labels in \LaTeX, if |\Cr| calls 
% a label that have not yet been defined are, then 
% the result is replaced by ``\textrm{C\textsuperscript{st}\textbf{??}}''.
% A message is written at the end of the compilation to indicate 
% the need of a second compilation to get all the references right.
% 
% \DescribeMacro{\pagerefconstant}
% This macros takes the label of a constant as a mandatory
% argument and returns the page were the constant is. 
%
% \DescribeMacro{\resetconstant}
% This macros resets the counter of constants, so that the 
% next call to |\C| will print again $C_1$.
%
% \section{Family of constants}
% 
% What if one whishes to use two families of 
% constants $\C[example1]$, $\C[example1]$, ... and $\C$, $\C$, ...
% in the same document, and that the $K_{(i)}$'s are reseted
% at each new section? A possibility consists then in defining 
% a new family of constant using the following code in the preamble.
% \begin{verbatim}
%\newcommand{\parenthezises}[1]{(\arabic{#1})}
%\newconstantfamily{example1}{
%	symbol=K,
%	format=\parenthezises,
%	reset={section}
%}
% \end{verbatim}
%
% \subsection{Defining a family}
%
% \DescribeMacro{\newconstantfamily} 
% The macro |\newconstantfamily| allows one to define a new 
% family of constants. Its first argument is the name of the 
% family, while the second argument uses the key-value principle. 
% 
% The key |symbol| is for the symbol that is used. 
% The key |format| shall takes as argument a command
% with one argument that can be applied to a counter
% (such as |\alph|, |\roman|, ...), or any user-defined command 
% such a |\parenthezises| above.
% The key |reset| takes the name of a counter and thus 
% the counter for this family of constants is reseted
% each time the corresponding counter is stepped by one.
% Note that several |reset| key may be used (technically, 
% it adds the name of the counter to a list of counters to be reseted
% each time a given counter is stepped).
% Here, possible names are |section|, |subsection|, |equation|, ...
%
% By default, there is one family which is defined, whose
% name is |normal|.
%
% If a key is missing, then the corresponding standard values are used
% (that is |symbol=C|, |format=\arabic| and no |reset| key).
%
% \DescribeMacro{\renewconstantfamily}
% If |\newconstantfamily| is called upon a family name that 
% has been already defined, then the compilers stops and 
% returns an error message. The |\renewconstantfamily| 
% (still to be used in the preamble) 
% allows one to override the behavior of a family
% without getting an arror message. Using |normal| as 
% a family name, one can get replace the standard behavior
% of |\C|.
% 
% \subsection{Using a family}
%
% \DescribeMacro{\C}
% \DescribeMacro{\Cl}
% \DescribeMacro{\Cr}
% \DescribeMacro{\pagerefconstant}
% Using a family is simple: it is sufficient to 
% call |\C| and |\Cl| with an optional argument
% which is the family name (if the name is incorrect,
% an error message is printed), that is 
% |\C[example1]| and |\Cl[example1]{cst-2}|
% to get $\C[example1]$ and~$\Cl[example1]{cst-2}$.
% For |\Cr|, there is no need to call the family,
% as it is stored with the family name. Thus, 
% |\Cr{cst-2}| will print $\Cr{cst-2}$. The macro
% |\pagerefconstant| also do not need any reference
% to a family name.
%
% \DescribeMacro{\resetconstant}
% The command |\resetconstant| also accepts the family 
% name as an optional argument.
% 
%
% \iffalse
%<*package>
% \fi
% \section{The code}
% \label{sec-1}
%
% The mechanism of labelling constants is similar 
% to the mechanism used by the standard \LaTeX\ 
% |\label| and |\ref| mechanism (see the files |source2e.pdf|, 
% |latex.ltx| and |ltxref.dtx|), excepted that 
% the family of the constant is taken into 
% account.
% 
% This works the following way:
% \begin{enumerate}
% \item The |aux| file is read first. If a line of type 
% \begin{quote}
% |\newlabelconstant{|\cstlabel|}{{|\cstnumber|}{|\cstpage|}{|\family|}}|
% \end{quote}
% is found, then a new macro |\cstr@|\cstlabel\ is created. This 
% macro shall expand into 
% \begin{quote}
% |{{|\cstnumber|}{|\cstpage|}{|\family|}}|
% \end{quote}
% where \cstnumber\ is the number of the constant, 
% \cstpage\ is the page were it appears and \family\ is its family name.
% 
% \item When a reference \cstlabel\ to a constant is found (call
% of |\Cr{|\cstlabel|}|), then 
% \TeX\ determines if |\cstr@|\cstlabel\ is already defined. 
% If not, then it prints a symbol for unknown constants and send 
% a warning message. 
%
% \item When a label to a constant is defined (call of 
% |\Cr[\family]{|\cstlabel|}|), then \TeX\ writes into the 
% |aux| file the corresponding |\newlabelconstant| line.
%
% \item At the end of the document, the |aux| file is read 
% once to determined wether or not there the source file has 
% to be compiled or not.
% \end{enumerate}
%
%
% \subsection{Initialization}
%
% The initializaton call the package |keyval|. 
%
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{constants}%
  [2008/03/25 v.1 Labeling and numbering constants]
\PackageInfo{constants}
  {This package aims to label et number constants in a mathematical proof.}
\RequirePackage{keyval}
%    \end{macrocode}
%
% \subsection{Macros associated to constants}
%
% When a family \family\ of constants is defined, several macros are
% created, that are |\cst@family@|\family, to check the existence
% of a family, |\cst@format@|\family, that takes a counter name as argument, 
% and |\cst@symbol@|\family, that expand into the symbol of the constant.
% In addition, a counter |cst@counter@|\family\ is created. 
% 
% \subsection{Macros for testing existence of families}
%
% \DescribeMacro{\@if@constant@exists}
% When a new family \family\ is defined, a macro 
% |\cst@family@|\family\ is defined, that expands to nothing.
%
%    \begin{macrocode}
\def\@if@constant@exists#1#2#3{\@ifundefined{cst@family@#1}{#3}{#2}}
%    \end{macrocode}
%
% \subsection{The family of constants \emph{normal}}
%
% The normal family is the family by default. The corresponding 
% macros are then defined.
%
%    \begin{macrocode}
\global\@namedef{cst@family@normal}{}
\newcounter{cst@counter@normal}
\def\cst@format@normal#1{\arabic{#1}}
\def\cst@symbol@normal{C}
%    \end{macrocode}
%
% \subsection{Definition of families}
%
% \DescribeMacro{\newconstantfamily}
% The macro |\newconstantfamily| defines the macros and counter
% associated to a family.
%    \begin{macrocode}
\newcommand{\newconstantfamily}[2]{
\@if@constant@exists{#1}{%
	\PackageError{constants}{The family of constants '#1' already exists}{%
Use \protect\renewconstantfamily\space to override}}%
{%
\expandafter\def\csname cst@family@#1\endcsname{}
\expandafter\def\csname cst@format@#1\endcsname{\cst@format@normal}
\expandafter\def\csname cst@symbol@#1\endcsname{\cst@symbol@normal}
\expandafter\newcounter{cst@counter@#1}
\define@key{constants}{format}%
{\expandafter\def\csname cst@format@#1\endcsname{##1}}
\define@key{constants}{symbol}%
{\expandafter\def\csname cst@symbol@#1\endcsname{##1}}
\define@key{constants}{reset}{\@addtoreset{cst@counter@#1}{##1}}
\setkeys{constants}{#2}
}}
%    \end{macrocode}
%
% \DescribeMacro{\renewconstantfamily}
% The |\renewconstantfamily| also redefines the macros associated to 
% constants, but does not re-create the counter. 
%
%    \begin{macrocode}
\newcommand{\renewconstantfamily}[2]{
\@if@constant@exists{#1}{
\define@key{constants}{format}{%
\expandafter\def\csname cst@format@#1\endcsname{##1}}
\define@key{constants}{symbol}{%
\expandafter\def\csname cst@symbol@#1\endcsname{##1}}
\define@key{constants}{reset}{\@addtoreset{cst@counter@#1}{##1}}
\setkeys{constants}{#2}
}{%
	\PackageError{constants}{The family of constants '#1' already exists}{%
Use \protect\renewconstantfamily\space to override}}%
}
%    \end{macrocode}
%
% The macros |\newconstantfamily| and |\renewconstantfamily|
% can only be called in the preamble.
%
%    \begin{macrocode}
\@onlypreamble\newconstantfamily
\@onlypreamble\renewconstantfamily
%    \end{macrocode}
%
% \subsection{Reading constants informations}
% 
% The following macros aims to read the informations
% from the macro |\cstr@|\cstlabel\ (See Section~\ref{sec-1}).
%
% When constants informations are read from the |aux| file, 
% the format, deduced from the family name \family, 
% is put in |\cst@tmp@format| and the symbol is put
% in |\cst@tmp@symbol|. By default, these macros expand into 
% |\cst@undefined@format| and |\cst@undefined@symbol|.
%    \begin{macrocode}
\def\G@refundefinedconstanttrue{%
  \gdef\@refundefinedconstant{%
    \@latex@warning@no@line{%
There were undefined references to constants}}}
\let\@refundefinedconstant\relax
\def\cst@tmp@format{cst@undefined@format}
\def\cst@tmp@symbol{cst@undefined@symbol}
%    \end{macrocode}
%
% \DescribeMacro{\@firstofthree}
% \DescribeMacro{\@secondofthree}
% \DescribeMacro{\@thirdofthree}
% These macros return respectively their first, second and third argument.
%    \begin{macrocode}
\long\def\@firstofthree#1#2#3{#1}
\long\def\@secondofthree#1#2#3{#2}
\long\def\@thirdofthree#1#2#3{#3}
%    \end{macrocode}
%
% If a reference to a macro is not defined, then 
% the counter value is not expanded, while a 
% symbol ``\textrm{C\textsuperscript{st}\textbf{??}}'' is returned.
%    \begin{macrocode}
\def\cst@undefined@format#1{}
\def\cst@undefined@symbol{%
\nfss@text{\reset@font\textrm{C\textsuperscript{st}\textbf{??}}}}
%    \end{macrocode}
%
% \DescribeMacro{\@setrefconstant}
% This macro expands into one of the arguments of the constant. 
% The argument |#1| shall be of type |cstr@|\cstlabel, 
% the argument |#2| shall then be |\@firstofthree|, 
% |\@secondofthree| and |\@thirdofthree|. The third argument 
% |#3| expands into |{{|\cstnumber|}{|\cstpage|}{|\family|}}|.
% If |cstr@|\cstlabel\ is not defined, then the package send
% a warning and the macro expands to ``\textbf{??}''.
%    \begin{macrocode}
\def\@setrefconstant#1#2#3{%
  \ifx#1\relax
   \protect\G@refundefinedconstanttrue
   \nfss@text{\reset@font\bfseries ??}%
   \@latex@warning{Reference to constant `#3' on page \thepage \space
             undefined}%
  \else
   \expandafter#2#1\null
  \fi}
%    \end{macrocode}
%
% \DescribeMacro{\@setfamconstant}
% This macro is similar to |\@setrefconstant| but 
% initializes |\cst@tmp@format| and |\cst@tmp@symbol|
% to |\cst@format@|\family\ and |\cst@fsymbol@|\family.
%    \begin{macrocode}
\def\@setfamconstant#1#2#3{%
\ifx#1\relax%
	\def\cst@tmp@format{cst@undefined@format}\null
	\def\cst@tmp@symbol{cst@undefined@symbol}\null
\else% 
	\def\cst@tmp@format{cst@format@\expandafter#2#1}\null
	\def\cst@tmp@symbol{cst@symbol@\expandafter#2#1}\null
\fi}
%    \end{macrocode}
%
% \DescribeMacro{\@setcounterconstant}
% This macro is similar to |\@setrefconstant| but 
% set the temporary counter |cst@tmp@counter| to 
% the value of \cstnumber.
%    \begin{macrocode}
\newcounter{cst@tmp@counter}
\def\@setcounterconstant#1#2#3{%
  \ifx#1\relax
   \protect\G@refundefinedconstanttrue
   \@latex@warning{Reference to constant `#3' on page \thepage \space
             undefined}%
  \else
   	\setcounter{cst@tmp@counter}{\expandafter#2#1}\null
\fi}
%    \end{macrocode}
%
% \DescribeMacro{\refconstant}
% \DescribeMacro{\familyconstant}
% \DescribeMacro{\counterconstant}
% These macros are used to call |\@setrefconstant|, |\@setfamconstant|
% and |\@setcounterconstant|.
%    \begin{macrocode}
\def\refconstant#1{%
\expandafter\@setrefconstant\csname cstr@#1\endcsname\@firstofthree{#1}}
\def\familyconstant#1{%
\expandafter\@setfamconstant\csname cstr@#1\endcsname\@thirdofthree{#1}}
\def\counterconstant#1{%
\expandafter\@setcounterconstant%
\csname cstr@#1\endcsname\@firstofthree{#1}}
%    \end{macrocode}
%
% \subsection{Calling constants}
%
% \DescribeMacro{\Cr}
% The macro is used to call a referenced constant.
% Using |\counterconstant| and |\familyconstant|, 
% the macros |\cst@tmp@symbols|, |\cst@tmp@format| 
% and the counter |cst@tmp@counter| have been properly initialized.
%    \begin{macrocode}
\newcommand{\Cr}[1]{%
\counterconstant{#1}%
\familyconstant{#1}%
{\@nameuse{\cst@tmp@symbol}}_{\@nameuse{\cst@tmp@format}{cst@tmp@counter}}}
%    \end{macrocode}
%
% \DescribeMacro{\C}
% This macro checks the existence of a family of constants
% and then expand to the symbol with the value of the counter.
%    \begin{macrocode}
\newcommand{\C}[1][normal]{%
\@if@constant@exists{#1}{%
\expandafter\refstepcounterconstant{cst@counter@#1}%
{\@nameuse{cst@symbol@#1}}_{\@nameuse{cst@format@#1}{cst@counter@#1}}}%
{\PackageError{constants}{Family for constants '#1' not defined}{
Check the name or use \protect\newconstantfamily}}%
}
%    \end{macrocode}
% \DescribeMacro{\Cl}
% This macro calls |\C| and then call |\labelconstant| to 
% add the constant label into the |aux| file.
%    \begin{macrocode}
\newcommand{\Cl}[2][normal]{\C[#1]\labelconstant{#2}{\string #1}}
%    \end{macrocode}
%
% \DescribeMacro{\pagerefconstant}
% This macro is similar to |refconstant| but returns the page number. 
%    \begin{macrocode}
\def\pagerefconstant#1{%
\expandafter\@setrefconstant\csname cstr@#1\endcsname
   \@secondofthree{#1}}
%    \end{macrocode}
%
% \DescribeMacro{\refstepcouterconstant}
% This macro is used to increment the number of the constants.
%    \begin{macrocode}
\def\refstepcounterconstant#1{\stepcounter{#1}%
    \protected@edef\@currentlabelconstant
       {\csname p@#1\endcsname\csname the#1\endcsname}%
}
%    \end{macrocode}
%
%
% \subsection{Writing informations in the \texttt{aux} file}
%
% \DescribeMacro{\@newl@belconstant}
% This macro checks the existence of |#1@#2| (here
% |cstr| is passed as argument |#1| and \cstlabel\ is passed as
% argument |#2|). If |#1@#2| has already been defined, then 
% it claims that the label already exists. 
% then it creates this macros that expands into |#3|, which 
% shall then expand into 
% \begin{quote}
% |{{|\cstnumber|}{|\cstpage|}{|\family|}}|
% \end{quote}
% This macro is called by |\newlabelconstant| and is 
% executed only when reading the |aux| file at the beginning
% of the page processing. In addition, it can only be called
% in the preamble.
%    \begin{macrocode}
\def\@newl@belconstant#1#2#3{{%
  \@ifundefined{#1@#2}%
    \relax
    {\gdef \@multiplelabelsconstant {%
       \@latex@warning@no@line{%
There were multiply-defined labels for constants}}%
     \@latex@warning@no@line{Label for constant `#2' multiply defined}}%
  \global\@namedef{#1@#2}{#3} 
}}
\def\@currentlabelconstant{}
\def\newlabelconstant{\@newl@belconstant{cstr}}
\@onlypreamble\@newl@belconstant
\let \@multiplelabelsconstant \relax
%    \end{macrocode}
%
% \DescribeMacro{\labelconstant}
% This macro is called when a new label is created and 
% writes the corresponding informations into the |aux| file. 
%    \begin{macrocode}
\def\labelconstant#1#2{\@bsphack
  \protected@write\@auxout{}%
	 {\string\newlabelconstant{#1}{{\@currentlabelconstant}{\thepage}{#2}}}%
  \@esphack}
%    \end{macrocode}
%
% The following codes corresponds to the final check to determine 
% if a supplementary compilation is needed.
%
%    \begin{macrocode}
\AtEndDocument{
\clearpage
\let\@newl@belconstant\@empty
\begingroup
     \if@filesw
       \immediate\closeout\@mainaux
       \let\@setckpt\@gobbletwo
       \let\@newl@belconstant\@testdef
       \let\@newl@bel\@testdef
       \@tempswafalse
       \makeatletter \input\jobname.aux
     \fi
	\@refundefinedconstant
     \if@filesw
       \ifx \@multiplelabelsconstant \relax
         \if@tempswa
           \@latex@warning@no@line{%
				Label(s) for constants may have changed.
               	Rerun to get cross-references right}%
         \fi
       \else
         \@multiplelabelsconstant
       \fi
     \fi
\endgroup
\deadcycles\z@\@@end
}
%    \end{macrocode}
%
% \subsection{Reseting constants}
%
% The macro |\resetconstant| set the counter |cst@counter@|\family\ to $0$.
% \DescribeMacro{\resetconstant}
%    \begin{macrocode}
\newcommand{\resetconstant}[1][normal]{%
\@if@constant@exists{#1}{%
	\setcounter{cst@counter@#1}{0}}{%
{\PackageError{constants}{Family for constants '#1' not defined}{%
Check the name or use \protect\newconstantfamily}}%
}}
%    \end{macrocode}
%
% \iffalse
%</package>
% \fi
% \Finale
\endinput