Debian Codegraph @

texmf-dist/doc/latex/zref/zref-example.tex

raw
1 %%
2 %% This is file `zref-example.tex',
3 %% generated with the docstrip utility.
4 %%
5 %% The original source files were:
6 %%
7 %% zref.dtx (with options: `example')
8 %%
9 %% This is a generated file.
10 %%
11 %% Project: zref
12 %% Version: 2026-03-07 v2.37
13 %%
14 %% Copyright (C)
15 %% 2006-2012 Heiko Oberdiek
16 %% 2016-2026 Oberdiek Package Support Group
17 %%
18 %% This work may be distributed and/or modified under the
19 %% conditions of the LaTeX Project Public License, either
20 %% version 1.3c of this license or (at your option) any later
21 %% version. This version of this license is in
22 %% https://www.latex-project.org/lppl/lppl-1-3c.txt
23 %% and the latest version of this license is in
24 %% https://www.latex-project.org/lppl.txt
25 %% and version 1.3 or later is part of all distributions of
26 %% LaTeX version 2005/12/01 or later.
27 %%
28 %% This work has the LPPL maintenance status "maintained".
29 %%
30 %% The Current Maintainers of this work are
31 %% Heiko Oberdiek and the Oberdiek Package Support Group
32 %% https://github.com/ho-tex/zref/issues
33 %%
34 %% This work consists of the main source file zref.dtx
35 %% and the derived files
36 %% zref.sty, zref.pdf, zref.ins, zref.drv, zref-base.sty,
37 %% zref-abspage.sty, zref-abspos.sty, zref-counter.sty,
38 %% zref-dotfill.sty, zref-env.sty, zref-hyperref.sty,
39 %% zref-lastpage.sty, zref-marks.sty, zref-nextpage.sty,
40 %% zref-pageattr.sty, zref-pagelayout.sty, zref-perpage.sty,
41 %% zref-runs.sty, zref-savepos.sty, zref-thepage.sty,
42 %% zref-titleref.sty, zref-totpages.sty, zref-user.sty,
43 %% zref-xr.sty, zref-example.tex, zref-example-lastpage.tex,
44 %% zref-example-nextpage.tex, zref-test1.tex,
45 %% zref-test-base.tex, zref-test-runs.tex,
46 %% zref-test-titleref-memoir.tex.
47 %%
48 \documentclass{book}
49
50 \usepackage[ngerman]{babel}%
51
52 \usepackage[savepos,totpages,titleref,dotfill,counter,user]{zref}
53
54 \makeatletter
55 \zref@newprop{chaptitle}{}
56 \zref@addprop{main}{chaptitle}
57
58 \newcommand*{\ChapterStart}[2]{%
59 \cleardoublepage
60 \def\current@chapid{#1}%
61 \zref@setcurrent{chaptitle}{#2}%
62 \chapter{#2}%
63 \zlabel{chap:#1}%
64 }
65 \newcommand*{\ChapterStop}{%
66 \cleardoublepage
67 \zref@wrapper@immediate{%
68 \zref@labelbyprops{chapend:\current@chapid}{abspage}%
69 }%
70 }
71 \newcommand*{\ChapterPages}[1]{%
72 \zrefused{chap:#1}%
73 \zrefused{chapend:#1}%
74 \number\numexpr
75 \zref@extract{chapend:#1}{abspage}%
76 -\zref@extract{chap:#1}{abspage}%
77 +1\relax
78 }
79 \makeatother
80 \begin{document}
81 \makeatletter
82
83 \frontmatter
84 \zlabel{documentstart}
85
86 \begin{itemize}
87 \item
88 The frontmatter part has
89 \number\numexpr\zref@extract{chap:first}{abspage}-1\relax
90 ~pages.
91 \item
92 Chapter \zref{chap:first} has \ChapterPages{first} page(s).
93 \item
94 Section \zref{hello} is on the
95 \ifcase\numexpr
96 \zref@extractdefault{hello}{page}{0}%
97 -\zref@extractdefault{chap:first}{page}{0}%
98 +1\relax
99 ??\or first\or second\or third\or forth\fi
100 ~page inside its chapter.
101 \item
102 The document has
103 \zref[abspage]{LastPage} pages.
104 This number is \ifodd\ztotpages odd\else even\fi.
105 \item
106 The last page is labeled with \zpageref{LastPage}.
107 \item
108 The title of chapter \zref{chap:next} %
109 is ``\zref[chaptitle]{chap:next}''.
110 \end{itemize}
111
112 \tableofcontents
113
114 \mainmatter
115 \ChapterStart{first}{First chapter}
116
117 \section{Test}
118 \zlabel{a"o}
119 Section \zref{a"o} on page
120 \zref@wrapper@babel\zref@extract{a"o}{page}.
121
122 Text.
123 \newpage
124
125 \section{Hello World}
126 \zlabel{hello}
127
128 \ChapterStop
129
130 \ChapterStart{next}{Next chapter with \emph{umlauts}: "a"o"u"s}
131
132 The width of the first column is
133 \the\dimexpr \zposx{secondcol}sp - \zposx{firstcol}sp\relax,\\
134 the height difference of the two baselines is
135 \the\dimexpr \zposy{firstcol}sp - \zposy{secondline}sp\relax:\\
136 \begin{tabular}{ll}
137 \zsavepos{firstcol}Hello&\zsavepos{secondcol}World\\
138 \zsavepos{secondline}Second line&foobar\\
139 \end{tabular}
140
141 \zrefused{firstcol}
142 \zrefused{secondcol}
143 \zrefused{secondline}
144
145 \ChapterStop
146 \ChapterStart{dotfill}{Test for dotfill feature}
147 \newcommand*{\dftest}[1]{%
148 #1&
149 [\makebox[{#1}]{\dotfill}]&
150 [\makebox[{#1}]{\zdotfill}]\\
151 }
152 \begin{tabular}{rll}
153 & [\verb|\dotfill|] & [\verb|\zdotfill|]\\
154 \dftest{0.43em}
155 \dftest{0.44em}
156 \dftest{0.45em}
157 \dftest{0.87em}
158 \dftest{0.88em}
159 \dftest{0.89em}
160 \dftest{1.31em}
161 \dftest{1.32em}
162 \dftest{1.33em}
163 \end{tabular}
164 \ChapterStop
165 \end{document}
166 \endinput
167 %%
168 %% End of file `zref-example.tex'.