| 1 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2 |
% |
| 3 |
% Module: ZzTeX Bibliography Facility |
| 4 |
% |
| 5 |
% Synopsis: This module provides a new bibliography facility to replace |
| 6 |
% zzbibtex. It is more flexible so that it can handle numeric, |
| 7 |
% key, and author/year citations. |
| 8 |
% |
| 9 |
% Author: Paul C. Anagnostopoulos |
| 10 |
% Created: 1 December 2016 |
| 11 |
% |
| 12 |
% Copyright 1989--2020 by Paul C. Anagnostopoulos |
| 13 |
% under The MIT License (opensource.org/licenses/MIT) |
| 14 |
% |
| 15 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 16 |
|
| 17 |
% Initialization |
| 18 |
% -------------- |
| 19 |
|
| 20 |
|
| 21 |
\def \zbiblioinit {% |
| 22 |
\if \definedp{\bibliodesign}% |
| 23 |
\begingroup |
| 24 |
\bibliodesign |
| 25 |
\globaldefs = 1 |
| 26 |
\citestyle = \citestyle |
| 27 |
\endgroup |
| 28 |
\fi} |
| 29 |
|
| 30 |
% Bibliography Cross-Reference |
| 31 |
% ------------ --------------- |
| 32 |
|
| 33 |
|
| 34 |
% When tags are loaded, define the name \=zB:tag to contain the |
| 35 |
% bibliographic info in this format: |
| 36 |
% folio\zmark key\zmark {author}{year}{full-author} |
| 37 |
|
| 38 |
\def \xrefbib #1#2#3#4{% {folio}{key}{{author}{year}{full-author}}{tag} |
| 39 |
\ifnum \xrefmode=\xrefloadtagmode |
| 40 |
\if \definedp{\=zB:#4}\zduptag{#4}\fi |
| 41 |
\withname\gdef{\=zB:#4}{#1\zmark#2\zmark#3}% |
| 42 |
\fi} |
| 43 |
|
| 44 |
% This macro loads the cite cross-reference entries and invokes the |
| 45 |
% specified macro for each one. |
| 46 |
|
| 47 |
\def \mapxrefcites #1{% {\macro} |
| 48 |
{\let \zmapcitemacro = #1\relax |
| 49 |
\zxloadcomp{\xrefloadcitemode}}} |
| 50 |
|
| 51 |
\def \xrefcite #1#2#3#4{% {page}{}{}{tag} |
| 52 |
\ifnum \xrefmode=\xrefloadcitemode |
| 53 |
\zmapcitemacro{#1}{#4}% |
| 54 |
\fi} |
| 55 |
|
| 56 |
% Biblio Block |
| 57 |
% ------ ----- |
| 58 |
|
| 59 |
|
| 60 |
\defineblock{\biblio}{\endbiblio}{\false}{} |
| 61 |
|
| 62 |
%~block biblio |
| 63 |
% \citestyle = integer % Citation style. |
| 64 |
% \setflag \indexcites = boolean % If true, index each cite (not implemented). |
| 65 |
% \setflag \citeself = boolean % If true, \bibitem cites itself (not implemented). |
| 66 |
%~end |
| 67 |
|
| 68 |
\definecount{\citestyle}{-1} |
| 69 |
|
| 70 |
\chardef \citebynumber = 0 |
| 71 |
\chardef \citebykey = 1 |
| 72 |
\chardef \citebyauthoryear = 2 |
| 73 |
|
| 74 |
|
| 75 |
\def \biblio {% |
| 76 |
\blockcantbein{\biblio}{\biblio}% |
| 77 |
\blockmustbein{\biblio}{\list}% |
| 78 |
\beginblockscope{biblio}% |
| 79 |
\global\increment \bibliodepth |
| 80 |
\setflag \citeself = \false %~default soft |
| 81 |
\processdesign{\biblio}{}% |
| 82 |
\global\increment \biblionumber} |
| 83 |
|
| 84 |
\def \endbiblio {% |
| 85 |
\endgraf |
| 86 |
\fakepar % In case biblio is empty. |
| 87 |
\global\decrement \bibliodepth |
| 88 |
\endblockscope{biblio}} |
| 89 |
|
| 90 |
% Bibliography Items |
| 91 |
% ------------ ----- |
| 92 |
|
| 93 |
|
| 94 |
\definecount{\zbibitemnumber}{0} |
| 95 |
\definetoks{\zbibauthor} |
| 96 |
\definetoks{\zbibyear} |
| 97 |
\definetoks{\zbibfullauthor} |
| 98 |
\definetoks{\bibitemtag} % Tag of current \bibitem. |
| 99 |
|
| 100 |
|
| 101 |
%~ The |\bibitem| command is used in a |\biblio| block to start |
| 102 |
%~ each entry in the bibliography. It takes two arguments; the |
| 103 |
%~ format of the first argument depends on the citation style. |
| 104 |
%~ * Cited by number: |\bibitem{}{*tag*}| |
| 105 |
%~ * Cited by key: |\bibitem{*key*}{*tag*}| |
| 106 |
%~ * Cited by author/year: |\bibitem{*author*;*year*;*full-author*}{*tag*}| |
| 107 |
%~ *. |
| 108 |
%~ In the author/year format, the second semicolon and *full-author* are |
| 109 |
%~ optional. |
| 110 |
|
| 111 |
\def \bibitem #1#2{% {[info]}{tag} |
| 112 |
\blockmustbein{\bibitem}{\biblio}% |
| 113 |
\zbibitemnumber = \itemnumber |
| 114 |
\increment \zbibitemnumber |
| 115 |
\ifcase \citestyle |
| 116 |
\edef \zbibkey {\the\zbibitemnumber}% |
| 117 |
\zbibauthor = {}% |
| 118 |
\zbibyear = {}% |
| 119 |
\zbibfullauthor = {}% |
| 120 |
\or |
| 121 |
\def \zbibkey {#1}% |
| 122 |
\zbibauthor = {}% |
| 123 |
\zbibyear = {}% |
| 124 |
\zbibfullauthor = {}% |
| 125 |
\or |
| 126 |
\def \zbibkey {}% |
| 127 |
\zparseauthoryear #1;;;\zmark |
| 128 |
\else |
| 129 |
\error{invalidcitestyle}{The \string\citestyle parameter is invalid: \the\citestyle}% |
| 130 |
\fi |
| 131 |
\bibitemtag = {#2}% |
| 132 |
\item{\zbibkey}% |
| 133 |
\if \PDFhyperlinks \PDFmark{T:#2}\fi |
| 134 |
\if \notp{\emptyargp{#2}}% |
| 135 |
\edef \znext {% |
| 136 |
\noexpand\xref{bib}{\noexpand\folio} |
| 137 |
{\zbibkey} |
| 138 |
{{\the\zbibauthor}{\the\zbibyear}{\the\zbibfullauthor}} |
| 139 |
{#2}}% |
| 140 |
\znext |
| 141 |
\fi |
| 142 |
%%% \if \indexcites |
| 143 |
%%% \edef \znext {\noexpand\xbiblio1{\the\zbibauthor}}% |
| 144 |
%%% \znext |
| 145 |
%%% \fi |
| 146 |
\ignorespaces} |
| 147 |
|
| 148 |
\def \zparseauthoryear #1;#2;#3;#4\zmark{% |
| 149 |
\if \orp{\emptyargp{#1}}{\emptyargp{#2}}% |
| 150 |
\error{nocitetags}{The author and/or year are missing}% |
| 151 |
\fi |
| 152 |
\zbibauthor = {#1}% |
| 153 |
\zbibyear = {#2}% |
| 154 |
\zbibfullauthor = {#3}} |
| 155 |
|
| 156 |
% Bibliography Citation Page List |
| 157 |
% ------------ -------- ---- ---- |
| 158 |
|
| 159 |
|
| 160 |
\setflag \zcitexrefsloaded = \false |
| 161 |
|
| 162 |
|
| 163 |
%~ If this macro is specified as the |\endpartext| of a bibliography |
| 164 |
%~ |\list|, then each entry in the bibliography will include a list |
| 165 |
%~ of the pages citing that entry. The argument determines whether |
| 166 |
%~ each page is made into a hyperlinked PDF button. |
| 167 |
%~ |
| 168 |
%~ In order for the citation information to be available, the |
| 169 |
%~ |\xrefcites| document parameter must be set to 1. |
| 170 |
|
| 171 |
\def \citepagelist #1{% {button?} |
| 172 |
\if \notp{\zcitexrefsloaded}% |
| 173 |
\mapxrefcites{\zbibcitelist}% |
| 174 |
\global\setflag \zcitexrefsloaded = \true |
| 175 |
\fi |
| 176 |
\setflag \zbibfirstpage = \true |
| 177 |
\def \zbibprevpage {}% |
| 178 |
\withname\maplistlf {\=citetag:\the\bibitemtag} |
| 179 |
{\zbibcitepage{##1}{#1}}} |
| 180 |
|
| 181 |
\def \zbibcitelist #1#2{% {page}{tag} |
| 182 |
\if \withname\undefinedp {\=citetag:#2}% |
| 183 |
\withname\setlist {\=citetag:#2}={}% |
| 184 |
\fi |
| 185 |
\withname\appendlf {\=citetag:#2}{#1}} |
| 186 |
|
| 187 |
\def \zbibcitepage #1#2{% {page}{button?} |
| 188 |
\stringeql{\zsamepage}{#1}{\zbibprevpage}% |
| 189 |
\if \notp{\zsamepage}% |
| 190 |
\if \notp{\emptydefp{\zbibprevpage}},\space \fi |
| 191 |
\if #2% |
| 192 |
\pagebutton{#1}{#1}% |
| 193 |
\else |
| 194 |
#1% |
| 195 |
\fi |
| 196 |
\def \zbibprevpage {#1}% |
| 197 |
\fi} |
| 198 |
|
| 199 |
% Low-Level Citation Commands |
| 200 |
% --------- -------- -------- |
| 201 |
|
| 202 |
|
| 203 |
%~ This command produces the key of the bibliography entry specified |
| 204 |
%~ by the *tag*. The command makes sense only for the numbered or |
| 205 |
%~ keyed citation styles. |
| 206 |
|
| 207 |
\def \citekey #1{% {tag} %^citation |
| 208 |
\if \eqlp{\citestyle}{\citebyauthoryear}% |
| 209 |
\warning{badcitekey}{The \noexpand\citekey command doesn't make sense |
| 210 |
when citing by author/year}% |
| 211 |
\fi |
| 212 |
\zcitetaginfo{#1}% |
| 213 |
\zcitetext{#1}{\zcitekey}% |
| 214 |
\zxrefcite{\true}{#1}} |
| 215 |
%%% \if \indexcites \zciteindex{\zcitekey}\fi} |
| 216 |
|
| 217 |
%~ This command produces the author of the bibliography entry specified |
| 218 |
%~ by the *tag*. The command makes sense only for the author/year |
| 219 |
%~ citation style. |
| 220 |
|
| 221 |
\def \citeauthor #1{% {tag} %^citation |
| 222 |
\if \neqlp{\citestyle}{\citebyauthoryear}% |
| 223 |
\warning{badciteauthor}{The \noexpand\citeauthor command only makes sense |
| 224 |
when citing by author/year}% |
| 225 |
\fi |
| 226 |
\zcitetaginfo{#1}% |
| 227 |
\zcitetext{#1}{\zciteauthor}% |
| 228 |
\zxrefcite{\true}{#1}} |
| 229 |
|
| 230 |
%~ This command produces the year of the bibliography entry specified |
| 231 |
%~ by the *tag*. The command makes sense only for the author/year |
| 232 |
%~ citation style. |
| 233 |
|
| 234 |
\def \citeyear #1{% {tag} %^citation |
| 235 |
\if \neqlp{\citestyle}{\citebyauthoryear}% |
| 236 |
\warning{badciteyear}{The \noexpand\citeyear command only makes sense |
| 237 |
when citing by author/year}% |
| 238 |
\fi |
| 239 |
\zcitetaginfo{#1}% |
| 240 |
\zcitetext{#1}{\zciteyear}% |
| 241 |
\zxrefcite{\true}{#1}} |
| 242 |
|
| 243 |
%~ This command produces the full author of the bibliography entry specified |
| 244 |
%~ by the *tag*. The command makes sense only for the author/year |
| 245 |
%~ citation style. |
| 246 |
|
| 247 |
\def \citefullauthor #1{% {tag} %^citation |
| 248 |
\if \neqlp{\citestyle}{\citebyauthoryear}% |
| 249 |
\warning{badcitefullauthor}{The \noexpand\citefullauthor command only makes sense |
| 250 |
when citing by author/year}% |
| 251 |
\fi |
| 252 |
\zcitetaginfo{#1}% |
| 253 |
\zcitetext{#1}{\zcitefullauthor}% |
| 254 |
\zxrefcite{\true}{#1}} |
| 255 |
|
| 256 |
\def \zcitetaginfo #1{% {tag} |
| 257 |
\zcitenoinfo |
| 258 |
\if \definedp{\=zB:#1}% |
| 259 |
\expandafterthrice\zcitetaginfoa \name{\=zB:#1}% |
| 260 |
\else |
| 261 |
\writelog{ZzTeX citation: undefined tag `#1'.}% |
| 262 |
\zxwriteinfo{\false}{undef-tag}{#1}{}% |
| 263 |
\global\increment \zuntagrefs |
| 264 |
\fi} |
| 265 |
|
| 266 |
\def \zcitetaginfoa #1\zmark#2\zmark#3#4#5{% folio\zmark key\zmark |
| 267 |
% {author}{year}{full-author} |
| 268 |
\if \eqlp{\citestyle}{\citebyauthoryear}% |
| 269 |
\def \zciteauthor {#3}% |
| 270 |
\def \zciteyear {#4}% |
| 271 |
\def \zcitefullauthor {#5}% |
| 272 |
\else |
| 273 |
\def \zcitekey {#2}% |
| 274 |
\fi} |
| 275 |
|
| 276 |
\def \zcitenoinfo {% |
| 277 |
\def \zcitekey {???}% |
| 278 |
\def \zciteauthor {???author???}% |
| 279 |
\def \zciteyear {???}% |
| 280 |
\def \zcitefullauthor {???full-author???}} |
| 281 |
|
| 282 |
\def \zcitetext #1#2{% {tag}{text} |
| 283 |
\if \DVIWindoinuse \colorspecial{ifview color push rgb .5 .22 .24}\fi |
| 284 |
\if \PDFhyperlinks |
| 285 |
\tagbutton{#1}{#2}% |
| 286 |
\else |
| 287 |
#2% |
| 288 |
\fi |
| 289 |
\if \DVIWindoinuse \colorspecial{ifview color pop}\fi} |
| 290 |
|
| 291 |
\def \zxrefcite #1#2{% {defined?}{tag} |
| 292 |
\ifcase \xrefcites |
| 293 |
\relax |
| 294 |
\or |
| 295 |
\xref{cite}{\folio}{}{}{#2}% |
| 296 |
\else |
| 297 |
\customcitexref{#1}{#2}% {boolean}{tag} |
| 298 |
\fi} |
| 299 |
|
| 300 |
%%%\def \zciteindex #1{% {\zcitemacro} |
| 301 |
%%% \expandafter\xcite\expandafter1\expandafter{#1}} |
| 302 |
|
| 303 |
% High-Level Citation Commands |
| 304 |
% ---------- -------- -------- |
| 305 |
|
| 306 |
|
| 307 |
%~ This high-level citation command produces the key or author/year |
| 308 |
%~ of the bibliography entry specified by the *tag*. The text |
| 309 |
%~ is formatted in the style appropriate for a noun in a sentence. |
| 310 |
%~ There are two formats for the command: |
| 311 |
%~ * |\citenoun{*tag*}| accepts a tag and produces the key or author/year. |
| 312 |
%~ * |\citenoun{*tag*;*info*}| accepts a tag and additional |
| 313 |
%~ information such as a page number or section reference. |
| 314 |
%~ *. |
| 315 |
%~ The format of the text produced is controlled by the |\citenounformat|, |
| 316 |
%~ |\citenouninfoformat|, and |\citepunct| macros in the design file. |
| 317 |
|
| 318 |
\def \citenoun #1{% {tag[;info]} %^citation |
| 319 |
\expandafter\zsetcitepunc \citepunct |
| 320 |
\zcitetagsinfo #1;;\zmark |
| 321 |
\def \zcitenounsep {}% |
| 322 |
\expandafter\zcitenoun \zcitetags,\zmark} |
| 323 |
|
| 324 |
\def \zcitenoun #1,#2\zmark {% tag,other-tags\zmark |
| 325 |
\zcitenounsep |
| 326 |
\edef \zcitenounsep {\zcitesep}% |
| 327 |
\if \eqlp{\citestyle}{\citebyauthoryear}% |
| 328 |
\if \emptydefp{\zciteinfo}% |
| 329 |
\zciteonetag{\citenounformat}#1!!\zmark |
| 330 |
\else |
| 331 |
\citenouninfoformat{\citeauthor{#1}}{\citeyear{#1}}{\zciteinfo}% |
| 332 |
\fi |
| 333 |
\else |
| 334 |
\if \emptydefp{\zciteinfo}% |
| 335 |
\citenounformat{\citekey{#1}}% |
| 336 |
\else |
| 337 |
\citenouninfoformat{\citekey{#1}}{\zciteinfo}% |
| 338 |
\fi |
| 339 |
\fi |
| 340 |
\if \notp{\emptyargp{#2}}\zcitenoun #2\zmark \fi} |
| 341 |
|
| 342 |
%~ This high-level citation command produces the key or author/year |
| 343 |
%~ of the bibliography entry specified by the *tag*. The text |
| 344 |
%~ is formatted in the style appropriate for a parenthetical |
| 345 |
%~ citation list. There are two formats for the command: |
| 346 |
%~ * |\citeparen{*tag-list*}| accepts one or more tags separated |
| 347 |
%~ by commas and produces a parenthetical list of keys or author/years. |
| 348 |
%~ * |\citeparen{*tag*;*info*}| accepts a tag and additional |
| 349 |
%~ information such as a page number or section reference. |
| 350 |
%~ *. |
| 351 |
%~ The format of the text produced is controlled by the |\citeparenformat|, |
| 352 |
%~ |\citepareninfoformat|, and |\citepunct| macros in the design file. |
| 353 |
|
| 354 |
\def \citeparen #1{% {tags[;info]} %^citation |
| 355 |
\expandafter\zsetcitepunc \citepunct |
| 356 |
\zcitetagsinfo #1;;\zmark |
| 357 |
\expandafter\zciteparen \zcitetags,\zmark |
| 358 |
\zcitecfence} |
| 359 |
|
| 360 |
\def \zciteparen #1,#2\zmark {% tag,other-tags\zmark |
| 361 |
\zciteofence |
| 362 |
\edef \zciteofence {\zcitesep}% |
| 363 |
\if \eqlp{\citestyle}{\citebyauthoryear}% |
| 364 |
\if \emptydefp{\zciteinfo}% |
| 365 |
\zciteonetag{\citeparenformat}#1!!\zmark |
| 366 |
\else |
| 367 |
\citepareninfoformat{\citeauthor{#1}}{\citeyear{#1}}{\zciteinfo}% |
| 368 |
\fi |
| 369 |
\else |
| 370 |
\if \emptydefp{\zciteinfo}% |
| 371 |
\citeparenformat{\citekey{#1}}% |
| 372 |
\else |
| 373 |
\citepareninfoformat{\citekey{#1}}{\zciteinfo}% |
| 374 |
\fi |
| 375 |
\fi |
| 376 |
\if \notp{\emptyargp{#2}}\zciteparen #2\zmark \fi} |
| 377 |
|
| 378 |
%~ This high-level citation command produces the key or author/year |
| 379 |
%~ of the bibliography entry specified by the *tag*. The text |
| 380 |
%~ is formatted in the style appropriate for a citation that is part |
| 381 |
%~ of a surrounding parenthetical sentence. |
| 382 |
%~ There are two formats for the command: |
| 383 |
%~ * |\citeplain{*tag*}| accepts a tag and produces the key or author/year. |
| 384 |
%~ * |\citeplain{*tag*;*info*}| accepts a tag and additional |
| 385 |
%~ information such as a page number or section reference. |
| 386 |
%~ *. |
| 387 |
%~ The format of the text produced is controlled by the |\citeplainformat| |
| 388 |
%~ and |\citeplaininfoformat| macros in the design file. |
| 389 |
|
| 390 |
\def \citeplain #1{% {tag[;info]} %^citation |
| 391 |
\zcitetagsinfo #1;;\zmark |
| 392 |
\expandafter\zciteplain \zcitetags,\zmark} |
| 393 |
|
| 394 |
\def \zciteplain #1,#2\zmark {% tag,other-tags\zmark |
| 395 |
\if \eqlp{\citestyle}{\citebyauthoryear}% |
| 396 |
\if \emptydefp{\zciteinfo}% |
| 397 |
\zciteonetag{\citeparenformat}#1!!\zmark |
| 398 |
\else |
| 399 |
\citepareninfoformat{\citeauthor{#1}}{\citeyear{#1}}{\zciteinfo}% |
| 400 |
\fi |
| 401 |
\else |
| 402 |
\if \emptydefp{\zciteinfo}% |
| 403 |
\citeparenformat{\citekey{#1}}% |
| 404 |
\else |
| 405 |
\citepareninfoformat{\citekey{#1}}{\zciteinfo}% |
| 406 |
\fi |
| 407 |
\fi |
| 408 |
\if \notp{\emptyargp{#2}}\zciteplain #2\zmark \fi} |
| 409 |
|
| 410 |
\def \zsetcitepunc #1#2#3{% |
| 411 |
\def \zciteofence {#1}% |
| 412 |
\def \zcitecfence {#2}% |
| 413 |
\def \zcitesep {#3}} |
| 414 |
|
| 415 |
\def \zcitetagsinfo #1;#2;#3\zmark {% {tags[;info]} |
| 416 |
\if \emptyargp{#1}% |
| 417 |
\warning{nocitetags}{No bibliography entry tags were specified}% |
| 418 |
\fi |
| 419 |
\def \zcitetags {#1}% |
| 420 |
\def \zciteinfo {#2}} |
| 421 |
|
| 422 |
\def \zciteonetag #1#2!#3!#4\zmark {% |
| 423 |
\if \emptyargp{#2}% |
| 424 |
\citeyear{#3}% |
| 425 |
\else |
| 426 |
#1{\citeauthor{#2}}{\citeyear{#2}}% |
| 427 |
\fi} |