summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/thmtools/source/aliasctr.dtx
diff options
context:
space:
mode:
Diffstat (limited to 'macros/latex/contrib/thmtools/source/aliasctr.dtx')
-rw-r--r--macros/latex/contrib/thmtools/source/aliasctr.dtx117
1 files changed, 117 insertions, 0 deletions
diff --git a/macros/latex/contrib/thmtools/source/aliasctr.dtx b/macros/latex/contrib/thmtools/source/aliasctr.dtx
new file mode 100644
index 0000000000..3c75e11c98
--- /dev/null
+++ b/macros/latex/contrib/thmtools/source/aliasctr.dtx
@@ -0,0 +1,117 @@
+% \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}}{%
+ \@ifdefinable{c@#1}{%
+% \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 hyperref.
+% \begin{macrocode}
+ \@@gletover{theH#1}{theH#2}%
+ \@@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