Debian Codegraph @

texmf-dist/tex/plain/zztex/zztag.tex

raw
1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 %
3 % Module: ZzTeX Tag Facilities
4 %
5 % Synopsis: This module contains the definitions necessary to implement
6 % tags and references to them.
7 %
8 % Note: Tag names beginning with `zX:' are reserved for ZzTeX:
9 %
10 % zA: design alternative choices (obsolete)
11 % zB: bibliographic tags
12 % zE: frame page numbers
13 % zF: float page numbers
14 % zH: help text
15 % zM: margin note page numbers
16 % zP: proof note page numbers
17 % zR: margin rule page numbers
18 % zS: snapshot information
19 %
20 % Author: Paul C. Anagnostopoulos
21 % Created: 19 September 1989
22 %
23 % Copyright 1989--2020 by Paul C. Anagnostopoulos
24 % under The MIT License (opensource.org/licenses/MIT)
25 %
26 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27
28 % Tag Definition
29 % --- ----------
30
31
32 \definetoks{\taginfonumber}
33 \taginfonumber = {???}
34 \definetoks{\taginfotitle}
35 \taginfotitle = {???}
36 \definecount{\zmistags}{0}
37
38
39 % The number is fully expanded, while the title is not expanded.
40 % Then we make sure they are never expanded again.
41
42 \def \settaginfo #1#2{% {number}{title}
43 \edef \znext {\taginfonumber = {#1}}%
44 \znext
45 \taginfotitle = {#2}}
46
47 \def \tag #1{% {name}
48 \if \emptytoksp{\taginfonumber}%
49 \warning{notaginfo}{ZzTeX reference: Misplaced tag '#1'}%
50 \global\increment \zmistags
51 \fi
52 \zbeginhidewrite
53 \edef \znext {\noexpand\xref{tag}{\noexpand\folio}%
54 {\the\taginfonumber}%
55 {\the\taginfotitle}
56 {#1}}%
57 \znext
58 \if \PDFhyperlinks \PDFmark{T:#1}\fi
59 \zendhidewrite}
60
61 \def \tagwith #1#2{% {name}{reference-text}
62 \zbeginhidewrite
63 \edef \znext {\noexpand\xref{tag}{\noexpand\folio}%
64 {#2}%
65 {???notitle???}
66 {#1}}%
67 \znext
68 \if \PDFhyperlinks \PDFmark{T:#1}\fi
69 \zendhidewrite}
70
71 % This is a special command when you just want to know the page number.
72
73 \def \tagpageonly #1{% {name}
74 \zbeginhidewrite
75 \edef \znext {\noexpand\xref{tag}{\noexpand\folio}%
76 {???nonumber???}%
77 {???notitle???}
78 {#1}}%
79 \znext
80 \if \PDFhyperlinks \PDFmark{T:#1}\fi
81 \zendhidewrite}
82
83 \def \uniquetag #1#2{% {prefix}{counter}
84 #1:\the\divisionname-#2}
85
86 % Subtag Definition
87 % ------ ----------
88
89
90 \definecount{\subtagnumber}{0}
91
92
93 \def \setsubtagnumber #1{% {integer}
94 \subtagnumber = #1\relax}
95
96 \def \subtag #1#2{% {name}{subnumber}
97 \zparsesubnumber #2???\zmark
98 \tagwith{#1}{\zsubtagtext}}
99
100 \def \zparsesubnumber #1?#2?#3?#4\zmark{%
101 \if \emptyargp{#2}%
102 \edef \zsubtagtext {\the\taginfonumber #1}%
103 \else
104 \increment \subtagnumber
105 \edef \zsubtagtext {\the\taginfonumber #1#2\subtagnumber#3}%
106 \fi}
107
108 % Tag Reference
109 % --- ---------
110
111
112 % This counter keeps track of the number of undefined tag references.
113
114 \definecount{\zuntagrefs}{0}
115
116
117 \def \refnumber #1{% {tag-name}
118 \zbeginrefhilight
119 \if \definedp{\=#1}%
120 \zreftext{#1}{\expandafterthrice\ztagdata \name{\=#1}\zmark1}%
121 \else
122 \zuntag{#1}{???}%
123 \fi
124 \zendrefhilight}
125
126 \let \ref = \refnumber % Because it's so common.
127
128 \def \refpage #1{% {tag-name}
129 \zbeginrefhilight
130 \if \definedp{\=#1}%
131 \zreftext{#1}{\expandafterthrice\ztagdata \name{\=#1}\zmark0}%
132 \else
133 \zuntag{#1}{???}%
134 \fi
135 \zendrefhilight}
136
137 \def \reftitle #1{% {tag-name}
138 \zbeginrefhilight
139 \if \notp{\allowreftitle}%
140 \warning{noreftitle}{Use of \string\reftitle is not allowed}%
141 ???not allowed???%
142 \else \if \definedp{\=#1}%
143 {\zadjtitle = \zadjtitlenone
144 \zreftext{#1}{\expandafterthrice\ztagdata \name{\=#1}\zmark2}}%
145 \else
146 \zuntag{#1}{???title???}%
147 \fi\fi
148 \zendrefhilight}
149
150 \def \zbeginrefhilight {%
151 \if \DVIWindoinuse
152 \colorspecial{ifview color push rgb 1 0 .25}% % Color the reference.
153 \fi}
154
155 \def \zendrefhilight {%
156 \if \DVIWindoinuse
157 \colorspecial{ifview color pop}% % Done with color.
158 \fi}
159
160 \def \zreftext #1#2{% {tag}{text}
161 \if \PDFhyperlinks
162 \tagbutton{#1}{#2}%
163 \else
164 #2%
165 \fi}
166
167 \def \ztagdata #1\zmark#2\zmark#3\zmark#4{%
168 \ifcase #4 #1\or #2\or #3\fi} % Space after #4 is critical!
169
170 \def \zuntag #1#2{% {tag}{what-to-set}
171 \writelog{ZzTeX reference: Undefined tag `#1'.}%
172 \zxwriteinfo{\false}{undef-tag}{#1}{}%
173 \global\increment \zuntagrefs
174 #2}
175
176 % Determining the Page
177 % ----------- --- ----
178
179
180 % This command allows us to use the tag facility to determine which page
181 % a particular element is on, in case the design of the element depends
182 % on whether it is on a recto or verso.
183
184 \def \whichpage #1#2{% {\count-reg}{tag-name}
185 \def \zreg {#1}%
186 \if \definedp{\=#2}%
187 \edef \zpg {\expandafterthrice\ztagdata \name{\=#2}\zmark0}%
188 \expandafter\zwhichpagea \zpg--\zmark
189 \else
190 \zuntag{#2}{\relax}%
191 #1=\pagenumber
192 \fi\relax}
193
194 \def \zwhichpagea #1-#2-#3\zmark{%
195 \if \emptyargp{#2}%
196 \zwhichpageb #1\zmark
197 \else
198 \zwhichpageb #2\zmark
199 \fi}
200
201 \def \zwhichpageb #1\zmark{%
202 \setbox \zboxa=\hbox{\zreg=0#1}%
203 \if \dimzerop{\wd\zboxa}%
204 \zreg=#1%
205 \else
206 \zreg=\pagenumber
207 \fi}
208
209 % Tag Cross-Reference
210 % --- ---------------
211
212
213 % These counters keep track of the number of duplicate tags, and the
214 % number of tags that have changed since the previous run.
215
216 \definecount{\zduptags}{0}
217 \definecount{\zchangedtags}{0}
218
219
220 % Define the macro \=tag to contain the page, number, and title.
221 % However, use of the title is controlled by \allowreftitle.
222
223 \def \xreftag #1#2#3#4{% {page}{number}{title}{tag}
224 \ifnum \xrefmode=\xrefloadtagmode
225 \if \definedp{\=#4}\zduptag{#4}\fi
226 \xreftagdef{#1}{#2}{#3}{\=#4}%
227 \else\ifnum \xrefmode=\xrefcopymode
228 \xreftagchk{#1}{#2}{#3}{\=#4}%
229 \fi\fi}
230
231 \def \xreftagdef #1#2#3#4{% {page}{number}{title}{\name}
232 \if \allowreftitle
233 \withname\gdef{#4}{#1\zmark#2\zmark#3}%
234 \else
235 \withname\gdef{#4}{#1\zmark#2\zmark}%
236 \fi}
237
238 \def \xreftagchk #1#2#3#4{% {page}{number}{title}{\name}
239 \xreftagdef{#1}{#2}{#3}{\zxrefchk}%
240 \expandaftertwice\ifx \name{#4}\zxrefchk
241 \else
242 \global\increment \zchangedtags
243 \fi}
244
245 \def \zduptag #1{% {tag}
246 \writelog{ZzTeX reference: Duplicate tag `#1'.}%
247 \global\increment \zduptags}
248
249 % Tag Cross-Reference Summary
250 % --- --------------- -------
251
252
253 \def \ztagsummary {%
254 \if \posp{\zuntagrefs}%
255 \remark{Number of undefined tags in this run: \number\zuntagrefs.}%
256 \fi
257 \if \posp{\zduptags}%
258 \remark{Number of duplicate tags in this run: \number\zduptags._%
259 \space\space\space\space\space\space\space Eliminate duplicates %
260 and reprocess the book twice.}%
261 \fi
262 \if \posp{\zmistags}%
263 \remark{Number of misplaced tags in this run: \number\zmistags.}%
264 \fi
265 \if \posp{\zchangedtags}%
266 \remark{Number of tags changed since previous run: \number\zchangedtags._%
267 \space\space\space\space\space\space\space Reprocess the book %
268 to obtain correct cross-references.}%
269 \fi}