| 1 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2 |
% |
| 3 |
% Module: ZzTeX Interface to BibTeX |
| 4 |
% |
| 5 |
% Synopsis: This module provides the definitions necessary for ZzTeX to |
| 6 |
% interface to BibTeX. |
| 7 |
% |
| 8 |
% Author: Paul C. Anagnostopoulos |
| 9 |
% Created: 21 July 1992 |
| 10 |
% |
| 11 |
% Copyright 1989--2020 by Paul C. Anagnostopoulos |
| 12 |
% under The MIT License (opensource.org/licenses/MIT) |
| 13 |
% |
| 14 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 15 |
|
| 16 |
% Bibliography Preparation |
| 17 |
% ------------ ----------- |
| 18 |
|
| 19 |
|
| 20 |
\def \zbiblioinit {} |
| 21 |
|
| 22 |
\ignore |
| 23 |
\setflag \zbiblioing = \false |
| 24 |
|
| 25 |
\def \preparebiblio {% |
| 26 |
\setflag \zbiblioing = \true} |
| 27 |
|
| 28 |
\def \zbibfinal {% |
| 29 |
\if \zbiblioing |
| 30 |
\remark{[Generating auxiliary file for BibTeX.}% |
| 31 |
{\immediate\openout \zwritea = \jobname.aux\relax |
| 32 |
\immediate\write \zwritea |
| 33 |
{\zcomment BibTeX auxiliary file for book `\jobname'.}% |
| 34 |
\processdesign{\biblio}{}% |
| 35 |
\immediate\write \zwritea {\string\bibstyle{\the\bibliostyle}}% |
| 36 |
\immediate\write \zwritea {\string\bibdata{\the\bibliofiles}}% |
| 37 |
\let \zxmodesave = \xrefmode |
| 38 |
\let \xrefmode = \xrefloadauxmode |
| 39 |
\input \jobname.zzc\relax |
| 40 |
\let \xrefmode = \zxmodesave |
| 41 |
\immediate\write \zwritea {\zcomment [end]}% |
| 42 |
\immediate\closeout \zwritea} |
| 43 |
\remark{Auxiliary file complete.]}% |
| 44 |
\fi} |
| 45 |
|
| 46 |
\endignore |
| 47 |
|
| 48 |
% Citations |
| 49 |
% --------- |
| 50 |
|
| 51 |
|
| 52 |
%~ This citation command produces the key associated with |
| 53 |
%~ the specified tag. The key is usually the bibliography |
| 54 |
%~ entry number or the author/year combination.&/ |
| 55 |
%~ *Note:* Some books do not allow this command to be used. |
| 56 |
|
| 57 |
\def \cite #1{% {tag} %^citation |
| 58 |
\ensurepar |
| 59 |
\if \definedp{\=zB:#1}% |
| 60 |
\zcitetext{#1}{\expandafterthrice\zbibdata \name{\=zB:#1}0}% |
| 61 |
\else |
| 62 |
\zuncite{#1}% |
| 63 |
\fi |
| 64 |
\zxrefcite{\true}{#1}} |
| 65 |
|
| 66 |
%~ This citation command produces the author associated with |
| 67 |
%~ the specified tag. |
| 68 |
|
| 69 |
\def \citeauthor #1{% {tag} %^citation |
| 70 |
\ensurepar |
| 71 |
\if \definedp{\=zB:#1}% |
| 72 |
\zcitetext{#1}{\expandafterthrice\zbibdata \name{\=zB:#1}1}% |
| 73 |
\else |
| 74 |
\zuncite{#1}% |
| 75 |
\fi |
| 76 |
\zxrefcite{\true}{#1}} |
| 77 |
|
| 78 |
%~ This citation command produces the year associated with |
| 79 |
%~ the specified tag. |
| 80 |
|
| 81 |
\def \citeyear #1{% {tag} %^citation |
| 82 |
\ensurepar |
| 83 |
\if \definedp{\=zB:#1}% |
| 84 |
\zcitetext{#1}{\expandafterthrice\zbibdata \name{\=zB:#1}2}% |
| 85 |
\else |
| 86 |
\zuncite{#1}% |
| 87 |
\fi |
| 88 |
\zxrefcite{\true}{#1}} |
| 89 |
|
| 90 |
\def \nocite #1{% {tag} |
| 91 |
\zxrefcite{\false}{#1}} |
| 92 |
|
| 93 |
\def \zcitetext #1#2{% {tag}{text} |
| 94 |
\if \PDFhyperlinks |
| 95 |
\tagbutton{#1}{#2}% |
| 96 |
\else |
| 97 |
#2% |
| 98 |
\fi} |
| 99 |
|
| 100 |
\def \zxrefcite #1#2{% |
| 101 |
\ifcase \xrefcites |
| 102 |
\relax |
| 103 |
\or |
| 104 |
\xref{cite}{\folio}{}{}{#2}% |
| 105 |
\else |
| 106 |
\customcitexref{#1}{#2}% {boolean}{tag} |
| 107 |
\fi} |
| 108 |
|
| 109 |
\def \zbibdata #1\zmark#2\zmark#3#4#5#6{% folio\zmark xxx\zmark |
| 110 |
% {label}{author}{year}n |
| 111 |
\if \DVIWindoinuse \colorspecial{ifview color push rgb .75 .35 0}\fi |
| 112 |
\ifcase #6 #3\or #4\or #5\fi |
| 113 |
\if \DVIWindoinuse \colorspecial{ifview color pop}\fi |
| 114 |
\if \indexcites \xcite1{#4}\fi} |
| 115 |
|
| 116 |
\def \zuncite #1{% |
| 117 |
\writelog{ZzTeX citation: undefined tag `#1'.}% |
| 118 |
\zxwriteinfo{\false}{undef-tag}{#1}{}% |
| 119 |
\global\increment \zuntagrefs |
| 120 |
\zbibdata -\zmark-\zmark{???}--0} |
| 121 |
|
| 122 |
% Bibliography Cross-Reference |
| 123 |
% ------------ --------------- |
| 124 |
|
| 125 |
|
| 126 |
% When tags are loaded, define the name \=zB:tag to contain the |
| 127 |
% bibliographic info. |
| 128 |
|
| 129 |
\def \xrefbib #1#2#3#4{% {page}{???}{{label}{author}{year}}{tag} |
| 130 |
\ifnum \xrefmode=\xrefloadtagmode |
| 131 |
\if \definedp{\=zB:#4}\zduptag{#4}\fi |
| 132 |
\withname\gdef{\=zB:#4}{#1\zmark#2\zmark#3}% |
| 133 |
\fi} |
| 134 |
|
| 135 |
% This macro loads the cite cross-reference entries and invokes the |
| 136 |
% specified macro for each one. |
| 137 |
|
| 138 |
\def \mapxrefcites #1{% {\macro} |
| 139 |
{\let \zmapcitemacro = #1\relax |
| 140 |
\zxloadcomp{\xrefloadcitemode}}} |
| 141 |
|
| 142 |
\def \xrefcite #1#2#3#4{% {page}{}{}{tag} |
| 143 |
\ifnum \xrefmode=\xrefloadcitemode |
| 144 |
\zmapcitemacro{#1}{#4}% |
| 145 |
\fi} |
| 146 |
|
| 147 |
% Biblio Block |
| 148 |
% ------ ----- |
| 149 |
|
| 150 |
|
| 151 |
\defineblock{\biblio}{\endbiblio}{\false}{} |
| 152 |
|
| 153 |
%~block biblio |
| 154 |
% \bibliofiles = {file,...} % List of biblio database files. |
| 155 |
% \bibliostyle = {name} % Name of biblio style. |
| 156 |
% \setflag \citeself = boolean % If true, \bibitem cites itself. |
| 157 |
%~end |
| 158 |
|
| 159 |
\definetoks{\bibliofiles} |
| 160 |
\definetoks{\bibliostyle} |
| 161 |
|
| 162 |
\definecount{\zbiblionum}{0} |
| 163 |
|
| 164 |
|
| 165 |
\def \biblio {% |
| 166 |
\blockcantbein{\biblio}{\biblio}% |
| 167 |
\blockmustbein{\biblio}{\list}% |
| 168 |
\beginblockscope{biblio}% |
| 169 |
\global\increment \bibliodepth |
| 170 |
\setflag \citeself = \false %~default soft |
| 171 |
\processdesign{\biblio}{}% |
| 172 |
\global\increment \biblionumber |
| 173 |
\def \begin ##1##2{}% |
| 174 |
\def \end ##1{}% |
| 175 |
\let \bibitem = \zbibitem |
| 176 |
\let \newblock = \relax |
| 177 |
\let \em = \it |
| 178 |
\zbiblionum = 0\relax} |
| 179 |
|
| 180 |
\def \endbiblio {% |
| 181 |
\endgraf |
| 182 |
\fakepar % In case biblio is empty. |
| 183 |
\global\decrement \bibliodepth |
| 184 |
\endblockscope{biblio}} |
| 185 |
|
| 186 |
% Bibliography Item |
| 187 |
% ------------ ---- |
| 188 |
|
| 189 |
|
| 190 |
\definetoks{\zbibtoksa} |
| 191 |
\definetoks{\zbibtoksb} |
| 192 |
\definetoks{\zbibtoksc} |
| 193 |
\definetoks{\bibitemtag} % Tag of current \bibitem. |
| 194 |
|
| 195 |
|
| 196 |
% This supports items of the form `\bibitem[label][author][year]{tag}'. |
| 197 |
|
| 198 |
\def \zbibitem {% |
| 199 |
\futurelet\znext \zbibitema} |
| 200 |
|
| 201 |
\def \zbibitema {% |
| 202 |
\ifx \znext[% |
| 203 |
\let \znext = \zbibitemb |
| 204 |
\else |
| 205 |
\increment \zbiblionum |
| 206 |
% Expand \number\zbiblionum by hand. |
| 207 |
\edef \znext {\noexpand\zbibitemb[\number\zbiblionum]}% |
| 208 |
\fi |
| 209 |
\znext} |
| 210 |
|
| 211 |
\def \zbibitemb[#1]{% [label] |
| 212 |
\zbibtoksa = {#1}% |
| 213 |
\futurelet\znext \zbibitemc} |
| 214 |
|
| 215 |
\def \zbibitemc {% |
| 216 |
\if \tokeqlp{\znext}{[}% |
| 217 |
\let \znext = \zbibitemd |
| 218 |
\else |
| 219 |
\def \znext {\zbibitemd[???]}% |
| 220 |
\fi |
| 221 |
\znext} |
| 222 |
|
| 223 |
\def \zbibitemd[#1]{% [author] |
| 224 |
\zbibtoksb = {#1}% |
| 225 |
\futurelet\znext \zbibiteme} |
| 226 |
|
| 227 |
\def \zbibiteme {% |
| 228 |
\if \tokeqlp{\znext}{[}% |
| 229 |
\let \znext = \zbibitemf |
| 230 |
\else |
| 231 |
\def \znext {\zbibitemf[???]}% |
| 232 |
\fi |
| 233 |
\znext} |
| 234 |
|
| 235 |
\def \zbibitemf[#1]#2{% [year]{tag} |
| 236 |
\zbibtoksc = {#1}% |
| 237 |
\bibitemtag = {#2}% |
| 238 |
\item{\the\zbibtoksa}% |
| 239 |
\if \PDFhyperlinks \PDFmark{T:#2}\fi |
| 240 |
\if \notp{\emptyargp{#2}}% |
| 241 |
\edef \znext{\noexpand\xref{bib}{\noexpand\folio} |
| 242 |
{???} |
| 243 |
{{\the\zbibtoksa}{\the\zbibtoksb}{\the\zbibtoksc}} |
| 244 |
{#2}}% |
| 245 |
\znext |
| 246 |
\if \citeself \nocite{#2}\fi |
| 247 |
\fi |
| 248 |
\if \indexcites |
| 249 |
\edef \znext {\noexpand\xbiblio1{\the\zbibtoksb}}% |
| 250 |
\znext |
| 251 |
\fi |
| 252 |
\ignorespaces} |
| 253 |
|
| 254 |
% Bibliography Citation Page List |
| 255 |
% ------------ -------- ---- ---- |
| 256 |
|
| 257 |
|
| 258 |
\setflag \zcitexrefsloaded = \false |
| 259 |
|
| 260 |
|
| 261 |
% If this macro is specified as the \endpartext of a bibliography |
| 262 |
% list, it will append a list of the citation pages to each entry. |
| 263 |
|
| 264 |
\def \citepagelist #1{% {button?} |
| 265 |
\if \notp{\zcitexrefsloaded}% |
| 266 |
\mapxrefcites{\zbibcitelist}% |
| 267 |
\global\setflag \zcitexrefsloaded = \true |
| 268 |
\fi |
| 269 |
\setflag \zbibfirstpage = \true |
| 270 |
\def \zbibprevpage {}% |
| 271 |
\withname\maplistlf {\=citetag:\the\bibitemtag} |
| 272 |
{\zbibcitepage{##1}{#1}}} |
| 273 |
|
| 274 |
\def \zbibcitelist #1#2{% {page}{tag} |
| 275 |
\if \withname\undefinedp {\=citetag:#2}% |
| 276 |
\withname\setlist {\=citetag:#2}={}% |
| 277 |
\fi |
| 278 |
\withname\appendlf {\=citetag:#2}{#1}} |
| 279 |
|
| 280 |
\def \zbibcitepage #1#2{% {page}{button?} |
| 281 |
\stringeql{\zsamepage}{#1}{\zbibprevpage}% |
| 282 |
\if \notp{\zsamepage}% |
| 283 |
\if \notp{\emptydefp{\zbibprevpage}},\space \fi |
| 284 |
\if #2% |
| 285 |
\pagebutton{#1}{#1}% |
| 286 |
\else |
| 287 |
#1% |
| 288 |
\fi |
| 289 |
\def \zbibprevpage {#1}% |
| 290 |
\fi} |