Debian Codegraph @

texmf-dist/source/latex/tools/showkeys.dtx

raw
1 % \iffalse meta-comment
2 %
3 % Copyright (C) 1993-2025
4 %
5 % The LaTeX Project and any individual authors listed elsewhere
6 % in this file.
7 %
8 % This file is part of the Standard LaTeX `Tools Bundle'.
9 % -------------------------------------------------------
10 %
11 % It may be distributed and/or modified under the
12 % conditions of the LaTeX Project Public License, either version 1.3c
13 % of this license or (at your option) any later version.
14 % The latest version of this license is in
15 % https://www.latex-project.org/lppl.txt
16 % and version 1.3c or later is part of all distributions of LaTeX
17 % version 2005/12/01 or later.
18 %
19 % The list of all files belonging to the LaTeX `Tools Bundle' is
20 % given in the file `manifest.txt'.
21 %
22 % \fi
23 % \iffalse
24 %% File: showkeys.dtx Copyright (C) 1992-1997 David Carlisle
25 %% File: showkeys.dtx Copyright (C) 2006-2025 David Carlisle, LaTeX Project
26 %
27 %<*dtx>
28 \ProvidesFile{showkeys.dtx}
29 %</dtx>
30 %<package>\NeedsTeXFormat{LaTeX2e}
31 %<package>
32 % For every rollback request before 2022 use the 2014 version:
33 %<package>\DeclareRelease{}{1994-06-01}{showkeys-2014-10-28.sty}
34 %<package>\DeclareRelease{}{2014-10-28}{showkeys-2014-10-28.sty}
35 %<package>\DeclareCurrentRelease{}{2022-06-01}
36 %<package>
37 %<package>\ProvidesPackage{showkeys}
38 %<driver> \ProvidesFile{showkeys.drv}
39 % \fi
40 % \ProvidesFile{showkeys.dtx}
41 [2024/05/23 v3.21 Show cite and label keys (DPC, MH)]
42 %
43 % \iffalse
44 %<*driver>
45 \documentclass{ltxdoc}
46 \usepackage
47 % [notcite,notref,color]
48 {showkeys}
49 \setlength{\belowcaptionskip}{\baselineskip}
50 \setlength{\abovecaptionskip}{0pt}
51 \begin{document}
52 \DocInput{showkeys.dtx}
53 \end{document}
54 %</driver>
55 % \fi
56 %
57 % \GetFileInfo{showkeys.dtx}
58 % \title{The \textsf{showkeys} package\thanks{This file
59 % has version number \fileversion, last
60 % revised \filedate.}}
61 % \author{David Carlisle \and Morten H\o gholm}
62 % \date{\filedate}
63 % \MaintainedByLaTeXTeam{tools}
64 % \maketitle
65 %
66 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
67 %
68 %
69 %
70 % \changes{v1.01}{1992/08/25}{Initial version}
71 % \changes{v1.02}{1994/01/05}
72 % {Fix incorrect initialisation ([email protected])}
73 % \changes{v2.00}{1994/01/31}{new version for LaTeX2e}
74 % \changes{v2.01}{1994/06/30}{Fix \cs{ProvidesPackage} usage.}
75 % \changes{v3.00}{1994/09/07}
76 % {Support harvard, varioref and natbib packages,}
77 % \changes{v3.02}{1995/03/17}
78 % {Support new AMS files}
79 % \changes{v3.18}{2022/04/12}
80 % {Support starred references}
81 % \section{Introduction}\label{sec:intro}
82 %
83 % |showkeys.sty| modifies the |\label|, |\ref|, |\pageref|, |\cite|, and
84 % |\bibitem| commands so that the `internal' key is printed. The package
85 % tries hard to position these labels so that the formatting of the rest
86 % of the document is unchanged. |\label| and |\bibitem| cause the
87 % key to appear in a box either in the margin, or in a \TeX\ box of zero
88 % width, which may possibly over-print other text. The |\ref|,
89 % |\pageref| and |\cite| commands print their arguments in small type,
90 % raised just above the line, like this: \ref{sec:intro}.
91 % This package works with the \textsf{fleqn} option, the packages
92 % in the AMS-\LaTeX\ collection, and the \textsf{varioref},
93 % \textsf{natbib} and \textsf{harvard} packages.
94 %
95 % \changes{v2.00}{1992/01/31}
96 % {leqno or ams* may now be loaded after showkeys}
97 %
98 % \section{Package Options}\label{options}
99 % Some people have commented that the printing of the |\ref| and
100 % |\cite| keys is less useful than the printing of the |\label| keys
101 % and so \textsf{showkeys} now supports two options that can be given
102 % in the |\usepackage| command:
103 % \begin{description}
104 % \item[notref] to stop the redefinition of |\ref| and |\pageref|,
105 % and related commands from the \textsf{varioref} package.
106 % \item[notcite] to stop the redefinition of |\cite| and related
107 % commands from the \textsf{harvard} and \textsf{natbib} packages.
108 % \end{description}
109 % So if the package is loaded with |\usepackage[notref]{showkeys}|
110 % then |\ref| will have its standard definition, but |\label| will
111 % print its key argument (usually in the margin).
112 %
113 % If you find the printed keys distracting, but don't want to use the
114 % above options to stop them altogether, you may use:
115 % \begin{description}
116 % \item[color] Print the keys in a distinguishing colour. The default
117 % value is a light grey.
118 % \end{description}
119 % The colours may be changed by redefining the following two colours
120 % after the package is loaded:
121 % |refkey| (also used for |\cite|) and
122 % |labelkey| (also used for |\bibitem|).
123 % The defaults are:
124 %\begin{verbatim}
125 % \definecolor{refkey}{gray}{.75}
126 % \definecolor{labelkey}{gray}{.75}
127 %\end{verbatim}
128 %
129 % If this option is used the \textsf{color} package will be loaded.
130 %
131 % The package accepts two further options.
132 % \begin{description}
133 % \item[final] to suppress the action of this package, for `final'
134 % versions.
135 % \item[draft] the normal behaviour of this package.
136 % \end{description}
137 % Clearly there is not much point in entering the |final| option
138 % directly in the |\usepackage| command, as just not loading this
139 % package would have the same effect, and execute more quickly,
140 % however the |final| option may be useful as it may be used once in
141 % the |documentclass| command to affect any number of packages that
142 % may be loaded. The |draft| option does not do anything, but is there
143 % to honour an informal convention that packages have these options in
144 % pairs.
145 %
146 % You can also control the appearance of the typeset label with the
147 % command |\showkeyslabelformat|, which takes one argument. The default is
148 % \begin{verbatim}
149 % \providecommand*\showkeyslabelformat[1]{%
150 % \fbox{\normalfont\small\ttfamily#1}}
151 % \end{verbatim}
152 % The command is called inside a group so you can put in local
153 % modifications of |\fboxsep|, for instance, without them leaking to
154 % the rest of the document.
155 %
156 %
157 % \section{More Examples}\label{examples}
158 % The only other similar package that I could find in the macro index,
159 % \cite{DMJ:mi}, was |showlabels.sty|, \cite{GN:sl}. After the first
160 % draft of this package was written, I found \cite{anon:sk} on my local
161 % installation! I think the current package is more robust than
162 % \cite{anon:sk}, but I thought that |showkeys| was rather a good name,
163 % so I have stolen it for this file.
164 %
165 % \begin{enumerate}
166 % \item \label{e^1}This has |\label| immediately after |\item|.
167 % \item This has the |\label| at the end.\label{e^2}
168 % \end{enumerate}
169 %
170 % \[
171 % \mbox{A minipage :- }\left\{
172 % \begin{minipage}{3in}
173 % Within environments like this |minipage|, we cannot use
174 % |\marginpar|\footnotemark,
175 % so the appearance is slightly different. Here is that |enumerate|
176 % environment again:
177 %
178 % \begin{enumerate}
179 % \item \label{m&e^1}This has |\label| immediately after |\item|.
180 % \item This has the |\label| at the end.\label{m&e^2}
181 % \end{enumerate}
182 % \end{minipage}
183 % \right.
184 % \]
185 %
186 % Displayed math (without |equation| counter).
187 % \[0=0\label{disp}\]
188 %
189 % Some text referring to the maths on page~\pageref{disp}, and the
190 % item~\ref{e^1}.\footnotetext{Actually \texttt{\string\marginpar} is
191 % not used at all in this package now.}
192 %
193 % If |showkeys| thinks that the current environment is going to produce
194 % an ``equation number'', then it does not show the label where the
195 % |\label| command occurs, but tries to put it in the margin, as shown
196 % with equation~\ref{eq:xx}.
197 % The package `knows' about the standard |equation| and |eqnarray|
198 % environments, and also all the numbered alignment environments offered
199 % by the AMS\LaTeX\ package, |amsmath|.
200 %
201 % ^^A (|amstex.sty| must be loaded before |showkeys.sty|
202 % ^^A for this to work.)
203 % \changes{v2.00}{1992/01/31}
204 % {leqno or ams* may now be loaded after showkeys}
205 %
206 % \begin{equation}
207 % 1=1\label{eq:xx}
208 % \end{equation}
209 %
210 % \begin{eqnarray}
211 % 2&=&2\label{eqnar:a}\\
212 % 3&=&3\nonumber\\
213 % 4&=&4\label{eqnar:b}
214 % \end{eqnarray}
215 %
216 %
217 % \begin{figure}[ht]
218 % Within a |figure| environment, the |\label| must not come before the
219 % |\caption| command. If you place |\label| inside the argument of
220 % |\caption| the label will be shown like this:
221 %
222 % \caption{Within the caption argument.\label{cap:a}}
223 %
224 % If you place |\label| immediately after the |\caption| command it will
225 % be shown like this:
226 %
227 % \caption{Immediately after the caption argument.}\label{cap:b}
228 %
229 % If you place the |\label| command at some random point after the
230 % |\caption| command, it may be shown like:
231 %
232 % \caption{In vertical mode not immediately after a box.}
233 % \vspace{2pt}
234 %
235 % \label{cap:c}
236 % \end{figure}
237 %
238 %
239 % \begin{thebibliography}{9}
240 %
241 % \bibitem{GN:sl}
242 % Gil Neiger, \emph{showlabels.sty},
243 % Undated package, similar to this one, but shows labels
244 % inline, affecting the formatting of the document.
245 %
246 % \bibitem{anon:sk}
247 % Anonymous, \emph{showkeys.sty},
248 % Package, dated 14 May 1988. Very similar to this one,
249 % also uses |\marginpar| in outer vertical mode.
250 %
251 % \bibitem{DMJ:mi}
252 % David M. Jones, \emph{\TeX\ Macro Index},
253 % A catalogue of \TeX\ macros, including \LaTeX\ packages,
254 % available from all good \TeX\ archives.
255 %
256 % \end{thebibliography}
257 %
258 % \MaybeStop{}
259 %
260 % \section{The Macros}
261 %
262 % \begin{macrocode}
263 %<*package>
264 % \end{macrocode}
265 %
266 %
267 % First we handle the options. Normally all related commands are
268 % defined to show their `keys'. But since v3.03 one can specify:
269 %
270 % \texttt{notref} to stop the redefinition of |\ref| (and |\pageref|,
271 % and related commands from \textsf{varioref} package),
272 %
273 % \texttt{notcite} to stop the redefinition of |\cite| and related
274 % commands from the \textsf{harvard} and \textsf{natbib} packages.
275 %
276 % \changes{v3.03}{1995/04/25}
277 % {Add option handling.}
278 % \begin{macrocode}
279 \DeclareOption{notref}{\let\SK@ref\@empty}
280 \DeclareOption{notcite}{\let\SK@cite\@empty}
281 % \end{macrocode}
282 %
283 % \begin{macro}{\SK@refcolor}
284 % \begin{macro}{\SK@labelcolor}
285 % Colour commands. Normally no-op.
286 % \begin{macrocode}
287 \let\SK@refcolor\relax
288 \let\SK@labelcolor\relax
289 % \end{macrocode}
290 % \end{macro}
291 % \end{macro}
292 %
293 % \changes{v3.11}{1996/11/01}
294 % {Colour support added, inspired by tools/2297}
295 % |color| option loads the \textsf{color} package and defines the
296 % colours. Delayed to the end of the package as package loading not
297 % allowed in this option section.
298 % \begin{macrocode}
299 \DeclareOption{color}{\AtEndOfPackage{%
300 \RequirePackage{color}%
301 \definecolor{refkey}{gray}{.75}%
302 \definecolor{labelkey}{gray}{.75}%
303 \def\SK@refcolor{\color{refkey}}%
304 \def\SK@labelcolor{\color{labelkey}}}}
305 % \end{macrocode}
306 %
307 % \changes{v3.04}{1995/10/30}
308 % {final and draft options handling.}
309 % \changes{v3.15}{2007/08/07}
310 % {Fix \cs{showkeyslabelformat} for final option PR/3918.}
311 % Allow |final| to be specified in the document class options
312 % to suppress the loading of this package.
313 % \begin{macrocode}
314 \DeclareOption{final}{%
315 \providecommand*\showkeyslabelformat[1]{}%
316 \endinput}
317 \DeclareOption{draft}{}
318 % \end{macrocode}
319 %
320 % \begin{macrocode}
321 \ProcessOptions
322 % \end{macrocode}
323 %
324 % \changes{v2.00}{1992/01/31}
325 % {\cmd{reset@font} is now standard}
326 %
327 % \begin{macro}{\SK@label}
328 % \begin{macro}{\SK@bibitem}
329 % \begin{macro}{\SK@lbibitem}
330 % The saved original definitions
331 % \begin{macrocode}
332 \let\SK@label\label
333 \let\SK@bibitem\@bibitem
334 \let\SK@lbibitem\@lbibitem
335 % \end{macrocode}
336 % \end{macro}
337 % \end{macro}
338 % \end{macro}
339 %
340 %
341 % \begin{macro}{\label}
342 % \changes{v3.09}{1996/08/30}
343 % {Add extra group so brace hack works. Donald Arseneau tools/2147}
344 % \changes{v3.19}{2023/05/11}
345 % {Use label hook if format is new enough.}
346 % The new definition, print the argument, and then do the old
347 % definition.
348 % \begin{macrocode}
349 \@ifl@t@r\fmtversion{2023-06-01}
350 {\AddToHookWithArguments{label}{\SK@\SK@@label{#1}}}
351 {\def\label#1{%
352 \@bsphack
353 \SK@\SK@@label{#1}%
354 \begingroup
355 \SK@label{#1}%
356 \endgroup
357 \@esphack}}
358 % \end{macrocode}
359 % \end{macro}
360 %
361 % \begin{macro}{\@bibitem}
362 % \begin{macro}{\@lbibitem}
363 % \changes{v3.02}{1995/03/17}
364 % {New label code.}
365 % For |\bibitem|, position the \textsf{showkeys} code as for a standard
366 % list with |\item| and |\label|.
367 % \begin{macrocode}
368 \def\@bibitem#1{%
369 \SK@bibitem{#1}\SK@\SK@@label{#1}\ignorespaces}
370 % \end{macrocode}
371 %
372 % \begin{macrocode}
373 \def\@lbibitem[#1]#2{%
374 \SK@lbibitem[{#1}]{#2}\SK@\SK@@label{#2}\ignorespaces}
375 % \end{macrocode}
376 % \end{macro}
377 % \end{macro}
378 %
379 % \begin{macro}{\SK@}
380 % \changes{v3.07}{1996/05/17}
381 % {use \cs{protected@edef} for tools/2147}
382 % Grab hold of |#2| via |\meaning| so characters like |&| and
383 % |^| do not cause problems later, and pass the result on to the command
384 % |#1|.
385 % \begin{macrocode}
386 \def\SK@#1#2{%
387 \protected@edef\@tempa{#2}%
388 \expandafter#1\meaning\@tempa\SK@}
389 % \end{macrocode}
390 % \end{macro}
391 %
392 %
393 %
394 % \begin{macro}{\showkeyslabelformat}
395 % \changes{v3.13}{2006/01/09}{Added command}
396 % \begin{macrocode}
397 \providecommand*\showkeyslabelformat[1]{%
398 \fbox{\normalfont\small\ttfamily#1}}
399 % \end{macrocode}
400 % \end{macro}
401 % \begin{macro}{\SK@@label}
402 % \changes{v3.13}{2006/01/09}{Do not hardwire label format}
403 % Strip off the initial segment of the |\meaning| output, and then put
404 % the rest either in a |\marginpar| or in a box of size 0pt,
405 % hopefully not disturbing the surrounding text.
406 % \begin{macrocode}
407 \def\SK@@label#1>#2\SK@{%
408 % \end{macrocode}
409 % Need to work globally as in some cases like alignments, and |fleqn|,
410 % the counter will be printed in a different group to the |\label|
411 % command.
412 % \begin{macrocode}
413 \gdef\SK@lab{\smash{\SK@labelcolor\showkeyslabelformat{#2}}}%
414 \ifvmode
415 \if@inlabel
416 % \end{macrocode}
417 % \changes{v3.02}{1995/03/17}
418 % {New code for `in label' case.}
419 % \changes{v3.20}{2023/12/16}
420 % {Avoid adding an extra box layer github/1123}
421 % If the |\label| is straight after |\item| (|\bibitem| is handled by
422 % this case as well) then the item label has not been added to the page
423 % yet. It is hanging around in the box |\@labels| waiting for the
424 % paragraph to start. So just need to attach the label to this box.
425 % \begin{macrocode}
426 \global\setbox\@labels\hbox{%
427 \llap{\SK@lab\SK@lab@relax
428 \kern\@totalleftmargin\kern\marginparsep}%
429 \unhbox\@labels}%
430 % \end{macrocode}
431 %
432 % \begin{macrocode}
433 \else
434 % \end{macrocode}
435 % \changes{v3.10}{1996/09/06}
436 % {Save prevdepth and restore later}
437 % If we insert a box into the main vertical list, do not want to
438 % change |\prevdepth| as that would affect vertical spacing in the
439 % document. (The box itself should not cause any difference in break
440 % points as there is a node there anyway coming from the |\write| to
441 % the aux file.)
442 % \begin{macrocode}
443 \dimen@\prevdepth
444 \nointerlineskip
445 % \end{macrocode}
446 % The inner vertical mode cases are mainly designed to do the right
447 % thing with float captions, but seem to work OK in other cases as well.
448 % \begin{macrocode}
449 \ifinner
450 \skip@\lastskip\unskip
451 % \end{macrocode}
452 % In inner vertical mode, attach the label to the right of the
453 % immediately preceding box, if it is a box before the current point.
454 % Otherwise just put it in a box of zero dimensions, with no interline
455 % skip. This may slightly move the surrounding text (but perhaps not
456 % now that |\prevdepth| is restored).
457 % \changes{v3.00}{1994/09/07}
458 % {Back up over a previous skip because of the new
459 % \cs{belowcaptionskip}}
460 % \changes{v3.04}{1995/10/30}
461 % {\cs{advance} added, to total two successive skips.}
462 % \changes{v3.04}{1995/10/30}
463 % {\cs{nointerlineskip} called before \cs{ifvoid} test, not just
464 % void case}
465 % \changes{v3.04}{1995/10/30}
466 % {\cs{marginparskip} added in inner vmode case}
467 % \begin{macrocode}
468 \advance\skip@\lastskip\unskip
469 \setbox\z@\lastbox
470 % \end{macrocode}
471 % \changes{v3.10}{1996/09/06}
472 % {Inner vertical mode case, put it in the margin.}
473 % \changes{v3.14}{2006/09/25}
474 % {The label put in the margin shouldn't make box 255 wider (PR/3884).}
475 % \begin{macrocode}
476 \ifvoid\z@
477 \llap{\SK@lab\SK@lab@relax\kern\marginparsep}%
478 \else
479 \hbox{\box\z@\rlap{\kern\marginparsep\SK@labx}}%
480 \fi
481 \vskip\skip@
482 \else
483 % \end{macrocode}
484 % In outer vertical mode, previously used a |\vadjust| at the start of
485 % the next paragraph (and before that used |\marginpar|). These
486 % methods sometimes cause extra space, eg if paragraph starts with a
487 % math display, so now just insert the box directly, taking care not
488 % to change |\prevdepth|.
489 % \changes{v3.02}{1995/03/17}
490 % {Use \cs{vadjust} instead of \cs{marginpar}}
491 % \changes{v3.10}{1996/09/06}
492 % {Insert the box directly}
493 % \begin{macrocode}
494 \llap{\SK@lab\SK@lab@relax\kern\marginparsep}%
495 \fi
496 % \end{macrocode}
497 % Restore |\prevdepth|.
498 % \begin{macrocode}
499 \prevdepth\dimen@
500 % \end{macrocode}
501 %
502 % \begin{macrocode}
503 \fi
504 \else
505 % \end{macrocode}
506 % If we are in a numbered equation-style environment, do nothing as the
507 % code to print the number will also print the label, otherwise just
508 % stick the label at the current point, in a box of zero dimensions.
509 % \changes{v3.02}{1995/03/17}
510 % {Add \cs{ifmmode} test}
511 % \begin{macrocode}
512 \csname SK@\@currenvir\endcsname
513 \ifSK@equation\else
514 \ifmmode
515 \SK@labx
516 \else
517 % \end{macrocode}
518 % Inner horizontal mode. Not much we can do, just stick it here.
519 % \changes{v3.03}{1995/04/25}
520 % {Fix inner horizontal mode case (broken in 3.02)}
521 % \begin{macrocode}
522 \ifinner
523 \rlap\SK@lab
524 \else
525 % \end{macrocode}
526 % In outer horizontal mode use |\vadjust| to get to the margin.
527 % \changes{v3.02}{1995/03/17}
528 % {Use \cs{vadjust} in horizontal mode}
529 % \begin{macrocode}
530 \vadjust{\llap{\SK@lab\kern\marginparsep}}%
531 \fi
532 \SK@lab@relax
533 \fi
534 \fi
535 \fi}
536 % \end{macrocode}
537 % \end{macro}
538 %
539 % \begin{macro}{\tagform@}
540 % \changes{v2.00}{1992/01/31}
541 % {Defer tests to begin document}
542 % \changes{v3.02}{1995/03/17}
543 % {Support new AMS files}
544 % \begin{macro}{\@eqnnum}
545 % \changes{v3.13}{2006/01/09}
546 % {Change to also work correctly for \texttt{leqno} option.}
547 % \begin{macro}{\maketag@@@}
548 % \changes{v3.13}{2006/01/09}
549 % {Support for \cs{tag*} tools/3693.}
550 % Firstly we grab |\@eqnnum|.
551 % \begin{macrocode}
552 \AtBeginDocument{%
553 \let\SK@eqnnum\@eqnnum
554 % \end{macrocode}
555 % Then check for \textsf{amsmath} where we grab the internal commands
556 % |\tagform@| and |\maketag@@@|. Redefine them and redefine |\@eqnnum|
557 % as well.
558 % \begin{macrocode}
559 \@ifpackageloaded{amsmath}{%
560 \let\SK@tagform@\tagform@
561 \let\SK@maketag@@@\maketag@@@
562 \iftagsleft@
563 \def\tagform@#1{%
564 \ifx\df@label\@empty
565 \SK@lab@relax
566 \else
567 \expandafter\SK@@label\meaning\df@label\SK@
568 \fi
569 \llap{\SK@lab\kern\marginparsep}%
570 \SK@lab@relax\SK@tagform@{#1}}%
571 \def\maketag@@@#1{%
572 \ifx\df@label\@empty
573 \SK@lab@relax
574 \else
575 \expandafter\SK@@label\meaning\df@label\SK@
576 \fi
577 \llap{\SK@lab\kern\marginparsep}\SK@lab@relax
578 \SK@maketag@@@{#1}%
579 }%
580 \def\@eqnnum{%
581 \llap{\SK@lab\kern\displaywidth\kern\marginparsep}%
582 \SK@lab@relax\SK@eqnnum}%
583 \else
584 % \end{macrocode}
585 % Almost the same for tags on the right, except we use |\rlap| and
586 % typeset it after the tag.
587 % \begin{macrocode}
588 \def\tagform@#1{%
589 \ifx\df@label\@empty
590 \SK@lab@relax
591 \else
592 \expandafter\SK@@label\meaning\df@label\SK@
593 \fi
594 % \end{macrocode}
595 % \changes{v3.08}{1996/07/10}{Missing percent added. /2215}
596 % \begin{macrocode}
597 \SK@tagform@{#1}%
598 \rlap{\kern\marginparsep\SK@lab}\SK@lab@relax}%
599 \def\maketag@@@#1{%
600 \ifx\df@label\@empty
601 \SK@lab@relax
602 \else
603 \expandafter\SK@@label\meaning\df@label\SK@
604 \fi
605 \SK@maketag@@@{#1}%
606 \rlap{\kern\marginparsep\SK@lab}\SK@lab@relax
607 }%
608 \def\@eqnnum{\SK@eqnnum\rlap{\kern\marginparsep\SK@lab}%
609 \SK@lab@relax}%
610 \fi
611 }%
612 % \end{macrocode}
613 % If \textsf{amsmath} wasn't loaded we check explicitly if the
614 % \texttt{leqno} option was used in |\documentclass| and redefine
615 % accordingly.
616 % \begin{macrocode}
617 {%
618 \@ifundefined{[email protected]}{%
619 \def\@eqnnum{\SK@eqnnum\rlap{\kern\marginparsep\SK@lab}%
620 \SK@lab@relax}%
621 }{%
622 \def\@eqnnum{%
623 \llap{\SK@lab\kern\displaywidth\kern\marginparsep}%
624 \SK@lab@relax\SK@eqnnum}%
625 }%
626 }%
627 }
628 % \end{macrocode}
629 % \end{macro}
630 % \end{macro}
631 % \end{macro}
632 %
633 % \begin{macro}{\SK@labx}
634 % Print the label, and then globally reset the print command to
635 % |\relax|.
636 % \begin{macrocode}
637 \def\SK@labx{\rlap\SK@lab\global\let\SK@lab\relax}
638 % \end{macrocode}
639 % \end{macro}
640 %
641 % \begin{macro}{\SK@lab@relax}
642 % Clear the label.
643 % \changes{v1.02}{1994/01/05}{Execute to initialise correctly}
644 % \begin{macrocode}
645 \def\SK@lab@relax{\global\let\SK@lab\relax}\SK@lab@relax
646 % \end{macrocode}
647 % \end{macro}
648 %
649 % \begin{macro}{\SK@equation}
650 % \begin{macro}{\SK@eqnarray}
651 % The following environments print an equation number, so |\label|
652 % should not print its argument at the point where it appears.
653 % Note this will fail to show the label if you are in an |eqnarray|
654 % environment, and use |\label| together with |\nonumber|. This might
655 % just about make sense if you are going to use |\pageref|, but that is
656 % too bad\ldots
657 % \begin{macrocode}
658 \newif\ifSK@equation
659 \let\SK@equation\SK@equationtrue
660 \let\SK@eqnarray\SK@equationtrue
661 % \end{macrocode}
662 % \end{macro}
663 % \end{macro}
664 %
665 % \begin{macro}{\eqnarray}
666 % \changes{v3.09}{1996/08/30}
667 % {Fix eqnarray AMS incompatibility. tools/2252}
668 % When the AMS packages are loaded |showkeys| assumes environments
669 % work `The AMS way'. However, |eqnarray| (unlike |equation|) is not
670 % redefined, so here we need to remove some of the AMS hacks.
671 % \begin{macrocode}
672 \toks@\expandafter{\eqnarray}
673 \edef\eqnarray{\let\noexpand\tagform@\noexpand\SK@tagform@\the\toks@}
674 % \end{macrocode}
675 % \end{macro}
676 %
677 % \begin{macro}{\SK@align}
678 % \begin{macro}{\SK@alignat}
679 % \begin{macro}{\SK@xalignat}
680 % \begin{macro}{\SK@xxalignat}
681 % \begin{macro}{\SK@gather}
682 % \begin{macro}{\SK@multline}
683 % \begin{macro}{\SK@flalign}
684 % \changes{v3.02}{1995/03/17}
685 % {Add \cs{SK@flalign}}
686 % The AMS environments
687 % \begin{macrocode}
688 \let\SK@align\SK@equationtrue
689 \let\SK@alignat\SK@equationtrue
690 \let\SK@xalignat\SK@equationtrue
691 \let\SK@xxalignat\SK@equationtrue
692 \let\SK@gather\SK@equationtrue
693 \let\SK@multline\SK@equationtrue
694 \let\SK@flalign\SK@equationtrue
695 % \end{macrocode}
696 % \end{macro}
697 % \end{macro}
698 % \end{macro}
699 % \end{macro}
700 % \end{macro}
701 % \end{macro}
702 % \end{macro}
703 %
704 % \begin{macro}{\SK@align*}
705 % \begin{macro}{\SK@alignat*}
706 % \begin{macro}{\SK@flalign*}
707 % \begin{macro}{\SK@gather*}
708 % \begin{macro}{\SK@multline*}
709 % \begin{macro}{\SK@equation*}
710 % \changes{v3.13}{2006/01/09}
711 % {Add the starred AMS environments for tools/3697.}
712 % Starred versions of the AMS environments.
713 % \begin{macrocode}
714 \expandafter\let\csname SK@align*\endcsname\SK@equationtrue
715 \expandafter\let\csname SK@alignat*\endcsname\SK@equationtrue
716 \expandafter\let\csname SK@flalign*\endcsname\SK@equationtrue
717 \expandafter\let\csname SK@gather*\endcsname\SK@equationtrue
718 \expandafter\let\csname SK@multline*\endcsname\SK@equationtrue
719 \expandafter\let\csname SK@equation*\endcsname\SK@equationtrue
720 % \end{macrocode}
721 % \end{macro}
722 % \end{macro}
723 % \end{macro}
724 % \end{macro}
725 % \end{macro}
726 % \end{macro}
727 %
728 % \begin{macro}{\SK@def}
729 % \changes{v3.05}{1995/11/09}
730 % {Macro added}
731 % This macro redefines a command |#1|. The new definition can make use
732 % of the old definition as |\SK@|\emph{old name}. If |#1| is really a
733 % |\protect|'ed command with the real definition in a `\emph{space}'
734 % command then the `space' version is used as the old definition.
735 % Need to test this for each command as some package may have changed
736 % the status of a command to being `protected'.
737 % The new definition is made as if with |\DeclareRobustCommand|, but
738 % with |\def| syntax for the argument specification.
739 % \begin{macrocode}
740 \def\SK@def#1{%
741 \edef\@tempa{\expandafter\@gobble\string#1}%
742 \@ifundefined{\@tempa\space}%
743 {\expandafter\let\csname SK@\@tempa\endcsname#1}%
744 {\expandafter\let\csname SK@\@tempa\expandafter\endcsname
745 \csname\@tempa\space\endcsname}%
746 \expandafter\def\expandafter#1\expandafter{%
747 \expandafter\protect\csname\@tempa\space\endcsname}%
748 \expandafter\def\csname\@tempa\space\endcsname}
749 % \end{macrocode}
750 % \end{macro}
751 %
752 % The next section redefines |\ref| and |\pageref| (unless the
753 % \texttt{notref} option was given).
754 % \begin{macrocode}
755 \ifx\SK@ref\@empty
756 % \end{macrocode}
757 % Even if \texttt{notref} option is used, need to fudge the
758 % \textsf{varioref} commands as they use |\label| internally.
759 % \changes{v3.04}{1995/10/30}
760 % {improve varioref support in notref option case, for
761 % tools/1744}
762 % \changes{v3.13}{2006/01/09}{Updated varioref support, for latex/3373}
763 % \changes{v3.15}{2006/06/19}
764 % {Prevent loss of brackets}
765 % \changes{v3.18}{2022/04/12}
766 % {update varioref support: it no longer uses label, so no patch
767 % needed if notref is used.}
768 % \begin{macrocode}
769 \else
770 % \end{macrocode}
771 %
772 % \begin{macro}{\ref}
773 % \begin{macro}{\pageref}
774 % Save the redefinition to |\begin{document}| so that this package can
775 % work with packages that redefine |\cite|. Tested with harvard and
776 % natbib packages. Also add code at this point to support varioref.
777 % \changes{v3.00}{1994/09/07}
778 % {Delay \cs{ref} redefinition.}
779 % \changes{v3.03}{1995/04/25}
780 % {Make redefinition conditional on notref option}
781 % \changes{v3.15}{2006/06/19}
782 % {Prevent loss of brackets}
783 % \changes{v3.18}{2022/04/12}
784 % {support new kernel commands with starred versions}
785 % \changes{v3.18}{2022/04/12}
786 % {update varioref support: it no longer uses label}
787 % \begin{macrocode}
788 \AtBeginDocument{%
789 \let\@kernel@ref@\@kernel@ref
790 \let\@kernel@sref@\@kernel@sref
791 \SK@def\@kernel@ref#1{\SK@\SK@@ref{#1}\SK@@kernel@ref{#1}}%
792 \SK@def\@kernel@sref#1{\SK@\SK@@ref{#1}\SK@@kernel@sref{#1}}%
793 \SK@def\@kernel@pageref#1{\SK@\SK@@ref{#1}\SK@@kernel@pageref{#1}}%
794 \SK@def\@kernel@spageref#1{\SK@\SK@@ref{#1}\SK@@kernel@spageref{#1}}%
795 \SK@def\@kernel@Ref#1{{\let\@kernel@ref\@kernel@ref@\SK@\SK@@ref{#1}\SK@@kernel@Ref{#1}}}%
796 \SK@def\@kernel@sRef#1{\let\@kernel@sref\@kernel@sref@\SK@\SK@@ref{#1}\SK@@kernel@sRef{#1}}%
797 % \end{macrocode}
798 % varioref support.
799 % \begin{macrocode}
800 \@ifpackageloaded{varioref}{%
801 \SK@def\@@vpageref#1[#2]#3{{%
802 \leavevmode\unskip\SK@\SK@@ref{#3}\SK@@@vpageref{#1}[{#2}]{#3}}}%%
803 }{}}
804 % \end{macrocode}
805 %
806 % \begin{macrocode}
807 \fi
808 % \end{macrocode}
809 % \end{macro}
810 % \end{macro}
811 %
812 % Now redefine |\cite| unless \texttt{notcite} option given.
813 % \begin{macrocode}
814 \ifx\SK@cite\@empty
815 % \end{macrocode}
816 % \changes{v3.06}{1995/11/22}
817 % {Fix \cs{harvarditem} support}
818 % \begin{macrocode}
819 \AtBeginDocument{%
820 \ifx\HAR@checkdef\@undefined\else
821 \expandafter\let\expandafter
822 \SK@HAR@bi\csname\string\harvarditem\endcsname
823 \expandafter\def\csname\string\harvarditem\endcsname[#1]#2#3#4{%
824 \SK@HAR@bi[{#1}]{#2}{#3}{#4}\SK@\SK@@label{#4}}%
825 \fi}
826 \else
827 % \end{macrocode}
828 %
829 % \begin{macro}{\cite}
830 % \changes{v3.00}{1994/09/07}
831 % {Delay \cs{cite} redefinition.}
832 % \changes{v3.03}{1995/04/25}
833 % {Make redefinition conditional on notcite option}
834 % \begin{macrocode}
835 \AtBeginDocument{%
836 \ifx\HAR@checkdef\@undefined
837 % \end{macrocode}
838 % Standard (non-harvard) support, including extra cite commands from
839 % \textsf{natbib} and \textsf{cite}.
840 % \changes{v3.01}{1994/09/09}
841 % {Add \cs{citefullauthor}}
842 % \changes{v3.12}{1997/06/12}
843 % {Support cite package. tools/2490}
844 % \changes{v3.17}{2014/04/24}
845 % {redefine \cs{@citex} rather than \cs{cite} for tools/4162}
846 %
847 % If \textsf{cite} or \textsf{overcite} is being used, redefine |\citen|
848 % rather than |\cite| so as not to spoil the space and punctuation
849 % calculations done by those packages.
850 % \begin{macrocode}
851 \ifx\citen\@undefined
852 \SK@def\@citex[#1]#2{\SK@citex[{#1}]{#2}}%
853 \else
854 \SK@def\citen#1{\SK@\SK@@ref{#1}\SK@citen{#1}}%
855 \fi
856 \SK@def\citeauthor#1{\SK@\SK@@ref{#1}\SK@citeauthor{#1}}%
857 \SK@def\citefullauthor#1{\SK@\SK@@ref{#1}\SK@citefullauthor{#1}}%
858 \SK@def\citeyear#1{\SK@\SK@@ref{#1}\SK@citeyear{#1}}%
859 \else
860 % \end{macrocode}
861 % In the \textsf{harvard} style do \emph{not} redefine individual cite
862 % commands. Just redefine one internal command that is used in all the
863 % citation forms.
864 % \begin{macrocode}
865 \SK@def\HAR@checkdef#1#2{%
866 \expandafter\SK@\expandafter\SK@@ref\expandafter{#1}%
867 \SK@HAR@checkdef{#1}{#2}}%
868 \expandafter\let\expandafter
869 \SK@HAR@bi\csname\string\harvarditem\endcsname
870 % \end{macrocode}
871 % \changes{v3.06}{1995/11/22}
872 % {Fix \cs{harvarditem} support}
873 % \begin{macrocode}
874 \expandafter\def\csname\string\harvarditem\endcsname[#1]#2#3#4{%
875 \SK@HAR@bi[{#1}]{#2}{#3}{#4}\SK@\SK@@label{#4}}%
876 \fi}
877 % \end{macrocode}
878 %
879 % \changes{v3.17}{2014/04/24}
880 % {Change name, redefine \cs{@citex} rather than \cs{cite} for tools/4162}
881 % \begin{macrocode}
882 \def\SK@citex[#1]#2{%
883 \SK@\SK@@ref{#2}\SK@@citex[{#1}]{#2}}
884 % \end{macrocode}
885 %
886 % \begin{macrocode}
887 \fi
888 % \end{macrocode}
889 % \end{macro}
890 %
891 % \begin{macro}{\SK@@ref}
892 % This is much simpler than the printing of the label, as we know
893 % that we can be in horizontal mode.
894 % Note extra group for colour safety.
895 % \changes{v3.14}{2006/09/25}
896 % {Add fix for pdf\TeX.}
897 % \changes{v3.16}{2011/11/24}
898 % {revert change made at v3.14 because of tools/4173}
899 % \begin{macrocode}
900 \def\SK@@ref#1>#2\SK@{%
901 \leavevmode\vbox to\z@{{%
902 \vss
903 \SK@refcolor
904 \rlap{\vrule\raise .75em%
905 \hbox{\underbar{\normalfont\footnotesize\ttfamily#2}}}}}}
906 % \end{macrocode}
907 % \end{macro}
908 %
909 % \begin{macrocode}
910 %</package>
911 % \end{macrocode}
912 %
913 % \Finale
914 %