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
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Module: ZzTeX Tag Facilities
%
% Synopsis: This module contains the definitions necessary to implement
% tags and references to them.
%
% Note: Tag names beginning with `zX:' are reserved for ZzTeX:
%
% zA: design alternative choices (obsolete)
% zB: bibliographic tags
% zE: frame page numbers
% zF: float page numbers
% zH: help text
% zM: margin note page numbers
% zP: proof note page numbers
% zR: margin rule page numbers
% zS: snapshot information
%
% Author: Paul C. Anagnostopoulos
% Created: 19 September 1989
%
% Copyright 1989--2020 by Paul C. Anagnostopoulos
% under The MIT License (opensource.org/licenses/MIT)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Tag Definition
% --- ----------
\definetoks{\taginfonumber}
\taginfonumber = {???}
\definetoks{\taginfotitle}
\taginfotitle = {???}
\definecount{\zmistags}{0}
% The number is fully expanded, while the title is not expanded.
% Then we make sure they are never expanded again.
\def \settaginfo #1#2{% {number}{title}
\edef \znext {\taginfonumber = {#1}}%
\znext
\taginfotitle = {#2}}
\def \tag #1{% {name}
\if \emptytoksp{\taginfonumber}%
\warning{notaginfo}{ZzTeX reference: Misplaced tag '#1'}%
\global\increment \zmistags
\fi
\zbeginhidewrite
\edef \znext {\noexpand\xref{tag}{\noexpand\folio}%
{\the\taginfonumber}%
{\the\taginfotitle}
{#1}}%
\znext
\if \PDFhyperlinks \PDFmark{T:#1}\fi
\zendhidewrite}
\def \tagwith #1#2{% {name}{reference-text}
\zbeginhidewrite
\edef \znext {\noexpand\xref{tag}{\noexpand\folio}%
{#2}%
{???notitle???}
{#1}}%
\znext
\if \PDFhyperlinks \PDFmark{T:#1}\fi
\zendhidewrite}
% This is a special command when you just want to know the page number.
\def \tagpageonly #1{% {name}
\zbeginhidewrite
\edef \znext {\noexpand\xref{tag}{\noexpand\folio}%
{???nonumber???}%
{???notitle???}
{#1}}%
\znext
\if \PDFhyperlinks \PDFmark{T:#1}\fi
\zendhidewrite}
\def \uniquetag #1#2{% {prefix}{counter}
#1:\the\divisionname-#2}
% Subtag Definition
% ------ ----------
\definecount{\subtagnumber}{0}
\def \setsubtagnumber #1{% {integer}
\subtagnumber = #1\relax}
\def \subtag #1#2{% {name}{subnumber}
\zparsesubnumber #2???\zmark
\tagwith{#1}{\zsubtagtext}}
\def \zparsesubnumber #1?#2?#3?#4\zmark{%
\if \emptyargp{#2}%
\edef \zsubtagtext {\the\taginfonumber #1}%
\else
\increment \subtagnumber
\edef \zsubtagtext {\the\taginfonumber #1#2\subtagnumber#3}%
\fi}
% Tag Reference
% --- ---------
% This counter keeps track of the number of undefined tag references.
\definecount{\zuntagrefs}{0}
\def \refnumber #1{% {tag-name}
\zbeginrefhilight
\if \definedp{\=#1}%
\zreftext{#1}{\expandafterthrice\ztagdata \name{\=#1}\zmark1}%
\else
\zuntag{#1}{???}%
\fi
\zendrefhilight}
\let \ref = \refnumber % Because it's so common.
\def \refpage #1{% {tag-name}
\zbeginrefhilight
\if \definedp{\=#1}%
\zreftext{#1}{\expandafterthrice\ztagdata \name{\=#1}\zmark0}%
\else
\zuntag{#1}{???}%
\fi
\zendrefhilight}
\def \reftitle #1{% {tag-name}
\zbeginrefhilight
\if \notp{\allowreftitle}%
\warning{noreftitle}{Use of \string\reftitle is not allowed}%
???not allowed???%
\else \if \definedp{\=#1}%
{\zadjtitle = \zadjtitlenone
\zreftext{#1}{\expandafterthrice\ztagdata \name{\=#1}\zmark2}}%
\else
\zuntag{#1}{???title???}%
\fi\fi
\zendrefhilight}
\def \zbeginrefhilight {%
\if \DVIWindoinuse
\colorspecial{ifview color push rgb 1 0 .25}% % Color the reference.
\fi}
\def \zendrefhilight {%
\if \DVIWindoinuse
\colorspecial{ifview color pop}% % Done with color.
\fi}
\def \zreftext #1#2{% {tag}{text}
\if \PDFhyperlinks
\tagbutton{#1}{#2}%
\else
#2%
\fi}
\def \ztagdata #1\zmark#2\zmark#3\zmark#4{%
\ifcase #4 #1\or #2\or #3\fi} % Space after #4 is critical!
\def \zuntag #1#2{% {tag}{what-to-set}
\writelog{ZzTeX reference: Undefined tag `#1'.}%
\zxwriteinfo{\false}{undef-tag}{#1}{}%
\global\increment \zuntagrefs
#2}
% Determining the Page
% ----------- --- ----
% This command allows us to use the tag facility to determine which page
% a particular element is on, in case the design of the element depends
% on whether it is on a recto or verso.
\def \whichpage #1#2{% {\count-reg}{tag-name}
\def \zreg {#1}%
\if \definedp{\=#2}%
\edef \zpg {\expandafterthrice\ztagdata \name{\=#2}\zmark0}%
\expandafter\zwhichpagea \zpg--\zmark
\else
\zuntag{#2}{\relax}%
#1=\pagenumber
\fi\relax}
\def \zwhichpagea #1-#2-#3\zmark{%
\if \emptyargp{#2}%
\zwhichpageb #1\zmark
\else
\zwhichpageb #2\zmark
\fi}
\def \zwhichpageb #1\zmark{%
\setbox \zboxa=\hbox{\zreg=0#1}%
\if \dimzerop{\wd\zboxa}%
\zreg=#1%
\else
\zreg=\pagenumber
\fi}
% Tag Cross-Reference
% --- ---------------
% These counters keep track of the number of duplicate tags, and the
% number of tags that have changed since the previous run.
\definecount{\zduptags}{0}
\definecount{\zchangedtags}{0}
% Define the macro \=tag to contain the page, number, and title.
% However, use of the title is controlled by \allowreftitle.
\def \xreftag #1#2#3#4{% {page}{number}{title}{tag}
\ifnum \xrefmode=\xrefloadtagmode
\if \definedp{\=#4}\zduptag{#4}\fi
\xreftagdef{#1}{#2}{#3}{\=#4}%
\else\ifnum \xrefmode=\xrefcopymode
\xreftagchk{#1}{#2}{#3}{\=#4}%
\fi\fi}
\def \xreftagdef #1#2#3#4{% {page}{number}{title}{\name}
\if \allowreftitle
\withname\gdef{#4}{#1\zmark#2\zmark#3}%
\else
\withname\gdef{#4}{#1\zmark#2\zmark}%
\fi}
\def \xreftagchk #1#2#3#4{% {page}{number}{title}{\name}
\xreftagdef{#1}{#2}{#3}{\zxrefchk}%
\expandaftertwice\ifx \name{#4}\zxrefchk
\else
\global\increment \zchangedtags
\fi}
\def \zduptag #1{% {tag}
\writelog{ZzTeX reference: Duplicate tag `#1'.}%
\global\increment \zduptags}
% Tag Cross-Reference Summary
% --- --------------- -------
\def \ztagsummary {%
\if \posp{\zuntagrefs}%
\remark{Number of undefined tags in this run: \number\zuntagrefs.}%
\fi
\if \posp{\zduptags}%
\remark{Number of duplicate tags in this run: \number\zduptags._%
\space\space\space\space\space\space\space Eliminate duplicates %
and reprocess the book twice.}%
\fi
\if \posp{\zmistags}%
\remark{Number of misplaced tags in this run: \number\zmistags.}%
\fi
\if \posp{\zchangedtags}%
\remark{Number of tags changed since previous run: \number\zchangedtags._%
\space\space\space\space\space\space\space Reprocess the book %
to obtain correct cross-references.}%
\fi}
|