| 1 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2 |
% |
| 3 |
% Module: ZzTeX Cross-Referencing Facilities |
| 4 |
% |
| 5 |
% Synopsis: |
| 6 |
% |
| 7 |
% Author: Paul C. Anagnostopoulos |
| 8 |
% Created: 19 September 1989 |
| 9 |
% |
| 10 |
% Copyright 1989--2020 by Paul C. Anagnostopoulos |
| 11 |
% under The MIT License (opensource.org/licenses/MIT) |
| 12 |
% |
| 13 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 14 |
|
| 15 |
% Data Structures |
| 16 |
% ---- ---------- |
| 17 |
|
| 18 |
|
| 19 |
\definewrite{\zxrootfile} |
| 20 |
|
| 21 |
\definewrite{\zxdivfile} |
| 22 |
\setflag \zxdivopen = \false |
| 23 |
|
| 24 |
\definewrite{\zxcompfile} |
| 25 |
\setflag \zxcompavail = \false |
| 26 |
|
| 27 |
\chardef \xrefbadmode = 0 % Invalid mode. |
| 28 |
\chardef \xrefrunmode = 1 % Normal running environment. |
| 29 |
\chardef \xrefsnapmode = 2 % Taking a division snapshot. |
| 30 |
\chardef \xrefcopymode = 3 % Copying cross-reference files. |
| 31 |
\chardef \xrefloadmodes = 4 % Beginning of load modes: |
| 32 |
\chardef \xrefloadtagmode = 5 % Load tag definitions. |
| 33 |
\chardef \xrefloadtocmode = 6 % Load table of contents. |
| 34 |
\chardef \xrefloadauxmode = 7 % Create BibTeX auxiliary file. |
| 35 |
\chardef \xrefloadendmode = 8 % Load endnotes. |
| 36 |
\chardef \xrefloadcitemode = 9 % Load citation folios. |
| 37 |
|
| 38 |
\let \xrefmode = \xrefbadmode % Default mode. |
| 39 |
|
| 40 |
% Comment Lines |
| 41 |
% ------- ----- |
| 42 |
|
| 43 |
|
| 44 |
{\catcode`\%=\catother |
| 45 |
\gdef \zcomment {%\space} |
| 46 |
} % \catcode |
| 47 |
|
| 48 |
|
| 49 |
\def \zxwritecomment #1#2#3{% {file}{keyword}{values} |
| 50 |
\immediate\write #1 {\zcomment #2: #3}} |
| 51 |
|
| 52 |
% Initialization |
| 53 |
% -------------- |
| 54 |
|
| 55 |
|
| 56 |
\def \zxrefinit {% |
| 57 |
\zxcompinit |
| 58 |
\zxopenroot |
| 59 |
\let \xrefmode = \xrefrunmode} |
| 60 |
|
| 61 |
\def \zxcompinit {% |
| 62 |
\checkfile{\zxcompavail}{\jobname.zzc}% |
| 63 |
\if \zxcompavail |
| 64 |
\zxloadcomp{\xrefloadtagmode}% |
| 65 |
\else |
| 66 |
\checkfile{\zxcompavail}{\jobname.zzx}% |
| 67 |
\if \zxcompavail |
| 68 |
\zxgencomp |
| 69 |
\zxloadcomp{\xrefloadtagmode}% |
| 70 |
\else |
| 71 |
\remark{There is no cross-reference file available for this run.}% |
| 72 |
\fi |
| 73 |
\fi} |
| 74 |
|
| 75 |
\def \zxopenroot {% |
| 76 |
\immediate\openout \zxrootfile = \jobname.zzx\relax |
| 77 |
\zxwritecomment{\zxrootfile}{root}{\jobname}} |
| 78 |
|
| 79 |
% Division Handling |
| 80 |
% -------- -------- |
| 81 |
|
| 82 |
|
| 83 |
\def \zxdivinit #1#2{% {division-name}{setting-it?} |
| 84 |
\immediate\write \zxrootfile {\noexpand\zinputzzx{#1}}% |
| 85 |
\if #2% |
| 86 |
\immediate\openout \zxdivfile = #1.zzx\relax |
| 87 |
\global\setflag \zxdivopen = \true |
| 88 |
\zxwritecomment{\zxdivfile}{division}{#1}% |
| 89 |
\immediate\write \zxdivfile |
| 90 |
{\noexpand\xref{div}{}{}{}{\the\divisionname}\zcomment}% |
| 91 |
\fi} |
| 92 |
|
| 93 |
% There is nothing to do with each entry in the cross-reference file. |
| 94 |
|
| 95 |
\def \xrefdiv #1#2#3#4{} |
| 96 |
|
| 97 |
|
| 98 |
\def \zxdivfinal #1{% |
| 99 |
\if \zxdivopen |
| 100 |
\ztakesnap |
| 101 |
\zxwritecomment{\zxdivfile}{end}{#1}% |
| 102 |
\immediate\closeout \zxdivfile |
| 103 |
\global\setflag \zxdivopen = \false |
| 104 |
\fi} |
| 105 |
|
| 106 |
% Finalization |
| 107 |
% ------------ |
| 108 |
|
| 109 |
|
| 110 |
\def \zxreffinal {% |
| 111 |
\zxwritecomment{\zxrootfile}{end}{\jobname}% |
| 112 |
\immediate\closeout \zxrootfile |
| 113 |
\zxgencomp} |
| 114 |
|
| 115 |
% Generate Composite File |
| 116 |
% -------- --------- ---- |
| 117 |
|
| 118 |
|
| 119 |
\def \zxgencomp {% |
| 120 |
\remark{Generating composite cross-reference file:}% |
| 121 |
\immediate\openout \zxcompfile = \jobname.zzc\relax |
| 122 |
\zxwriteinfo{\true}{jobname}{\jobname}{}% |
| 123 |
\zxwriteinfo{\true}{time}{\number\year.\number\month.\number\day}{\formattime}% |
| 124 |
\zxwriteinfo{\true}{version}{\ZzTeXversion}{}% |
| 125 |
\zxwriteinfo{\true}{author}{\bookauthor}{}% |
| 126 |
\zxwriteinfo{\true}{title}{\booktitle}{}% |
| 127 |
\zxwriteinfo{\true}{publisher}{\bookpublisher}{}% |
| 128 |
\zxwriteinfo{\true}{ISBN}{\bookISBN}{}% |
| 129 |
\zxwriteinfo{\true}{art-root}{\zartroot}{}% |
| 130 |
\zxwriteinfo{\true}{place-art}{\zplaceart}{}% |
| 131 |
\zxwriteinfo{\true}{PDF-hyperlinks}{\PDFhyperlinks}{}% |
| 132 |
\zxwriteinfo{\true}{proof}{\the\zproofid}{}% |
| 133 |
\zxwriteinfo{\true}{compositor}{\ininame}{\iniorganization}% |
| 134 |
\zxwriteinfo{\true}{trim}{\the\trimwidth}{\the\trimheight}% |
| 135 |
\zxwriteinfo{\true}{head-margin}{\the\headmargin}{}% |
| 136 |
\zxwriteinfo{\true}{inner-margin}{\the\eveninnermargin}{\the\oddinnermargin}% |
| 137 |
\let \zxmodesave = \xrefmode |
| 138 |
\let \xrefmode = \xrefcopymode |
| 139 |
\input \jobname.zzx\relax |
| 140 |
\let \xrefmode = \zxmodesave |
| 141 |
\zxwritecomment{\zxcompfile}{end}{\jobname}% |
| 142 |
\immediate\closeout \zxcompfile} |
| 143 |
|
| 144 |
% This macro writes an information entry in the composite cross-reference |
| 145 |
% file. |
| 146 |
|
| 147 |
\def \zxwriteinfo #1#2#3#4{% {composite?}{key}{value1}{value2} |
| 148 |
\if #1% |
| 149 |
\immediate\write \zxcompfile {\noexpand\xref{info}{}{#2}{#3}{#4}\zcomment}% |
| 150 |
\else |
| 151 |
\zbeginhidewrite |
| 152 |
\edef \znext {\noexpand\xref{info}{\noexpand\folio}% |
| 153 |
{#2}% |
| 154 |
{#3} |
| 155 |
{#4}}% |
| 156 |
\znext |
| 157 |
\zendhidewrite |
| 158 |
\fi} |
| 159 |
|
| 160 |
%%% \immediate\write #1{\noexpand\xref{info}{#2}{#3}{#4}{\noexpand\folio}\zcomment}} |
| 161 |
|
| 162 |
% There is nothing to do when info entries are executed. |
| 163 |
|
| 164 |
\def \xrefinfo #1#2#3#4{} |
| 165 |
|
| 166 |
% This macro is used in the root cross-reference file to suck in the |
| 167 |
% division cross-reference files. |
| 168 |
|
| 169 |
\def \zinputzzx #1{% |
| 170 |
\checkfile{\znext}{#1.zzx}% |
| 171 |
\if \znext \input #1.zzx \fi} |
| 172 |
|
| 173 |
% Load Composite File |
| 174 |
% ---- --------- ---- |
| 175 |
|
| 176 |
|
| 177 |
\def \zxloadcomp #1{% {xref-mode} |
| 178 |
\if \zxcompavail |
| 179 |
\let \zxmodesave = \xrefmode |
| 180 |
\let \xrefmode =#1% |
| 181 |
\input \jobname.zzc\relax |
| 182 |
\let \xrefmode = \zxmodesave |
| 183 |
\fi} |
| 184 |
|
| 185 |
\def \zxloadothercomp #1#2{% {file}{xref-mode} |
| 186 |
\let \zxmodesave = \xrefmode |
| 187 |
\let \xrefmode = #2% |
| 188 |
\input #1\relax |
| 189 |
\let \xrefmode = \zxmodesave} |
| 190 |
|
| 191 |
\def \loadrelatedxref #1{% {file} |
| 192 |
\zxloadothercomp{#1}{\xrefloadtagmode}} |
| 193 |
|
| 194 |
% Cross-Reference Macro |
| 195 |
% --------------- ----- |
| 196 |
|
| 197 |
|
| 198 |
% Here's how the arguments are treated in each of the modes: |
| 199 |
% |
| 200 |
% Mode type page arg3 title arg5 |
| 201 |
% |
| 202 |
% load expanded --- passed to appropriate \xrefxxx macro --- |
| 203 |
% copy expanded expanded expanded unexpanded expanded |
| 204 |
% run expanded unexpanded expanded unexpanded expanded |
| 205 |
% snap expanded expanded expanded expanded expanded |
| 206 |
|
| 207 |
% This macro is written for speed. |
| 208 |
|
| 209 |
\long\def \xref #1#2#3#4#5{% {type}{page-number}{arg3}{title}{arg5} |
| 210 |
\ifnum \xrefmode>\xrefloadmodes |
| 211 |
\name{\xref#1}{#2}{#3}{#4}{#5}% |
| 212 |
\else\ifnum \xrefmode=\xrefcopymode |
| 213 |
{\def \zxtitle {#4}% |
| 214 |
\immediate\write \zxcompfile {\noexpand\xref{#1}{#2}{#3}% |
| 215 |
{\expandafter\zdefof \meaning\zxtitle\zmark}{#5}\zcomment}}% |
| 216 |
\name{\xref#1}{#2}{#3}{#4}{#5}% In case they want to do something. |
| 217 |
\else\ifnum \xrefmode=\xrefrunmode |
| 218 |
{\def \zxtitle {#4}% |
| 219 |
\edef \znext {\noexpand\noexpand\noexpand\xref |
| 220 |
{#1}{\noexpand#2}{#3}% |
| 221 |
{\expandafter\zdefof \meaning\zxtitle\zmark}{#5}}% |
| 222 |
\expandafter\zxwrite\expandafter{\znext\zcomment}}% |
| 223 |
\if \vmodep \repeatpenalty \fi % In case glue follows write. |
| 224 |
\else\ifnum \xrefmode=\xrefsnapmode |
| 225 |
\immediate\zxwrite{\noexpand\xref{#1}{#2}{#3}{#4}{#5}\zcomment}% |
| 226 |
\else |
| 227 |
\zxnomode |
| 228 |
\fi\fi\fi\fi} |
| 229 |
|
| 230 |
\def \zxwrite {% |
| 231 |
\if \zxdivopen \write \zxdivfile \else \write \zxrootfile \fi} |
| 232 |
|
| 233 |
\def \zxnomode {% |
| 234 |
\zzerror{No cross-reference mode is set}} |
| 235 |
|
| 236 |
% Page Hints |
| 237 |
% ---- ----- |
| 238 |
|
| 239 |
|
| 240 |
\def \pagehint #1{% |
| 241 |
\xref{hint}{\noexpand\folio}{}{#1}{}} |
| 242 |
|
| 243 |
% There is nothing to do when hint entries are executed. |
| 244 |
|
| 245 |
\def \xrefhint #1#2#3#4{} |