Debian Codegraph @

texmf-dist/source/latex/thmtools/thm-listof.dtx

raw
1 % \iffalse meta-comment
2 %
3 % Copyright (C) 2008-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 % \fi
13 %
14 %\iffalse (hide this from DocInput)
15 %<*listof>
16 %\fi
17 %
18 % This package provides two main commands:
19 % \DescribeMacro{\listoftheorems}
20 % |\listoftheorems| will generate, well, a list of all theorems, lemmas,
21 % etc. in your document. This list is hyperlinked if you use \pkg{hyperref},
22 % and it will list the optional argument to the theorem.
23 %
24 % Currently, some options can be given as an optional argument keyval list:
25 % \begin{description}
26 % \item[numwidth] The width allocated for the numbers, default 2.3em. Since
27 % you are more likely to have by-section numbering than with figures, this
28 % needs to be accessible.
29 % \item[ignore=foo,bar] A last-second call to |\ignoretheorems|, see below.
30 % \item[onlynamed=foo,bar] Only list those foo and bar environments that
31 % had an optional title. This weeds out unimportant definitions, for
32 % example. If no argument is given, this applies to all environments
33 % defined by |\newtheorem| and |\declaretheorem|.
34 % \item[show=foo,bar] Undo a previous |\ignoretheorems| and restore default
35 % formatting for these environments. Useful in combination with
36 % ignoreall.
37 % \item[ignoreall]
38 % \item[showall] Like applying ignore or show with a list of all theorems
39 % you have defined.
40 % \item[title]
41 % Provide a title for this list overwriting the default in |\listtheoremname|.
42 % \end{description}
43 %
44 % \DescribeMacro{\listtheoremname}
45 % The heading name is stored in the macro |\listtheoremname| and is
46 % ``List of Theorems'' by default. All other formatting aspects are taken
47 % from |\listoffigures|. (As a matter of fact, |\listoffigures| is called
48 % internally.)
49 %
50 % \DescribeMacro{\ignoretheorems}
51 % |\ignoretheorems|\marg{remark,example,...} can be used to suppress some
52 % types of theorem from the LoTh. Be careful not to have spaces in the list,
53 % those are currently \emph{not} filtered out.
54 %
55 % There's currently no interface to change the look of the list. If you're
56 % daring, the code for the theorem type ``lemma'' is in |\l@lemma| and so on.
57 %
58 %\StopEventually{}
59 % \begin{macrocode}
60 \let\@xa=\expandafter
61 \let\@nx=\noexpand
62 \RequirePackage{thm-patch,keyval,kvsetkeys}
63
64 \def\thmtlo@oldchapter{0}%
65 \newcommand\thmtlo@chaptervspacehack{}
66 \ifcsname c@chapter\endcsname
67 \ifx\c@chapter\relax\else
68 \def\thmtlo@chaptervspacehack{%
69 \ifnum \value{chapter}=\thmtlo@oldchapter\relax\else
70 % new chapter, add vspace to loe.
71 \addtocontents{loe}{\protect\addvspace{10\p@}}%
72 \xdef\thmtlo@oldchapter{\arabic{chapter}}%
73 \fi
74 }%
75 \fi
76 \fi
77
78
79 \providecommand\listtheoremname{List of Theorems}
80 \newcommand\listoftheorems[1][]{%
81 %% much hacking here to pick up the definition from the class
82 %% without oodles of conditionals.
83 \begingroup
84 \setlisttheoremstyle{#1}%
85 \let\listfigurename\listtheoremname
86 \def\contentsline##1{%
87 \csname thmt@contentsline@##1\endcsname{##1}%
88 }%
89 \@for\thmt@envname:=\thmt@allenvs\do{%
90 % CHECK: is \cs{l@\thmt@envname} repeatedly defined?
91 \thmtlo@newentry
92 }%
93 \let\thref@starttoc\@starttoc
94 \def\@starttoc##1{\thref@starttoc{loe}}%
95 % new hack: to allow multiple calls, we defer the opening of the
96 % loe file to AtEndDocument time. This is before the aux file is
97 % read back again, that is early enough.
98 % TODO: is it? crosscheck include/includeonly!
99 \@fileswfalse
100 \AtEndDocument{%
101 \if@filesw
102 \@ifundefined{tf@loe}{%
103 \expandafter\newwrite\csname tf@loe\endcsname
104 \immediate\openout \csname tf@loe\endcsname \jobname.loe\relax
105 }{}%
106 \fi
107 }%
108 %\expandafter
109 \listoffigures
110 \endgroup
111 }
112
113 \newcommand\setlisttheoremstyle[1]{%
114 \kvsetkeys{thmt-listof}{#1}%
115 }
116 \define@key{thmt-listof}{numwidth}{\def\thmt@listnumwidth{#1}}
117 \define@key{thmt-listof}{ignore}[\thmt@allenvs]{\ignoretheorems{#1}}
118 \define@key{thmt-listof}{onlynamed}[\thmt@allenvs]{\onlynamedtheorems{#1}}
119 \define@key{thmt-listof}{show}[\thmt@allenvs]{\showtheorems{#1}}
120 \define@key{thmt-listof}{ignoreall}[true]{\ignoretheorems{\thmt@allenvs}}
121 \define@key{thmt-listof}{showall}[true]{\showtheorems{\thmt@allenvs}}
122 % FMi 2019-09-31 allow local title
123 \define@key{thmt-listof}{title}{\def\listtheoremname{#1}}
124 % -- FMi
125 \newif\ifthmt@listswap
126 \def\thmt@TRUE{true}
127 \def\thmt@FALSE{false}
128 \define@key{thmt-listof}{swapnumber}[true]{%
129 \def\thmt@tmp{#1}%
130 \ifx\thmt@tmp\thmt@TRUE
131 \thmt@listswaptrue
132 \else\ifx\thmt@tmp\thmt@FALSE
133 \thmt@listswapfalse
134 \else
135 \PackageError{thmtools}{Unknown value `#1' to key swapnumber}{}%
136 \fi\fi
137 }
138
139 \ifdefined\@tocline
140 % for ams classes (amsart.cls, amsproc.cls, amsbook.cls) which
141 % don't use \@dottedtocline and don't provide \@dotsep
142 \def\thmtlo@newentry{%
143 \@xa\def\csname l@\thmt@envname\endcsname{% CHECK: why p@edef?
144 % similar to \l@figure defined in ams classes
145 \@tocline{0}{3pt plus2pt}{0pt}{\thmt@listnumwidth}{}%
146 }%
147 }
148 \providecommand*\thmt@listnumwidth{1.5pc}
149 \else
150 \def\thmtlo@newentry{%
151 \@xa\def\csname l@\thmt@envname\endcsname{% CHECK: why p@edef?
152 \@dottedtocline{1}{1.5em}{\thmt@listnumwidth}%
153 }%
154 }
155 \providecommand*\thmt@listnumwidth{2.3em}
156 \fi
157
158 \providecommand\thmtformatoptarg[1]{ (#1)}
159
160 \newcommand\thmt@mklistcmd{%
161 \thmtlo@newentry
162 \ifthmt@isstarred
163 \@xa\def\csname ll@\thmt@envname\endcsname{%
164 \protect\ifthmt@listswap
165 \protect\else
166 \protect\numberline{\protect\let\protect\autodot\protect\@empty}%
167 \protect\fi
168 \thmt@thmname
169 \ifx\@empty\thmt@shortoptarg\else\protect\thmtformatoptarg{\thmt@shortoptarg}\fi
170 }%
171 \else
172 \@xa\def\csname ll@\thmt@envname\endcsname{%
173 \protect\ifthmt@listswap
174 \thmt@thmname~\csname the\thmt@envname\endcsname
175 \protect\else
176 \protect\numberline{\csname the\thmt@envname\endcsname}%
177 \thmt@thmname
178 \protect\fi
179 \ifx\@empty\thmt@shortoptarg\else\protect\thmtformatoptarg{\thmt@shortoptarg}\fi
180 }%
181 \fi
182 \@xa\gdef\csname thmt@contentsline@\thmt@envname\endcsname{%
183 \thmt@contentslineShow% default:show
184 }%
185 }
186 \def\thmt@allenvs{\@gobble}
187 \newcommand\thmt@recordenvname{%
188 \edef\thmt@allenvs{\thmt@allenvs,\thmt@envname}%
189 }
190 \g@addto@macro\thmt@newtheorem@predefinition{%
191 \thmt@mklistcmd
192 \thmt@recordenvname
193 }
194
195 \addtotheorempostheadhook{%
196 \thmtlo@chaptervspacehack
197 \addcontentsline{loe}{\thmt@envname}{%
198 \csname ll@\thmt@envname\endcsname
199 }%
200 }
201
202 \newcommand\showtheorems[1]{%
203 \@for\thmt@thm:=#1\do{%
204 \typeout{showing \thmt@thm}%
205 \@xa\let\csname thmt@contentsline@\thmt@thm\endcsname
206 =\thmt@contentslineShow
207 }%
208 }
209
210 \newcommand\ignoretheorems[1]{%
211 \@for\thmt@thm:=#1\do{%
212 \@xa\let\csname thmt@contentsline@\thmt@thm\endcsname
213 =\thmt@contentslineIgnore
214 }%
215 }
216 \newcommand\onlynamedtheorems[1]{%
217 \@for\thmt@thm:=#1\do{%
218 \global\@xa\let\csname thmt@contentsline@\thmt@thm\endcsname
219 =\thmt@contentslineIfNamed
220 }%
221 }
222
223 \AtBeginDocument{%
224 \@ifpackageloaded{hyperref}{%
225 \let\thmt@hygobble\@gobble
226 }{%
227 \let\thmt@hygobble\@empty
228 }
229 \let\thmt@contentsline\contentsline
230 }
231
232 \def\thmt@contentslineIgnore#1#2#3{%
233 \thmt@hygobble
234 }
235 \def\thmt@contentslineShow{%
236 \thmt@contentsline
237 }
238
239 \def\thmt@contentslineIfNamed#1#2#3{%
240 \thmt@ifhasoptname #2\thmtformatoptarg\@nil{%
241 \thmt@contentslineShow{#1}{#2}{#3}%
242 }{%
243 \thmt@contentslineIgnore{#1}{#2}{#3}%
244 %\thmt@contentsline{#1}{#2}{#3}%
245 }
246 }
247
248 \def\thmt@ifhasoptname #1\thmtformatoptarg#2\@nil{%
249 \ifx\@nil#2\@nil
250 \@xa\@secondoftwo
251 \else
252 \@xa\@firstoftwo
253 \fi
254 }
255 % \end{macrocode}
256 %\iffalse
257 %</listof>
258 %\fi