| 1 |
% \iffalse |
| 2 |
%% File: nameref.dtx |
| 3 |
%% Copyright (C) 1995-1999 Sebastian Rahtz |
| 4 |
%% 2000 Sebastian Rahtz, Heiko Oberdiek |
| 5 |
%% 2001-2012 Heiko Oberdiek |
| 6 |
%% 2016-2019 Oberdiek Package Support Group |
| 7 |
%% 2019-2026 The LaTeX Project |
| 8 |
%% https://github.com/latex3/hyperref/issues |
| 9 |
%% |
| 10 |
%% This file is part of the `Hyperref Bundle'. |
| 11 |
%% ------------------------------------------- |
| 12 |
%% |
| 13 |
%% This work may be distributed and/or modified under the |
| 14 |
%% conditions of the LaTeX Project Public License, either version 1.3 |
| 15 |
%% of this license or (at your option) any later version. |
| 16 |
%% The latest version of this license is in |
| 17 |
%% http://www.latex-project.org/lppl.txt |
| 18 |
%% and version 1.3 or later is part of all distributions of LaTeX |
| 19 |
%% version 2005/12/01 or later. |
| 20 |
%% |
| 21 |
%% This work has the LPPL maintenance status `maintained'. |
| 22 |
%% |
| 23 |
%% The Current Maintainer of this work is The LaTeX Project. |
| 24 |
%% |
| 25 |
%% The list of all files belonging to the `Hyperref Bundle' is |
| 26 |
%% given in the file `manifest.txt'. |
| 27 |
% |
| 28 |
%<*dtx> |
| 29 |
\ProvidesFile{nameref.dtx} |
| 30 |
%</dtx> |
| 31 |
%<package>\NeedsTeXFormat{LaTeX2e} |
| 32 |
%<package>\ProvidesPackage{nameref} |
| 33 |
%<driver>\ProvidesFile{nameref.drv} |
| 34 |
% \fi |
| 35 |
% \ProvidesFile{nameref.dtx} |
| 36 |
[2026-01-29 v2.58 Cross-referencing by name of section]% |
| 37 |
% |
| 38 |
% |
| 39 |
% \iffalse |
| 40 |
%<*driver> |
| 41 |
\PassOptionsToPackage{numbered}{hypdoc} |
| 42 |
\documentclass{ltxdoc} |
| 43 |
\usepackage[numbered]{hypdoc} |
| 44 |
\usepackage{bmhydoc} |
| 45 |
\usepackage{hologo} |
| 46 |
\EnableCrossrefs |
| 47 |
\CodelineIndex |
| 48 |
\newcommand*{\xpackage}[1]{\textsf{#1}} |
| 49 |
\begin{document} |
| 50 |
\GetFileInfo{nameref.sty}% |
| 51 |
\title{% |
| 52 |
Section name references in \LaTeX |
| 53 |
\thanks{% |
| 54 |
This file has version number \fileversion, % |
| 55 |
last revised \filedate.% |
| 56 |
}% |
| 57 |
}% |
| 58 |
\author{Sebastian Rahtz (deceased)\\% |
| 59 |
Heiko Oberdiek (inactive)\\% |
| 60 |
The \LaTeX\ Project\\% |
| 61 |
\texttt{https://github.com/latex3/hyperref/issues}}% |
| 62 |
\date{\filedate}% |
| 63 |
\maketitle |
| 64 |
\makeatletter |
| 65 |
\@ifundefined{HyperrefOverview}{}{% |
| 66 |
\HyperrefOverview*% |
| 67 |
}% |
| 68 |
\tableofcontents |
| 69 |
\DocInput{nameref.dtx}% |
| 70 |
\PrintIndex |
| 71 |
\end{document} |
| 72 |
%</driver> |
| 73 |
% \fi |
| 74 |
% |
| 75 |
% \StopEventually{} |
| 76 |
% |
| 77 |
% \section{Introduction} |
| 78 |
% Cross-referencing to include the \emph{name} of the section, rather than |
| 79 |
% just the number or page. This works by redefining some of the inside |
| 80 |
% \LaTeX\ macros, so it is vulnerable to future changes. |
| 81 |
% |
| 82 |
% \section{Background and advice for package and class authors} |
| 83 |
% The package redefines the \cs{label} command to write additionally |
| 84 |
% \cs{@currentlabelname} to the \texttt{.aux} file. This can then be referenced with |
| 85 |
% \cs{nameref}. Package authors who want to support \textsf{nameref} should |
| 86 |
% define this command (locally) in a suitable way. |
| 87 |
% The content should be so that it can be safely written |
| 88 |
% to the \texttt{.aux} file. \textsf{nameref} itself uses the package |
| 89 |
% \textsf{gettitlestring} but this is not required. |
| 90 |
% |
| 91 |
% \textsf{nameref} patches a number of commands (mostly sectioning |
| 92 |
% commands) and environments so that they |
| 93 |
% store \cs{@currentlabelname}. A class or a package that want to provide native |
| 94 |
% support instead can suppress this patches by defining commands described below. |
| 95 |
% The commands must be defined before the patch is made, in most cases before |
| 96 |
% \textsf{nameref} is loaded, sometimes only before begin document. |
| 97 |
% |
| 98 |
% \begin{description} |
| 99 |
% \item[sectioning commands] Redefined are |
| 100 |
% \begin{itemize} |
| 101 |
% \item |
| 102 |
% \cs{@sect}: beside adding a command that stores the |
| 103 |
% title of a sectioning command (if present the optional argument is used) |
| 104 |
% \textsf{nameref} also stores the level number in a counter \texttt{section@level} |
| 105 |
% (reason is unknown, only two packages, \textsf{e-french} and \textsf{pdfscreen} |
| 106 |
% seem to use it), and surrounds the text with \cs{Sectionformat} (only used by |
| 107 |
% \textsf{acmart}, \textsf{memoir}, \textsf{pdfscreen}, \textsf{pdfslide}), a |
| 108 |
% command which takes two argument: the first the text, the second the level. |
| 109 |
% |
| 110 |
% \item \cs{@ssect}: command to store the title added, |
| 111 |
% \cs{Sectionformat} is added. |
| 112 |
% |
| 113 |
% \item \cs{@part}, \cs{@spart}, \cs{@chapter}, \cs{@schapter}: |
| 114 |
% command to store the title added |
| 115 |
% \end{itemize} |
| 116 |
% |
| 117 |
% All the patches excepted the last are disabled if the command |
| 118 |
% \cs{NR@nopatch@sectioning} is defined (the actual definition is irrelevant, only |
| 119 |
% existence is tested. |
| 120 |
% This currently only suppress the actual patches, the counter, |
| 121 |
% \cs{Sectionformat} and also the internal copies \cs{NR@sect} etc are still |
| 122 |
% defined. |
| 123 |
% |
| 124 |
% \item[captions] The following commands are patched |
| 125 |
% \begin{itemize} |
| 126 |
% \item \cs{@caption}: command to store the title added. This is done at begin |
| 127 |
% document, but only if \textsf{hyperref} is not detected. With \textsf{hyperref} |
| 128 |
% the patch is done there (and must be disabled in \textsf{hyperref}). |
| 129 |
% |
| 130 |
% This patch can be disabled by defining \cs{NR@nopatch@caption} |
| 131 |
% |
| 132 |
% \item \cs{LT@c@ption} (from the \textsf{longtable} package): |
| 133 |
% command to store the title added. |
| 134 |
% |
| 135 |
% This patch can be disabled by defining \cs{NR@nopatch@longtable} |
| 136 |
% |
| 137 |
% \item \cs{lst@MakeCaption} (from the \textsf{listings} package) |
| 138 |
% |
| 139 |
% This patch can be disabled by defining \cs{NR@nopatch@listings} |
| 140 |
% \end{itemize} |
| 141 |
% |
| 142 |
% \item[lists] The following command is patched |
| 143 |
% \begin{itemize} |
| 144 |
% \item \cs{descriptionlabel}: command to store the label text added. To |
| 145 |
% reference this text the \cs{label} must be put \emph{inside} the label. |
| 146 |
% This is not compatible with the \textsf{enumitem} package as internal |
| 147 |
% formatting commands are written to the \texttt{.aux} file too. |
| 148 |
% |
| 149 |
% This patch can be disabled by defining \cs{NR@nopatch@lists} |
| 150 |
% \end{itemize} |
| 151 |
% |
| 152 |
% \item[theorems] |
| 153 |
% |
| 154 |
% \begin{itemize} |
| 155 |
% \item \cs{@opargbegintheorem}: command to store the title added. |
| 156 |
% |
| 157 |
% This patch can be disabled by defining \cs{NR@nopatch@theorem} |
| 158 |
% |
| 159 |
% \item \cs{@begintheorem} (if amsthm is loaded and if |
| 160 |
% the command has a tested meaning): command to store the title added. |
| 161 |
% |
| 162 |
% This patch can be disabled by defining \cs{NR@nopatch@amsthm} |
| 163 |
% |
| 164 |
% \end{itemize} |
| 165 |
% \item[beamer] In the \textsf{beamer} class the following commands are |
| 166 |
% patched: \cs{beamer@section}, \cs{beamer@subsection}, \cs{beamer@subsubsection}, |
| 167 |
% \cs{beamer@descriptionitem} and the template \texttt{theorem begin}. If |
| 168 |
% \cs{NR@nopatch@beamer} is defined nothing is done. |
| 169 |
% \end{description} |
| 170 |
% |
| 171 |
% \section{History} |
| 172 |
% Sebastian Rahtz, for Lou Burnard, March 15th 1994;\\ |
| 173 |
% SPQR CERN July 1994;\\ |
| 174 |
% Last mod. Sept. 3th MG;\\ |
| 175 |
% Sept. 19th SPQR;\\ |
| 176 |
% April 11th 1995 SPQR (added section formatting hook);\\ |
| 177 |
% April 14th 1995 SPQR (compatibility with hyperref);\\ |
| 178 |
% June 22 1995 SPQR (removed typeout from Sectionformat);\\ |
| 179 |
% September 22 1997 added varioref hacks by Corey Minyard;\\ |
| 180 |
% September 28th changes by David Carlisle.\\ |
| 181 |
% More recent changes are recorded in ChangeLog. |
| 182 |
% |
| 183 |
% The versions before 2009/11/27 v2.32 did not expand the |
| 184 |
% title strings (of \cs{section}, \cs{caption}, \dots). |
| 185 |
% Then the behaviour switched to expanding, because this |
| 186 |
% allows to remove unwanted macros (\cs{label}, \dots). |
| 187 |
% Despite this method is used in package \textsf{titleref} |
| 188 |
% and class \textsf{memoir}, the first feedbacks let me conclude |
| 189 |
% that this is not robust enough. Therefore I wrote package |
| 190 |
% \textsf{gettitlestring} that uses the non-expanding |
| 191 |
% method as default. It also allows me to use this package |
| 192 |
% in package \textsf{zref-titleref}. |
| 193 |
% See the package documentation of package \textsf{gettitlestring} |
| 194 |
% how to change the method. It also provides a hook to remove |
| 195 |
% additional unwanted macros, not supported by the package. |
| 196 |
% Example: |
| 197 |
%\begin{quote} |
| 198 |
%\begin{verbatim} |
| 199 |
%\usepackage{gettitlestring} |
| 200 |
%\GetTitleStringDisableCommands{% |
| 201 |
% \let\mylabel\@gobble |
| 202 |
% \renewcommand\myindex[2]{}% |
| 203 |
%} |
| 204 |
%\end{verbatim} |
| 205 |
%\end{quote} |
| 206 |
% |
| 207 |
% \section{Implementation} |
| 208 |
% \begin{macrocode} |
| 209 |
%<*package> |
| 210 |
% \end{macrocode} |
| 211 |
% |
| 212 |
% \begin{macrocode} |
| 213 |
\RequirePackage{refcount}[2006/02/12] |
| 214 |
\RequirePackage{gettitlestring}[2009/12/18] |
| 215 |
% \end{macrocode} |
| 216 |
|
| 217 |
% \begin{macrocode} |
| 218 |
\ExplSyntaxOn |
| 219 |
\let\NR@GlobalAppendToMacro\tl_gput_right:Nn |
| 220 |
\ExplSyntaxOff |
| 221 |
|
| 222 |
% \end{macrocode} |
| 223 |
% In formats older than 2023-06-01 |
| 224 |
% we redefine |\label| so that it also writes the name of the |
| 225 |
% current section to the .aux file; if the name ends in a dot, |
| 226 |
% we zap it. To allow for the \xpackage{hyperref} package, also write |
| 227 |
% fourth and fifth fields (empty by default; |
| 228 |
% used for cross-ref name, and file). |
| 229 |
% \begin{macro}{\NR@strip@period} |
| 230 |
% \begin{macrocode} |
| 231 |
\def\NR@strip@period#1.\@empty#2\@nil{#1} |
| 232 |
% \end{macrocode} |
| 233 |
% \end{macro} |
| 234 |
% |
| 235 |
% \begin{macro}{\strip@period} |
| 236 |
% Macro \cs{strip@period} was removed in \xpackage{nameref} |
| 237 |
% 2012/07/28 v2.41 and reinserted in 2012/07/31 v2.42 for compatibility |
| 238 |
% reasons with package \xpackage{subfig}. |
| 239 |
% \begin{macrocode} |
| 240 |
\def\strip@period#1.\relax#2\@@@{#1} |
| 241 |
% \end{macrocode} |
| 242 |
% \end{macro} |
| 243 |
% |
| 244 |
% \begin{macrocode} |
| 245 |
\def\NR@sanitize@labelname{% |
| 246 |
\@onelevel@sanitize\@currentlabelname |
| 247 |
\edef\@currentlabelname{% |
| 248 |
\expandafter\NR@strip@period\@currentlabelname |
| 249 |
\@empty.\@empty\@nil |
| 250 |
}% |
| 251 |
} |
| 252 |
% \end{macrocode} |
| 253 |
% |
| 254 |
% \subsection{\cs{label} stuff} |
| 255 |
% |
| 256 |
% Here is tested, whether package \xpackage{showkeys} is loaded. |
| 257 |
% But if option final is used, the macros of \xpackage{showkeys} |
| 258 |
% are not defined, so we have to check an additional |
| 259 |
% test. |
| 260 |
% \begin{macro}{\ifNR@showkeys} |
| 261 |
% \begin{macrocode} |
| 262 |
\newif\ifNR@showkeys |
| 263 |
\NR@showkeysfalse |
| 264 |
\@ifpackageloaded{showkeys}{% |
| 265 |
\begingroup |
| 266 |
\@ifundefined{SK@@label}{% |
| 267 |
}{% |
| 268 |
\global\NR@showkeystrue |
| 269 |
}% |
| 270 |
\endgroup |
| 271 |
}{} |
| 272 |
% \end{macrocode} |
| 273 |
% \end{macro} |
| 274 |
% \begin{macro}{\label@hook} |
| 275 |
% Starting with LaTeX 2023-06-01 it is not longer needed to |
| 276 |
% redefine \cs{label} as the kernel provides a hook and |
| 277 |
% stores \cs{@currentlabelname}. But as there are packages like ntheorem |
| 278 |
% and revtex which overwrites the kernel definition and then break nameref |
| 279 |
% and hyperref we add a guard. |
| 280 |
% We still support \cs{label@hook} for now as it is used below in \cs{slabel} |
| 281 |
% and also in hyperref. |
| 282 |
% \begin{macrocode} |
| 283 |
\providecommand*{\label@hook}{} |
| 284 |
\NR@GlobalAppendToMacro{\label@hook}{% |
| 285 |
\NR@sanitize@labelname |
| 286 |
} |
| 287 |
\@ifl@t@r\fmtversion{2023-06-01} |
| 288 |
{ |
| 289 |
\def\NR@label@copy#1{\@bsphack |
| 290 |
\begingroup |
| 291 |
\UseHookWithArguments{label}{1}{#1}% |
| 292 |
\protected@write\@auxout{}% |
| 293 |
{\string\newlabel{#1}{{\@currentlabel}{\thepage}% |
| 294 |
{\@currentlabelname}{\@currentHref}{\@kernel@reserved@label@data}}}% |
| 295 |
\endgroup |
| 296 |
\@esphack} |
| 297 |
\@ifl@t@r\fmtversion{2026-06-01} |
| 298 |
{ |
| 299 |
\def\NR@label@copy#1{\@bsphack |
| 300 |
\begingroup |
| 301 |
\UseHookWithArguments{label}{1}{#1}% |
| 302 |
\protected@write\@auxout{\let\label\@gobble@om\let\index\@gobble@som\let\glossary\@gobble@om}% |
| 303 |
{\string\newlabel{#1}{{\@currentlabel}{\thepage}% |
| 304 |
{\@currentlabelname}{\@currentHref}{\@kernel@reserved@label@data}}}% |
| 305 |
\endgroup |
| 306 |
\@esphack |
| 307 |
}} |
| 308 |
{} |
| 309 |
\ifx\label\NR@label@copy |
| 310 |
\else |
| 311 |
\PackageWarning{nameref}{The definition of \string\label\space has changed! |
| 312 |
\MessageBreak Check your packages! |
| 313 |
\MessageBreak Replacing it with the kernel definition} |
| 314 |
\let\label\NR@label@copy |
| 315 |
\let\ltx@label\label %for amsmath |
| 316 |
\fi |
| 317 |
\AddToHookWithArguments{label}{\def\label@name{#1}\label@hook} |
| 318 |
} |
| 319 |
{ |
| 320 |
|
| 321 |
% \end{macrocode} |
| 322 |
% \end{macro} |
| 323 |
% \begin{macro}{\label} |
| 324 |
% \begin{macrocode} |
| 325 |
\def\label#1{% |
| 326 |
\@bsphack |
| 327 |
\begingroup |
| 328 |
\def\label@name{#1}% |
| 329 |
\label@hook |
| 330 |
\protected@write\@auxout{}{% |
| 331 |
\string\newlabel{#1}{% |
| 332 |
{\@currentlabel}% |
| 333 |
{\thepage}% |
| 334 |
{\@currentlabelname}% |
| 335 |
{\@currentHref}{}% |
| 336 |
}% |
| 337 |
}% |
| 338 |
\endgroup |
| 339 |
\@esphack |
| 340 |
}% |
| 341 |
\ifNR@showkeys |
| 342 |
\def\label#1{% |
| 343 |
\@bsphack |
| 344 |
\SK@\SK@@label{#1}% |
| 345 |
\begingroup |
| 346 |
\def\label@name{#1}% |
| 347 |
\label@hook |
| 348 |
\protected@write\@auxout{}{% |
| 349 |
\string\newlabel{#1}{% |
| 350 |
{\@currentlabel}% |
| 351 |
{\thepage}% |
| 352 |
{\@currentlabelname}% |
| 353 |
{\@currentHref}{}% |
| 354 |
}% |
| 355 |
}% |
| 356 |
\endgroup |
| 357 |
\@esphack |
| 358 |
}% |
| 359 |
\fi |
| 360 |
} |
| 361 |
% \end{macrocode} |
| 362 |
% \end{macro} |
| 363 |
% \begin{macro}{\ltx@label} |
| 364 |
% Starting with LaTeX 2023-06-01 it is not longer needed to update the |
| 365 |
% amsmath command \cs{ltx@label} as nameref no longer changes \cs{label} |
| 366 |
% \begin{macrocode} |
| 367 |
\@ifl@t@r\fmtversion{2023-06-01} |
| 368 |
{}{\let\ltx@label\label} |
| 369 |
% \end{macrocode} |
| 370 |
% \end{macro} |
| 371 |
% Needed for the \emph{subeqnarray} package. |
| 372 |
% \begin{macro}{\slabel} |
| 373 |
% \begin{macrocode} |
| 374 |
\@ifundefined{slabel}{}{% |
| 375 |
\def\slabel#1{% |
| 376 |
\@bsphack |
| 377 |
\if@filesw |
| 378 |
\begingroup |
| 379 |
\def\label@name{#1}% |
| 380 |
\label@hook |
| 381 |
\let\thepage\relax |
| 382 |
\def\protect{\noexpand\noexpand\noexpand}% |
| 383 |
\edef\@tempa{% |
| 384 |
\write\@auxout{% |
| 385 |
\string\newlabel{#1}{% |
| 386 |
{\thesubequation}% |
| 387 |
{\thepage}% |
| 388 |
{\@currentlabelname}% |
| 389 |
{\@currentHref}{}% |
| 390 |
}% |
| 391 |
}% |
| 392 |
}% |
| 393 |
\expandafter\endgroup |
| 394 |
\@tempa |
| 395 |
\if@nobreak\ifvmode\nobreak\fi\fi |
| 396 |
\fi |
| 397 |
\@esphack |
| 398 |
}% |
| 399 |
} |
| 400 |
% \end{macrocode} |
| 401 |
% \end{macro} |
| 402 |
% Overload an AMS \hologo{LaTeX} command, which uses |\newlabel|. Sigh! |
| 403 |
% \begin{macro}{\@writetocindents@} |
| 404 |
% \begin{macrocode} |
| 405 |
\def\@writetocindents@{% |
| 406 |
\begingroup |
| 407 |
\@for\@tempa:=-1,0,1,2,3\do{% |
| 408 |
\immediate\write\@auxout{% |
| 409 |
\string\newlabel{tocindent\@tempa}{% |
| 410 |
\csname r@tocindent\@tempa\endcsname{}{}{}{}% |
| 411 |
}% |
| 412 |
}% |
| 413 |
}% |
| 414 |
\endgroup |
| 415 |
} |
| 416 |
% \end{macrocode} |
| 417 |
% \end{macro} |
| 418 |
% |
| 419 |
% \subsection{Changes of section macros} |
| 420 |
% |
| 421 |
% Add to the underlying section heading macros so that they |
| 422 |
% note the section name for use by label. |
| 423 |
% |
| 424 |
% If a section heading or the like has a |\label| in it, |
| 425 |
% we need to extract it, or subsequent processing breaks. |
| 426 |
% |
| 427 |
% \begin{macro}{\NR@gettitle} |
| 428 |
% \begin{macrocode} |
| 429 |
\def\NR@gettitle#1{% |
| 430 |
\GetTitleString{#1}% |
| 431 |
\let\@currentlabelname\GetTitleStringResult |
| 432 |
} |
| 433 |
% \end{macrocode} |
| 434 |
% \end{macro} |
| 435 |
% |
| 436 |
% First the numbered sections. While we are about it, put in |
| 437 |
% a useful section formatting macro. |
| 438 |
% \begin{macro}{\NR@sect} |
| 439 |
% \begin{macrocode} |
| 440 |
\let\NR@sect\@sect |
| 441 |
% \end{macrocode} |
| 442 |
% \end{macro} |
| 443 |
% \begin{macrocode} |
| 444 |
\newcounter{section@level} |
| 445 |
% \end{macrocode} |
| 446 |
% \begin{macro}{\@sect} |
| 447 |
% \begin{macrocode} |
| 448 |
\@ifundefined{NR@nopatch@sectioning} |
| 449 |
{\def\@sect#1#2#3#4#5#6[#7]#8{% |
| 450 |
\setcounter{section@level}{#2}% |
| 451 |
\NR@gettitle{#7}% |
| 452 |
\NR@sect{#1}{#2}{#3}{#4}{#5}{#6}[{#7}]{\Sectionformat{#8}{#2}}% |
| 453 |
}}{} |
| 454 |
% \end{macrocode} |
| 455 |
% \end{macro} |
| 456 |
% and now the unnumbered ones |
| 457 |
% \begin{macro}{\NR@ssect} |
| 458 |
% \begin{macrocode} |
| 459 |
\let\NR@ssect\@ssect |
| 460 |
% \end{macrocode} |
| 461 |
% \end{macro} |
| 462 |
% \begin{macro}{\@ssect} |
| 463 |
% \begin{macrocode} |
| 464 |
\@ifundefined{NR@nopatch@sectioning} |
| 465 |
{\def\@ssect#1#2#3#4#5{% |
| 466 |
\NR@gettitle{#5}% |
| 467 |
\NR@ssect{#1}{#2}{#3}{#4}{\Sectionformat{#5}{#1}}% |
| 468 |
}}{} |
| 469 |
% \end{macrocode} |
| 470 |
% \end{macro} |
| 471 |
% |
| 472 |
% Parts and chapters are treated differently. sigh. |
| 473 |
% \cs{@part} and \cs{@spart} are \cs{long} because of class memoir. |
| 474 |
% |
| 475 |
% \begin{macrocode} |
| 476 |
\let\NR@part\@part |
| 477 |
\let\NR@spart\@spart |
| 478 |
\let\NR@chapter\@chapter |
| 479 |
\let\NR@schapter\@schapter |
| 480 |
\@ifundefined{NR@nopatch@sectioning} |
| 481 |
{% |
| 482 |
\long\def\@part[#1]#2{% |
| 483 |
\NR@gettitle{#1}% |
| 484 |
\NR@part[{#1}]{#2}% |
| 485 |
} |
| 486 |
\long\def\@spart#1{% |
| 487 |
\NR@gettitle{#1}% |
| 488 |
\NR@spart{#1}% |
| 489 |
} |
| 490 |
\def\@chapter[#1]#2{% |
| 491 |
\NR@gettitle{#1}% |
| 492 |
\NR@chapter[{#1}]{#2}% |
| 493 |
} |
| 494 |
\def\@schapter#1{% |
| 495 |
\NR@gettitle{#1}% |
| 496 |
\NR@schapter{#1}% |
| 497 |
}}{} |
| 498 |
% \end{macrocode} |
| 499 |
% |
| 500 |
% Captions |
| 501 |
% |
| 502 |
% \begin{macrocode} |
| 503 |
\AtBeginDocument{% |
| 504 |
\@ifpackageloaded{hyperref}{} |
| 505 |
{% |
| 506 |
\@ifundefined{NR@nopatch@caption} |
| 507 |
{\let\NR@@caption\@caption |
| 508 |
\long\def\@caption#1[#2]{% |
| 509 |
\NR@gettitle{#2}% |
| 510 |
\NR@@caption{#1}[{#2}]% |
| 511 |
}}% |
| 512 |
{}% |
| 513 |
}% |
| 514 |
% \end{macrocode} |
| 515 |
% |
| 516 |
% \begin{macrocode} |
| 517 |
\@ifpackageloaded{longtable}{% |
| 518 |
\@ifundefined{NR@nopatch@longtable} |
| 519 |
{% |
| 520 |
\let\NRorg@LT@c@ption\LT@c@ption |
| 521 |
\def\LT@c@ption#1[#2]#3{% |
| 522 |
\NRorg@LT@c@ption{#1}[{#2}]{#3}% |
| 523 |
\def\@tempa{#2}% |
| 524 |
\ifx\@tempa\@empty |
| 525 |
\else |
| 526 |
\NR@gettitle{#2}% |
| 527 |
\fi |
| 528 |
}% |
| 529 |
}{}% |
| 530 |
}{}% |
| 531 |
% \end{macrocode} |
| 532 |
% |
| 533 |
% Environment `description'. |
| 534 |
% \begin{macrocode} |
| 535 |
\@ifundefined{descriptionlabel}{% |
| 536 |
}{% |
| 537 |
\@ifundefined{NR@nopatch@lists} |
| 538 |
{\let\NRorg@descriptionlabel\descriptionlabel |
| 539 |
\def\descriptionlabel#1{% |
| 540 |
\NR@gettitle{#1}% |
| 541 |
\NRorg@descriptionlabel{#1}% |
| 542 |
}% |
| 543 |
}{}% |
| 544 |
}% |
| 545 |
} |
| 546 |
% \end{macrocode} |
| 547 |
% |
| 548 |
% \subsubsection{Theorems} |
| 549 |
% |
| 550 |
% \begin{macrocode} |
| 551 |
\@ifundefined{NR@nopatch@theorem}{% |
| 552 |
\@ifundefined{@opargbegintheorem}{}{% |
| 553 |
\let\NRorg@opargbegintheorem\@opargbegintheorem |
| 554 |
\def\@opargbegintheorem#1#2#3{% |
| 555 |
\NR@gettitle{#3}% |
| 556 |
\NRorg@opargbegintheorem{#1}{#2}{#3}% |
| 557 |
}% |
| 558 |
} |
| 559 |
}{} |
| 560 |
\@ifundefined{NR@nopatch@amsthm}{% |
| 561 |
\AtBeginDocument{% |
| 562 |
\@ifpackageloaded{amsthm}{% |
| 563 |
\let\NRorg@begintheorem\@begintheorem |
| 564 |
\begingroup |
| 565 |
\edef\x{macro:\string#1\string#2[\string#3]}% |
| 566 |
\@onelevel@sanitize\x |
| 567 |
\def\y#1->#2\@nil{#1}% |
| 568 |
\edef\z{\expandafter\y\meaning\@begintheorem->\@nil}% |
| 569 |
\@onelevel@sanitize\z |
| 570 |
\expandafter\endgroup |
| 571 |
\ifx\x\z |
| 572 |
\def\@begintheorem#1#2[#3]{% |
| 573 |
\NR@gettitle{#3}% |
| 574 |
\NRorg@begintheorem{#1}{#2}[{#3}]% |
| 575 |
}% |
| 576 |
\fi |
| 577 |
}{}% |
| 578 |
}}{} |
| 579 |
% \end{macrocode} |
| 580 |
% |
| 581 |
% \subsection{Referencing stuff} |
| 582 |
% |
| 583 |
% We default the label and hypertext reference to be empty. |
| 584 |
% \begin{macrocode} |
| 585 |
\providecommand*{\@currentlabelname}{} |
| 586 |
\providecommand*{\@currentHref}{} |
| 587 |
% \end{macrocode} |
| 588 |
% Since the second part of the preserved reference now has five parts |
| 589 |
% (number, page, name, hypertext reference and file), we need extra utility |
| 590 |
% macros: |
| 591 |
% \begin{macro}{\@firstoffive} |
| 592 |
% \begin{macrocode} |
| 593 |
\long\def\@firstoffive#1#2#3#4#5{#1} |
| 594 |
% \end{macrocode} |
| 595 |
% \end{macro} |
| 596 |
% \begin{macro}{\@secondoffive} |
| 597 |
% \begin{macrocode} |
| 598 |
\long\def\@secondoffive#1#2#3#4#5{#2} |
| 599 |
% \end{macrocode} |
| 600 |
% \end{macro} |
| 601 |
% \begin{macro}{\@thirdoffive} |
| 602 |
% \begin{macrocode} |
| 603 |
\long\def\@thirdoffive#1#2#3#4#5{#3} |
| 604 |
% \end{macrocode} |
| 605 |
% \end{macro} |
| 606 |
% \begin{macro}{\@fourthoffive} |
| 607 |
% \begin{macrocode} |
| 608 |
\long\def\@fourthoffive#1#2#3#4#5{#4} |
| 609 |
% \end{macrocode} |
| 610 |
% \end{macro} |
| 611 |
% \begin{macro}{\@fifthoffive} |
| 612 |
% \begin{macrocode} |
| 613 |
\long\def\@fifthoffive#1#2#3#4#5{#5} |
| 614 |
% \end{macrocode} |
| 615 |
% \end{macro} |
| 616 |
% We have to redefine |\ref|, |\Ref| and |\pageref| to know about extra |
| 617 |
% reference elements. Make them robust, and compatible with Babel. |
| 618 |
% We also define starred versions so that it doesn't depend on hyperref |
| 619 |
% if they are defined or not. We use the same internal names as hyperref. |
| 620 |
% The Babel switch is mimicked if not already defined. |
| 621 |
% Some support for package \xpackage{showkeys} is implemented. If |
| 622 |
% option |notref| of that package is set, |\SK@ref| has the |
| 623 |
% meaning of |\@empty|. |
| 624 |
% \begin{macro}{\@safe@activestrue} |
| 625 |
% \begin{macrocode} |
| 626 |
\providecommand*\@safe@activestrue{}% |
| 627 |
% \end{macrocode} |
| 628 |
% \end{macro} |
| 629 |
% \begin{macro}{\@safe@activesfalse} |
| 630 |
% \begin{macrocode} |
| 631 |
\providecommand*\@safe@activesfalse{}% |
| 632 |
% \end{macrocode} |
| 633 |
% \end{macro} |
| 634 |
% \begin{macro}{\NR@ref@showkeys} |
| 635 |
% \begin{macrocode} |
| 636 |
\newcommand\NR@ref@showkeys[1]{}% |
| 637 |
% \end{macrocode} |
| 638 |
% \end{macro} |
| 639 |
% \begin{macro}{\NR@setref} |
| 640 |
% \begin{macrocode} |
| 641 |
\def\NR@setref#1{% |
| 642 |
\begingroup |
| 643 |
\@safe@activestrue |
| 644 |
\expandafter |
| 645 |
\endgroup |
| 646 |
\expandafter\NR@@setref\csname r@#1\endcsname |
| 647 |
} |
| 648 |
% \end{macrocode} |
| 649 |
% \end{macro} |
| 650 |
% \begin{macro}{\NR@@setref} |
| 651 |
% \begin{macrocode} |
| 652 |
\def\NR@@setref#1{% |
| 653 |
\ifx\@undefined#1% |
| 654 |
\let#1\relax |
| 655 |
\fi |
| 656 |
\@setref#1% |
| 657 |
} |
| 658 |
% \end{macrocode} |
| 659 |
% \end{macro} |
| 660 |
% \begin{macro}{\T@ref} |
| 661 |
% \begin{macrocode} |
| 662 |
\def\T@ref#1{% |
| 663 |
\NR@ref@showkeys{#1}% |
| 664 |
\NR@setref{#1}\@firstoffive{#1}% |
| 665 |
}% |
| 666 |
% \end{macrocode} |
| 667 |
% \end{macro} |
| 668 |
% \begin{macro}{\@refstar} |
| 669 |
% \begin{macrocode} |
| 670 |
\def\@refstar#1{% |
| 671 |
\NR@ref@showkeys{#1}% |
| 672 |
\NR@setref{#1}\@firstoffive{#1}% |
| 673 |
}% |
| 674 |
% \end{macrocode} |
| 675 |
% \end{macro} |
| 676 |
% \begin{macro}{\T@pageref} |
| 677 |
% \begin{macrocode} |
| 678 |
\def\T@pageref#1{% |
| 679 |
\NR@ref@showkeys{#1}% |
| 680 |
\NR@setref{#1}\@secondoffive{#1}% |
| 681 |
}% |
| 682 |
% \end{macrocode} |
| 683 |
% \end{macro} |
| 684 |
% \begin{macro}{\@pagerefstar} |
| 685 |
% \begin{macrocode} |
| 686 |
\def\@pagerefstar#1{% |
| 687 |
\NR@ref@showkeys{#1}% |
| 688 |
\NR@setref{#1}\@secondoffive{#1}% |
| 689 |
}% |
| 690 |
% \end{macrocode} |
| 691 |
% \end{macro}% |
| 692 |
% \begin{macro}{\T@Ref} |
| 693 |
% \begin{macrocode} |
| 694 |
\def\T@Ref#1{% |
| 695 |
\NR@ref@showkeys{#1}% |
| 696 |
\NR@setref{#1}\NR@MakeUppercaseFirstOfFive{#1}% |
| 697 |
}% |
| 698 |
\def\NR@MakeUppercaseFirstOfFive#1#2#3#4#5{% |
| 699 |
\MakeUppercase#1% |
| 700 |
}% |
| 701 |
% \end{macrocode} |
| 702 |
% \end{macro} |
| 703 |
% \begin{macro}{\@Refstar} |
| 704 |
% \begin{macrocode} |
| 705 |
\def\@Refstar#1{% |
| 706 |
\NR@ref@showkeys{#1}% |
| 707 |
\NR@setref{#1}\NR@MakeUppercaseFirstOfFive{#1}% |
| 708 |
}% |
| 709 |
% \end{macrocode} |
| 710 |
% \end{macro}% |
| 711 |
% \begin{macrocode} |
| 712 |
\ifNR@showkeys |
| 713 |
\ifx\SK@ref\@empty |
| 714 |
\else |
| 715 |
\renewcommand\NR@ref@showkeys[1]{% |
| 716 |
\@safe@activestrue |
| 717 |
\SK@\SK@@ref{#1}% |
| 718 |
\@safe@activesfalse} |
| 719 |
\fi |
| 720 |
\fi |
| 721 |
% \end{macrocode} |
| 722 |
% Package \xpackage{hyperref} uses the same |
| 723 |
% definitions of |\ref|, |\Ref| and |
| 724 |
% |\pageref| but has to redefine the non-starred command to |
| 725 |
% add the hyperlink support. |
| 726 |
% |\DeclareRobustCommand| is used by \xpackage{hyperref}. |
| 727 |
% Package |nameref| can be loaded before, after |
| 728 |
% \xpackage{hyperref} or after |
| 729 |
% \xpackage{hyperref}'s definitions in |\AtBeginDocument|. |
| 730 |
% We have to postpone the definition to |\AtBeginDocument| to |
| 731 |
% avoid that showkeys overwrites them again. |
| 732 |
% \begin{macrocode} |
| 733 |
\AddToHook{begindocument}{% |
| 734 |
% \end{macrocode} |
| 735 |
% \begin{macro}{\ref} |
| 736 |
% \begin{macrocode} |
| 737 |
\DeclareDocumentCommand\ref{s} |
| 738 |
{\IfBooleanTF{#1}{\@refstar}{\T@ref}}% |
| 739 |
% \end{macrocode} |
| 740 |
% \end{macro} |
| 741 |
% \begin{macro}{\pageref} |
| 742 |
% \begin{macrocode} |
| 743 |
\DeclareDocumentCommand\pageref{s} |
| 744 |
{\IfBooleanTF{#1}{\@pagerefstar}{\T@pageref}}% |
| 745 |
% \end{macrocode} |
| 746 |
% \end{macro} |
| 747 |
% \begin{macro}{\Ref} |
| 748 |
% \begin{macrocode} |
| 749 |
\DeclareDocumentCommand\Ref{s} |
| 750 |
{\IfBooleanTF{#1}{\@Refstar}{\T@Ref}}% |
| 751 |
% \end{macrocode} |
| 752 |
% \end{macro} |
| 753 |
% \begin{macrocode} |
| 754 |
} |
| 755 |
% \end{macrocode} |
| 756 |
% \begin{macrocode} |
| 757 |
\DeclareHookRule{begindocument}{showkeys}{before}{nameref} |
| 758 |
% \end{macrocode} |
| 759 |
% |
| 760 |
% |
| 761 |
% \subsection{Usage and frontend} |
| 762 |
% Access the (third) name part with |\nameref|; |
| 763 |
% \begin{macro}{\T@nameref} |
| 764 |
% \begin{macrocode} |
| 765 |
\def\T@nameref#1{% |
| 766 |
\NR@ref@showkeys{#1}% |
| 767 |
\begingroup |
| 768 |
\let\label\@gobble |
| 769 |
\NR@setref{#1}\@thirdoffive{#1}% |
| 770 |
\endgroup |
| 771 |
}% |
| 772 |
% \end{macrocode} |
| 773 |
% \end{macro} |
| 774 |
% \begin{macro}{\@namerefstar} |
| 775 |
% \begin{macrocode} |
| 776 |
\def\@namerefstar#1{% |
| 777 |
\NR@ref@showkeys{#1}% |
| 778 |
\begingroup |
| 779 |
\let\label\@gobble |
| 780 |
\NR@setref{#1}\@thirdoffive{#1}% |
| 781 |
\endgroup |
| 782 |
}% |
| 783 |
% \end{macrocode} |
| 784 |
% \end{macro} |
| 785 |
% \begin{macrocode} |
| 786 |
% \end{macrocode} |
| 787 |
% \begin{macro}{\nameref} |
| 788 |
% \begin{macrocode} |
| 789 |
\@ifundefined{nameref} |
| 790 |
{ |
| 791 |
\NewDocumentCommand\nameref{s} |
| 792 |
{\IfBooleanTF{#1}{\@namerefstar}{\T@nameref}} |
| 793 |
} |
| 794 |
{ |
| 795 |
\PackageWarning{nameref}{Redefining \string\nameref} |
| 796 |
\RenewDocumentCommand\nameref{s} |
| 797 |
{\IfBooleanTF{#1}{\@namerefstar}{\T@nameref}} |
| 798 |
} |
| 799 |
% \end{macrocode} |
| 800 |
% \end{macro} |
| 801 |
% \begin{macro}{\Nameref} |
| 802 |
% An extended form which gives title and page number. |
| 803 |
% Not really useful, quotes are english, and no starred version. |
| 804 |
% varioref can do that better. Remove?? |
| 805 |
% \begin{macrocode} |
| 806 |
\def\Nameref#1{`\nameref{#1}' on page~\pageref{#1}} |
| 807 |
% \end{macrocode} |
| 808 |
% \end{macro} |
| 809 |
% |
| 810 |
% \begin{macro}{\Sectionformat} |
| 811 |
% The default for |\Sectionformat| |
| 812 |
% \begin{macrocode} |
| 813 |
\providecommand\Sectionformat[2]{#1} |
| 814 |
% \end{macrocode} |
| 815 |
% \end{macro} |
| 816 |
% |
| 817 |
% |
| 818 |
% \subsection{Compatibility with varioref} |
| 819 |
% |
| 820 |
% [This section was derived by Corey Minyard \texttt{[email protected]} |
| 821 |
% from the \xpackage{varioref} package] |
| 822 |
% Changed in 2019-09-12 by Frank Mittelbach to adapt to changes in |
| 823 |
% varioref |
| 824 |
% \begin{macrocode} |
| 825 |
\AtBeginDocument{% |
| 826 |
\ifx\csname @@vpageref\endcsname\relax |
| 827 |
\else |
| 828 |
% \end{macrocode} |
| 829 |
% This requires a varioref newer than 2019-09-12 |
| 830 |
% \begin{macrocode} |
| 831 |
\let\NR@@vpageref\@@vpageref |
| 832 |
\def\@@vpageref#1[#2]#3{% |
| 833 |
\begingroup |
| 834 |
\csname @safe@activestrue\endcsname |
| 835 |
\edef\x{#3}% |
| 836 |
\@onelevel@sanitize\x |
| 837 |
\toks@{% |
| 838 |
\NR@@vpageref{#1}[{#2}]% |
| 839 |
}% |
| 840 |
\edef\x{\endgroup |
| 841 |
\the\toks@{\x}% |
| 842 |
}% |
| 843 |
\x |
| 844 |
}% |
| 845 |
\DeclareRobustCommand\vnameref[1]{% |
| 846 |
\unskip~\nameref{#1} % |
| 847 |
\@vpageref[\unskip]{#1}% |
| 848 |
}% |
| 849 |
\fi |
| 850 |
} |
| 851 |
% \end{macrocode} |
| 852 |
% |
| 853 |
% \subsection{Support for package \xpackage{listings}} |
| 854 |
% |
| 855 |
% \begin{macrocode} |
| 856 |
\AtBeginDocument{% |
| 857 |
\@ifpackageloaded{listings}{% |
| 858 |
\@ifundefined{NR@nopatch@listings} |
| 859 |
{% |
| 860 |
\let\NROrg@lst@MakeCaption\lst@MakeCaption |
| 861 |
\def\lst@MakeCaption{% |
| 862 |
\ifx\lst@label\@empty |
| 863 |
\else |
| 864 |
\let\@currentlabelname\lst@@caption |
| 865 |
\fi |
| 866 |
\NROrg@lst@MakeCaption |
| 867 |
}% |
| 868 |
}{}% |
| 869 |
}{}% |
| 870 |
} |
| 871 |
% \end{macrocode} |
| 872 |
% |
| 873 |
% \begin{macrocode} |
| 874 |
%</package> |
| 875 |
% \end{macrocode} |
| 876 |
% |
| 877 |
% \Finale |
| 878 |
\endinput |