-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathzref.dtx
6827 lines (6787 loc) · 194 KB
/
zref.dtx
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
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
% \iffalse meta-comment
%
% File: zref.dtx
% Version: 2023-09-14 v2.35
% Info: A new reference scheme for LaTeX
%
% Copyright (C)
% 2006-2012 Heiko Oberdiek
% 2016-2020 Oberdiek Package Support Group
% https://github.com/ho-tex/zref/issues
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either
% version 1.3c of this license or (at your option) any later
% version. This version of this license is in
% https://www.latex-project.org/lppl/lppl-1-3c.txt
% and the latest version of this license is in
% https://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of
% LaTeX version 2005/12/01 or later.
%
% This work has the LPPL maintenance status "maintained".
%
% The Current Maintainers of this work are
% Heiko Oberdiek and the Oberdiek Package Support Group
% https://github.com/ho-tex/zref/issues
%
% This work consists of the main source file zref.dtx
% and the derived files
% zref.sty, zref.pdf, zref.ins, zref.drv, zref-base.sty,
% zref-abspage.sty, zref-abspos.sty, zref-counter.sty,
% zref-dotfill.sty, zref-env.sty, zref-hyperref.sty,
% zref-lastpage.sty, zref-marks.sty, zref-nextpage.sty,
% zref-pageattr.sty, zref-pagelayout.sty, zref-perpage.sty,
% zref-runs.sty, zref-savepos.sty, zref-thepage.sty,
% zref-titleref.sty, zref-totpages.sty, zref-user.sty,
% zref-xr.sty, zref-example.tex, zref-example-lastpage.tex,
% zref-example-nextpage.tex, zref-test1.tex,
% zref-test-base.tex, zref-test-runs.tex,
% zref-test-titleref-memoir.tex.
%
% Distribution:
% CTAN:macros/latex/contrib/zref/zref.dtx
% CTAN:macros/latex/contrib/zref/zref.pdf
%
% Unpacking:
% (a) If zref.ins is present:
% tex zref.ins
% (b) Without zref.ins:
% tex zref.dtx
% (c) If you insist on using LaTeX
% latex \let\install=y\input{zref.dtx}
% (quote the arguments according to the demands of your shell)
%
% Documentation:
% (a) If zref.drv is present:
% latex zref.drv
% (b) Without zref.drv:
% latex zref.dtx; ...
% The class ltxdoc loads the configuration file ltxdoc.cfg
% if available. Here you can specify further options, e.g.
% use A4 as paper format:
% \PassOptionsToClass{a4paper}{article}
%
% Program calls to get the documentation (example):
% pdflatex zref.dtx
% makeindex -s gind.ist zref.idx
% pdflatex zref.dtx
% makeindex -s gind.ist zref.idx
% pdflatex zref.dtx
%
% Installation:
% TDS:tex/latex/zref/zref.sty
% TDS:tex/latex/zref/zref-base.sty
% TDS:tex/latex/zref/zref-abspage.sty
% TDS:tex/latex/zref/zref-abspos.sty
% TDS:tex/latex/zref/zref-counter.sty
% TDS:tex/latex/zref/zref-dotfill.sty
% TDS:tex/latex/zref/zref-env.sty
% TDS:tex/latex/zref/zref-hyperref.sty
% TDS:tex/latex/zref/zref-lastpage.sty
% TDS:tex/latex/zref/zref-marks.sty
% TDS:tex/latex/zref/zref-nextpage.sty
% TDS:tex/latex/zref/zref-pageattr.sty
% TDS:tex/latex/zref/zref-pagelayout.sty
% TDS:tex/latex/zref/zref-perpage.sty
% TDS:tex/latex/zref/zref-runs.sty
% TDS:tex/latex/zref/zref-savepos.sty
% TDS:tex/latex/zref/zref-thepage.sty
% TDS:tex/latex/zref/zref-titleref.sty
% TDS:tex/latex/zref/zref-totpages.sty
% TDS:tex/latex/zref/zref-user.sty
% TDS:tex/latex/zref/zref-xr.sty
% TDS:doc/latex/zref/zref.pdf
% TDS:doc/latex/zref/zref-example.tex
% TDS:doc/latex/zref/zref-example-lastpage.tex
% TDS:doc/latex/zref/zref-example-nextpage.tex
% TDS:source/latex/zref/zref.dtx
%
%<*ignore>
\begingroup
\catcode123=1 %
\catcode125=2 %
\def\x{LaTeX2e}%
\expandafter\endgroup
\ifcase 0\ifx\install y1\fi\expandafter
\ifx\csname processbatchFile\endcsname\relax\else1\fi
\ifx\fmtname\x\else 1\fi\relax
\else\csname fi\endcsname
%</ignore>
%<*install>
\input docstrip.tex
\Msg{************************************************************************}
\Msg{* Installation}
\Msg{* Package: zref 2023-09-14 v2.35 A new reference scheme for LaTeX (HO)}
\Msg{************************************************************************}
\keepsilent
\askforoverwritefalse
\let\MetaPrefix\relax
\preamble
This is a generated file.
Project: zref
Version: 2023-09-14 v2.35
Copyright (C)
2006-2012 Heiko Oberdiek
2016-2023 Oberdiek Package Support Group
This work may be distributed and/or modified under the
conditions of the LaTeX Project Public License, either
version 1.3c of this license or (at your option) any later
version. This version of this license is in
https://www.latex-project.org/lppl/lppl-1-3c.txt
and the latest version of this license is in
https://www.latex-project.org/lppl.txt
and version 1.3 or later is part of all distributions of
LaTeX version 2005/12/01 or later.
This work has the LPPL maintenance status "maintained".
The Current Maintainers of this work are
Heiko Oberdiek and the Oberdiek Package Support Group
https://github.com/ho-tex/zref/issues
This work consists of the main source file zref.dtx
and the derived files
zref.sty, zref.pdf, zref.ins, zref.drv, zref-base.sty,
zref-abspage.sty, zref-abspos.sty, zref-counter.sty,
zref-dotfill.sty, zref-env.sty, zref-hyperref.sty,
zref-lastpage.sty, zref-marks.sty, zref-nextpage.sty,
zref-pageattr.sty, zref-pagelayout.sty, zref-perpage.sty,
zref-runs.sty, zref-savepos.sty, zref-thepage.sty,
zref-titleref.sty, zref-totpages.sty, zref-user.sty,
zref-xr.sty, zref-example.tex, zref-example-lastpage.tex,
zref-example-nextpage.tex, zref-test1.tex,
zref-test-base.tex, zref-test-runs.tex,
zref-test-titleref-memoir.tex.
\endpreamble
\let\MetaPrefix\DoubleperCent
\generate{%
\file{zref.ins}{\from{zref.dtx}{install}}%
\file{zref.drv}{\from{zref.dtx}{driver}}%
\usedir{tex/latex/zref}%
\file{zref.sty}{\from{zref.dtx}{package}}%
\file{zref-base.sty}{\from{zref.dtx}{base}}%
\file{zref-abspage.sty}{\from{zref.dtx}{abspage}}%
\file{zref-abspos.sty}{\from{zref.dtx}{abspos}}%
\file{zref-counter.sty}{\from{zref.dtx}{counter}}%
\file{zref-dotfill.sty}{\from{zref.dtx}{dotfill}}%
\file{zref-env.sty}{\from{zref.dtx}{env}}%
\file{zref-hyperref.sty}{\from{zref.dtx}{hyperref}}%
\file{zref-lastpage.sty}{\from{zref.dtx}{lastpage}}%
\file{zref-marks.sty}{\from{zref.dtx}{marks}}%
\file{zref-nextpage.sty}{\from{zref.dtx}{nextpage}}%
\file{zref-pageattr.sty}{\from{zref.dtx}{pageattr}}%
\file{zref-pagelayout.sty}{\from{zref.dtx}{pagelayout}}%
\file{zref-perpage.sty}{\from{zref.dtx}{perpage}}%
\file{zref-runs.sty}{\from{zref.dtx}{runs}}%
\file{zref-savepos.sty}{\from{zref.dtx}{savepos}}%
\file{zref-thepage.sty}{\from{zref.dtx}{thepage}}%
\file{zref-titleref.sty}{\from{zref.dtx}{titleref}}%
\file{zref-totpages.sty}{\from{zref.dtx}{totpages}}%
\file{zref-user.sty}{\from{zref.dtx}{user}}%
\file{zref-xr.sty}{\from{zref.dtx}{xr}}%
\usedir{doc/latex/zref}%
\file{zref-example.tex}{\from{zref.dtx}{example}}%
\file{zref-example-lastpage.tex}{\from{zref.dtx}{example-lastpage}}%
\file{zref-example-nextpage.tex}{\from{zref.dtx}{example-nextpage}}%
% \usedir{doc/latex/zref/test}%
% \file{zref-test1.tex}{\from{zref.dtx}{test1}}%
% \file{zref-test-base.tex}{\from{zref.dtx}{test-base}}%
% \file{zref-test-runs.tex}{\from{zref.dtx}{test-runs}}%
% \file{zref-test-titleref-memoir.tex}{\from{zref.dtx}{test-titleref-memoir}}%
}
\catcode32=13\relax% active space
\let =\space%
\Msg{************************************************************************}
\Msg{*}
\Msg{* To finish the installation you have to move the following}
\Msg{* files into a directory searched by TeX:}
\Msg{*}
\Msg{* zref.sty, zref-base.sty, zref-abspage.sty, zref-abspos.sty,}
\Msg{* zref-counter.sty, zref-dotfill.sty, zref-env.sty,}
\Msg{* zref-hyperref.sty, zref-lastpage.sty, zref-marks.sty,}
\Msg{* zref-nextpage.sty, zref-pageattr.sty, zref-pagelayout.sty,}
\Msg{* zref-perpage.sty, zref-runs.sty, zref-savepos.sty,}
\Msg{* zref-thepage.sty, zref-titleref.sty, zref-totpages.sty,}
\Msg{* zref-user.sty, zref-xr.sty}
\Msg{*}
\Msg{* To produce the documentation run the file `zref.drv'}
\Msg{* through LaTeX.}
\Msg{*}
\Msg{* Happy TeXing!}
\Msg{*}
\Msg{************************************************************************}
\endbatchfile
%</install>
%<*ignore>
\fi
%</ignore>
%<*driver>
\NeedsTeXFormat{LaTeX2e}
\ProvidesFile{zref.drv}%
[2023-09-14 v2.35 A new reference scheme for LaTeX (HO)]%
\documentclass{ltxdoc}
\usepackage{holtxdoc}[2011/11/22]
\setlength{\emergencystretch}{1em}
\begin{document}
\DocInput{zref.dtx}%
\end{document}
%</driver>
% \fi
%
%
%
% \GetFileInfo{zref.drv}
%
% \title{The \xpackage{zref} package}
% \date{2023-09-14 v2.35}
% \author{Heiko Oberdiek\thanks
% {Please report any issues at \url{https://github.com/ho-tex/zref/issues}}}
%
% \maketitle
%
% \begin{abstract}
% Package \xpackage{zref} tries to get rid of the restriction
% in \hologo{LaTeX}'s reference system that only two properties are
% supported. The package implements an extensible referencing
% system, where properties are handled in a more flexible way.
% It offers an interface for macro programmers for the access
% to the system and some applications that uses the new
% reference scheme.
% \end{abstract}
%
% \tableofcontents
%
% \newcommand*{\metacs}[1]{\texttt{\itshape #1}}
%
% \newcommand{\markexp}{^^A
% \textsuperscript{exp}^^A
% \space
% }
% \newcommand{\markexptwo}{^^A
% \textsuperscript{exp2}^^A
% \space
% }
% \newcommand{\markrobust}{^^A
% \textsuperscript{robust}^^A
% \space
% }
% \newcommand{\marknowarn}{^^A
% \textsuperscript{nowarn}^^A
% \space
% }
% \newcommand{\markbabel}{^^A
% \textsuperscript{babel}^^A
% \space
% }
%
% \section{Introduction}
%
% Standard \hologo{LaTeX}'s reference system with \cs{label}, \cs{ref},
% and \cs{pageref} supports two properties, the appearance of
% the counter that is last incremented by \cs{refstepcounter} and
% the page with the \cs{label} command.
%
% Unhappily \hologo{LaTeX} does not provide an interface for adding
% another properties. Packages such as \xpackage{hyperref},
% \xpackage{nameref}, or \xpackage{titleref} are forced to
% use ugly hacks to extend the reference system.
% These ugly hacks are one of the causes for \xpackage{hyperref}'s
% difficulty regarding compatibility with other packages.
%
% \subsection{Standard \hologo{LaTeX} behaviour}
%
% References are created by the \cs{label} command:
% \begin{quote}
% |\chapter{Second chapter}|\\
% |\section{First section on page 7} % section 2.1|\\
% |\label{myref}|
% \end{quote}
% Now \hologo{LaTeX} records the section number |2.1| and the page |7|
% in the reference. Internally the reference is a list with
% two entries:
% \begin{quote}
% |\r@myref| $\rightarrow$ |{2.1}{7}|
% \end{quote}
% The length of the list if fixed in the \hologo{LaTeX} kernel,
% An interface for adding new properties is missing.
%
% There are several tries to add new properties:
% \begin{description}
% \item[\xpackage{hyperref}] uses a list of five
% properties instead of the standard list with two entries.
% This causes many compatibility problems with \hologo{LaTeX} and
% other packages.
% \item[\xpackage{titleref}] stores its title data into the
% first entry in the list. \hologo{LaTeX} is happy because it
% does only see its list with two entries. The situation
% becomes more difficult, if more properties are added
% this way. Then the macros form a nested structure
% inside the first reference argument for the label.
% Expandable extractions will then become painful.
% \end{description}
%
% \subsection{Basic idea}
%
% Some time ago Morten H\o gholm sent me an experimental
% cross referencing mechanism as ``expl3'' code. His
% idea is:
% \begin{quote}
% |\g_xref_mylabel_plist| $\rightarrow$\\
% \mbox{}\qquad|\xref_dance_key{salsa}\xref_name_key{Morten}|\dots
% \end{quote}
% The entries have the following format:
% \begin{quote}
% |\xref_|\meta{your key}|_key{|\meta{some text}|}|
% \end{quote}
% This approach is much more flexible:
% \begin{itemize}
% \item New properties can easily be added, just use a new key.
% \item The length of the list is not fixed. A reference
% can use a subset of the keys.
% \item The order of the entries does not matter.
% \end{itemize}
% Unhappily I am not familiar with the experimental code
% for \hologo{LaTeX3} that will need some time before its first release.
% Thus I have implemented it as \hologo{LaTeXe} package without disturbing
% the existing \hologo{LaTeX} reference system.
%
% \subsection{Interfaces}
%
% The package provides a generic \emph{interface for programmers}.
% Commands of this interface are prefixed by \cs{zref@}.
%
% Option \xoption{user} enables the \emph{user interface}.
% Here the commands are prefixed by \cs{z} to avoid name
% clashes with existing macros.
%
% Then the packages provides some \emph{modules}. They
% are applications for the reference system and can also be
% considered as examples how to use the reference system.
%
% The modules can be loaded as packages. The package
% name is prefixed with |zref-|, for example:
%\begin{quote}
%\begin{verbatim}
%\RequirePackage{zref-abspage}
%\end{verbatim}
%\end{quote}
% This is the preferred way if the package is loaded from
% within other packages to avoid option clashes.
%
% As alternative package |zref| can be used and the modules
% are given as options:
%\begin{quote}
%\begin{verbatim}
%\usepackage[perpage,user]{zref}
%\end{verbatim}
%\end{quote}
%
% \section{Interface for programmers}
%
% The user interface is described in the next section \ref{sec:user}.
%
% \subsection{Entities}
%
% \paragraph{Reference.}
% Internally a reference is a list of key value pairs:
% \begin{quote}
% |\Z@R@myref| $\rightarrow$
% |\default{2.1}\page{7}|
% \end{quote}
% The generic format of a entry is:
% \begin{quote}
% |\Z@R@|\meta{refname} $\rightarrow$
% |\|\meta{propname}|{|\meta{value}|}|
% \end{quote}
% \meta{refname} is the name that denoted references
% (the name used in \cs{label} and \cs{ref}). \meta{propname}
% is the name of the property or key. The property key macro
% is never executed, it is used in parameter text matching only.
%
% \paragraph{Property.}
% Because the name of a property is used in a macro name
% that must survive the \xfile{.aux} file, the name is
% restricted to letters and `@'.
%
% \paragraph{Property list.}
% Often references are used for special purposes. Thus it
% saves memory if just the properties are used in this
% reference that are necessary for its purpose.
%
% Therefore this package uses the concept of \emph{property lists}.
% A property list is a set of properties. The set of properties
% that is used by the default \cs{label} command is the
% \emph{main property list}.
%
% \subsection{Property list}
%
% \markexp means that the implementation of the
% marked macro is expandable. \markexptwo goes a step further
% and marks the macro expandable in exact two expansion steps.
%
% \begin{declcs}{zref@newlist}
% \M{listname}
% \end{declcs}
% Declares a new empty property list.
%
% \begin{declcs}{zref@addprop}
% \M{listname} \M{propname}\\
% \cs{zref@localaddprop} \M{listname} \M{propname}
% \end{declcs}
% Adds the property \meta{propname}
% to the property list \meta{listname}.
% The property and list must exist.
% The addition is global by \cs{zref@addprop} and limited to
% local scope by \cs{zref@localaddprop}.
% Between 2010/04/19 v2.13 and 2010/10/22 v2.19 a comma separated list
% of properties could be used as argument \meta{propname}.
% Since 2010/10/22 v2.19 the addition of several properties
% at once is supported by \cs{zref@addprops}.
%
% \begin{declcs}{zref@addprops}
% \M{listname} \M{propname list}\\
% \cs{zref@localaddprops} \M{listname} \M{propname list}
% \end{declcs}
% These macros add a comma separated list of properties
% \meta{propname list} to list \meta{listname}.
% \cs{zref@addprops} works globally and \cs{zref@localaddprops}
% locally. Since 2010/10/22 v2.19.
%
% \begin{declcs}{zref@listexists}
% \M{listname} \M{then}
% \end{declcs}
% Executes \meta{then} if the property list \meta{listname} exists
% or raise an error otherwise.
%
% \begin{declcs}{zref@iflistundefined}\markexp \M{listname}
% \M{then} \M{else}
% \end{declcs}
% Executes \meta{then} if the list exists or \meta{else}
% otherwise.
%
% \begin{declcs}{zref@iflistcontainsprop}
% \M{listname} \M{propname} \M{then} \M{else}
% \end{declcs}
% Executes \meta{then} if the property \meta{propname} is part
% of property list \meta{listname} or otherwise it
% runs the \meta{else} part.
%
% \subsection{Property}
%
% \begin{declcs}{zref@newprop}
% \* \M{propname} |[|\meta{default}|]| \M{value}
% \end{declcs}
% This command declares and configures a new property with
% name \meta{propname}.
%
% In case of unknown references
% or the property does not exist in the reference, the
% \meta{default} is used as value. If it is not specified
% here, a global default is used, see \cs{zref@setdefault}.
%
% The correct values of some properties are not known
% immediately but at page shipout time. Prominent example
% is the page number. These properties are declared with
% the star form of the command.
%
% \begin{declcs}{zref@setcurrent}
% \M{propname} \M{value}
% \end{declcs}
% This sets the current value of the property \meta{propname}.
% It is a generalization of setting \hologo{LaTeX}'s \cs{currentlabel}.
%
% \begin{declcs}{zref@getcurrent}\markexptwo
% \M{propname}
% \end{declcs}
% This returns the current value of the property \meta{propname}.
% The value may not be correct, especially if the property
% is bound to a page (start form of \cs{zref@newprop}) and the
% right value is only known at shipout time (e.g. property `page').
% In case of errors (e.g. unknown property) the empty string is
% returned.
%
% Since version 2010/04/22 v2.14 \cs{zref@getcurrent} supports
% \cs{zref@wrapper@unexpanded}.
%
% \begin{declcs}{zref@propexists}
% \M{propname} \M{then}
% \end{declcs}
% Calls \meta{then} if the property \meta{propname} is available
% or generates an error message otherwise.
%
% \begin{declcs}{zref@ifpropundefined}\markexp
% \M{propname} \M{then} \M{else}
% \end{declcs}
% Calls \meta{then} or \meta{else} depending on the existence
% of property \meta{propname}.
%
% \subsection{Reference generation}
%
% \begin{declcs}{zref@label}
% \M{refname}
% \end{declcs}
% This works similar to \cs{label}. The reference \meta{refname} is
% created and put into the \xfile{.aux} file with the
% properties of the main property list.
%
% \begin{declcs}{zref@labelbylist}
% \M{refname} \M{listname}
% \end{declcs}
% Same as \cs{zref@label} except that the properties are
% taken from the specified property list \meta{listname}.
%
% \begin{declcs}{zref@labelbyprops}
% \M{refname} |{|\meta{propnameA}|,|\meta{propnameB}|,|\dots|}|
% \end{declcs}
% Same as \cs{zref@label} except that these properties
% are used that are given as comma separated list in the
% second argument.
%
% \begin{declcs}{zref@newlabel}
% \M{refname} |{|\dots|}|
% \end{declcs}
% This is the macro that is used in the \xfile{.aux} file.
% It is basically the same as \cs{newlabel} apart from
% the format of the data in the second argument.
%
% \subsection{Data extraction}
%
% \begin{declcs}{zref@extractdefault}\markexptwo
% \M{refname} \M{propname} \M{default}
% \end{declcs}
% This is the basic command that references the value of a
% property \meta{propname} for the reference \meta{refname}.
% In case of errors such as undefined reference the \meta{default}
% is used instead.
%
% \begin{declcs}{zref@extract}\markexptwo
% \M{refname} \M{propname}
% \end{declcs}
% The command is an abbreviation for \cs{zref@extractdefault}.
% As default the default of the property is taken, otherwise
% the global default.
%
% Example for page references:
% \begin{quote}
% \begin{tabular}{@{}ll}
% \hologo{LaTeX}:& |\pageref{foobar}|\\
% \xpackage{zref}:& |\zref@extract{foobar}{page}|
% \end{tabular}
% \end{quote}
% Both \cs{zref@extract} and \cs{zref@extractdefault} are
% expandable. That means, these macros can directly
% be used in expandable calculations, see the example file.
% On the other side, babel's shorthands are not supported,
% there are no warnings in case of undefined references.
%
% If an user interface doesn't need expandable macros
% then it can use \cs{zref@refused} and \cs{zref@wrapper@babel}
% for its user macros.
%
% \begin{declcs}{zref@refused}
% \M{refname}
% \end{declcs}
% This command is not expandable. It causes the warnings if
% the reference \meta{refname} is not defined. Use the
% \cs{zref@extract} commands inside expandable contexts and
% mark their use outside by \cs{zref@refused}, see the example
% file.
%
% \begin{declcs}{zref@def@extract}%
% \M{cmd} \M{refname} \M{propname}\\
% \cs{zref@def@extractdefault}
% \M{cmd} \M{refname} \M{propname} \M{default}
% \end{declcs}
% Both macros extract the property \meta{propname} from the reference
% \meta{refname} the same way as macros \cs{zref@extract} and
% \cs{zref@extractdefault}. The result is stored in macro \meta{cmd}.
% Also \cs{zref@refused} is called to notify \hologo{LaTeX} that
% the reference \meta{refname} is used. Added in 2011/10/04 v2.22.
%
% \begin{declcs}{zref@ifrefundefined}\markexp
% \M{refname} \M{then} \M{else}
% \end{declcs}
% Macro \cs{zref@ifrefundefined} calls arguments \meta{then} or \meta{else}
% dependent on the existence of the reference \meta{refname}.
%
% \begin{declcs}{zifrefundefined}
% \M{refname} \M{then} \M{else}
% \end{declcs}
% Macro \cs{zifrefundefined} calls \cs{ref@refused} before
% executing \cs{zref@ifrefundefined}. Babel shorthands are
% supported in \meta{refname}.
%
% \begin{declcs}{zref@ifrefcontainsprop}\markexp
% \M{refname} \M{propname} \M{then} \M{else}
% \end{declcs}
% Test whether a reference provides a property.
%
% \subsection{Setup}
%
% \begin{declcs}{zref@default}
% \end{declcs}
% Holds the global default for unknown values.
%
% \begin{declcs}{zref@setdefault}
% |{|\meta{value}|}|
% \end{declcs}
% Sets the global default for unknown values.
% The global default is used, if a property does not specify
% an own default and the value for a property
% cannot be extracted. This can happen if the reference is
% unknown or the reference does not have the property.
%
% \begin{declcs}{zref@setmainlist}
% |{|\meta{value}|}|
% \end{declcs}
% Sets the name of the main property list. The package
% sets and uses |main|.
%
% \subsection{Declared properties}
%
% \begin{quote}
% \renewcommand*{\arraystretch}{1.05}
% \setlength{\tabcolsep}{2\tabcolsep}
% \def\VV{\vphantom{\large \"Ag}}
% \def\EMPTY{{\itshape\textless empty\textgreater}}
% \def\pl#1{&thepage&\cs{number}\cs{#1}}
% \begin{tabular}{@{}>{\sffamily}l|>{\ttfamily}l|>{\ttfamily}l|>{\ttfamily}l@{}}
% \rmfamily Module&
% \rmfamily Property&
% \rmfamily Property list&
% \rmfamily Default\\
% \hline
% (base)
% & default & main & \EMPTY\\
% & page & main & \EMPTY\\
% \hline
% abspage
% & abspage & main & 0\\
% \hline
% counter
% & counter & main & \EMPTY\\
% \hline
% hyperref
% & anchor & main & \EMPTY\\
% & url & & \EMPTY\\
% \hline
% pageattr
% & pdfpageattr & thepage & \dots\\
% & pdfpagesattr & LastPage & \dots\\
% \hline
% pagelayout\footnotemark
% \pl{mag}\\
% \pl{paperwidth}\\
% \pl{paperheight}\\
% \pl{stockwidth}\\
% \pl{stockheight}\\
% \pl{pdfpageheight}\\
% \pl{pdfpagewidth}\\
% \pl{pdfhorigin}\\
% \pl{pdfvorigin}\\
% \pl{hoffset}\\
% \pl{voffset}\\
% \pl{topmargin}\\
% \pl{oddsidemargin}\\
% \pl{evensidemargin}\\
% \pl{textwidth}\\
% \pl{textheight}\\
% \pl{headheight}\\
% \pl{headsep}\\
% \pl{footskip}\\
% \pl{marginparwidth}\\
% \pl{marginparsep}\\
% \pl{columnwidth}\\
% \pl{columnsep}\\
% \hline
% perpage
% & pagevalue & perpage & 0\\
% & page & perpage & \EMPTY\\
% & abspage & perpage & 0\\
% \hline
% savepos
% & posx & savepos & 0\\
% & posy & savepos & 0\\
% \hline
% titleref
% & title & main & \EMPTY\\
% \hline
% xr
% & anchor & & \EMPTY\\
% & externaldocument & & \EMPTY\\
% & theotype & & \EMPTY\\
% & title & & \EMPTY\\
% & url & & \EMPTY\\
% \end{tabular}
% \footnotetext{Module \xmodule{pagelayout} only defines properties
% if the parameter exists.}%
% \end{quote}
%
% \subsection{Wrapper for advanced situations}
%
% \begin{declcs}{zref@wrapper@babel}
% |{|\dots|}| \M{name}
% \end{declcs}
% This macro helps to add shorthand support. The second
% argument is protected, then the code of the first argument
% is called with the protected name appended. Examples
% are in the sources.
%
% \begin{declcs}{zref@wrapper@immediate}
% |{|\dots|}|
% \end{declcs}
% There are situations where a label must be written instantly
% to the \xfile{.aux} file, for example after the last page.
% If the \cs{zlabel} or \cs{label} command is put inside this wrapper,
% immediate writing is enabled. See the implementation for
% module \xmodule{lastpage} for an example of its use.
%
% \begin{declcs}{zref@wrapper@unexpanded}
% |{|\dots|}|
% \end{declcs}
% Assuming someone wants to extract a value for property |bar|
% and store the result in a macro |\foo| without traces of
% the expanding macros and without expanding the value.
% This (theoretical?) problem can be solved by this wrapper:
% \begin{quote}
%\begin{verbatim}
%\zref@wrapper@unexpanded{%
% \edef\foo{%
% \zref@extract{someref}{bar}%
% }%
%}
%\end{verbatim}
% \end{quote}
% The \cs{edef} forces the expansion of \cs{zref@extract},
% but the extraction of the value is prevented by
% the wrapper that uses \hologo{eTeX}'\ \cs{unexpanded} for this
% purpose. Supported macros are \cs{zref@extract}, \cs{zref@extractdefault}
% and since version 2010/04/22 v2.14 macro \cs{zref@getcurrent}.
%
% \subsection{Counter for unique names}
%
% Some modules (\xmodule{titleref} and \xmodule{dotfillmin})
% need unique names for automatically generated label names.
%
% \begin{declcs}{zref@require@unique}
% \end{declcs}
% This command creates the unique counter |zref@unique| if the
% counter does not already exist.
%
% \begin{declcs}{thezref@unique}
% \end{declcs}
% This command is used to generate unique label names.
%
% \section{User interface}\label{sec:user}
%
% \subsection{Module \xmodule{user}}
%
% The user interface for this package and its modules
% is enabled by \xpackage{zref}'s package option \xmodule{user}
% or package \xpackage{zref-user}.
% The names of user commands are prefixed by |z| in order
% to avoid name clashes with existing macros of the same
% functionality. Thus the package does not disturb the
% traditional reference scheme, both can be used together.
%
% The syntax descriptions contain the following markers
% that are intended as hints for programmers:
% \begin{quote}
% \begin{tabular}{@{}ll@{}}
% \markbabel\unskip & Babel shorthands are allowed.\\
% \markrobust\unskip & Robust macro.\\
% \markexp\unskip & Expandable version:\\
% & \textbullet\ robust,
% unless the extracted values are fragile,\\
% & \textbullet\ no babel shorthand support.\\
% \markexptwo\unskip & Expandable like \markexp and:\\
% & \textbullet\ expandable in exact two steps.\\
% \end{tabular}
% \end{quote}
%
% The basic user interface of the package without modules
% are commands that mimic the standard \hologo{LaTeX} behaviour
% of \cs{label}, \cs{ref}, and \cs{pageref}:
%
% \begin{declcs}{zlabel}
% \M{refname}\markbabel
% \end{declcs}
% Similar to \cs{label}. It generates a label with name
% \meta{refname} in the new reference scheme.
%
% \begin{declcs}{zref}
% |[|\meta{propname}|]| \M{refname}\markbabel
% \end{declcs}
% Without optional argument similar to \cs{ref}, it returns
% the default reference property. This property is named
% |default|:
% \[
% |\zref{|x|}| \equiv |\zref[default]{|x|}|
% \]
%
% \begin{declcs}{zpageref}
% \M{refname}\markbabel
% \end{declcs}
% Convenience macro, similar to \cs{pageref}.
% \[
% |\zpageref{|x|}| \equiv |\zref[page]{|x|}|
% \]
%
% \begin{declcs}{zrefused}
% \M{refname}\markbabel
% \end{declcs}
% Some of the user commands in the modules are expandable.
% The use of such commands do not cause any undefined
% reference warnings, because inside of expandable
% contexts this is not possible. However, if there is
% a place outside of expandable contexts, \cs{refused}
% is strongly recommended. The reference \meta{refname}
% is marked as used, undefined ones will generate
% warnings.
%
% \subsection{Module \xmodule{abspage}}
% A new property |abspage| is defined and added to the
% main property list. It makes use of the LaTeX count |\ReadonlyShipoutCounter|
% to keep track of the page numbers.
%
% Thus you can reference the absolute page number:
% \begin{quote}
% |Section \zref{foo} is on page \zpageref{foo}.|\\
% |This is page \zref[abspage]{foo}|\\
% |of \zref[abspage]{LastPage}.|
% \end{quote}
% The example also makes use of module \xmodule{lastpage}.
%
% For compatibility also a counter |abspage| is provided
% which is increased at shipout too.
% For technical and historical reasons this counter is zero based:
% if you use it directly on the first page, e.g
% with |\arabic{abspage}| you will get 0 as value. (When using |\zref| to retrieve
% the |abspage| property the first page will be page 1 as expected.).
% It must be noted that the \texttt{perpage} package also provides a |abspage|
% counter which is \emph{not} zero based but gives 1 on the first page if \texttt{zref-abspage} is
% not loaded or loaded after \texttt{perpage}.
%
%
% \subsection{Module \xmodule{lastpage}}
%
% Provides the functionality of package \xpackage{lastpage}
% \cite{lastpage} in the new reference scheme.
% The label |LastPage| is put at the end of the document.
% You can refer the last page number with:
% \begin{quote}
% |\zref@extract{LastPage}{page}| (+ |\zref@refused{LastPage}|)\\
% \end{quote}
% or
% \begin{quote}
% |\zpageref{LastPage}| (module \xmodule{user})
% \end{quote}
%
% Since version 2008/10/01 v2.3 the module defines the list |LastPage|.
% In addition to the properties of the main list label |LastPage| also
% stores the properties of this list |LastPage|. The default of this
% list is empty. The list can be used by the user to add additional
% properties for label |LastPage|.
%
% \subsubsection{Tests for last page}
%
% Since version 2010/03/26 v2.8 the macros \cs{zref@iflastpage}
% and \cs{ziflastpage} were added. They test the reference,
% whether it is a reference of the last page.
%
% \begin{declcs}{zref@iflastpage}\markexp \M{refname} \M{then} \M{else}
% \end{declcs}
% Macro \cs{zref@iflastpage} compares the references \meta{refname}
% with \meta{LastPage}. Basis of the comparison is the value of
% property |abspage|, because the values are different for different
% pages. This is not ensured by property |page|. Therefore module
% \xmodule{abspage} is loaded by module \xmodule{lastpage}.
% If both values of property |abspage| are present and match,
% then \meta{then} is executed, otherwise code \meta{else} is called.
% If one or both references are undefined or lack the property |abspage|,
% then \meta{else} is executed.
%
% Macro \cs{zref@iflastpage} is expandable, therefore \cs{zref@refused}
% should be called on \meta{refname} and \meta{LastPage}.
%
% \begin{declcs}{ziflastpage} \M{refname} \M{then} \M{else}
% \end{declcs}
% Macro \cs{ziflastpage} has the same function as \cs{zref@iflastpage},
% but adds support for babel shorthands in \meta{refname} and
% calls \cs{zref@refused}. However macro \cs{ziflastpage} is not
% expandable.
%
% \subsubsection{Example}
%
% \begin{macrocode}
%<*example-lastpage>
%<<END_EXAMPLE
\NeedsTeXFormat{LaTeX2e}
\documentclass{report}
\newcounter{foo}
\renewcommand*{\thefoo}{\Alph{foo}}
\usepackage{zref-lastpage,zref-user}[2019/11/29]
\makeatletter
\zref@newprop{thefoo}{\thefoo}
\zref@newprop{valuefoo}{\the\value{foo}}
\zref@newprop{chapter}{\thechapter}
\zref@addprops{LastPage}{thefoo,valuefoo,chapter}
\makeatother
\newcommand*{\foo}{%
\stepcounter{foo}%
[Current foo: \thefoo]%
}
\begin{document}
\chapter{First chapter}
Last page is \zref{LastPage}.\\
Last chapter is \zref[chapter]{LastPage}.\\
Last foo is \zref[thefoo]{LastPage}.\\
Last value of foo is \zref[valuefoo]{LastPage}.\\
\foo
\chapter{Second chapter}
\foo\foo\foo
\chapter{Last chapter}
\foo
\end{document}
%END_EXAMPLE
%</example-lastpage>
% \end{macrocode}
%
% \subsection{Module \xmodule{thepage}}
%
% This module \xmodule{thepage} loads module \xmodule{abspage},
% constructs a reference name using the absolute page number
% and remembers property |page|. Other properties can be added
% by adding them to the property list |thepage|.
%
% \begin{declcs}{zthepage} \M{absolute page number}\\
% \end{declcs}
% Macro \cs{zthepage} is basically a \cs{zpageref}. The reference
% name is yield by the \meta{absolute page number}. If the reference
% is not defined, then the default for property |page| is used.
%
% \begin{declcs}{zref@thepage@name}\markexp \M{absolute page number}
% \end{declcs}
% Macro \cs{zref@thepage@name} returns the internal reference
% name that is constructed using the \meta{absolute page number}.
% The internal reference name should not be used directly, because
% it might change in future versions.
%
% \begin{declcs}{zref@thepage}\markexp \M{absolute page number}\\
% \cs{zref@thepage@refused} \M{absolute page number}
% \end{declcs}
% Macro \cs{zref@thepage} returns the page number (\cs{thepage})
% of \meta{absolute page number}. Because this macro is expandable,
% \cs{zref@thepage@refused} is used outside an expandable context
% to mark the reference as used.
%
%
% \subsection{Module \xmodule{nextpage}}
%
% \begin{declcs}{znextpage}
% \end{declcs}
% Macro \cs{znextpage} prints \cs{thepage} of the following page.