Debian Codegraph @

texmf-dist/source/latex/thmtools/aliasctr.dtx

raw
1 % \iffalse meta-comment
2 %
3 % Copyright (C) 2005-2014 by Ulrich M. Schwarz
4 % Copyright (C) 2019 by Frank Mittelbach
5 % Copyright (C) 2020- by Yukai Chou
6 %
7 % This file may be distributed and/or modified under the conditions of
8 % the LaTeX Project Public License, version 1.3c.
9 % The license can be obtained from
10 % http://www.latex-project.org/lppl/lppl-1-3c.txt
11 %
12 %<*code>
13 % \fi
14 % |\@counteralias{#1}{#2}| makes |#1| a counter that uses |#2|'s count register.
15 % This is useful for things like \pkg{hyperref}'s |\autoref|, which otherwise
16 % can't distinguish theorems and definitions if they share a counter.
17 %
18 % For detailed information, see Die TeXnische Kom\"odie 3/2006.
19 % \StopEventually{}
20 % \begin{macro}{\@addtoreset}
21 % add |\@elt{#1}| to |\cl@#2|.
22 % This differs from the kernel implementation insofar as we trail the
23 % cl lists until we find one that is empty or starts with |\@elt|.
24 % \begin{macrocode}
25 \def\aliasctr@f@llow#1#2\@nil#3{%
26 \ifx#1\@elt
27 \noexpand #3%
28 \else
29 \expandafter\aliasctr@f@llow#1\@elt\@nil{#1}%
30 \fi
31 }
32 % \end{macrocode}
33 %
34 % \begin{macrocode}
35 \newcommand\aliasctr@follow[1]{%
36 \expandafter\aliasctr@f@llow
37 % \end{macrocode}
38 % Don't be confused: the third parameter is ignored here, we always
39 % have recursion here since the \emph{token} |\cl@#1| is (hopefully) not |\@elt|.
40 % \begin{macrocode}
41 \csname cl@#1\endcsname\@elt\@nil{\csname cl@#1\endcsname}%
42 }
43 % \end{macrocode}
44 %
45 % \begin{macrocode}
46 \renewcommand*\@addtoreset[2]{\bgroup
47 \edef\aliasctr@@truelist{\aliasctr@follow{#2}}%
48 \let\@elt\relax
49 \expandafter\@cons\aliasctr@@truelist{{#1}}%
50 \egroup}
51 % \end{macrocode}
52 %
53 % This code has been adapted from David Carlisle's \pkg{remreset}. We
54 % load that here only to prevent it from being loaded again.
55 % \begin{macrocode}
56 % FMi 2019-07-31 \@removereset is in the kernel these days
57 \@ifundefined{@removefromreset}{\RequirePackage{remreset}}{}
58 \renewcommand*\@removefromreset[2]{\bgroup
59 \edef\aliasctr@@truelist{\aliasctr@follow{#2}}%
60 \expandafter\let\csname c@#1\endcsname\@removefromreset
61 \def\@elt##1{%
62 \expandafter\ifx\csname c@##1\endcsname\@removefromreset
63 \else
64 \noexpand\@elt{##1}%
65 \fi}%
66 \expandafter\xdef\aliasctr@@truelist{%
67 \aliasctr@@truelist}
68 \egroup}
69 % \end{macrocode}
70 % \end{macro}
71 %
72 % \begin{macro}{\@counteralias}
73 % make |#1| a counter that uses counter |#2|'s count register.
74 % \begin{macrocode}
75 \newcommand\@counteralias[2]{{%
76 \def\@@gletover##1##2{%
77 \expandafter\global
78 \expandafter\let\csname ##1\expandafter\endcsname
79 \csname ##2\endcsname
80 }%
81 \@ifundefined{c@#2}{\@nocounterr{#2}}{%
82 \expandafter\@ifdefinable\csname c@#1\endcsname{%
83 % \end{macrocode}
84 % Four values make a counter foo:
85 % \begin{itemize}
86 % \item the count register accessed through |\c@foo|,
87 % \item the output macro |\thefoo|,
88 % \item the prefix macro |\p@foo|,
89 % \item the reset list |\cl@foo|.
90 % \end{itemize}
91 % \pkg{hyperref} adds |\theHfoo| in particular.
92 % \begin{macrocode}
93 \@@gletover{c@#1}{c@#2}%
94 \@@gletover{the#1}{the#2}%
95 % \end{macrocode}
96 % I don't see |\@counteralias| being called hundreds of times,
97 % let's just unconditionally create |\theHctr|-macros for \pkg{hyperref}.
98 % \begin{macrocode}
99 \@@gletover{theH#1}{theH#2}%
100 % \end{macrocode}
101 % YkC: Compatibility with \pkg{cleveref}, copied from \pkg{cleveref}'s
102 % support for \pkg{aliascnt}.
103 % Here |\cref@resetby| requires its first argument to be the actual counter
104 % name, not a macro storing the name. Thanks to Willie Wong.
105 % \begin{macrocode}
106 \@ifpackageloaded{cleveref}{%
107 \edef\aliasctr@temp{%
108 \noexpand\cref@resetby{#2}{\noexpand\cref@result}}%
109 \aliasctr@temp
110 \ifx\cref@result\relax\else%
111 \cref@addtoreset{#1}{\cref@result}%
112 \fi
113 }{}%
114 \@@gletover{p@#1}{p@#2}%
115 \expandafter\global
116 \expandafter\def\csname cl@#1\expandafter\endcsname
117 \expandafter{\csname cl@#2\endcsname}%
118 % \end{macrocode}
119 % It is not necessary to save the value again: since we share a
120 % count register, we will pick up the restored value of the
121 % original counter.
122 % \begin{macrocode}
123 %\@addtoreset{#1}{@ckpt}%
124 }%
125 }%
126 }}
127 % \end{macrocode}
128 % \end{macro}
129 %\iffalse
130 %</code>
131 %\fi