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 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426
|
\def\filedate{2003/12/03}
\def\fileversion{2.21}
%
% \iffalse
% File: nameref.dtx
% Copyright (C) 1995-9 Sebastian Rahtz
% 2000-3 Sebastian Rahtz, Heiko Oberdiek
%
%% This file is part of the `Hyperref Bundle'.
%% -------------------------------------------
%%
%% It may be distributed under the conditions of the LaTeX Project Public
%% License, either version 1.2 of this license or (at your option) any
%% later version. The latest version of this license is in
%% http://www.latex-project.org/lppl.txt
%% and version 1.2 or later is part of all distributions of LaTeX
%% version 1999/12/01 or later.
%%
%% The list of all files belonging to the `Hyperref Bundle' is
%% given in the file `manifest.txt'.
%<*driver>
\documentclass{ltxdoc}
\begin{document}
\title{%
Section name references in \LaTeX
\thanks{%
This file has version number \fileversion,
last revised \filedate.%
}%
}
\author{Sebastian Rahtz}
\date{\filedate}
\maketitle
\tableofcontents
\DocInput{nameref.dtx}
\end{document}
%</driver>
% \fi
% \CheckSum{463}
% \StopEventually{}
% \section{Introduction}
% Cross-referencing to include the \emph{name} of the section, rather than
% just the number or page. This works by redefining some of the inside
% \LaTeX\ macros, so it is vulnerable to future changes.
% \section{History}
% Sebastian Rahtz, for Lou Burnard, March 15th 1994;
% SPQR CERN July 1994;
% Last mod. Sept. 3th MG;
% Sept. 19th SPQR;
% April 11th 1995 SPQR (added section formatting hook);
% April 14th 1995 SPQR (compatibility with hyperref);
% June 22 1995 SPQR (removed typeout from Sectionformat);
% September 22 1997 added varioref hacks by Corey Minyard;
% September 28th changes by David Carlisle.
% \begin{macrocode}
%<*package>
\ProvidesPackage{nameref}[\filedate\space v\fileversion
\space Cross-referencing by name of section]
% \end{macrocode}
%
% We redefine |\label| so that it also writes the name of the
% current section to the .aux file; if the name ends in a dot,
% we zap it. To allow for the hyperref package, also write
% fourth and fifth fields (empty by default;
% used for cross-ref name, and file).
% \begin{macrocode}
\def\strip@period#1.\relax#2\@@@{#1}
% \end{macrocode}
%
% Here is tested, whether package showkeys is loaded.
% But if option final is used, the macros of showkeys
% are not defined, so we have to check an additional
% test.
% \begin{macrocode}
\newif\ifNR@showkeys
\NR@showkeysfalse
\@ifpackageloaded{showkeys}{%
\begingroup
\@ifundefined{SK@@label}{%
}{%
\global\NR@showkeystrue
}%
\endgroup
}{}
% \end{macrocode}
% \begin{macrocode}
\def\label#1{%
\@bsphack
\begingroup
\let\label\@gobble
\def\ref{\protect\ref}%
\edef\@currentlabstr{%
\expandafter\strip@prefix\meaning\@currentlabelname
}%
\protected@write\@auxout{}{%
\string\newlabel{#1}{%
{\@currentlabel}%
{\thepage}%
{\expandafter\strip@period\@currentlabstr\relax.\relax\@@@}%
{\@currentHref}{}%
}%
}%
\endgroup
\@esphack
}%
\ifNR@showkeys
\def\label#1{%
\@bsphack
\SK@\SK@@label{#1}%
\begingroup
\let\label\@gobble
\def\ref{\protect\ref}%
\edef\@currentlabstr{%
\expandafter\strip@prefix\meaning\@currentlabelname
}%
\protected@write\@auxout{}{%
\string\newlabel{#1}{%
{\@currentlabel}%
{\thepage}%
{\expandafter\strip@period\@currentlabstr\relax.\relax\@@@}%
{\@currentHref}{}%
}%
}%
\endgroup
\@esphack
}%
\fi
% \end{macrocode}
% \begin{macrocode}
\let\ltx@label\label
% \end{macrocode}
% Needed for the \emph{subeqnarray} package.
% \begin{macrocode}
\@ifundefined{slabel}{}{%
\def\slabel#1{%
\@bsphack
\if@filesw
{%
\let\label\@gobble
\def\ref{\protect\ref}%
\edef\@currentlabstr{%
\expandafter\strip@prefix\meaning\@currentlabelname
}%
\let\thepage\relax
\def\protect{\noexpand\noexpand\noexpand}%
\edef\@tempa{%
\write\@auxout{%
\string\newlabel{#1}{%
{\thesubequation}%
{\thepage}%
{\expandafter\strip@period
\@currentlabstr\relax.\relax\@@@}%
{\@currentHref}{}%
}%
}%
}%
\expandafter
}%
\@tempa
\if@nobreak\ifvmode\nobreak\fi\fi
\fi
\@esphack
}%
}
% \end{macrocode}
% Overload an AMS \LaTeX\ command, which uses |\newlabel|. Sigh!
% \begin{macrocode}
\def\@writetocindents@{%
\begingroup
\@for\@tempa:=-1,0,1,2,3\do{%
\immediate\write\@auxout{%
\string\newlabel{tocindent\@tempa}{%
\csname r@tocindent\@tempa\endcsname{}{}{}{}%
}%
}%
}%
\endgroup}
% \end{macrocode}
% Add to the underlying section heading macros so that they
% note the section name for use by label.
%
% If a section heading or the like has a |\label| in it,
% we need to extract it, or subsequent processing breaks.
% This is done by the label-writing routine.
%
% First the numbered sections. While we are about it, put in
% a useful section formatting macro.
% \begin{macrocode}
\let\NR@sect\@sect
\newcounter{section@level}
\def\@sect#1#2#3#4#5#6[#7]#8{%
\setcounter{section@level}{#2}%
\def\@currentlabelname{#7}%
\NR@sect{#1}{#2}{#3}{#4}{#5}{#6}[{#7}]{\Sectionformat{#8}{#2}}%
}
% \end{macrocode}
% and now the unnumbered ones
% \begin{macrocode}
\let\NR@ssect\@ssect
\def\@ssect#1#2#3#4#5{%
\def\@currentlabelname{#5}%
\NR@ssect{#1}{#2}{#3}{#4}{\Sectionformat{#5}{#1}}%
}
% \end{macrocode}
%
% Parts and chapters are treated differently. sigh.
%
% \begin{macrocode}
\let\NR@part\@part
\def\@part[#1]#2{%
\def\@currentlabelname{#1}%
\NR@part[{#1}]{#2}%
}
\let\NR@chapter\@chapter
\def\@chapter[#1]#2{%
\def\@currentlabelname{#1}%
\NR@chapter[{#1}]{#2}%
}
\let\NR@schapter\@schapter
\def\@schapter#1{%
\def\@currentlabelname{#1}%
\NR@schapter{#1}%
}
% \end{macrocode}
%
% Compatibility for package titlesec.
% \begin{macrocode}
\AtBeginDocument{%
\@ifpackageloaded{titlesec}{%
\let\NRorg@ttl@sect@i\ttl@sect@i
\def\ttl@sect@i#1#2[#3]#4{%
\def\@currentlabelname{#4}%
\NRorg@ttl@sect@i{#1}{#2}[{#3}]{#4}%
}%
}{}%
}
% \end{macrocode}
%
% We default the label and hypertext reference to be empty.
% \begin{macrocode}
\def\@currentlabelname{}
\def\@currentHref{}
% \end{macrocode}
% Since the second part of the preserved reference now has five parts
% (number, page, name, hypertext reference and file), we need extra utility
% macros:
% \begin{macrocode}
\long\def\@firstoffive#1#2#3#4#5{#1}
\long\def\@secondoffive#1#2#3#4#5{#2}
\long\def\@thirdoffive#1#2#3#4#5{#3}
\long\def\@fourthoffive#1#2#3#4#5{#4}
\long\def\@fifthoffive#1#2#3#4#5{#5}
% \end{macrocode}
% We have to redefine |\ref| and |\pageref| to know about extra
% reference elements. Make them robust, and compatible with Babel.
% The Babel switch is mimicked if not already defined.
% Some support for package |showkeys| is implemented. If
% option |notref| of that package is set, |\SK@ref| has the
% meaning of |\@empty|.
% \begin{macrocode}
\providecommand*\@safe@activestrue{}%
\providecommand*\@safe@activesfalse{}%
\def\T@ref#1{%
\@safe@activestrue
\expandafter\@setref\csname r@#1\endcsname\@firstoffive{#1}%
\@safe@activesfalse
}%
\def\T@pageref#1{%
\@safe@activestrue
\expandafter\@setref\csname r@#1\endcsname\@secondoffive{#1}%
\@safe@activesfalse
}%
\ifNR@showkeys
\ifx\SK@ref\@empty
\else
\def\T@ref#1{%
\@safe@activestrue
\SK@\SK@@ref{#1}%
\expandafter\@setref\csname r@#1\endcsname\@firstoffive{#1}%
\@safe@activesfalse
}%
\def\T@pageref#1{%
\@safe@activestrue
\SK@\SK@@ref{#1}%
\expandafter\@setref\csname r@#1\endcsname\@secondoffive{#1}%
\@safe@activesfalse
}%
\fi
\fi
% \end{macrocode}
% Package |hyperref| uses its own definitions of |\ref| and
% |\pageref| because it extends the syntax by the star form.
% |\DeclareRobustCommand| is used by hyperref.
% Package |nameref| can be loaded before, after hyperref or after
% hyperref's definitions in |\AtBeginDocument|.
% \begin{macrocode}
\@ifpackageloaded{hyperref}{%
}{%
\DeclareRobustCommand{\ref}{\T@ref}%
\DeclareRobustCommand{\pageref}{\T@pageref}%
}
% \end{macrocode}
% \section{Usage and frontend}
% Access the (third) name part with |\nameref|;
% \begin{macrocode}
\def\T@nameref#1{%
\@safe@activestrue
\expandafter\@setref\csname r@#1\endcsname\@thirdoffive{#1}%
\@safe@activesfalse
}%
\ifNR@showkeys
\ifx\SK@ref\@empty
\else
\def\T@nameref#1{%
\@safe@activestrue
\SK@\SK@@ref{#1}%
\expandafter\@setref\csname r@#1\endcsname\@thirdoffive{#1}%
\@safe@activesfalse
}%
\fi
\fi
\def\nameref{\protect\T@nameref}
% \end{macrocode}
% An extended form which gives title and page number.
% \begin{macrocode}
\def\Nameref#1{`\nameref{#1}' on page~\pageref{#1}}
% \end{macrocode}
%
% The default for |\Sectionformat|
% \begin{macrocode}
\providecommand\Sectionformat[2]{#1}
% \end{macrocode}
% \subsection{Compatibility with varioref}
% [This section was derived by Corey Minyard \texttt{minyard@acm.org}
% from the varioref package]
% \begin{macrocode}
\ifx\csname @@vpageref\endcsname\relax
\else
\def\@@vpageref#1[#2]#3{%
\leavevmode\unskip
\global\advance\c@vrcnt\@ne
\@ifundefined{r@\the\c@vrcnt @vr}%
{\@namedef{r@\the\c@vrcnt @vr}{{??}{??}{??}{??}{??}}}{}%
\edef\@tempa{%
\expandafter\expandafter\expandafter
\@secondoffive\csname r@\the\c@vrcnt @vr\endcsname
}%
\@ifundefined{r@\the\c@vrcnt @xvr}%
{\@namedef{r@\the\c@vrcnt @xvr}{{??}{??}{??}{??}{??}}}{}%
\edef\@tempb{%
\expandafter\expandafter\expandafter
\@secondoffive\csname r@\the\c@vrcnt @xvr\endcsname
}%
{%
\let\@currentlabel\@empty
\expandafter\label\expandafter{\the\c@vrcnt @xvr}%
}%
\ifx\@tempa\@tempb
\else
\vref@err{%
\noexpand\vref at page boundary
\@tempb-\@tempa\space (may loop)%
}%
\fi
\@ifundefined{r@#3}{\@namedef{r@#3}{{??}{??}{??}{??}{??}}}{}%
\edef\@tempb{%
\expandafter\expandafter\expandafter
\@secondoffive\csname r@#3\endcsname
}%
\space
\ifx\@tempa\@tempb
#1%
\else
#2%
\is@pos@number\@tempb{%
\is@pos@number\@tempa{%
\@tempcnta\@tempa
\advance\@tempcnta\@ne
}{%
\@tempcnta\maxdimen
}%
\ifnum \@tempb =\@tempcnta
\ifodd\@tempcnta
\if@twoside
\reftextfaceafter
\else
\reftextafter
\fi
\else
\reftextafter
\fi
\else
\advance\@tempcnta-2
\ifnum \@tempb =\@tempcnta
\ifodd\@tempcnta
\reftextbefore
\else
\if@twoside
\reftextfacebefore
\else
\reftextbefore
\fi
\fi
\else
\reftextfaraway{#3}%
\fi
\fi
}{%
\reftextfaraway{#3}%
}%
\fi
{%
\let\@currentlabel\@empty
\expandafter\label\expandafter{\the\c@vrcnt @vr}%
}%
}%
\DeclareRobustCommand\vnameref[1]{%
\unskip~\nameref{#1}%
\@vpageref[\unskip]{#1}%
}
\fi
%</package>
% \end{macrocode}
%
% \Finale
\endinput
|