Debian Codegraph @

texmf-dist/source/latex/refcount/refcount.dtx

raw
1 % \iffalse meta-comment
2 %
3 % File: refcount.dtx
4 % Version: 2019/12/15 v3.6
5 % Info: Data extraction from label references
6 %
7 % Copyright (C)
8 % 1998, 2000, 2006, 2008, 2010, 2011 Heiko Oberdiek
9 % 2016-2019 Oberdiek Package Support Group
10 % https://github.com/ho-tex/refcount/issues
11 %
12 % This work may be distributed and/or modified under the
13 % conditions of the LaTeX Project Public License, either
14 % version 1.3c of this license or (at your option) any later
15 % version. This version of this license is in
16 % https://www.latex-project.org/lppl/lppl-1-3c.txt
17 % and the latest version of this license is in
18 % https://www.latex-project.org/lppl.txt
19 % and version 1.3 or later is part of all distributions of
20 % LaTeX version 2005/12/01 or later.
21 %
22 % This work has the LPPL maintenance status "maintained".
23 %
24 % The Current Maintainers of this work are
25 % Heiko Oberdiek and the Oberdiek Package Support Group
26 % https://github.com/ho-tex/refcount/issues
27 %
28 % This work consists of the main source file refcount.dtx
29 % and the derived files
30 % refcount.sty, refcount.pdf, refcount.ins, refcount.drv,
31 % refcount-test1.tex, refcount-test2.tex, refcount-test3.tex,
32 % refcount-test4.tex, refcount-test5.tex.
33 %
34 % Distribution:
35 % CTAN:macros/latex/contrib/refcount/refcount.dtx
36 % CTAN:macros/latex/contrib/refcount/refcount.pdf
37 %
38 % Unpacking:
39 % (a) If refcount.ins is present:
40 % tex refcount.ins
41 % (b) Without refcount.ins:
42 % tex refcount.dtx
43 % (c) If you insist on using LaTeX
44 % latex \let\install=y\input{refcount.dtx}
45 % (quote the arguments according to the demands of your shell)
46 %
47 % Documentation:
48 % (a) If refcount.drv is present:
49 % latex refcount.drv
50 % (b) Without refcount.drv:
51 % latex refcount.dtx; ...
52 % The class ltxdoc loads the configuration file ltxdoc.cfg
53 % if available. Here you can specify further options, e.g.
54 % use A4 as paper format:
55 % \PassOptionsToClass{a4paper}{article}
56 %
57 % Programm calls to get the documentation (example):
58 % pdflatex refcount.dtx
59 % makeindex -s gind.ist refcount.idx
60 % pdflatex refcount.dtx
61 % makeindex -s gind.ist refcount.idx
62 % pdflatex refcount.dtx
63 %
64 % Installation:
65 % TDS:tex/latex/refcount/refcount.sty
66 % TDS:doc/latex/refcount/refcount.pdf
67 % TDS:source/latex/refcount/refcount.dtx
68 %
69 %<*ignore>
70 \begingroup
71 \catcode123=1 %
72 \catcode125=2 %
73 \def\x{LaTeX2e}%
74 \expandafter\endgroup
75 \ifcase 0\ifx\install y1\fi\expandafter
76 \ifx\csname processbatchFile\endcsname\relax\else1\fi
77 \ifx\fmtname\x\else 1\fi\relax
78 \else\csname fi\endcsname
79 %</ignore>
80 %<*install>
81 \input docstrip.tex
82 \Msg{************************************************************************}
83 \Msg{* Installation}
84 \Msg{* Package: refcount 2019/12/15 v3.6 Data extraction from label references (HO)}
85 \Msg{************************************************************************}
86
87 \keepsilent
88 \askforoverwritefalse
89
90 \let\MetaPrefix\relax
91 \preamble
92
93 This is a generated file.
94
95 Project: refcount
96 Version: 2019/12/15 v3.6
97
98 Copyright (C)
99 1998, 2000, 2006, 2008, 2010, 2011 Heiko Oberdiek
100 2016-2019 Oberdiek Package Support Group
101
102 This work may be distributed and/or modified under the
103 conditions of the LaTeX Project Public License, either
104 version 1.3c of this license or (at your option) any later
105 version. This version of this license is in
106 https://www.latex-project.org/lppl/lppl-1-3c.txt
107 and the latest version of this license is in
108 https://www.latex-project.org/lppl.txt
109 and version 1.3 or later is part of all distributions of
110 LaTeX version 2005/12/01 or later.
111
112 This work has the LPPL maintenance status "maintained".
113
114 The Current Maintainers of this work are
115 Heiko Oberdiek and the Oberdiek Package Support Group
116 https://github.com/ho-tex/refcount/issues
117
118
119 This work consists of the main source file refcount.dtx
120 and the derived files
121 refcount.sty, refcount.pdf, refcount.ins, refcount.drv,
122 refcount-test1.tex, refcount-test2.tex, refcount-test3.tex,
123 refcount-test4.tex, refcount-test5.tex.
124
125 \endpreamble
126 \let\MetaPrefix\DoubleperCent
127
128 \generate{%
129 \file{refcount.ins}{\from{refcount.dtx}{install}}%
130 \file{refcount.drv}{\from{refcount.dtx}{driver}}%
131 \usedir{tex/latex/refcount}%
132 \file{refcount.sty}{\from{refcount.dtx}{package}}%
133 }
134
135 \catcode32=13\relax% active space
136 \let =\space%
137 \Msg{************************************************************************}
138 \Msg{*}
139 \Msg{* To finish the installation you have to move the following}
140 \Msg{* file into a directory searched by TeX:}
141 \Msg{*}
142 \Msg{* refcount.sty}
143 \Msg{*}
144 \Msg{* To produce the documentation run the file `refcount.drv'}
145 \Msg{* through LaTeX.}
146 \Msg{*}
147 \Msg{* Happy TeXing!}
148 \Msg{*}
149 \Msg{************************************************************************}
150
151 \endbatchfile
152 %</install>
153 %<*ignore>
154 \fi
155 %</ignore>
156 %<*driver>
157 \NeedsTeXFormat{LaTeX2e}
158 \ProvidesFile{refcount.drv}%
159 [2019/12/15 v3.6 Data extraction from label references (HO)]%
160 \documentclass{ltxdoc}
161 \usepackage{holtxdoc}[2011/11/22]
162 \begin{document}
163 \DocInput{refcount.dtx}%
164 \end{document}
165 %</driver>
166 % \fi
167 %
168 %
169 %
170 % \GetFileInfo{refcount.drv}
171 %
172 % \title{The \xpackage{refcount} package}
173 % \date{2019/12/15 v3.6}
174 % \author{Heiko Oberdiek\thanks
175 % {Please report any issues at \url{https://github.com/ho-tex/refcount/issues}}}
176 %
177 % \maketitle
178 %
179 % \begin{abstract}
180 % References are not numbers, however they often store numerical
181 % data such as section or page numbers. \cs{ref} or \cs{pageref}
182 % cannot be used for counter assignments or calculations because
183 % they are not expandable, generate warnings, or can even be links.
184 % The package provides expandable macros to extract the data
185 % from references. Packages \xpackage{hyperref}, \xpackage{nameref},
186 % \xpackage{titleref}, and \xpackage{babel} are supported.
187 % \end{abstract}
188 %
189 % \tableofcontents
190 %
191 % \section{Usage}
192 %
193 % \subsection{Setting counters}
194 %
195 % The following commands are similar to \LaTeX's
196 % \cs{setcounter} and \cs{addtocounter},
197 % but they extract the number value from a reference:
198 % \begin{quote}
199 % \cs{setcounterref}, \cs{addtocounterref}\\
200 % \cs{setcounterpageref}, \cs{addtocounterpageref}
201 % \end{quote}
202 % They take two arguments:
203 % \begin{quote}
204 % \cs{...counter...ref} |{|\meta{\LaTeX\ counter}|}|
205 % |{|\meta{reference}|}|
206 % \end{quote}
207 % An undefined references produces the usual LaTeX warning
208 % and its value is assumed to be zero.
209 % Example:
210 % \begin{quote}
211 %\begin{verbatim}
212 %\newcounter{ctrA}
213 %\newcounter{ctrB}
214 %\refstepcounter{ctrA}\label{ref:A}
215 %\setcounterref{ctrB}{ref:A}
216 %\addtocounterpageref{ctrB}{ref:A}
217 %\end{verbatim}
218 % \end{quote}
219 %
220 % \subsection{Expandable commands}
221 %
222 % These commands that can be used in expandible contexts
223 % (inside calculations, \cs{edef}, \cs{csname}, \cs{write}, \dots):
224 % \begin{quote}
225 % \cs{getrefnumber}, \cs{getpagerefnumber}
226 % \end{quote}
227 % They take one argument, the reference:
228 % \begin{quote}
229 % \cs{get...refnumber} |{|\meta{reference}|}|
230 % \end{quote}
231 % The default for undefined references can be changed
232 % with macro \cs{setrefcountdefault}, for example this
233 % package calls:
234 % \begin{quote}
235 % \cs{setrefcountdefault}|{0}|
236 % \end{quote}
237 %
238 % Since version 2.0 of this package there is a new
239 % command:
240 % \begin{quote}
241 % \cs{getrefbykeydefault} |{|\meta{reference}|}|
242 % |{|\meta{key}|}| |{|\meta{default}|}|
243 % \end{quote}
244 % This generalized version allows the extraction
245 % of further properties of a reference than the
246 % two standard ones. Thus the following properties
247 % are supported, if they are available:
248 % \begin{quote}
249 % \begin{tabular}{@{}l|l|l@{}}
250 % Key & Description & Package\\
251 % \hline
252 % \meta{empty} & same as \cs{ref} & \LaTeX\\
253 % |page| & same as \cs{pageref} & \LaTeX\\
254 % |title| & section and caption titles & \xpackage{titleref}\\
255 % |name| & section and caption titles & \xpackage{nameref}\\
256 % |anchor| & anchor name & \xpackage{hyperref}\\
257 % |url| & url/file & \xpackage{hyperref}/\xpackage{xr}
258 % \end{tabular}
259 % \end{quote}
260 %
261 % Since version 3.2 the expandable macros described before
262 % in this section
263 % are expandable in exact two expansion steps.
264 %
265 % \subsection{Undefined references}
266 %
267 % Because warnings and assignments cannot be used in
268 % expandible contexts, undefined references do not
269 % produce a warning, their values are assumed to be zero.
270 % Example:
271 % \begin{quote}
272 %\begin{verbatim}
273 %\label{ref:here}% somewhere
274 %\refused{ref:here}% see below
275 %\ifodd\getpagerefnumber{ref:here}%
276 % reference is on an odd page
277 %\else
278 % reference is on an even page
279 %\fi
280 %\end{verbatim}
281 % \end{quote}
282 %
283 % In case of undefined references the user usually want's
284 % to be informed. Also \LaTeX\ prints a warning at
285 % the end of the \LaTeX\ run. To notify \LaTeX\ and
286 % get a normal warning, just use
287 % \begin{quote}
288 % \cs{refused} |{|\meta{reference}|}|
289 % \end{quote}
290 % outside the expanding context. Example, see above.
291 %
292 % \subsubsection{Check for undefined references}
293 %
294 % In version 3.2 macros were added, that test, whether references
295 % are defined.
296 % \begin{declcs}{IfRefUndefinedExpandable} \M{refname} \M{then} \M{else}\\
297 % \cs{IfRefUndefinedBabel} \M{refname} \M{then} \M{else}
298 % \end{declcs}
299 % If the reference is not available and therefore undefined, then
300 % argument \meta{then} is executed, otherwise argument \meta{else}
301 % is called. Macro \cs{IfRefUndefinedExpandable} is expandable,
302 % but \meta{refname} must not contain babel shorthand characters.
303 % Macro \cs{IfRefUndefinedBabel} supports shorthand characters of
304 % babel, but it is not expandable.
305 %
306 % \subsection{Notes}
307 %
308 % \begin{itemize}
309 % \item
310 % The method of extracting the number in this
311 % package also works in cases, where the
312 % reference cannot be used directly, because
313 % a package such as \xpackage{hyperref} has added
314 % extra stuff (hyper link), so that the reference cannot
315 % be used as number any more.
316 % \item
317 % If the reference does not contain a number,
318 % assignments to a counter will fail of course.
319 % \end{itemize}
320 %
321 %
322 % \StopEventually{
323 % }
324 %
325 % \section{Implementation}
326 %
327 % \begin{macrocode}
328 %<*package>
329 % \end{macrocode}
330 % Reload check, especially if the package is not used with \LaTeX.
331 % \begin{macrocode}
332 \begingroup\catcode61\catcode48\catcode32=10\relax%
333 \catcode13=5 % ^^M
334 \endlinechar=13 %
335 \catcode35=6 % #
336 \catcode39=12 % '
337 \catcode44=12 % ,
338 \catcode45=12 % -
339 \catcode46=12 % .
340 \catcode58=12 % :
341 \catcode64=11 % @
342 \catcode123=1 % {
343 \catcode125=2 % }
344 \expandafter\let\expandafter\x\csname [email protected]\endcsname
345 \ifx\x\relax % plain-TeX, first loading
346 \else
347 \def\empty{}%
348 \ifx\x\empty % LaTeX, first loading,
349 % variable is initialized, but \ProvidesPackage not yet seen
350 \else
351 \expandafter\ifx\csname PackageInfo\endcsname\relax
352 \def\x#1#2{%
353 \immediate\write-1{Package #1 Info: #2.}%
354 }%
355 \else
356 \def\x#1#2{\PackageInfo{#1}{#2, stopped}}%
357 \fi
358 \x{refcount}{The package is already loaded}%
359 \aftergroup\endinput
360 \fi
361 \fi
362 \endgroup%
363 % \end{macrocode}
364 % Package identification:
365 % \begin{macrocode}
366 \begingroup\catcode61\catcode48\catcode32=10\relax%
367 \catcode13=5 % ^^M
368 \endlinechar=13 %
369 \catcode35=6 % #
370 \catcode39=12 % '
371 \catcode40=12 % (
372 \catcode41=12 % )
373 \catcode44=12 % ,
374 \catcode45=12 % -
375 \catcode46=12 % .
376 \catcode47=12 % /
377 \catcode58=12 % :
378 \catcode64=11 % @
379 \catcode91=12 % [
380 \catcode93=12 % ]
381 \catcode123=1 % {
382 \catcode125=2 % }
383 \expandafter\ifx\csname ProvidesPackage\endcsname\relax
384 \def\x#1#2#3[#4]{\endgroup
385 \immediate\write-1{Package: #3 #4}%
386 \xdef#1{#4}%
387 }%
388 \else
389 \def\x#1#2[#3]{\endgroup
390 #2[{#3}]%
391 \ifx#1\@undefined
392 \xdef#1{#3}%
393 \fi
394 \ifx#1\relax
395 \xdef#1{#3}%
396 \fi
397 }%
398 \fi
399 \expandafter\x\csname [email protected]\endcsname
400 \ProvidesPackage{refcount}%
401 [2019/12/15 v3.6 Data extraction from label references (HO)]%
402 % \end{macrocode}
403 %
404 % \begin{macrocode}
405 \begingroup\catcode61\catcode48\catcode32=10\relax%
406 \catcode13=5 % ^^M
407 \endlinechar=13 %
408 \catcode123=1 % {
409 \catcode125=2 % }
410 \catcode64=11 % @
411 \def\x{\endgroup
412 \expandafter\edef\csname rc@AtEnd\endcsname{%
413 \endlinechar=\the\endlinechar\relax
414 \catcode13=\the\catcode13\relax
415 \catcode32=\the\catcode32\relax
416 \catcode35=\the\catcode35\relax
417 \catcode61=\the\catcode61\relax
418 \catcode64=\the\catcode64\relax
419 \catcode123=\the\catcode123\relax
420 \catcode125=\the\catcode125\relax
421 }%
422 }%
423 \x\catcode61\catcode48\catcode32=10\relax%
424 \catcode13=5 % ^^M
425 \endlinechar=13 %
426 \catcode35=6 % #
427 \catcode64=11 % @
428 \catcode123=1 % {
429 \catcode125=2 % }
430 \def\TMP@EnsureCode#1#2{%
431 \edef\rc@AtEnd{%
432 \rc@AtEnd
433 \catcode#1=\the\catcode#1\relax
434 }%
435 \catcode#1=#2\relax
436 }
437 \TMP@EnsureCode{33}{12}% !
438 \TMP@EnsureCode{39}{12}% '
439 \TMP@EnsureCode{42}{12}% *
440 \TMP@EnsureCode{45}{12}% -
441 \TMP@EnsureCode{46}{12}% .
442 \TMP@EnsureCode{47}{12}% /
443 \TMP@EnsureCode{91}{12}% [
444 \TMP@EnsureCode{93}{12}% ]
445 \TMP@EnsureCode{96}{12}% `
446 \edef\rc@AtEnd{\rc@AtEnd\noexpand\endinput}
447 % \end{macrocode}
448 %
449 % \subsection{Loading packages}
450 %
451 % \begin{macrocode}
452 \begingroup\expandafter\expandafter\expandafter\endgroup
453 \expandafter\ifx\csname RequirePackage\endcsname\relax
454 \input ltxcmds.sty\relax
455 \input infwarerr.sty\relax
456 \else
457 \RequirePackage{ltxcmds}[2011/11/09]%
458 \RequirePackage{infwarerr}[2010/04/08]%
459 \fi
460 % \end{macrocode}
461 %
462 % \subsection{Defining commands}
463 %
464 % \begin{macro}{\rc@IfDefinable}
465 % \begin{macrocode}
466 \ltx@IfUndefined{@ifdefinable}{%
467 \def\rc@IfDefinable#1{%
468 \ifx#1\ltx@undefined
469 \expandafter\ltx@firstofone
470 \else
471 \ifx#1\relax
472 \expandafter\expandafter\expandafter\ltx@firstofone
473 \else
474 \@PackageError{refcount}{%
475 Command \string#1 is already defined.\MessageBreak
476 It will not redefined by this package%
477 }\@ehc
478 \expandafter\expandafter\expandafter\ltx@gobble
479 \fi
480 \fi
481 }%
482 }{%
483 \let\rc@IfDefinable\@ifdefinable
484 }
485 % \end{macrocode}
486 % \end{macro}
487 %
488 % \begin{macro}{\rc@RobustDefOne}
489 % \begin{macro}{\rc@RobustDefZero}
490 % \begin{macrocode}
491 \ltx@IfUndefined{protected}{%
492 \ltx@IfUndefined{DeclareRobustCommand}{%
493 \def\rc@RobustDefOne#1#2#3#4{%
494 \rc@IfDefinable#3{%
495 #1\def#3##1{#4}%
496 }%
497 }%
498 \def\rc@RobustDefZero#1#2{%
499 \rc@IfDefinable#1{%
500 \def#1{#2}%
501 }%
502 }%
503 }{%
504 \def\rc@RobustDefOne#1#2#3#4{%
505 \rc@IfDefinable#3{%
506 \DeclareRobustCommand#2#3[1]{#4}%
507 }%
508 }%
509 \def\rc@RobustDefZero#1#2{%
510 \rc@IfDefinable#1{%
511 \DeclareRobustCommand#1{#2}%
512 }%
513 }%
514 }%
515 }{%
516 \def\rc@RobustDefOne#1#2#3#4{%
517 \rc@IfDefinable#3{%
518 \protected#1\def#3##1{#4}%
519 }%
520 }%
521 \def\rc@RobustDefZero#1#2{%
522 \rc@IfDefinable#1{%
523 \protected\def#1{#2}%
524 }%
525 }%
526 }
527 % \end{macrocode}
528 % \end{macro}
529 % \end{macro}
530 %
531 % \begin{macro}{\rc@newcommand}
532 % \begin{macrocode}
533 \ltx@IfUndefined{newcommand}{%
534 \def\rc@newcommand*#1[#2]#3{% hash-ok
535 \rc@IfDefinable#1{%
536 \ifcase#2 %
537 \def#1{#3}%
538 \or
539 \def#1##1{#3}%
540 \or
541 \def#1##1##2{#3}%
542 \else
543 \rc@InternalError
544 \fi
545 }%
546 }%
547 }{%
548 \let\rc@newcommand\newcommand
549 }
550 % \end{macrocode}
551 % \end{macro}
552 %
553 % \subsection{\cs{setrefcountdefault}}
554 %
555 % \begin{macro}{\setrefcountdefault}
556 % \begin{macrocode}
557 \rc@RobustDefOne\long{}\setrefcountdefault{%
558 \def\rc@default{#1}%
559 }
560 % \end{macrocode}
561 % \end{macro}
562 % \begin{macrocode}
563 \setrefcountdefault{0}
564 % \end{macrocode}
565 %
566 % \subsection{\cs{refused}}
567 %
568 % \begin{macro}{\refused}
569 % \begin{macrocode}
570 \ltx@IfUndefined{G@refundefinedtrue}{%
571 \rc@RobustDefOne{}{*}\refused{%
572 \begingroup
573 \csname @safe@activestrue\endcsname
574 \ltx@IfUndefined{r@#1}{%
575 \protect\G@refundefinedtrue
576 \rc@WarningUndefined{#1}%
577 }{}%
578 \endgroup
579 }%
580 }{%
581 \rc@RobustDefOne{}{*}\refused{%
582 \begingroup
583 \csname @safe@activestrue\endcsname
584 \ltx@IfUndefined{r@#1}{%
585 \csname protect\expandafter\endcsname
586 \csname G@refundefinedtrue\endcsname
587 \rc@WarningUndefined{#1}%
588 }{}%
589 \endgroup
590 }%
591 }
592 % \end{macrocode}
593 % \end{macro}
594 % \begin{macro}{\rc@WarningUndefined}
595 % \begin{macrocode}
596 \ltx@IfUndefined{@latex@warning}{%
597 \def\rc@WarningUndefined#1{%
598 \ltx@ifundefined{thepage}{%
599 \def\thepage{\number\count0 }%
600 }{}%
601 \@PackageWarning{refcount}{%
602 Reference `#1' on page \thepage\space undefined%
603 }%
604 }%
605 }{%
606 \def\rc@WarningUndefined#1{%
607 \@latex@warning{%
608 Reference `#1' on page \thepage\space undefined%
609 }%
610 }%
611 }
612 % \end{macrocode}
613 % \end{macro}
614 %
615 % \subsection{Setting counters by reference data}
616 %
617 % \subsubsection{Generic setting}
618 %
619 % \begin{macro}{\rc@set}
620 % Generic command for
621 % |\|$\{$|set|$,$|addto|$\}$|counter|$\{$|page|$,\}$|ref|:
622 %\begin{quote}
623 %\begin{tabular}[t]{@{}l@{: }l@{}}
624 % |#1|& \cs{setcounter}, \cs{addtocounter}\\
625 % |#2|& \cs{ltx@car} (for \cs{ref}), \cs{ltx@cartwo} (for \cs{pageref})\\
626 % |#3|& \hologo{LaTeX} counter\\
627 % |#4|& reference\\
628 %\end{tabular}
629 %\end{quote}
630 % \begin{macrocode}
631 \def\rc@set#1#2#3#4{%
632 \begingroup
633 \csname @safe@activestrue\endcsname
634 \refused{#4}%
635 \expandafter\rc@@set\csname r@#4\endcsname{#1}{#2}{#3}%
636 \endgroup
637 }
638 % \end{macrocode}
639 % \end{macro}
640 % \begin{macro}{\rc@@set}
641 %\begin{quote}
642 %\begin{tabular}[t]{@{}l@{: }l@{}}
643 % |#1|& \cs{r@<...>}\\
644 % |#2|& \cs{setcounter}, \cs{addtocounter}\\
645 % |#3|& \cs{ltx@car} (for \cs{ref}), \cs{ltx@carsecond} (for \cs{pageref})\\
646 % |#4|& \hologo{LaTeX} counter\\
647 %\end{tabular}
648 %\end{quote}
649 % \begin{macrocode}
650 \def\rc@@set#1#2#3#4{%
651 \ifx#1\relax
652 #2{#4}{\rc@default}%
653 \else
654 #2{#4}{%
655 \expandafter#3#1\rc@default\rc@default\@nil
656 }%
657 \fi
658 }
659 % \end{macrocode}
660 % \end{macro}
661 %
662 % \subsubsection{User commands}
663 %
664 % \begin{macro}{\setcounterref}
665 % \begin{macrocode}
666 \rc@RobustDefZero\setcounterref{%
667 \rc@set\setcounter\ltx@car
668 }
669 % \end{macrocode}
670 % \end{macro}
671 % \begin{macro}{\addtocounterref}
672 % \begin{macrocode}
673 \rc@RobustDefZero\addtocounterref{%
674 \rc@set\addtocounter\ltx@car
675 }
676 % \end{macrocode}
677 % \end{macro}
678 % \begin{macro}{\setcounterpageref}
679 % \begin{macrocode}
680 \rc@RobustDefZero\setcounterpageref{%
681 \rc@set\setcounter\ltx@carsecond
682 }
683 % \end{macrocode}
684 % \end{macro}
685 % \begin{macro}{\addtocounterpageref}
686 % \begin{macrocode}
687 \rc@RobustDefZero\addtocounterpageref{%
688 \rc@set\addtocounter\ltx@carsecond
689 }
690 % \end{macrocode}
691 % \end{macro}
692 %
693 % \subsection{Extracting references}
694 %
695 % \begin{macro}{\getrefnumber}
696 % \begin{macrocode}
697 \rc@newcommand*{\getrefnumber}[1]{%
698 \romannumeral
699 \ltx@ifundefined{r@#1}{%
700 \expandafter\ltx@zero
701 \rc@default
702 }{%
703 \expandafter\expandafter\expandafter\rc@extract@
704 \expandafter\expandafter\expandafter!%
705 \csname r@#1\expandafter\endcsname
706 \expandafter{\rc@default}\@nil
707 }%
708 }
709 % \end{macrocode}
710 % \end{macro}
711 % \begin{macro}{\getpagerefnumber}
712 % \begin{macrocode}
713 \rc@newcommand*{\getpagerefnumber}[1]{%
714 \romannumeral
715 \ltx@ifundefined{r@#1}{%
716 \expandafter\ltx@zero
717 \rc@default
718 }{%
719 \expandafter\expandafter\expandafter\rc@extract@page
720 \expandafter\expandafter\expandafter!%
721 \csname r@#1\expandafter\expandafter\expandafter\endcsname
722 \expandafter\expandafter\expandafter{%
723 \expandafter\rc@default
724 \expandafter}\expandafter{\rc@default}\@nil
725 }%
726 }
727 % \end{macrocode}
728 % \end{macro}
729 % \begin{macro}{\getrefbykeydefault}
730 % \begin{macrocode}
731 \rc@newcommand*{\getrefbykeydefault}[2]{%
732 \romannumeral
733 \expandafter\rc@getrefbykeydefault
734 \csname r@#1\expandafter\endcsname
735 \csname rc@extract@#2\endcsname
736 }
737 % \end{macrocode}
738 % \end{macro}
739 % \begin{macro}{\rc@getrefbykeydefault}
740 %\begin{quote}
741 %\begin{tabular}[t]{@{}l@{: }l@{}}
742 % |#1|& \cs{r@<...>}\\
743 % |#2|& \cs{rc@extract@<...>}\\
744 % |#3|& default\\
745 %\end{tabular}
746 %\end{quote}
747 % \begin{macrocode}
748 \long\def\rc@getrefbykeydefault#1#2#3{%
749 \ifx#1\relax
750 % reference is undefined
751 \ltx@ReturnAfterElseFi{%
752 \ltx@zero
753 #3%
754 }%
755 \else
756 \ltx@ReturnAfterFi{%
757 \ifx#2\relax
758 % extract method is missing
759 \ltx@ReturnAfterElseFi{%
760 \ltx@zero
761 #3%
762 }%
763 \else
764 \ltx@ReturnAfterFi{%
765 \expandafter
766 \rc@generic#1{#3}{#3}{#3}{#3}{#3}\@nil#2{#3}%
767 }%
768 \fi
769 }%
770 \fi
771 }
772 % \end{macrocode}
773 % \end{macro}
774 % \begin{macro}{\rc@generic}
775 %\begin{quote}
776 %\begin{tabular}[t]{@{}l@{: }l@{}}
777 % |#1|& first item in \cs{r@<...>}\\
778 % |#2|& remaining items in \cs{r@<...>}\\
779 % |#3|& \cs{rc@extract@<...>}\\
780 % |#4|& default\\
781 %\end{tabular}
782 %\end{quote}
783 % \begin{macrocode}
784 \long\def\rc@generic#1#2\@nil#3#4{%
785 #3{#1\TR@TitleReference\@empty{#4}\@nil}{#1}#2\@nil
786 }
787 % \end{macrocode}
788 % \end{macro}
789 % \begin{macro}{\rc@extract@}
790 % \begin{macrocode}
791 \long\def\rc@extract@#1#2#3\@nil{%
792 \ltx@zero
793 #2%
794 }
795 % \end{macrocode}
796 % \end{macro}
797 % \begin{macro}{\rc@extract@page}
798 % \begin{macrocode}
799 \long\def\rc@extract@page#1#2#3#4\@nil{%
800 \ltx@zero
801 #3%
802 }
803 % \end{macrocode}
804 % \end{macro}
805 % \begin{macro}{\rc@extract@name}
806 % \begin{macrocode}
807 \long\def\rc@extract@name#1#2#3#4#5\@nil{%
808 \ltx@zero
809 #4%
810 }
811 % \end{macrocode}
812 % \end{macro}
813 % \begin{macro}{\rc@extract@anchor}
814 % \begin{macrocode}
815 \long\def\rc@extract@anchor#1#2#3#4#5#6\@nil{%
816 \ltx@zero
817 #5%
818 }
819 % \end{macrocode}
820 % \end{macro}
821 % \begin{macro}{\rc@extract@url}
822 % \begin{macrocode}
823 \long\def\rc@extract@url#1#2#3#4#5#6#7\@nil{%
824 \ltx@zero
825 #6%
826 }
827 % \end{macrocode}
828 % \end{macro}
829 % \begin{macro}{\rc@extract@title}
830 % \begin{macrocode}
831 \long\def\rc@extract@title#1#2\@nil{%
832 \rc@@extract@title#1%
833 }
834 % \end{macrocode}
835 % \end{macro}
836 % \begin{macro}{\rc@@extract@title}
837 % \begin{macrocode}
838 \long\def\rc@@extract@title#1\TR@TitleReference#2#3#4\@nil{%
839 \ltx@zero
840 #3%
841 }
842 % \end{macrocode}
843 % \end{macro}
844 %
845 % \subsection{Macros for checking undefined references}
846 %
847 % \begin{macro}{\IfRefUndefinedExpandable}
848 % \begin{macrocode}
849 \rc@newcommand*{\IfRefUndefinedExpandable}[1]{%
850 \ltx@ifundefined{r@#1}\ltx@firstoftwo\ltx@secondoftwo
851 }
852 % \end{macrocode}
853 % \end{macro}
854 % \begin{macro}{\IfRefUndefinedBabel}
855 % \begin{macrocode}
856 \rc@RobustDefOne{}*\IfRefUndefinedBabel{%
857 \begingroup
858 \csname safe@actives@true\endcsname
859 \expandafter\expandafter\expandafter\endgroup
860 \expandafter\ifx\csname r@#1\endcsname\relax
861 \expandafter\ltx@firstoftwo
862 \else
863 \expandafter\ltx@secondoftwo
864 \fi
865 }
866 % \end{macrocode}
867 % \end{macro}
868 % \begin{macrocode}
869 \rc@AtEnd%
870 %</package>
871 % \end{macrocode}
872 %% \section{Installation}
873 %
874 % \subsection{Download}
875 %
876 % \paragraph{Package.} This package is available on
877 % CTAN\footnote{\CTANpkg{refcount}}:
878 % \begin{description}
879 % \item[\CTAN{macros/latex/contrib/refcount/refcount.dtx}] The source file.
880 % \item[\CTAN{macros/latex/contrib/refcount/refcount.pdf}] Documentation.
881 % \end{description}
882 %
883 %
884 % \paragraph{Bundle.} All the packages of the bundle `oberdiek'
885 % are also available in a TDS compliant ZIP archive. There
886 % the packages are already unpacked and the documentation files
887 % are generated. The files and directories obey the TDS standard.
888 % \begin{description}
889 % \item[\CTANinstall{install/macros/latex/contrib/refcount.tds.zip}]
890 % \end{description}
891 % \emph{TDS} refers to the standard ``A Directory Structure
892 % for \TeX\ Files'' (\CTANpkg{tds}). Directories
893 % with \xfile{texmf} in their name are usually organized this way.
894 %
895 % \subsection{Bundle installation}
896 %
897 % \paragraph{Unpacking.} Unpack the \xfile{oberdiek.tds.zip} in the
898 % TDS tree (also known as \xfile{texmf} tree) of your choice.
899 % Example (linux):
900 % \begin{quote}
901 % |unzip oberdiek.tds.zip -d ~/texmf|
902 % \end{quote}
903 %
904 % \subsection{Package installation}
905 %
906 % \paragraph{Unpacking.} The \xfile{.dtx} file is a self-extracting
907 % \docstrip\ archive. The files are extracted by running the
908 % \xfile{.dtx} through \plainTeX:
909 % \begin{quote}
910 % \verb|tex refcount.dtx|
911 % \end{quote}
912 %
913 % \paragraph{TDS.} Now the different files must be moved into
914 % the different directories in your installation TDS tree
915 % (also known as \xfile{texmf} tree):
916 % \begin{quote}
917 % \def\t{^^A
918 % \begin{tabular}{@{}>{\ttfamily}l@{ $\rightarrow$ }>{\ttfamily}l@{}}
919 % refcount.sty & tex/latex/refcount/refcount.sty\\
920 % refcount.pdf & doc/latex/refcount/refcount.pdf\\
921 % refcount.dtx & source/latex/refcount/refcount.dtx\\
922 % \end{tabular}^^A
923 % }^^A
924 % \sbox0{\t}^^A
925 % \ifdim\wd0>\linewidth
926 % \begingroup
927 % \advance\linewidth by\leftmargin
928 % \advance\linewidth by\rightmargin
929 % \edef\x{\endgroup
930 % \def\noexpand\lw{\the\linewidth}^^A
931 % }\x
932 % \def\lwbox{^^A
933 % \leavevmode
934 % \hbox to \linewidth{^^A
935 % \kern-\leftmargin\relax
936 % \hss
937 % \usebox0
938 % \hss
939 % \kern-\rightmargin\relax
940 % }^^A
941 % }^^A
942 % \ifdim\wd0>\lw
943 % \sbox0{\small\t}^^A
944 % \ifdim\wd0>\linewidth
945 % \ifdim\wd0>\lw
946 % \sbox0{\footnotesize\t}^^A
947 % \ifdim\wd0>\linewidth
948 % \ifdim\wd0>\lw
949 % \sbox0{\scriptsize\t}^^A
950 % \ifdim\wd0>\linewidth
951 % \ifdim\wd0>\lw
952 % \sbox0{\tiny\t}^^A
953 % \ifdim\wd0>\linewidth
954 % \lwbox
955 % \else
956 % \usebox0
957 % \fi
958 % \else
959 % \lwbox
960 % \fi
961 % \else
962 % \usebox0
963 % \fi
964 % \else
965 % \lwbox
966 % \fi
967 % \else
968 % \usebox0
969 % \fi
970 % \else
971 % \lwbox
972 % \fi
973 % \else
974 % \usebox0
975 % \fi
976 % \else
977 % \lwbox
978 % \fi
979 % \else
980 % \usebox0
981 % \fi
982 % \end{quote}
983 % If you have a \xfile{docstrip.cfg} that configures and enables \docstrip's
984 % TDS installing feature, then some files can already be in the right
985 % place, see the documentation of \docstrip.
986 %
987 % \subsection{Refresh file name databases}
988 %
989 % If your \TeX~distribution
990 % (\TeX\,Live, \mikTeX, \dots) relies on file name databases, you must refresh
991 % these. For example, \TeX\,Live\ users run \verb|texhash| or
992 % \verb|mktexlsr|.
993 %
994 % \subsection{Some details for the interested}
995 %
996 % \paragraph{Unpacking with \LaTeX.}
997 % The \xfile{.dtx} chooses its action depending on the format:
998 % \begin{description}
999 % \item[\plainTeX:] Run \docstrip\ and extract the files.
1000 % \item[\LaTeX:] Generate the documentation.
1001 % \end{description}
1002 % If you insist on using \LaTeX\ for \docstrip\ (really,
1003 % \docstrip\ does not need \LaTeX), then inform the autodetect routine
1004 % about your intention:
1005 % \begin{quote}
1006 % \verb|latex \let\install=y\input{refcount.dtx}|
1007 % \end{quote}
1008 % Do not forget to quote the argument according to the demands
1009 % of your shell.
1010 %
1011 % \paragraph{Generating the documentation.}
1012 % You can use both the \xfile{.dtx} or the \xfile{.drv} to generate
1013 % the documentation. The process can be configured by the
1014 % configuration file \xfile{ltxdoc.cfg}. For instance, put this
1015 % line into this file, if you want to have A4 as paper format:
1016 % \begin{quote}
1017 % \verb|\PassOptionsToClass{a4paper}{article}|
1018 % \end{quote}
1019 % An example follows how to generate the
1020 % documentation with pdf\LaTeX:
1021 % \begin{quote}
1022 %\begin{verbatim}
1023 %pdflatex refcount.dtx
1024 %makeindex -s gind.ist refcount.idx
1025 %pdflatex refcount.dtx
1026 %makeindex -s gind.ist refcount.idx
1027 %pdflatex refcount.dtx
1028 %\end{verbatim}
1029 % \end{quote}
1030 %
1031 % \begin{History}
1032 % \begin{Version}{1998/04/08 v1.0}
1033 % \item
1034 % First public release, written as answer in the
1035 % newsgroup \xnewsgroup{comp.text.tex}:
1036 % \URL{``\link{Re: Adding a \cs{ref} to a counter?}''}^^A
1037 % {https://groups.google.com/group/comp.text.tex/msg/c3f2a135ef5ee528}
1038 % \end{Version}
1039 % \begin{Version}{2000/09/07 v2.0}
1040 % \item
1041 % Documentation added.
1042 % \item
1043 % LPPL 1.2
1044 % \item
1045 % Package rewritten, new commands added.
1046 % \end{Version}
1047 % \begin{Version}{2006/02/20 v3.0}
1048 % \item
1049 % Support for \xpackage{hyperref} and \xpackage{nameref} improved.
1050 % \item
1051 % Support for \xpackage{titleref} and \xpackage{babel}'s shorthands added.
1052 % \item
1053 % New: \cs{refused}, \cs{getrefbykeydefault}
1054 % \end{Version}
1055 % \begin{Version}{2008/08/11 v3.1}
1056 % \item
1057 % Code is not changed.
1058 % \item
1059 % URLs updated.
1060 % \end{Version}
1061 % \begin{Version}{2010/12/01 v3.2}
1062 % \item
1063 % \cs{IfRefUndefinedExpandable} and \cs{IfRefUndefinedBabel} added.
1064 % \item
1065 % \cs{getrefnumber}, \cs{getpagerefnumber}, \cs{getrefbykeydefault}
1066 % are expandable in exact two expansion steps.
1067 % \item
1068 % Non-expandable macros are made robust.
1069 % \item
1070 % Test files added.
1071 % \end{Version}
1072 % \begin{Version}{2011/06/22 v3.3}
1073 % \item
1074 % Bug fix: \cs{rc@refused} is undefined for \cs{setcounterpageref}
1075 % and similar macros. (Bug found by Marc van Dongen.)
1076 % \end{Version}
1077 % \begin{Version}{2011/10/16 v3.4}
1078 % \item
1079 % Bug fix: \cs{setcounterpageref} and \cs{addtocounterpageref} fixed.
1080 % (Bug found by Staz.)
1081 % \item
1082 % Macros \cs{(set|addto)counter(page|)ref} are made robust.
1083 % \end{Version}
1084 % \begin{Version}{2016/05/16 v3.5}
1085 % \item
1086 % Documentation updates.
1087 % \end{Version}
1088 % \begin{Version}{2019/12/15 v3.6}
1089 % \item
1090 % Documentation updates.
1091 % \end{Version}
1092 % \end{History}
1093 %
1094 % \PrintIndex
1095 %
1096 % \Finale
1097 \endinput