Debian Codegraph @

texmf-dist/source/latex/aliascnt/aliascnt.dtx

raw
1 % \iffalse meta-comment
2 %
3 % File: aliascnt.dtx
4 % Version: 2026-03-08 v1.7
5 % Info: Alias counters
6 %
7 % Copyright (C)
8 % 2006, 2009 Heiko Oberdiek
9 % 2016-2026 Oberdiek Package Support Group
10 % https://github.com/ho-tex/aliascnt/issues
11 %
12 % This work may be distributed and/or modified under the
13 % conditions of the LaTeX Project Public License, either
14 % version 1.3c of this license or (at your option) any later
15 % version. This version of this license is in
16 % https://www.latex-project.org/lppl/lppl-1-3c.txt
17 % and the latest version of this license is in
18 % https://www.latex-project.org/lppl.txt
19 % and version 1.3 or later is part of all distributions of
20 % LaTeX version 2005/12/01 or later.
21 %
22 % This work has the LPPL maintenance status "maintained".
23 %
24 % The Current Maintainers of this work are
25 % Heiko Oberdiek and the Oberdiek Package Support Group
26 % https://github.com/ho-tex/aliascnt/issues
27 %
28 % This work consists of the main source file aliascnt.dtx
29 % and the derived files
30 % aliascnt.sty, aliascnt.pdf, aliascnt.ins, aliascnt.drv.
31 %
32 % Distribution:
33 % CTAN:macros/latex/contrib/aliascnt/aliascnt.dtx
34 % CTAN:macros/latex/contrib/aliascnt/aliascnt.pdf
35 %
36 % Unpacking:
37 % (a) If aliascnt.ins is present:
38 % tex aliascnt.ins
39 % (b) Without aliascnt.ins:
40 % tex aliascnt.dtx
41 % (c) If you insist on using LaTeX
42 % latex \let\install=y\input{aliascnt.dtx}
43 % (quote the arguments according to the demands of your shell)
44 %
45 % Documentation:
46 % (a) If aliascnt.drv is present:
47 % latex aliascnt.drv
48 % (b) Without aliascnt.drv:
49 % latex aliascnt.dtx; ...
50 % The class ltxdoc loads the configuration file ltxdoc.cfg
51 % if available. Here you can specify further options, e.g.
52 % use A4 as paper format:
53 % \PassOptionsToClass{a4paper}{article}
54 %
55 % Program calls to get the documentation (example):
56 % pdflatex aliascnt.dtx
57 % makeindex -s gind.ist aliascnt.idx
58 % pdflatex aliascnt.dtx
59 % makeindex -s gind.ist aliascnt.idx
60 % pdflatex aliascnt.dtx
61 %
62 % Installation:
63 % TDS:tex/latex/aliascnt/aliascnt.sty
64 % TDS:doc/latex/aliascnt/aliascnt.pdf
65 % TDS:source/latex/aliascnt/aliascnt.dtx
66 %
67 %<*ignore>
68 \begingroup
69 \catcode123=1 %
70 \catcode125=2 %
71 \def\x{LaTeX2e}%
72 \expandafter\endgroup
73 \ifcase 0\ifx\install y1\fi\expandafter
74 \ifx\csname processbatchFile\endcsname\relax\else1\fi
75 \ifx\fmtname\x\else 1\fi\relax
76 \else\csname fi\endcsname
77 %</ignore>
78 %<*install>
79 \input docstrip.tex
80 \Msg{************************************************************************}
81 \Msg{* Installation}
82 \Msg{* Package: aliascnt 2026-03-08 v1.7 Alias counters (HO)}
83 \Msg{************************************************************************}
84
85 \keepsilent
86 \askforoverwritefalse
87
88 \let\MetaPrefix\relax
89 \preamble
90
91 This is a generated file.
92
93 Project: aliascnt
94 Version: 2026-03-08 v1.7
95
96 Copyright (C)
97 2006, 2009 Heiko Oberdiek
98 2016-2026 Oberdiek Package Support Group
99
100 This work may be distributed and/or modified under the
101 conditions of the LaTeX Project Public License, either
102 version 1.3c of this license or (at your option) any later
103 version. This version of this license is in
104 https://www.latex-project.org/lppl/lppl-1-3c.txt
105 and the latest version of this license is in
106 https://www.latex-project.org/lppl.txt
107 and version 1.3 or later is part of all distributions of
108 LaTeX version 2005/12/01 or later.
109
110 This work has the LPPL maintenance status "maintained".
111
112 The Current Maintainers of this work are
113 Heiko Oberdiek and the Oberdiek Package Support Group
114 https://github.com/ho-tex/aliascnt/issues
115
116
117 This work consists of the main source file aliascnt.dtx
118 and the derived files
119 aliascnt.sty, aliascnt.pdf, aliascnt.ins, aliascnt.drv.
120
121 \endpreamble
122 \let\MetaPrefix\DoubleperCent
123
124 \generate{%
125 \file{aliascnt.ins}{\from{aliascnt.dtx}{install}}%
126 \file{aliascnt.drv}{\from{aliascnt.dtx}{driver}}%
127 \usedir{tex/latex/aliascnt}%
128 \file{aliascnt.sty}{\from{aliascnt.dtx}{package}}%
129 }
130
131 \catcode32=13\relax% active space
132 \let =\space%
133 \Msg{************************************************************************}
134 \Msg{*}
135 \Msg{* To finish the installation you have to move the following}
136 \Msg{* file into a directory searched by TeX:}
137 \Msg{*}
138 \Msg{* aliascnt.sty}
139 \Msg{*}
140 \Msg{* To produce the documentation run the file `aliascnt.drv'}
141 \Msg{* through LaTeX.}
142 \Msg{*}
143 \Msg{* Happy TeXing!}
144 \Msg{*}
145 \Msg{************************************************************************}
146
147 \endbatchfile
148 %</install>
149 %<*ignore>
150 \fi
151 %</ignore>
152 %<*driver>
153 \NeedsTeXFormat{LaTeX2e}
154 \ProvidesFile{aliascnt.drv}%
155 [2026-03-08 v1.7 Alias counters (HO)]%
156 \documentclass{ltxdoc}
157 \usepackage{holtxdoc}[2011/11/22]
158 \begin{document}
159 \DocInput{aliascnt.dtx}%
160 \end{document}
161 %</driver>
162 % \fi
163 %
164 %
165 %
166 % \GetFileInfo{aliascnt.drv}
167 %
168 % \title{The \xpackage{aliascnt} package}
169 % \date{2026-03-08 v1.7}
170 % \author{Heiko Oberdiek\thanks
171 % {Please report any issues at \url{https://github.com/ho-tex/aliascnt/issues}}}
172 %
173 % \maketitle
174 %
175 % \begin{abstract}
176 % Package \xpackage{aliascnt} introduces \emph{alias counters} that
177 % share the same counter register and clear list.
178 %
179 % {\em Starting with \LaTeX{} 2026-06-01 this package is obsolete as \LaTeX{} provides
180 % a similar functionality directly through the \cs{newcounteralias} command.
181 % This command is used automatically if theorem environments are defined that
182 % share a counter.}
183 % \end{abstract}
184 %
185 % \tableofcontents
186 %
187 % \section{User interface}
188 %
189 % \subsection{Introduction}
190 %
191 %
192 % There are features that rely on the name of counters. For
193 % example, \xpackage{hyperref}'s \cs{autoref} indirectly uses
194 % the counter name to determine which label text it puts in front
195 % of the reference number (\cite{hyperref}).
196 % In some circumstances this fail: several theorem environments
197 % are defined by \cs{newtheorem} that share the same counter.
198 %
199 %
200 %
201 % \subsection{Syntax}
202 %
203 % Macro names in user land contain the package name
204 % \texttt{aliascnt} in order to prevent name clashes.
205 %
206 % \newenvironment{desc}{^^A
207 % \list{}{^^A
208 % \setlength{\labelwidth}{0pt}^^A
209 % \setlength{\itemindent}{-.5\marginparwidth}^^A
210 % \setlength{\leftmargin}{0pt}^^A
211 % \let\makelabel\desclabel
212 % }^^A
213 % }{^^A
214 % \endlist
215 % }
216 % \newcommand*{\desclabel}[1]{^^A
217 % \hspace{\labelsep}^^A
218 % \normalfont
219 % #1^^A
220 % }
221 % \newcommand*{\itemcs}[2]{^^A
222 % \item[^^A
223 % \expandafter\SpecialUsageIndex\csname #1\endcsname
224 % {\cs{#1}#2}^^A
225 % ]\mbox{}\\*[.5ex]^^A
226 % \ignorespaces
227 % }
228 % \begin{desc}
229 % \itemcs{newaliascnt}{\marg{ALIASCNT}\marg{BASECNT}}
230 % An alias counter ALIASCNT is created that does not allocate
231 % a new \TeX\ counter register. It shares the count register and
232 % the clear list with counter BASECNT. If the value of either
233 % the two registers is changed, the changes affects both.
234 %
235 % In \LaTeX{} 2026-06-01 a similar alias counter can be created with
236 % \cs{newcounteralias}\marg{aliasctr}\marg{rootctr}.
237 %
238 % \itemcs{aliascntresetthe}{\marg{ALIASCNT}}
239 % This fixes a problem with \cs{newtheorem} if it
240 % is fooled by an alias counter with the same name:
241 % \begin{quote}
242 %\begin{verbatim}
243 %\newtheorem{foo}{Foo}% counter "foo"
244 %\newaliascnt{baz}{foo}% alias counter "baz"
245 %\newtheorem{baz}[baz]{Baz}
246 %\aliascntresetthe{baz}
247 %\end{verbatim}
248 % \end{quote}
249 %
250 % \emph{In \LaTeX{} 2026-06-01 this is no longer needed and the standard definitions
251 % will work:}
252 % \begin{quote}
253 %\begin{verbatim}
254 %\newtheorem{foo}{Foo}% counter "foo"
255 %\newtheorem{baz}[foo]{Baz} %creates alias counter "baz"
256 %\end{verbatim}
257 % \end{quote}
258 %
259 % \end{desc}
260 %
261 % \StopEventually{
262 % }
263 %
264 % \section{Implementation}
265 %
266 % \subsection{Identification}
267 %
268 % \begin{macrocode}
269 %<*package>
270 \NeedsTeXFormat{LaTeX2e}
271 \ProvidesPackage{aliascnt}%
272 [2026-03-08 v1.7 Alias counters (HO)]%
273 % \end{macrocode}
274 % Warning and fallback for \LaTeX{} 2026-06-01, see issue https://github.com/ho-tex/oberdiek/issues/104.
275 % \begin{macrocode}
276 \IfFormatAtLeastT{2026-06-01}{%
277 \PackageWarning{aliascnt}
278 {The package is obsolete. Check the documentation.}
279 \renewcommand*{\newcounteralias}[2]{%
280 \@ifundefined{c@#2}{%
281 \@nocounterr{#2}%
282 }{
283 \@ifundefined{c@#1}
284 {%
285 \global\expandafter\let
286 \csname c@#1\expandafter\endcsname\csname c@#2\endcsname
287 \expandafter\edef\csname the#1\endcsname{\expandafter\noexpand\csname the#2\endcsname}%
288 \expandafter\edef\csname theH#1\endcsname{\expandafter\noexpand\csname theH#2\endcsname}%
289 \expandafter\edef\csname p@#1\endcsname{\expandafter\noexpand\csname p@#2\endcsname}%
290 \expandafter\edef\csname cl@#1\endcsname{\expandafter\noexpand\csname cl@#2\endcsname}%
291 \expandafter\def\csname alias@ctr@#1\endcsname{#2}%
292 }%
293 {\@ifundefined{AC@cnt@#1}
294 {\def\reserved@a{c@#1}\@notdefinable}%
295 {\expandafter\edef\csname alias@ctr@#1\endcsname{\csname AC@cnt@#1\endcsname}}}
296 }%
297 }}
298 % \end{macrocode}
299 %
300 % \subsection{Create new alias counter}
301 %
302 % \begin{macro}{\newaliascnt}
303 % A new alias counter is set up by \cs{newaliascnt}.
304 % The following properties are added for the new counter CNT:
305 % \begin{description}
306 % \item[\mdseries\cs{theH}\meta{CNT}:] Compatibility for \xpackage{hyperref}
307 % \item[\mdseries\cs{AC@cnt@}\meta{CNT}:] Name of the referenced counter
308 % in the definition.
309 % \end{description}
310 % \begin{macrocode}
311 \newcommand*{\newaliascnt}[2]{%
312 \begingroup
313 \def\AC@glet##1{%
314 \global\expandafter\let\csname##1#1\expandafter\endcsname
315 \csname##1#2\endcsname
316 }%
317 \@ifundefined{c@#2}{%
318 \@nocounterr{#2}%
319 }{%
320 \expandafter\@ifdefinable\csname c@#1\endcsname{%
321 \AC@glet{c@}%
322 \AC@glet{the}%
323 \AC@glet{theH}%
324 \AC@glet{p@}%
325 \expandafter\gdef\csname AC@cnt@#1\endcsname{#2}%
326 \expandafter\gdef\csname cl@#1\expandafter\endcsname
327 \expandafter{\csname cl@#2\endcsname}%
328 }%
329 }%
330 \endgroup
331 }
332 % \end{macrocode}
333 % \end{macro}
334 %
335 % \begin{macro}{\aliascntresetthe}
336 % The \cs{the}\meta{CNT} macro is restored using the
337 % main counter.
338 % \begin{macrocode}
339 \newcommand*{\aliascntresetthe}[1]{%
340 \@ifundefined{AC@cnt@#1}{%
341 \PackageError{aliascnt}{%
342 `#1' is not an alias counter%
343 }\@ehc
344 }{%
345 \expandafter\let\csname the#1\expandafter\endcsname
346 \csname the\csname AC@cnt@#1\endcsname\endcsname
347 }%
348 }
349 % \end{macrocode}
350 % \end{macro}
351 %
352 % \subsection{Counter clear list}
353 %
354 % The alias counters share the same register and clear list.
355 % Therefore we must ensure that manipulations to the clear list
356 % are done with the clear list macro of a real counter.
357 % \begin{macro}{\AC@findrootcnt}
358 % \cs{AC@findrootcnt} walks through the aliasing relations
359 % to find the base counter.
360 % \begin{macrocode}
361 \newcommand*{\AC@findrootcnt}[1]{%
362 \@ifundefined{AC@cnt@#1}{%
363 #1%
364 }{%
365 \expandafter\AC@findrootcnt\csname AC@cnt@#1\endcsname
366 }%
367 }
368 % \end{macrocode}
369 % \end{macro}
370 %
371 % Clear lists are manipulated by \cs{@addtoreset} and
372 % \cs{@removefromreset}. The latter one is provided by
373 % the \xpackage{remreset} package (\cite{remreset} for old latex formats).
374 %
375 % \begin{macro}{\AC@patch}
376 % The same patch principle is applicable to both
377 % \cs{@addtoreset} and \cs{@removefromreset}.
378 % \begin{macrocode}
379 \def\AC@patch#1{%
380 \expandafter\let\csname AC@org@#1reset\expandafter\endcsname
381 \csname @#1reset\endcsname
382 \expandafter\def\csname @#1reset\endcsname##1##2{%
383 \csname AC@org@#1reset\endcsname{##1}{\AC@findrootcnt{##2}}%
384 }%
385 }
386 % \end{macrocode}
387 % \end{macro}
388 % If \xpackage{remreset} is not loaded we cannot delay
389 % the patch to \cs{AtBeginDocument}, because \cs{@removefromreset}
390 % can be called in between. Therefore we force the loading of
391 % the package.
392 % \begin{macrocode}
393 \ifx\@removefromreset\@undefined
394 \RequirePackage{remreset}
395 \fi
396 \AC@patch{addto}
397 \AC@patch{removefrom}
398 % \end{macrocode}
399 %
400 % \begin{macrocode}
401 %</package>
402 % \end{macrocode}
403 %
404 % \section{Installation}
405 %
406 % \subsection{Download}
407 %
408 % \paragraph{Package.} This package is available on
409 % CTAN\footnote{\CTANpkg{aliascnt}}:
410 % \begin{description}
411 % \item[\CTAN{macros/latex/contrib/aliascnt/aliascnt.dtx}] The source file.
412 % \item[\CTAN{macros/latex/contrib/aliascnt/aliascnt.pdf}] Documentation.
413 % \end{description}
414 %
415 %
416 % \subsection{Package installation}
417 %
418 % \paragraph{Unpacking.} The \xfile{.dtx} file is a self-extracting
419 % \docstrip\ archive. The files are extracted by running the
420 % \xfile{.dtx} through \plainTeX:
421 % \begin{quote}
422 % \verb|tex aliascnt.dtx|
423 % \end{quote}
424 %
425 % \paragraph{TDS.} Now the different files must be moved into
426 % the different directories in your installation TDS tree
427 % (also known as \xfile{texmf} tree):
428 % \begin{quote}
429 % \def\t{^^A
430 % \begin{tabular}{@{}>{\ttfamily}l@{ $\rightarrow$ }>{\ttfamily}l@{}}
431 % aliascnt.sty & tex/latex/aliascnt/aliascnt.sty\\
432 % aliascnt.pdf & doc/latex/aliascnt/aliascnt.pdf\\
433 % aliascnt.dtx & source/latex/aliascnt/aliascnt.dtx\\
434 % \end{tabular}^^A
435 % }^^A
436 % \sbox0{\t}^^A
437 % \ifdim\wd0>\linewidth
438 % \begingroup
439 % \advance\linewidth by\leftmargin
440 % \advance\linewidth by\rightmargin
441 % \edef\x{\endgroup
442 % \def\noexpand\lw{\the\linewidth}^^A
443 % }\x
444 % \def\lwbox{^^A
445 % \leavevmode
446 % \hbox to \linewidth{^^A
447 % \kern-\leftmargin\relax
448 % \hss
449 % \usebox0
450 % \hss
451 % \kern-\rightmargin\relax
452 % }^^A
453 % }^^A
454 % \ifdim\wd0>\lw
455 % \sbox0{\small\t}^^A
456 % \ifdim\wd0>\linewidth
457 % \ifdim\wd0>\lw
458 % \sbox0{\footnotesize\t}^^A
459 % \ifdim\wd0>\linewidth
460 % \ifdim\wd0>\lw
461 % \sbox0{\scriptsize\t}^^A
462 % \ifdim\wd0>\linewidth
463 % \ifdim\wd0>\lw
464 % \sbox0{\tiny\t}^^A
465 % \ifdim\wd0>\linewidth
466 % \lwbox
467 % \else
468 % \usebox0
469 % \fi
470 % \else
471 % \lwbox
472 % \fi
473 % \else
474 % \usebox0
475 % \fi
476 % \else
477 % \lwbox
478 % \fi
479 % \else
480 % \usebox0
481 % \fi
482 % \else
483 % \lwbox
484 % \fi
485 % \else
486 % \usebox0
487 % \fi
488 % \else
489 % \lwbox
490 % \fi
491 % \else
492 % \usebox0
493 % \fi
494 % \end{quote}
495 % If you have a \xfile{docstrip.cfg} that configures and enables \docstrip's
496 % TDS installing feature, then some files can already be in the right
497 % place, see the documentation of \docstrip.
498 %
499 % \subsection{Refresh file name databases}
500 %
501 % If your \TeX~distribution
502 % (\TeX\,Live, \mikTeX, \dots) relies on file name databases, you must refresh
503 % these. For example, \TeX\,Live\ users run \verb|texhash| or
504 % \verb|mktexlsr|.
505 %
506 % \subsection{Some details for the interested}
507 %
508 % \paragraph{Unpacking with \LaTeX.}
509 % The \xfile{.dtx} chooses its action depending on the format:
510 % \begin{description}
511 % \item[\plainTeX:] Run \docstrip\ and extract the files.
512 % \item[\LaTeX:] Generate the documentation.
513 % \end{description}
514 % If you insist on using \LaTeX\ for \docstrip\ (really,
515 % \docstrip\ does not need \LaTeX), then inform the autodetect routine
516 % about your intention:
517 % \begin{quote}
518 % \verb|latex \let\install=y\input{aliascnt.dtx}|
519 % \end{quote}
520 % Do not forget to quote the argument according to the demands
521 % of your shell.
522 %
523 % \paragraph{Generating the documentation.}
524 % You can use both the \xfile{.dtx} or the \xfile{.drv} to generate
525 % the documentation. The process can be configured by the
526 % configuration file \xfile{ltxdoc.cfg}. For instance, put this
527 % line into this file, if you want to have A4 as paper format:
528 % \begin{quote}
529 % \verb|\PassOptionsToClass{a4paper}{article}|
530 % \end{quote}
531 % An example follows how to generate the
532 % documentation with pdf\LaTeX:
533 % \begin{quote}
534 %\begin{verbatim}
535 %pdflatex aliascnt.dtx
536 %makeindex -s gind.ist aliascnt.idx
537 %pdflatex aliascnt.dtx
538 %makeindex -s gind.ist aliascnt.idx
539 %pdflatex aliascnt.dtx
540 %\end{verbatim}
541 % \end{quote}
542 %
543 % \section{Acknowledgement}
544 %
545 % \begin{description}
546 % \item[Ulrich Schwarz:] The package is based on his draft for
547 % ``Die \TeX nische Kom\"odie'', see \cite{schwarz}.
548 % \end{description}
549 %
550 % \begin{thebibliography}{9}
551 %
552 % \bibitem{schwarz}
553 % Ulrich Schwarz:
554 % \textit{Was hinten herauskommt z\"ahlt: Counter Aliasing in \LaTeX},
555 % \textit{Die \TeX nische Kom\"odie}, 3/2006, pages 8--14, Juli 2006.
556 %
557 % \bibitem{remreset}
558 % David Carlisle: \textit{The \xpackage{remreset} package};
559 % 1997/09/28;
560 % \CTANpkg{remreset}.
561 %
562 % \bibitem{hyperref}
563 % Sebastian Rahtz, Heiko Oberdiek:
564 % \textit{The \xpackage{hyperref} package};
565 % 2006/08/16 v6.75c;
566 % \CTANpkg{hyperref}.
567 %
568 % \end{thebibliography}
569 %
570 % \begin{History}
571 % \begin{Version}{2006/02/20 v1.0}
572 % \item
573 % First version.
574 % \end{Version}
575 % \begin{Version}{2006/08/16 v1.1}
576 % \item
577 % Update of bibliography.
578 % \end{Version}
579 % \begin{Version}{2006/09/25 v1.2}
580 % \item
581 % Bug fix (\cs{aliascntresetthe}).
582 % \end{Version}
583 % \begin{Version}{2009/09/08 v1.3}
584 % \item
585 % Bug fix of \cs{@ifdefinable}'s use (thanks to Uwe L\"uck).
586 % \end{Version}
587 % \begin{Version}{2016/05/16 v1.4}
588 % \item
589 % Documentation updates.
590 % \end{Version}
591 % \begin{Version}{2018/09/07 v1.5}
592 % \item
593 % Avoid loading obsolete remreset package..
594 % \end{Version}
595 % \begin{Version}{2026-03-06 v1.6}
596 % \item Extracted from the oberdiek bundle and moved into its own repository.
597 % Added fallback definition for \LaTeX{} 2026-06-01 (https://github.com/ho-tex/oberdiek/issues/104).
598 % \end{Version}
599 % \begin{Version}{2026-03-08 v1.7}
600 % \item Bug fix, corrected example in documentation.
601 % \end{Version}
602 % \end{History}
603 %
604 % \PrintIndex
605 %
606 % \Finale
607 \endinput