summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/thmtools/aliasctr.dtx
blob: 2d88038c08332dc045e8f3bd8b2b652d92949739 (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
% \iffalse meta-comment
%
% Copyright (C) 2005-2014 by Ulrich M. Schwarz
% Copyright (C) 2019      by Frank Mittelbach
% Copyright (C) 2020-     by Yukai Chou
%
% This file may be distributed and/or modified under the conditions of
% the LaTeX Project Public License, version 1.3c.
% The license can be obtained from
% http://www.latex-project.org/lppl/lppl-1-3c.txt
%
%<*code>
% \fi
%    |\@counteralias{#1}{#2}| makes |#1| a counter that uses |#2|'s count register.
%    This is useful for things like \pkg{hyperref}'s |\autoref|, which otherwise
%    can't distinguish theorems and definitions if they share a counter.
%
%    For detailed information, see Die TeXnische Kom\"odie 3/2006.
%    \StopEventually{}
%    \begin{macro}{\@addtoreset}
%    add |\@elt{#1}| to |\cl@#2|.
%    This differs from the kernel implementation insofar as we trail the
%    cl lists until we find one that is empty or starts with |\@elt|.
%    \begin{macrocode}
\def\aliasctr@f@llow#1#2\@nil#3{%
  \ifx#1\@elt
  \noexpand #3%
  \else
  \expandafter\aliasctr@f@llow#1\@elt\@nil{#1}%
  \fi
}
%    \end{macrocode}
%    
%    \begin{macrocode}
\newcommand\aliasctr@follow[1]{%
  \expandafter\aliasctr@f@llow
%    \end{macrocode}
%    Don't be confused: the third parameter is ignored here, we always
%    have recursion here since the \emph{token} |\cl@#1| is (hopefully) not |\@elt|.
%    \begin{macrocode}
  \csname cl@#1\endcsname\@elt\@nil{\csname cl@#1\endcsname}%
}
%    \end{macrocode}
%    
%    \begin{macrocode}
\renewcommand*\@addtoreset[2]{\bgroup
   \edef\aliasctr@@truelist{\aliasctr@follow{#2}}%
  \let\@elt\relax
  \expandafter\@cons\aliasctr@@truelist{{#1}}%
\egroup}
%    \end{macrocode}
%    
%    This code has been adapted from David Carlisle's \pkg{remreset}. We
%    load that here only to prevent it from being loaded again.
%    \begin{macrocode}
% FMi 2019-07-31 \@removereset is in the kernel these days
\@ifundefined{@removefromreset}{\RequirePackage{remreset}}{}
\renewcommand*\@removefromreset[2]{\bgroup
  \edef\aliasctr@@truelist{\aliasctr@follow{#2}}%
  \expandafter\let\csname c@#1\endcsname\@removefromreset
  \def\@elt##1{%
    \expandafter\ifx\csname c@##1\endcsname\@removefromreset
    \else
      \noexpand\@elt{##1}%
    \fi}%
  \expandafter\xdef\aliasctr@@truelist{%
    \aliasctr@@truelist}
\egroup}
%    \end{macrocode}
%    \end{macro}
%    
%    \begin{macro}{\@counteralias}
%    make |#1| a counter that uses counter |#2|'s count register.
%    \begin{macrocode}
\newcommand\@counteralias[2]{{%
    \def\@@gletover##1##2{%
      \expandafter\global
      \expandafter\let\csname ##1\expandafter\endcsname
      \csname ##2\endcsname
    }%
    \@ifundefined{c@#2}{\@nocounterr{#2}}{%
      \expandafter\@ifdefinable\csname c@#1\endcsname{%
%    \end{macrocode}
%    Four values make a counter foo:
%    \begin{itemize}
%    \item the count register accessed through |\c@foo|,
%    \item the output macro |\thefoo|,
%    \item the prefix macro |\p@foo|,
%    \item the reset list |\cl@foo|.
%    \end{itemize}
%    \pkg{hyperref} adds |\theHfoo| in particular.
%    \begin{macrocode}
        \@@gletover{c@#1}{c@#2}%
        \@@gletover{the#1}{the#2}%
%    \end{macrocode}
%    I don't see |\@counteralias| being called hundreds of times,
%    let's just unconditionally create  |\theHctr|-macros for \pkg{hyperref}.
%    \begin{macrocode}
        \@@gletover{theH#1}{theH#2}%
%    \end{macrocode}
%    YkC: Compatibility with \pkg{cleveref}, copied from \pkg{cleveref}'s 
%    support for \pkg{aliascnt}. 
%    Here |\cref@resetby| requires its first argument to be the actual counter
%    name, not a macro storing the name. Thanks to Willie Wong.
%    \begin{macrocode}
        \@ifpackageloaded{cleveref}{%
          \edef\aliasctr@temp{%
            \noexpand\cref@resetby{#2}{\noexpand\cref@result}}%
          \aliasctr@temp
          \ifx\cref@result\relax\else%
            \cref@addtoreset{#1}{\cref@result}%
          \fi
        }{}%
        \@@gletover{p@#1}{p@#2}%
        \expandafter\global
        \expandafter\def\csname cl@#1\expandafter\endcsname
        \expandafter{\csname cl@#2\endcsname}%
%    \end{macrocode}
%    It is not necessary to save the value again: since we share a
%    count register, we will pick up the restored value of the
%    original counter.
%    \begin{macrocode}
        %\@addtoreset{#1}{@ckpt}%
      }%
    }%
}}
%    \end{macrocode}
%    \end{macro}
%\iffalse
%</code>
%\fi