Debian Codegraph @

texmf-dist/tex/latex/hyperref/nameref.sty

raw
1 %%
2 %% This is file `nameref.sty',
3 %% generated with the docstrip utility.
4 %%
5 %% The original source files were:
6 %%
7 %% nameref.dtx (with options: `package')
8 %%
9 %% Copyright
10 %% 1995-2001 Sebastian Rahtz, with portions written by David Carlisle and Heiko Oberdiek
11 %% 2001-2015 Heiko Oberdiek
12 %% 2016-2019 Oberdiek Package Support Group
13 %% 2019-2026 LaTeX Project
14 %% https://github.com/latex3/hyperref/issues
15 %%
16 %% This file is part of the `Hyperref Bundle'.
17 %% -------------------------------------------
18 %%
19 %% This work may be distributed and/or modified under the
20 %% conditions of the LaTeX Project Public License, either version 1.3
21 %% of this license or (at your option) any later version.
22 %% The latest version of this license is in
23 %% http://www.latex-project.org/lppl.txt
24 %% and version 1.3 or later is part of all distributions of LaTeX
25 %% version 2005/12/01 or later.
26 %%
27 %% This work has the LPPL maintenance status `maintained'.
28 %%
29 %% The Current Maintainer of this work is the LaTeX Project.
30 %%
31 %% The list of all files belonging to the `Hyperref Bundle' is
32 %% given in the file `manifest.txt'.
33 %%
34 %% File: nameref.dtx
35 %% Copyright (C) 1995-1999 Sebastian Rahtz
36 %% 2000 Sebastian Rahtz, Heiko Oberdiek
37 %% 2001-2012 Heiko Oberdiek
38 %% 2016-2019 Oberdiek Package Support Group
39 %% 2019-2026 The LaTeX Project
40 %% https://github.com/latex3/hyperref/issues
41 %%
42 %% This file is part of the `Hyperref Bundle'.
43 %% -------------------------------------------
44 %%
45 %% This work may be distributed and/or modified under the
46 %% conditions of the LaTeX Project Public License, either version 1.3
47 %% of this license or (at your option) any later version.
48 %% The latest version of this license is in
49 %% http://www.latex-project.org/lppl.txt
50 %% and version 1.3 or later is part of all distributions of LaTeX
51 %% version 2005/12/01 or later.
52 %%
53 %% This work has the LPPL maintenance status `maintained'.
54 %%
55 %% The Current Maintainer of this work is The LaTeX Project.
56 %%
57 %% The list of all files belonging to the `Hyperref Bundle' is
58 %% given in the file `manifest.txt'.
59 \NeedsTeXFormat{LaTeX2e}
60 \ProvidesPackage{nameref}
61 [2026-01-29 v2.58 Cross-referencing by name of section]%
62 \RequirePackage{refcount}[2006/02/12]
63 \RequirePackage{gettitlestring}[2009/12/18]
64
65 \ExplSyntaxOn
66 \let\NR@GlobalAppendToMacro\tl_gput_right:Nn
67 \ExplSyntaxOff
68
69 \def\NR@strip@period#1.\@empty#2\@nil{#1}
70 \def\strip@period#1.\relax#2\@@@{#1}
71 \def\NR@sanitize@labelname{%
72 \@onelevel@sanitize\@currentlabelname
73 \edef\@currentlabelname{%
74 \expandafter\NR@strip@period\@currentlabelname
75 \@empty.\@empty\@nil
76 }%
77 }
78 \newif\ifNR@showkeys
79 \NR@showkeysfalse
80 \@ifpackageloaded{showkeys}{%
81 \begingroup
82 \@ifundefined{SK@@label}{%
83 }{%
84 \global\NR@showkeystrue
85 }%
86 \endgroup
87 }{}
88 \providecommand*{\label@hook}{}
89 \NR@GlobalAppendToMacro{\label@hook}{%
90 \NR@sanitize@labelname
91 }
92 \@ifl@t@r\fmtversion{2023-06-01}
93 {
94 \def\NR@label@copy#1{\@bsphack
95 \begingroup
96 \UseHookWithArguments{label}{1}{#1}%
97 \protected@write\@auxout{}%
98 {\string\newlabel{#1}{{\@currentlabel}{\thepage}%
99 {\@currentlabelname}{\@currentHref}{\@kernel@reserved@label@data}}}%
100 \endgroup
101 \@esphack}
102 \@ifl@t@r\fmtversion{2026-06-01}
103 {
104 \def\NR@label@copy#1{\@bsphack
105 \begingroup
106 \UseHookWithArguments{label}{1}{#1}%
107 \protected@write\@auxout{\let\label\@gobble@om\let\index\@gobble@som\let\glossary\@gobble@om}%
108 {\string\newlabel{#1}{{\@currentlabel}{\thepage}%
109 {\@currentlabelname}{\@currentHref}{\@kernel@reserved@label@data}}}%
110 \endgroup
111 \@esphack
112 }}
113 {}
114 \ifx\label\NR@label@copy
115 \else
116 \PackageWarning{nameref}{The definition of \string\label\space has changed!
117 \MessageBreak Check your packages!
118 \MessageBreak Replacing it with the kernel definition}
119 \let\label\NR@label@copy
120 \let\ltx@label\label %for amsmath
121 \fi
122 \AddToHookWithArguments{label}{\def\label@name{#1}\label@hook}
123 }
124 {
125
126 \def\label#1{%
127 \@bsphack
128 \begingroup
129 \def\label@name{#1}%
130 \label@hook
131 \protected@write\@auxout{}{%
132 \string\newlabel{#1}{%
133 {\@currentlabel}%
134 {\thepage}%
135 {\@currentlabelname}%
136 {\@currentHref}{}%
137 }%
138 }%
139 \endgroup
140 \@esphack
141 }%
142 \ifNR@showkeys
143 \def\label#1{%
144 \@bsphack
145 \SK@\SK@@label{#1}%
146 \begingroup
147 \def\label@name{#1}%
148 \label@hook
149 \protected@write\@auxout{}{%
150 \string\newlabel{#1}{%
151 {\@currentlabel}%
152 {\thepage}%
153 {\@currentlabelname}%
154 {\@currentHref}{}%
155 }%
156 }%
157 \endgroup
158 \@esphack
159 }%
160 \fi
161 }
162 \@ifl@t@r\fmtversion{2023-06-01}
163 {}{\let\ltx@label\label}
164 \@ifundefined{slabel}{}{%
165 \def\slabel#1{%
166 \@bsphack
167 \if@filesw
168 \begingroup
169 \def\label@name{#1}%
170 \label@hook
171 \let\thepage\relax
172 \def\protect{\noexpand\noexpand\noexpand}%
173 \edef\@tempa{%
174 \write\@auxout{%
175 \string\newlabel{#1}{%
176 {\thesubequation}%
177 {\thepage}%
178 {\@currentlabelname}%
179 {\@currentHref}{}%
180 }%
181 }%
182 }%
183 \expandafter\endgroup
184 \@tempa
185 \if@nobreak\ifvmode\nobreak\fi\fi
186 \fi
187 \@esphack
188 }%
189 }
190 \def\@writetocindents@{%
191 \begingroup
192 \@for\@tempa:=-1,0,1,2,3\do{%
193 \immediate\write\@auxout{%
194 \string\newlabel{tocindent\@tempa}{%
195 \csname r@tocindent\@tempa\endcsname{}{}{}{}%
196 }%
197 }%
198 }%
199 \endgroup
200 }
201 \def\NR@gettitle#1{%
202 \GetTitleString{#1}%
203 \let\@currentlabelname\GetTitleStringResult
204 }
205 \let\NR@sect\@sect
206 \newcounter{section@level}
207 \@ifundefined{NR@nopatch@sectioning}
208 {\def\@sect#1#2#3#4#5#6[#7]#8{%
209 \setcounter{section@level}{#2}%
210 \NR@gettitle{#7}%
211 \NR@sect{#1}{#2}{#3}{#4}{#5}{#6}[{#7}]{\Sectionformat{#8}{#2}}%
212 }}{}
213 \let\NR@ssect\@ssect
214 \@ifundefined{NR@nopatch@sectioning}
215 {\def\@ssect#1#2#3#4#5{%
216 \NR@gettitle{#5}%
217 \NR@ssect{#1}{#2}{#3}{#4}{\Sectionformat{#5}{#1}}%
218 }}{}
219 \let\NR@part\@part
220 \let\NR@spart\@spart
221 \let\NR@chapter\@chapter
222 \let\NR@schapter\@schapter
223 \@ifundefined{NR@nopatch@sectioning}
224 {%
225 \long\def\@part[#1]#2{%
226 \NR@gettitle{#1}%
227 \NR@part[{#1}]{#2}%
228 }
229 \long\def\@spart#1{%
230 \NR@gettitle{#1}%
231 \NR@spart{#1}%
232 }
233 \def\@chapter[#1]#2{%
234 \NR@gettitle{#1}%
235 \NR@chapter[{#1}]{#2}%
236 }
237 \def\@schapter#1{%
238 \NR@gettitle{#1}%
239 \NR@schapter{#1}%
240 }}{}
241 \AtBeginDocument{%
242 \@ifpackageloaded{hyperref}{}
243 {%
244 \@ifundefined{NR@nopatch@caption}
245 {\let\NR@@caption\@caption
246 \long\def\@caption#1[#2]{%
247 \NR@gettitle{#2}%
248 \NR@@caption{#1}[{#2}]%
249 }}%
250 {}%
251 }%
252 \@ifpackageloaded{longtable}{%
253 \@ifundefined{NR@nopatch@longtable}
254 {%
255 \let\NRorg@LT@c@ption\LT@c@ption
256 \def\LT@c@ption#1[#2]#3{%
257 \NRorg@LT@c@ption{#1}[{#2}]{#3}%
258 \def\@tempa{#2}%
259 \ifx\@tempa\@empty
260 \else
261 \NR@gettitle{#2}%
262 \fi
263 }%
264 }{}%
265 }{}%
266 \@ifundefined{descriptionlabel}{%
267 }{%
268 \@ifundefined{NR@nopatch@lists}
269 {\let\NRorg@descriptionlabel\descriptionlabel
270 \def\descriptionlabel#1{%
271 \NR@gettitle{#1}%
272 \NRorg@descriptionlabel{#1}%
273 }%
274 }{}%
275 }%
276 }
277 \@ifundefined{NR@nopatch@theorem}{%
278 \@ifundefined{@opargbegintheorem}{}{%
279 \let\NRorg@opargbegintheorem\@opargbegintheorem
280 \def\@opargbegintheorem#1#2#3{%
281 \NR@gettitle{#3}%
282 \NRorg@opargbegintheorem{#1}{#2}{#3}%
283 }%
284 }
285 }{}
286 \@ifundefined{NR@nopatch@amsthm}{%
287 \AtBeginDocument{%
288 \@ifpackageloaded{amsthm}{%
289 \let\NRorg@begintheorem\@begintheorem
290 \begingroup
291 \edef\x{macro:\string#1\string#2[\string#3]}%
292 \@onelevel@sanitize\x
293 \def\y#1->#2\@nil{#1}%
294 \edef\z{\expandafter\y\meaning\@begintheorem->\@nil}%
295 \@onelevel@sanitize\z
296 \expandafter\endgroup
297 \ifx\x\z
298 \def\@begintheorem#1#2[#3]{%
299 \NR@gettitle{#3}%
300 \NRorg@begintheorem{#1}{#2}[{#3}]%
301 }%
302 \fi
303 }{}%
304 }}{}
305 \providecommand*{\@currentlabelname}{}
306 \providecommand*{\@currentHref}{}
307 \long\def\@firstoffive#1#2#3#4#5{#1}
308 \long\def\@secondoffive#1#2#3#4#5{#2}
309 \long\def\@thirdoffive#1#2#3#4#5{#3}
310 \long\def\@fourthoffive#1#2#3#4#5{#4}
311 \long\def\@fifthoffive#1#2#3#4#5{#5}
312 \providecommand*\@safe@activestrue{}%
313 \providecommand*\@safe@activesfalse{}%
314 \newcommand\NR@ref@showkeys[1]{}%
315 \def\NR@setref#1{%
316 \begingroup
317 \@safe@activestrue
318 \expandafter
319 \endgroup
320 \expandafter\NR@@setref\csname r@#1\endcsname
321 }
322 \def\NR@@setref#1{%
323 \ifx\@undefined#1%
324 \let#1\relax
325 \fi
326 \@setref#1%
327 }
328 \def\T@ref#1{%
329 \NR@ref@showkeys{#1}%
330 \NR@setref{#1}\@firstoffive{#1}%
331 }%
332 \def\@refstar#1{%
333 \NR@ref@showkeys{#1}%
334 \NR@setref{#1}\@firstoffive{#1}%
335 }%
336 \def\T@pageref#1{%
337 \NR@ref@showkeys{#1}%
338 \NR@setref{#1}\@secondoffive{#1}%
339 }%
340 \def\@pagerefstar#1{%
341 \NR@ref@showkeys{#1}%
342 \NR@setref{#1}\@secondoffive{#1}%
343 }%
344 \def\T@Ref#1{%
345 \NR@ref@showkeys{#1}%
346 \NR@setref{#1}\NR@MakeUppercaseFirstOfFive{#1}%
347 }%
348 \def\NR@MakeUppercaseFirstOfFive#1#2#3#4#5{%
349 \MakeUppercase#1%
350 }%
351 \def\@Refstar#1{%
352 \NR@ref@showkeys{#1}%
353 \NR@setref{#1}\NR@MakeUppercaseFirstOfFive{#1}%
354 }%
355 \ifNR@showkeys
356 \ifx\SK@ref\@empty
357 \else
358 \renewcommand\NR@ref@showkeys[1]{%
359 \@safe@activestrue
360 \SK@\SK@@ref{#1}%
361 \@safe@activesfalse}
362 \fi
363 \fi
364 \AddToHook{begindocument}{%
365 \DeclareDocumentCommand\ref{s}
366 {\IfBooleanTF{#1}{\@refstar}{\T@ref}}%
367 \DeclareDocumentCommand\pageref{s}
368 {\IfBooleanTF{#1}{\@pagerefstar}{\T@pageref}}%
369 \DeclareDocumentCommand\Ref{s}
370 {\IfBooleanTF{#1}{\@Refstar}{\T@Ref}}%
371 }
372 \DeclareHookRule{begindocument}{showkeys}{before}{nameref}
373 \def\T@nameref#1{%
374 \NR@ref@showkeys{#1}%
375 \begingroup
376 \let\label\@gobble
377 \NR@setref{#1}\@thirdoffive{#1}%
378 \endgroup
379 }%
380 \def\@namerefstar#1{%
381 \NR@ref@showkeys{#1}%
382 \begingroup
383 \let\label\@gobble
384 \NR@setref{#1}\@thirdoffive{#1}%
385 \endgroup
386 }%
387 \@ifundefined{nameref}
388 {
389 \NewDocumentCommand\nameref{s}
390 {\IfBooleanTF{#1}{\@namerefstar}{\T@nameref}}
391 }
392 {
393 \PackageWarning{nameref}{Redefining \string\nameref}
394 \RenewDocumentCommand\nameref{s}
395 {\IfBooleanTF{#1}{\@namerefstar}{\T@nameref}}
396 }
397 \def\Nameref#1{`\nameref{#1}' on page~\pageref{#1}}
398 \providecommand\Sectionformat[2]{#1}
399 \AtBeginDocument{%
400 \ifx\csname @@vpageref\endcsname\relax
401 \else
402 \let\NR@@vpageref\@@vpageref
403 \def\@@vpageref#1[#2]#3{%
404 \begingroup
405 \csname @safe@activestrue\endcsname
406 \edef\x{#3}%
407 \@onelevel@sanitize\x
408 \toks@{%
409 \NR@@vpageref{#1}[{#2}]%
410 }%
411 \edef\x{\endgroup
412 \the\toks@{\x}%
413 }%
414 \x
415 }%
416 \DeclareRobustCommand\vnameref[1]{%
417 \unskip~\nameref{#1} %
418 \@vpageref[\unskip]{#1}%
419 }%
420 \fi
421 }
422 \AtBeginDocument{%
423 \@ifpackageloaded{listings}{%
424 \@ifundefined{NR@nopatch@listings}
425 {%
426 \let\NROrg@lst@MakeCaption\lst@MakeCaption
427 \def\lst@MakeCaption{%
428 \ifx\lst@label\@empty
429 \else
430 \let\@currentlabelname\lst@@caption
431 \fi
432 \NROrg@lst@MakeCaption
433 }%
434 }{}%
435 }{}%
436 }
437 \endinput
438 %%
439 %% End of file `nameref.sty'.