Debian Codegraph @

texmf-dist/doc/generic/librarian/librarian-doc.tex

raw
1 % This is the source of the documentation for the librarian package.
2 % Proper compilation requires: luatex (v.0.51 or later), a recent
3 % version of luaotfload, not to mention the Adobe Garamond Pro font,
4 % which however might be replaced by URW's Garamond. The required format
5 % is plain TeX in its modified luatex version.
6 % Three compilations are needed to get examples right.
7 %
8 % Author: Paul Isambert.
9 % E-mail: zappathustra AT free DOT fr
10 % Comments and suggestions are welcome.
11 % Date: April 2010.
12
13
14 %%%%%%%%%%%%%%%%%
15 %%%%% FONTS %%%%%
16 %%%%%%%%%%%%%%%%%
17
18 \input luaotfload.sty
19 \pdfadjustspacing=2
20 \directlua{%
21 % From otfl-font-dum.lua
22 local byte = string.byte
23 fonts.expansions.setups['threepercent'] = {
24
25 stretch = 3, shrink = 3, step = .5, factor = 1,
26
27 [byte('A')] = 0.5, [byte('B')] = 0.7, [byte('C')] = 0.7, [byte('D')] = 0.5, [byte('E')] = 0.7,
28 [byte('F')] = 0.7, [byte('G')] = 0.5, [byte('H')] = 0.7, [byte('K')] = 0.7, [byte('M')] = 0.7,
29 [byte('N')] = 0.7, [byte('O')] = 0.5, [byte('P')] = 0.7, [byte('Q')] = 0.5, [byte('R')] = 0.7,
30 [byte('S')] = 0.7, [byte('U')] = 0.7, [byte('W')] = 0.7, [byte('Z')] = 0.7,
31 [byte('a')] = 0.7, [byte('b')] = 0.7, [byte('c')] = 0.7, [byte('d')] = 0.7, [byte('e')] = 0.7,
32 [byte('g')] = 0.7, [byte('h')] = 0.7, [byte('k')] = 0.7, [byte('m')] = 0.7, [byte('n')] = 0.7,
33 [byte('o')] = 0.7, [byte('p')] = 0.7, [byte('q')] = 0.7, [byte('s')] = 0.7, [byte('u')] = 0.7,
34 [byte('w')] = 0.7, [byte('z')] = 0.7, [byte('2')] = 0.7, [byte('3')] = 0.7, [byte('6')] = 0.7,
35 [byte('8')] = 0.7, [byte('9')] = 0.7,
36 }
37 }
38
39 \def\currentstyle{rm}
40 \def\currentweight{rg}
41 \def\currentcase{lc}
42 \def\makecurrentfont{%
43 \csname\currentfont @\currentstyle @\currentweight @\currentcase\endcsname
44 }
45
46 \def\fontfeatures{+trep;+onum;+tlig;+liga;expansion=threepercent}
47 \def\mainfont{%
48 \def\currentfont{Garamond}%
49 \csname\currentfont @\currentstyle @\currentweight @\currentcase\endcsname
50 }
51 \expandafter\font\csname Garamond@rm@rg@lc\endcsname="AGaramondPro-Regular.otf:\fontfeatures" at 10pt
52 \expandafter\font\csname Garamond@rm@bf@lc\endcsname="AGaramondPro-Bold.otf:\fontfeatures" at 10pt
53 \expandafter\font\csname Garamond@rm@rg@sc\endcsname="AGaramondPro-Regular.otf:+smcp;\fontfeatures" at 10pt
54 \expandafter\font\csname Garamond@rm@bf@sc\endcsname="AGaramondPro-Bold.otf:+smcp;\fontfeatures" at 10pt
55 \expandafter\font\csname Garamond@it@rg@lc\endcsname="AGaramondPro-Italic.otf:\fontfeatures" at 10pt
56 \expandafter\font\csname Garamond@it@bf@lc\endcsname="AGaramondPro-BoldItalic.otf:\fontfeatures" at 10pt
57 \expandafter\font\csname Garamond@it@rg@sc\endcsname="AGaramondPro-Italic.otf:+smcp;\fontfeatures" at 10pt
58 \expandafter\font\csname Garamond@it@bf@sc\endcsname="AGaramondPro-BoldItalic.otf:+smcp;\fontfeatures" at 10pt
59 \mainfont
60
61 \font\titlefont="AGaramondPro-Italic.otf:\fontfeatures" at 20pt
62
63 \def\codefont{%
64 \def\currentfont{Inconsolata}%
65 \csname\currentfont @\currentstyle @\currentweight @\currentcase\endcsname
66 }
67 \expandafter\font\csname Inconsolata@rm@rg@lc\endcsname="Inconsolata.Otf:\fontfeatures;-trep" at 8.5pt
68 \expandafter\font\csname Inconsolata@rm@bf@lc\endcsname="Inconsolata.Otf:\fontfeatures;-trep" at 8.5pt
69 %\expandafter\font\csname Inconsolata@rm@rg@sc\endcsname="Inconsolata.Otf:+smcp;\fontfeatures;-trep" at 8.5pt
70 %\expandafter\font\csname Inconsolata@rm@bf@sc\endcsname="Inconsolata.Otf:+smcp;\fontfeatures;-trep" at 8.5pt
71 \expandafter\font\csname Inconsolata@it@rg@lc\endcsname="Inconsolata.Otf:slant=.2;\fontfeatures;-trep" at 8.5pt
72 \expandafter\font\csname Inconsolata@it@bf@lc\endcsname="Inconsolata.Otf:slant=.2;\fontfeatures;-trep" at 8.5pt
73 %\expandafter\font\csname Inconsolata@it@rg@sc\endcsname="Inconsolata.Otf:slant=.2;+smcp;\fontfeatures;-trep" at 8.5pt
74 %\expandafter\font\csname Inconsolata@it@bf@sc\endcsname="Inconsolata.Otf:slant=.2;+smcp;\fontfeatures;-trep" at 8.5pt
75
76 \def\it{%
77 \def\currentstyle{it}%
78 \makecurrentfont
79 }
80 \def\bf{%
81 \def\currentweight{bf}%
82 \makecurrentfont
83 }
84 \def\sc{%
85 \def\currentcase{sc}%
86 \makecurrentfont
87 }
88 \def\rm{%
89 \def\currentstyle{rm}%
90 \makecurrentfont
91 }
92 \def\textit#1{{\it#1}}
93
94
95
96 %%%%%%%%%%%%%%%%%%%%%%%
97 %%%%% PAGE LAYOUT %%%%%
98 %%%%%%%%%%%%%%%%%%%%%%%
99
100 \baselineskip=12pt
101 \topskip=\baselineskip
102 \vsize=41\baselineskip
103 \hsize=21pc
104 \parfillskip=.5\hsize plus 1fil minus .4\hsize
105 \pdfpagewidth=3\hsize
106 \pdfpageheight=\pdfpagewidth
107 \pdfhorigin=\dimexpr((\pdfpagewidth-2\hsize-1em)/2)
108 \pdfvorigin=\pdfhorigin
109 \parskip0pt \parindent0pt
110 \frenchspacing
111
112 \newbox\leftside
113 \newif\ifleftside \leftsidetrue
114 \output{%
115 \ifleftside
116 \global\setbox\leftside=\box255
117 \global\leftsidefalse
118 \else
119 \global\leftsidetrue
120 \shipout\hbox{%
121 \box\leftside\kern1em\box255
122 }%
123 \advancepageno
124 \fi
125 }
126
127
128
129 %%%%%%%%%%%%%%%%%%%%
130 %%%%% SECTIONS %%%%%
131 %%%%%%%%%%%%%%%%%%%%
132
133 \def\title#1{%
134 \hbox to \hsize{%
135 \vbox to 2\baselineskip{%
136 \vfill
137 \hbox{\titlefont\inred{#1}}%
138 \vfill
139 }%
140 \hfil
141 \vbox{%
142 \setbox0=\hbox{\texttt{[email protected]}}%
143 \hbox to\wd0{\hfil\textit{Paul Isambert}}%
144 \box0}%
145 }%
146 }
147 \newcount\sectioncount
148 \def\onelineskip{\vskip\baselineskip}
149 \def\makebookmarks{%
150 \def\lib{librarian}%
151 \def\TeX{TeX}}%
152 \def\section#1{%
153 \onelineskip
154 \advance\sectioncount1
155 \subsectioncount=0
156 \expandafter\gdef\csname\the\sectioncount sub\endcsname{0}%
157 \xdef\makebookmarks{%
158 \unexpanded\expandafter{\makebookmarks
159 \pdfoutline goto name}{section\the\sectioncount}%
160 count -\unexpanded\expandafter{\csname\the\sectioncount sub\endcsname{#1}}%
161 }%
162 \pdfdest name{section\the\sectioncount} xyz\penalty10000
163 \noindent
164 {%
165 \parfillskip0pt plus 1fil
166 \hfil\inred{\sc#1}\par}\penalty10000
167 \everypar\expandafter{%
168 \expandafter\parindent\the\parindent
169 \everypar={}}%
170 \parindent=0pt
171 }
172 \newcount\subsectioncount
173 \newif\iflefttitle
174 \def\subsection#1{%
175 \advance\subsectioncount1
176 \expandafter\xdef\csname\the\sectioncount sub\endcsname{%
177 \the\numexpr(1+\csname\the\sectioncount sub\endcsname)}%
178 \xdef\makebookmarks{%
179 \unexpanded\expandafter{\makebookmarks
180 \pdfoutline goto name}{section\the\sectioncount.\the\subsectioncount}%
181 \unexpanded{{#1}}%
182 }%
183 \onelineskip
184 \pdfdest name{section\the\sectioncount.\the\subsectioncount} xyz\penalty10000
185 \noindent
186 {%
187 \penalty0
188 \ifdim\pagetotal<\dimexpr(\pagegoal-\baselineskip)\relax
189 \ifleftside \lefttitletrue
190 \else \lefttitlefalse \fi
191 \else
192 \ifleftside \lefttitlefalse
193 \else \lefttitletrue \fi
194 \fi
195 \iflefttitle
196 \parfillskip0pt plus 1fil
197 \inred{\hbox to0pt{\hss\char"E09D\kern1em}\textit{#1}}
198 \else
199 \parfillskip0pt
200 \inred{\textit{#1}\hfill\hbox to0pt{\kern1em \char"E09D\hss}}
201 \fi
202 \par\penalty10000
203 }%
204 }
205
206
207
208 %%%%%%%%%%%%%%%%%%%%
209 %%%%% VERBATIM %%%%%
210 %%%%%%%%%%%%%%%%%%%%
211
212 \def\do#1{\catcode`#1=12}
213 \def\verbatim{%
214 \bgroup
215 \parfillskip0pt plus 1fill
216 \onelineskip
217 \obeylines \dospecials
218 \def\par{\leavevmode\endgraf}%
219 \parindent=0pt
220 \codefont \getcode
221 }%
222 \bgroup
223 \catcode`\|=0
224 \catcode`\\=12
225 |long|gdef|getcode#1\endverbatim{#1|egroup|onelineskip}%
226 |egroup
227 \newbox\cmdbox
228 \def\command#1{%
229 \bgroup
230 \codefont
231 \string#1%
232 \egroup
233 }
234 \def\cmd#1{%
235 \inred{\command{#1}}%
236 }
237 \def\tcmd#1{%
238 \command{#1}%
239 }
240 \def\cmddef{%
241 \onelineskip\subcmddef
242 }
243 \def\subcmddef#1{%
244 \noindent{\bf\cmd{#1}\parfillskip0pt plus 1fil \par}%
245 \penalty10000\noindent\ignorespaces
246 }
247 \def\arg#1{%
248 \bgroup
249 \codefont
250 \textit{\lower.08em\hbox{\char"003C}#1\lower.08em\hbox{\char"003E}}%
251 \egroup
252 }
253 \def\marg#1{%
254 \char"007B\arg{#1}\char"007D
255 }
256 \def\targ#1{%
257 \texttt{\char"007B #1\char"007D}%
258 }
259 \def\field#1{\texttt{\inred{#1}}}
260
261
262
263 %%%%%%%%%%%%%%%%%%%%%%%
264 %%%%% SOME MACROS %%%%%
265 %%%%%%%%%%%%%%%%%%%%%%%
266
267 \def\texttt#1{{\codefont#1}}
268 \def\inred{\incolor{.7 0 .1}}
269 \long\def\incolor#1#2{%
270 \pdfliteral{#1 rg}%
271 #2%
272 \pdfliteral{0 0 0 rg}%
273 }
274 \def\lib{\textit{librarian}}
275 \def\LaTeX{La\TeX} \def\ConTeXt{Con\TeX t}
276 \long\def\citation#1\endcitation{%
277 \onelineskip
278 \bgroup
279 \advance\leftskip2em \rightskip\leftskip
280 \incolor{.1 0 .5}{#1}\par
281 \egroup
282 \onelineskip
283 }
284
285
286 \pdfinfo{%
287 /Title (librarian-doc.pdf)
288 /Author (Paul Isambert)
289 }
290 \pdfcatalog{%
291 /PageMode /UseOutlines
292 }
293
294 \input librarian
295 \title{Librarian}
296
297 \section{Introduction}
298
299 \textit{Librarian} is a set of macros that handles bibliographic
300 references without Bib\TeX. It reads bibliographic files, extracts
301 information about entries, and sorts lists of entries according to
302 that informa\-tion and the user's specifications. \TeX\ code can then
303 be written to typeset citations and bibliographies or more generally
304 to write the equivalent of \texttt{bst} files, and absolutely
305 no knowledge of the Bib\TeX\ language is needed, nor is Bib\TeX\ itself.
306
307 The package is low-level in the sense that it doesn't do much more
308 than what's said above and offers little syntactic sugar to typeset
309 bibliographies. It is meant to make as few meaningful decisions as
310 possible, where `meaningful decisions' means operations that influence
311 the output or what the user can do. The way \lib\ extracts information
312 is immaterial (barring efficiency, of course) to the typesetting of
313 a bibliography, which depends strictly on the user's knowledge in
314 \TeX\ programming. On the contrary, predefined styles, for instance,
315 would be easier indeed but also more limited.
316
317 Besides, \lib\ is format-independent, relying on plain \TeX's usual
318 allocation macros only (which are similar in other formats, as far
319 as I can tell). Thus, a well-written bibliographic style should
320 work equally well in all formats; by `well written' I mean that it does
321 not use any format-specific commands, and at worst defines aliases
322 to those commands at the beginning of the file.
323
324 The first part of this document is a reference manual where \lib\
325 is explained thoroughly. The second part spells out a pair of
326 examples of bibliographic styles; the second example gives details
327 on the important parts of the file \texttt{authoryear.tex}, which
328 is distributed with the package and can be used as is.
329
330
331
332
333
334 \section{Reference manual}
335
336 \subsection{How to load \lib}
337
338 In plain, the package is loaded in the good old way:
339
340 \verbatim
341 \input librarian
342 \endverbatim
343
344 \noindent In La\TeX\ you must use the associated style file:
345
346 \verbatim
347 \usepackage{librarian}
348 \endverbatim
349
350 \noindent And in Con\TeX t you must load \lib\ with the
351 third-party file:
352
353 \verbatim
354 \usemodule[librarian]
355 \endverbatim
356
357 \subsection{Commands}
358
359 \cmddef{\Cite\marg{entry key}\marg{list}\marg{code1}\marg{code2}}
360 This adds \arg{entry key} to \arg{list} (if the latter doesn't exist,
361 it is created on the fly), unless it has already been added previously. If \arg{entry key}
362 has already been read in the bibliography (most likely in a previous
363 compilation), \cmd\EntryKey\ is set to \arg{entry key} and \arg{code1} is
364 executed. Otherwise, \lib\ will read the bibliographic files to retrieve information
365 about \arg{entrykey}, and for the moment \arg{code2} is executed (without
366 redefining \tcmd\EntryKey). With complex bibliographic styles, this command is
367 better embedded in macros.
368
369 \cmddef{\BibFile\marg{list of files}}
370 The \arg{list of files} is a comma-sepa\-rated list of bibliographic
371 files in which \lib\ will dig information about the requested entries.
372 The \texttt{.bib} extension is implicit, but you can give another
373 one, as in \tcmd{\BibFiles\targ{mybib,myotherbib.tex}}. The information
374 is passed to the next compilation thanks to an external file called
375 \texttt{\arg{jobname}.lbr} (the culprit to delete if things seem wrong to you).
376 If there remains no requested entry then the
377 files aren't read. \tcmd\BibFile\ can occur several times in a document,
378 but on each call, only those entries that have been \tcmd\Cite'd before
379 will be searched for in the bibliographic files, because calls
380 to \tcmd\Cite\ aren't passed from one compilation to the next. Most
381 complex bibliographic styles generally require three compilations to
382 get everything right.
383
384 %%%% Pour la page suivante:
385 \advance\vsize-\baselineskip
386 %%%% Clumsy but I had no time to implement
387 %%%% my own widow-killer here...
388
389 \cmddef{\SortingOrder\marg{list of fields}\marg{name parts}}
390 This sets the order in which lists will be sorted. The fields in
391 \arg{list of fields} are the ones you find in Bib\TeX\ entries,
392 plus the ones \lib\ adds to entries (like \texttt{name}), and they should
393 be separated by commas. Any field can be prefixed with `\texttt{-}',
394 which indicates that when it comes to this field entries will be
395 sorted in reverse order. The sorting works as follows: when comparing
396 two entries, \lib\ compares their values for the first field; if they
397 are the same, it tries the second field, and so on. If \arg{list of fields}
398 is exhausted, the entries are sorted according to the order of citation
399 in the document relative to the list that's being scanned (i.e. the value
400 of \tcmd\EntryNumber). The \arg{name parts}
401 are concatenated letters, with `\texttt{f}' denoting first name, `\texttt{l}'
402 denoting last name, `\texttt{v}' referring to the von part and `\texttt{j}'
403 referring to the junior part; it sets how names are compared, and although
404 there seems to be only two meaningful orders (\texttt{vlfj} and \texttt{lfvj}),
405 differing in how the von part is taken into account, you can do whatever you
406 want. Thus, \tcmd{\SortingOrder\targ{name,year,title}\targ{vlfj}} sorts entries in
407 the `author year' style, with titles differentiating entries by the same
408 author(s) written the same year, and with the von part taking precedence in
409 the last name. Instead, \tcmd{\SortingOrder\targ{name,-year}\targ{lfvj}}
410 will produce a bibliography sorted by names, with most recent references first,
411 and similar references sorted according to their order in the document, while
412 the von part doesn't matter in last names (and thus Ludwig van Beethoven is
413 sorted before Franz Schubert). In any case, \arg{name parts} have nothing
414 to do with how names are typeset in the bibliography. (In these examples,
415 \texttt{name} is used instead of \texttt{author} or \texttt{editor} on purpose.
416 See below about the \texttt{name} field.) By default, \lib\ doesn't sort entries.
417
418 \cmddef{\SortList\marg{list}}
419 This sorts \arg{list} according to the latest value of \tcmd\SortingOrder.
420 Thus different lists can be sorted with different orders. If \tcmd\SortList\
421 is called before \tcmd\BibFile, then new entries will be sorted on the
422 next compilation only. From one compilation to the next, \lib\ retains
423 the previous sorted entries and sorts only new entries, and entries that
424 are equal according to \tcmd\SortingOrder\ (because their relative order
425 may have changed). This saves time (especially in Lua\TeX\ where the many
426 calls to \tcmd\directlua\ are quite time-consuming). However, if the value
427 of \tcmd\SortingOrder\ when \tcmd\SortList\ is called has changed from the
428 previous compilation, all entries are sorted again.
429
430 \cmddef{\ReadList\marg{list}}
431 This loops over entries in \arg{list}, and for each it stores its key
432 in \cmd\EntryKey\ and calls \cmd\MakeReference, which by default does nothing,
433 and should be redefined to typeset the entry. For each entry you can use
434 the \cmd\ifequalentry\ conditional, which is true if the current entry
435 is part of a set of entries that are equal with regard to \tcmd\SortingOrder\
436 and are thus distinguished by citation order only, and false otherwise.
437 If the list is unsorted (i.e. \tcmd\SortingOrder\ is empty), then \tcmd\ifequalentry\
438 is always false, even though all entries are equal.
439
440
441
442 \cmddef{\SortDef\marg{command}\marg{definition}}
443 This defines \arg{command} as \arg{defi\-nition} at sorting time.
444 Indeed, macros shouldn't hinder sorting. However, \tcmd\TeX\ won't
445 be read as `TeX' and \textit{\TeX book} won't be sorted after
446 \textit{Tao Te Ching} but rather after \textit{Typographic Investigations},
447 because macros separate letters. So
448 \tcmd{\SortDef\tcmd\TeX\targ{tex}} is the proper way to get good sorting
449 (everything is sorted in lowercase, so no need to use `\texttt{TeX}').
450 \tcmd\SortDef\ can't define with parameter text, but a macro can
451 be defined to another one taking arguments, although it is generally
452 unnecessary: all braces are removed at sorting time. It is probably
453 very important to redefine accents (\lib\ doesn't), e.g. \tcmd{\SortDef\string\'\targ{}}
454 is vital if you want to see B\char"00E9 zier between Bernoulli and Boole.
455
456 \cmddef{\WriteInfo\marg{arg}}
457 \subcmddef{\WriteImmediateInfo\marg{arg}}
458 Since \lib\ reads and rewrites an external file on each compilation,
459 you can use it too. This writes \arg{arg} to that file, so that it is
460 made available for the next compilation; \arg{arg} is expanded as in
461 any \tcmd\write\ statement. \tcmd\WriteInfo\ writes at output time,
462 whereas \tcmd\WriteImmediateInfo\ writes immediately.
463
464 \cmddef\Preamble
465 This holds everything that has been encountered in \texttt{@preamble}
466 entries when reading bibliographies. It isn't passed from one compilation
467 to the next.
468
469 %%%% Pour la page suivante:
470 \advance\vsize\baselineskip
471 \cmddef{\CreateField\marg{field}}
472 If a field is unknown to \lib\ (there is no restriction in bibliographic entries),
473 \lib\ complains when asked to retrieve it with the commands below. This command
474 just enables it to work with unknown fields. By default, \lib\ knows the common
475 Bib\TeX\ fields and its own, of course.
476
477 \cmddef{\AbbreviateFirstname}
478 This turns first names into initials, e.g. \textit{John} into \textit{J.} and
479 \textit{Jean-Luc} into \textit{J.-L.} In order to get \textit{Ch.} from
480 \textit{Charles}, the name in the bibliographic file should be
481 `\texttt{\char`\{Ch\char`\}arles}', which is already the case for Bib\TeX.
482 Note that \lib\ sorts full names and thus \textit{J(ohn) Doe} and \textit{J(ack) Doe}
483 are different in this respect, even though they'll be indistinguishable in your
484 bibliography.
485
486
487
488
489
490
491 \onelineskip
492 The following macros all come in pairs made of \tcmd\Command\ and \tcmd\CommandFor,
493 where \tcmd\Command\ is \tcmd\CommandFor\ with \arg{entry key} set to \tcmd\EntryKey.
494 All along, I refer to bibliographic entries, naturally, and \textit{field\/} and \textit{value\/}
495 are to be understood in that context (see the next two sections for details).
496
497 \cmddef{\RetrieveField\marg{field}}
498 \subcmddef{\RetrieveFieldFor\marg{field}\marg{entry key}}
499 This produces the value of \arg{field} for \arg{entry key}. The command
500 uses \tcmd\lowercase, so you should use it with care, and basically avoid it
501 unless for typesetting fields. The following command should be preferred
502 if anything must be manipulated.
503
504 \cmddef{\RetrieveFieldIn\marg{field}\marg{command}}
505 \subcmddef{\RetrieveFieldInFor\marg{field}\marg{entry key}\marg{command}}
506 This one defines \arg{command} as the value of \arg{field} for \arg{entry key}.
507 If \arg{field} doesn't exist in \arg{entry key}, or else if \arg{entry key}
508 doesn't exist, then \arg{command} is defined as an empty command and
509 is equivalent to \tcmd\empty\ if the latter is defined as
510 \tcmd\def\tcmd\empty\texttt{\char`\{\char`\}}. Quite convenient for testing.
511
512 \cmddef{\EntryNumber\marg{list}}
513 \subcmddef{\EntryNumberFor\marg{entry key}\marg{list}}
514 This returns \textit{n} if \arg{entry key} is the \textit{n}th entry
515 in \arg{list}, i.e. if it is the \textit{n}th entry to be cited for the
516 first time in \arg{list}.
517
518 \cmddef{\EntryNumberIn\marg{list}\marg{command}}
519 \subcmddef{\EntryNumberInFor\marg{entry key}\marg{list}\marg{command}}
520 This defines \arg{command} as \textit{n}, where \textit{n} is defined
521 as above. (Beware that \arg{command} is a macro whose expansion produces
522 a number, not an integer denotation.) This is safer than the previous command
523 for the same reason as with \tcmd\RetrieveFieldFor, and is emptily defined
524 under the same circumstances.
525
526 \cmddef{\ReadName\marg{code}}
527 \subcmddef{\ReadNameFor\marg{entry key}\marg{code}}
528 For each person in the \texttt{name} field for \arg{entry key}, this stores the first name
529 in \cmd\Firstname\ (abbreviated if \tcmd\AbbreviateFirstname\ was called),
530 the last name in \cmd\Lastname, the von part in
531 \cmd\Von\ and the junior part in \cmd\Junior. There is also a
532 number \cmd\NameCount, which holds the place of the person in the
533 \texttt{name} field (i.e. the first author has \tcmd\NameCount\texttt{=1}).
534 Finally, \arg{code} is called with those values. There are aliases
535 \cmd\ReadNames\ and \cmd\ReadNamesFor. \cmd\ReadAuthor, \cmd\ReadAuthorFor,
536 \cmd\ReadEditor\ and \cmd\ReadEditorFor, and the versions with plural as well,
537 are defined equivalently for the \texttt{author} and
538 \texttt{editor} fields respectively. You can still use \tcmd{\RetrieveField
539 \targ{author}}, for instance, but those fields aren't designed
540 for typesetting in their basic form, hence this command.
541
542 \cmddef{\TypesetField\marg{field}\marg{command}\marg{code}}
543 \subcmddef{\TypesetFieldFor\marg{field}\marg{entry key}\marg{command}\marg{code}}
544 If \arg{field} isn't empty in \arg{entry key}, \arg{command} is
545 executed with the value of \arg{field} as its argument. So
546 \arg{command} should be a macro that takes one (and only one) argument.
547 If \arg{field} is empty, \arg{code} is executed instead.
548
549
550
551
552
553
554
555
556 \subsection{Fields}
557 Beside the fields that are found in bibliographic entries, \lib\ adds
558 some of its own, which can be convenient for dealing with references.
559 Here they are.
560
561 The \field{entrytype} field contains the type of the entry as recorded
562 in \texttt{bib} files at the beginning of each entry after the
563 \texttt{@} sign. Thus
564
565 \verbatim
566 @Book{Coover2002,
567 ...
568 }
569 \endverbatim
570
571 \noindent has `\texttt{book}' as the value for \texttt{entrytype}. Note
572 that lowercase is always used, whatever the actual case in the \texttt{bib} file.
573 The number of authors in the \texttt{author} field is the value of the \field{authornumber}
574 field, each author being distinguished from the next by the customary `\texttt{and}'.
575 An equivalent field, \field{editornumber}, does the same for \texttt{editor}.
576 Most importantly, the \field{name} field holds the same value as \texttt{author}
577 if there is such a field in the entry, or the value of \texttt{editor}
578 it it exists and there is no \texttt{author}. Thus edited books can be
579 cited along with normal books. That's why \texttt{name} appeared in
580 \tcmd\SortingOrder\ above: if it had been \texttt{author}, then collective
581 works wouldn't have been sorted correctly. Along with \texttt{name},
582 \field{namenumber} holds the value either of \texttt{authornumber} or
583 of \texttt{editornumber}, according to the same rule. Finally, \field{nametype}
584 takes one out of two values: \texttt{author} or \texttt{editor}. It
585 takes the former if the \texttt{name} field is set to the value of the \texttt{author}
586 field, and the latter if it is set to the value of the \texttt{editor} field.
587 Thus, when referencing collective works in a bibliography, you can add
588 `(ed.)' for instance after the value of \texttt{name} if \texttt{nametype}
589 is \texttt{editor}.
590
591
592
593
594 \subsection{A crash course in bibliographic entries (and how \lib\ reads them)}
595 This section is not necessary to the understanding of \lib\ but it can be
596 useful if in trouble. Suppose you have the following entry:
597
598 \verbatim
599 @Book{Coover2002,
600 author = {Coover, Robert},
601 title = {The Adventures of Lucky Pierre},
602 subtitle = {Director's Cut},
603 publisher = "Grove Press",
604 Address = {New York},
605 year = 2002,
606 }
607 \endverbatim
608
609 \noindent Then \lib\ stores all the fields for the `\texttt{coover2002}' entry key.
610 This key is in lowercase, and thus you can't distinguish two entries by case only
611 (this is how Bib\TeX\ works). This doesn't mean that you can't use
612 \tcmd{\Cite\targ{Coover2002}\targ{list}}: \lib\ does the necessary conversion.
613 The \texttt{entrytype} field is set to `\texttt{book}', in lowercase once again, and
614 this time you must be careful: `\texttt{book}' is a value, and since you'll probably
615 test it to know how the reference should be typeset in the bibliography, you
616 shouldn't compare it to, say, `\texttt{Book}', of course. And to finish with
617 lowercase, `\texttt{New York}' is the value of the \texttt{address} field,
618 not \texttt{Address}, but once again \lib\ does the conversion so you can call
619 \tcmd{\RetrieveField\targ{Address}\targ{cooVEr2002}}. Finally, the \texttt{subtitle}
620 field is no customary field, but you can use it. Up to there, \lib\ works
621 exactly like Bib\TeX.
622
623 But there are differences too. For one thing, \lib\ has no restriction on the type
624 of the entry, so you could have:
625
626 \verbatim
627 @novel{Coover2002,
628 author = {Coover, Robert},
629 title = {The Adventures of Lucky Pierre},
630 subtitle = {Director's Cut},
631 publisher = "Grove Press",
632 Address = {New York},
633 year = 2002,
634 }
635 \endverbatim
636
637 \noindent That's perfectly fine with \lib, although not with Bib\TeX.
638 There are no restrictions on fields either, and unlike Bib\TeX\ fields
639 aren't labelled as required or optional or ignored; in a bibliographic
640 style you can issue an error message if a field is missing, but \lib\
641 won't do it for you. And there are
642 annoying differences too. They occur in the way \lib\ reads the values of
643 fields. Here's how it works: if the first character (disregarding space) after
644 the `\texttt{=}' sign is a~\texttt{\string{}, then everything up to the next
645 balanced~\texttt{\string}} is taken as the value, and everything up to the comma
646 is discarded. (The last value of the entry may have no comma, but \lib\ adds one
647 before reading the entry.) If the first character is a~\texttt{\string"}, then
648 everything up to the next~\texttt{\string"}, with balanced braces, is taken
649 as the value, and everything up to the comma is discarded once again. Finally,
650 if the first character is none of the above, then \lib\ takes everything up
651 to the next comma as the value (while balancing braces, of course). The latter
652 case differs from Bib\TeX. Normally, only numerical values (like the value of
653 \texttt{year} in our example) can be given as such, unless strings are used.
654 But \lib\ is totally unable to understand strings. The following
655
656 \verbatim
657 @string{ny = "New York"}
658 @Book{Coover2002,
659 author = {Coover, Robert},
660 title = {The Adventures of Lucky Pierre},
661 subtitle = {Director's Cut},
662 publisher = "Grove Press",
663 Address = ny,
664 year = 2002,
665 }
666 \endverbatim
667
668 \noindent would yield `\texttt{New York}' as the value of \texttt{address} in
669 Bib\TeX, whereas with \lib\ it gives `\texttt{ny}' (and the \texttt{@string}
670 entry is simply ignored). In a situation as simple as the present one, you can
671 make do with macros in you document, i.e. a macro which when fed with `\texttt{ny}'
672 returns `\texttt{New York}' (problems arise if `\texttt{ny}' is the \textit{real}
673 value of a field, though), but it becomes more serious when you concatenate strings
674 with the \texttt{\string#} operator. No way to hide the truth: \lib\ will get
675 everything wrong. So if you're heavy on strings, better stick to Bib\TeX.
676
677
678
679
680
681
682 \section{Examples}
683 Although \lib\ doesn't use many commands, it might be hard to understand them
684 from scratch. This section details a pair of example styles so you can get
685 familiar with how things work. The first example is stripped to the minimum
686 just to learn the basic use of \lib's macros.
687 The second example is an \textit{Author~(Year)} style
688 with some refinements, dealing in particular with entries that have the same
689 author and the same year and should thus be distinguished by a suffix, and it
690 also shows how to handle cross-references. This style is thoroughly defined
691 in the file \texttt{authoryear.tex}, distributed with \lib.
692
693 Remember, though, that what you can do in \lib\ is what you can do in \TeX.
694 There's nothing arcane in \lib, and what you can achieve depends really
695 on your skill in \TeX. So don't feel limited; for instance, suppose you
696 want to make a list of your publications like:
697
698 \citation
699 {\it2010}\par
700 `My fascinating paper', {\it Journal of Science}, volume 55 (22), 210--224.\par
701 {\it The book I finally wrote}, Good Publishing House: City\-ville.\par
702 {\it2009}\par
703 `A talk on something', presented at...
704 \endcitation
705
706 \noindent That is, you want the year to be set above the entries, not
707 repeated each time: then, for each entry, retrieve its \texttt{year}
708 in a macro, and on the next one, compare with the current year. If it
709 has changed, print the new value. (Of course entries should be sorted
710 by date, otherwise it doesn't make sense.)
711
712 Another example: \lib\ doesn't abbreviate journal titles. But if you think
713 in \TeX, it is easily solved: just create a function from a journal title
714 to its abbreviation (if any), and call it on the value of the \texttt{journal}
715 field... and so on and so forth...
716
717
718
719 \subsection{A simple unsorted list with numerical references, which gets sorted later}
720 Our first example simply doesn't sort entries, and they are cited with
721 the number they get when they appear. To make things a little funnier,
722 though, we'll have a case of multiple bibliographies, e.g. one bibliography
723 per chapter. In each chapter we set \tcmd\currentchapter, and \tcmd\cite\
724 is as follows:
725
726 \verbatim
727 \def\cite#1{%
728 \Cite{#1}{\currentchapter}%
729 {[\EntryNumber{\currentchapter}]}{[??]}%
730 }
731 ...
732 \def\currentchapter{chapter1}
733 \endverbatim
734
735 \noindent And at the end of the chapter we'll have:
736
737 \verbatim
738 \ReadList{\currentchapter}
739 \endverbatim
740
741 \noindent whereas the \tcmd\BibFile\ command will appear
742 at the end of the book. What \tcmd\cite\ does is: store
743 the entry in the list associated with the chapter, print
744 `[??]' if there's no information associated with that entry (probably
745 because it hasn't been read in the bibliographic file yet) and
746 `[n]' instead, where \textit{n} is its number in that list, e.g.
747 `[3]' if that's the third entry in that chapter.
748
749 When \tcmd\ReadList\ is called, we need to have \tcmd\MakeReference\
750 ready, so here it is:
751
752 \verbatim
753 \def\empty{}
754 \def\MakeReference{%
755 \par \noindent
756 \llap{[\EntryNumber{\currentchapter}]~}%
757 \RetrieveFieldIn{namenumber}\tempcount
758 \ifx\tempcount\empty
759 \def\tempcount{0}%
760 \fi
761 \ReadName\makerefname.
762 \RetrieveField{title}.
763 \RetrieveField{year}.\par
764 }
765 \endverbatim
766
767 This produces `[n]' in the left margin (with plain \TeX's \tcmd\llap\
768 macro), and prints the name, the title, the year, separated by dots
769 and a space. To put it simply, that's an utterly boring citation style,
770 which doesn't take the entry type into account. The thing about \tcmd\tempcount\
771 is: we'll need it in \tcmd\ReadName\ with \tcmd\makerefname\ to check
772 whether we're at the last author. So we need it as a number; however,
773 on the first compilation, since \tcmd\BibFile\ appears after \tcmd\ReadList,
774 entries have no \texttt{namenumber} field, and thus \tcmd\tempcount\ is
775 empty... which is a very bad idea in an \tcmd\ifnum\ test. In that case
776 we set it to 0. Now here how names are typeset:
777
778 \verbatim
779 \def\space{ }
780 \def\makerefname{%
781 \ifnum\NameCount>1
782 \ifnum\NameCount=\tempcount\relax \space and \else , \fi
783 \fi
784 \Firstname
785 \unless\ifx\Von\empty \Von\space \fi
786 \space\Lastname
787 \unless\ifx\Junior\empty , \Junior \fi
788 }
789 \endverbatim
790
791 \noindent We check for the existence of the von and junior parts and
792 put them conditionally. Names are separated by a comma except the last
793 one which takes `and' instead. Note the crucial \tcmd\relax\ after
794 \tcmd\tempcount: the latter is a macro expanding to a number, and it
795 would gobble the next \tcmd\space\ if \tcmd\relax\ wasn't there.
796 I could have swapped \tcmd\NameCount\ and \tcmd\tempcount, since the
797 former is a real integer denotation, but we would have missed this
798 fascinating conversation.
799
800 Now we're done with that style. Suppose however we want sorted entries.
801 For instance:
802
803 \verbatim
804 \SortingOrder{name,year,title}{lfvj}
805 \endverbatim
806
807 Now, citing entries with the citation number isn't very convenient.
808 Instead, we want a number associated with the entry in the sorted
809 list. We need a new count, and on each chapter it should be reset to
810 0. For instance:
811
812 \verbatim
813 \newcount\entrycount
814 ...
815 \def\currentchapter{chapter24}
816 \entrycount=0
817 \endverbatim
818
819 \noindent Next, we redefine \tcmd\cite\ as follows:
820
821 \verbatim
822 \def\cite#1{%
823 \Cite{#1}{\currentchapter}%
824 {[\csname\EntryKey @\currentchapter\endcsname]}%
825 {[??]}%
826 }
827 \endverbatim
828
829 \noindent Now \tcmd\cite\ calls a command associated with the key
830 (note that \tcmd\EntryKey\ is useless, we could have used \texttt{\#1}
831 directly) and the chapter, which holds the number we want. The latter
832 was set in \tcmd\MakeCitation, redefined as:
833
834 \verbatim
835 \def\MakeReference{%
836 \par \noindent
837 \advance\entrycount1
838 \WriteImmediateInfo{%
839 \noexpand\expandafter\def
840 \noexpand\csname\EntryKey @\currentchapter
841 \noexpand\endcsname{\the\entrycount}%
842 }%
843 \llap{[\the\entrycount]~}%
844 % ... same as before
845 }
846 \endverbatim
847
848 \noindent This means: on each entry, advance \tcmd\entrycount\ and
849 store its value as the expansion of the command seen above, thanks
850 to \tcmd\WriteImmediateInfo. The rather clumsy code in the latter
851 just means that the following will be written to the external file:
852
853 \verbatim
854 \expandafter\def\csname coover2002@chapter24\endcsname{13}
855 \endverbatim
856
857 And of course, it is the value of \tcmd\entrycount\ that we put into the left margin.
858 Note that this style takes three compilations to get everything right:
859 in the first one, a new entry can't be sorted, because \tcmd\SortList\
860 appears before \tcmd\BibFile. In the second compilation, the entry is
861 sorted and its number is written to the external file. In the last one,
862 that number is read and used when the entry is cited. Here's the style
863 it produces:
864
865
866 %\input unsorted
867 %\Cite{Wallace2004}{\currentchapter}{}{} \Cite{Wallace1996}{\currentchapter}{}{}
868 %\citation
869 %Wallace's last book \cite{Wallace2004} was published eight years after his cult
870 %novel \cite{Wallace1996}.\par
871 %...\par
872 %\SortList{\currentchapter}
873 %\ReadList{\currentchapter}
874 %\endcitation
875
876 \Cite{Wallace2004}{empty}{}{} \Cite{Wallace1996}{empty}{}{}
877 \citation
878 Wallace's last book [2] was published eight years after his cult
879 novel [1].\par
880 ...\par
881 \quitvmode\llap{[1]~}David Foster Wallace. \RetrieveFieldFor{title}{Wallace1996}. \RetrieveFieldFor{year}{Wallace1996}.\par
882 \quitvmode\llap{[2]~}David Foster Wallace. \RetrieveFieldFor{title}{Wallace2004}. \RetrieveFieldFor{year}{Wallace2004}.\par
883 \endcitation
884
885
886
887
888
889 \subsection{An Author (Year) style, with similar entries and cross-references}
890 The basic idea here is to have a command \tcmd{\cite\targ{entry key}}
891 that produces an \textit{Author~(Year)} citation in the main document
892 (rather \textit{Name~(Year)}, but whatever). References are thus sorted
893 according to names and then year, and if two entries are equal with
894 regard to these fields, they should be sorted according to their relative
895 order of appearance in the document and distinguished with a suffixes,
896 e.g. `Wallace~(2003a)' and `Wallace~(2003b)'. To do so we'll use \tcmd\ifequalentry\
897 and \tcmd\WriteImmediateInfo.
898
899 However, such a simple \tcmd\cite\ is definitely not very fun. So let's
900 make it harder: it will take any number of entry keys and separate them
901 with commas (e.g. `Wallace~(1996), Coover~(2002)') unless the \texttt{name}
902 field is identical, in which case it won't be repeated and the year
903 will be put between the same parentheses as the previous entry
904 (e.g. `Wallace~(1996, 2003)'). So \tcmd\cite\ actually calls a
905 recursive macro (\tcmd\readcite) on its argument. Here's how it goes.
906 (Since \lib\ requires e\TeX, we can use it too; if you don't know anything
907 about it, the only important thing is that you can prefix a conditional
908 with \tcmd\unless\ to reverse its evaluation; i.e.
909 \tcmd{\unless\tcmd\ifwhatever\ A\tcmd\else\ B\tcmd\fi} is the same as
910 \tcmd{\ifwhatever\ B\tcmd\else\ A\tcmd\fi}. It's useful to write
911 \tcmd{\unless\tcmd\ifwhatever} instead of \tcmd{\ifwhatever\tcmd\else}
912 when you're interested in the false condition only.)
913
914 \verbatim
915 \def\terminator{\terminator} \def\empty{}
916 \def\cite#1{%
917 \def\prevauthor{}%
918 \readcite#1,\terminator,%
919 }
920 \def\readcite#1,{%
921 \def\temp{#1}%
922 \ifx\temp\terminator
923 )%
924 \let\tail\relax
925 \else
926 \let\tail\readcite
927 \unless\ifx\temp\empty
928 \Cite{#1}{main}\makecitation{}%
929 \fi
930 \fi\tail
931 }
932 \endverbatim
933
934 \noindent Since we don't know what the next entry will be, if any,
935 the final parenthesis is typeset when \tcmd\readcite\ meets the
936 terminator. (We take care of empty entries in case one writes
937 `\tcmd{\cite\targ{entry1,entry2,}}' by mistake, which becomes
938 `\texttt{entry1,entry2,,\string\terminator,}' for \tcmd\readcite.)
939 Note that in \texttt{authoryear.tex}, `(' and `)' are actually
940 replaced by macros (\tcmd\leftcitemark\ and \tcmd\rightcitemark)
941 that are defined as parentheses; it simply makes the switch to
942 another style easier.
943
944 All entries are added to the \texttt{main} list, and at the end
945 of the document we'll have to write:
946
947 \verbatim
948 % Perhaps some \SortDef's?
949 \BibFile{myfiles}
950 \SortingOrder{name,year}{lfvj}
951 \SortList{main}
952 \ReadList{main}
953 \endverbatim
954
955 But back to citation. \tcmd\readcite\ calls \tcmd\makecitation\
956 in case there are fields for the entry. Here it is. If the current
957 author is the same as in the previous entry (recorded in
958 \tcmd\prevauthor), then we just add a command and a space
959 to the previous date:
960
961 \verbatim
962 \def\makecitation{%
963 \RetrieveFieldIn{name}\temp
964 \ifx\temp\prevauthor ,
965 \endverbatim
966
967 \noindent On the other hand, if authors differ (unless the previous
968 one is empty, which means we're on the first citation), we close
969 the parenthesis (always added by the next entry to the previous
970 one, remember?), adds a comma and a space to separate entries,
971 and typeset the name with \tcmd\ReadName\ (which will make
972 use of \tcmd\tempcount). We also typeset an opening parenthesis
973 preceded by a hard space to welcome the upcoming year.
974
975 \verbatim
976 \else
977 \unless\ifx\prevauthor\empty ),\fi
978 \RetrieveFieldIn{namenumber}\tempcount
979 \ReadName\makecitename~(%
980 \fi
981 \endverbatim
982
983 \noindent And in any case we set \tcmd\prevauthor\ to the
984 current value of \texttt{name}, typeset the year and
985 add the suffix associated with that entry if it exists
986 (it is created when we use \tcmd\ReadList), somehow like
987 the entry number in the previous example.
988
989 \verbatim
990 \RetrieveFieldIn{name}\prevauthor
991 \RetrieveField{year}\csname\EntryKey @suffix\endcsname
992 }
993 \endverbatim
994
995 Now here's how names are typeset: they are separated by
996 commas, except the last one which is separated by \textit{and}
997 (e.g. `Jackson, Jameson and Johnson~(1980)'). Besides, if there
998 are more than 3 authors, only the first one is typeset,
999 followed by \textit{et alii}. The number 3 is of course
1000 totally arbitrary. Finally, each name is typeset as
1001 \texttt{\string\Von\string~\string\Lastname} with the \tcmd\Von\
1002 part optional, of course (maybe that makes too many hard
1003 spaces, though). Remember that \tcmd\tempcount\ holds the value of
1004 the \texttt{namenumber} field and that \tcmd\NameCount\ is
1005 the place of the author under investigation in the entire field.
1006 Hence, if they are more authors than allowed:
1007
1008 \verbatim
1009 \chardef\namelimit=3
1010 \def\makecitename{%
1011 \ifnum\tempcount>\namelimit
1012 \ifnum\NameCount=1
1013 \unless\ifx\Von\empty \Von~\fi
1014 \Lastname\space {\italics{et alii}}%
1015 \fi
1016 \endverbatim
1017
1018 \noindent Otherwise we typeset all names preceded by
1019 different markers: nothing for the first author, \textit{and}
1020 for the last one, and commas in between.
1021
1022 \verbatim
1023 \else
1024 \unless\ifnum\NameCount=1
1025 \ifnum\NameCount=\tempcount\relax \space and
1026 \else , \fi
1027 \fi
1028 \unless\ifx\Von\empty \Von~\fi
1029 \Lastname
1030 \fi
1031 }
1032 \endverbatim
1033
1034 \noindent And we're done with the \tcmd\cite\ command. We could
1035 add variation, e.g. \tcmd\citeauthor\ to typeset the \texttt{name}
1036 field, \tcmd\citeyear\ for the date, remove parentheses when needed,
1037 etc., but basically we've done the hardest part. The \tcmd\makecitename\
1038 macro shown here is slightly simpler than the real one in
1039 \texttt{authoryear.tex}. The latter first checks whether \tcmd\Lastname\
1040 is `\texttt{others}', in which case it typesets the \textit{et alii}
1041 phrase (a basic feature of Bib\TeX).
1042
1043 Now we have to define \tcmd\MakeCitation. It begins with \tcmd\ReadName\
1044 called with \tcmd\makerefname\ as in the previous example. Even though
1045 \tcmd\makrefname\ is slightly different (the first author is typeset
1046 as \textit{von Last, Jr, First} whereas the other authors remain in the
1047 \textit{First von Last, Jr} style), I won't show it here,
1048 because there's nothing much to learn.
1049
1050 \verbatim
1051 \def\MakeReference{%
1052 \par\noindent
1053 \RetrieveFieldIn{namenumber}\tempcount
1054 \ReadName\makerefname
1055 \endverbatim
1056
1057 \noindent In \tcmd\MakeReference\ still, we add a usual marker for collective
1058 works (\tcmd\editor\ is simply defined as `\texttt{editor}' elsewhere).
1059
1060 \verbatim
1061 \RetrieveFieldIn{nametype}\temp
1062 \ifx\temp\editor
1063 \RetrieveFieldIn{namenumber}\temp
1064 \ifnum\temp>1 \space (eds.)\else \space (ed.)\fi
1065 \fi
1066 \endverbatim
1067
1068 \noindent Then we typeset the date between parentheses with a suffix,
1069 which will be set by \tcmd\comparentries\ (and actually probably empty).
1070 This suffix is meant to distinguish entries that are equal according to
1071 \tcmd\SortingOrder.
1072
1073 \verbatim
1074 \space (\RetrieveField{year}%
1075 \csname\EntryKey @suffix\endcsname)
1076 \compareentries
1077 \endverbatim
1078
1079 \noindent Typesetting the rest of the entry depends on the entry type,
1080 which is fed to \tcmd\typesetref. At the end of the entry we call
1081 \tcmd\conditionalstop, a stop that appears if and only if there was no
1082 stop before (see \texttt{authoryear.tex} for details).
1083
1084
1085 \verbatim
1086 \RetrieveFieldIn{entrytype}\temp
1087 \typesetref\temp \conditionalstop
1088 }
1089 \endverbatim
1090
1091 The \tcmd\comparentries\ macro tests whether we are in equal entries
1092 relative to sorting and if so gives them a suffix.
1093
1094 \verbatim
1095 \newcount\sameentrycount
1096 \def\compareentries{%
1097 \ifequalentry
1098 \advance\sameentrycount1
1099 \WriteImmediateInfo{%
1100 \noexpand\expandafter\def
1101 \noexpand\csname\EntryKey @suffix\noexpand\endcsname
1102 {\toletter}}%
1103 \else \sameentrycount=0 \fi
1104 }
1105 \endverbatim
1106
1107 \noindent The \tcmd\toletter\ macro turns \tcmd\sameentrycount\
1108 into a letter and is quite uninteresting, so it isn't shown here.
1109 Note that this version of \tcmd\compareentries\ works because
1110 the first argument of \tcmd\SortOrder\ is set to `\texttt{name,year}',
1111 and hence two references written the same year by the same author
1112 are equal according to \lib, which can set the \tcmd\ifequelentry\
1113 conditional to the requested value. However, if \tcmd\SortOrder\
1114 was `\texttt{name,year,title}', then not only would the same two
1115 entries be sorted according to their titles,
1116 but most importantly they wouldn't be equal at all as far as \lib\
1117 is concerned (unless they have identical titles, of course),
1118 although in this bibliographic style they should be
1119 seen as such. In that case, \tcmd\compareentries\ should be more
1120 refined and store each entry's \texttt{name} and \texttt{year} fields
1121 in a macro to be compared to the next one.
1122
1123 But we were calling \tcmd\typesetref\ on the \texttt{entrytype} field.
1124 It launches a macro which typesets the rest of the entry according
1125 to its type, and \tcmd\createtype\ is meant to define such a macro:
1126
1127 \verbatim
1128 \def\typesetref#1{%
1129 \ifcsname#1@entrytype\endcsname
1130 \csname#1@entrytype\endcsname
1131 \else
1132 \errmessage{Unknown entry type: `#1'}%
1133 \fi
1134 }
1135 \def\createtype#1{%
1136 \expandafter\def\csname#1@entrytype\endcsname
1137 }
1138 \endverbatim
1139
1140 Before creating entries, here are some useful macros to be used with
1141 \tcmd\TypesetField. Indeed, to typeset references properly, punctuation
1142 should be added if and only if the corresponding field exists.
1143
1144 \verbatim
1145 \def\booktitle#1{\setbooktitle{\RetrieveField{#1}}}
1146 \def\setbooktitle#1{\italics{#1}}
1147 \def\articletitle#1{\setarticletitle{\RetrieveField{#1}}}
1148 \def\setarticletitle#1{`#1'}
1149 \def\addcomma#1{, #1}
1150 \def\addjournal#1{\addcomma{{\setbooktitle{#1}}}}
1151 \def\addcolon#1{: #1}
1152 \def\addpar#1{(#1)}
1153 \def\addbook#1{, in \setbooktitle{#1}}
1154 \def\addeditor#1{%
1155 \RetrieveFieldIn{editornumber}\tempcount
1156 , edited by \ReadEditor\makeedname}
1157 \endverbatim
1158
1159 \noindent The \tcmd\italics\ macro in \tcmd\setbooktitle\ should
1160 be set to whatever you use to typeset italics. Now, we can create
1161 entries:
1162
1163 \verbatim
1164 \createtype{book}{%
1165 \booktitle{title}%
1166 \TypesetField{publisher}\addcomma{}%
1167 \TypesetField{address}\addcolon{}%
1168 }
1169 \createtype{article}{%
1170 \articletitle{title}%
1171 \TypesetField{journal}\addjournal{}%
1172 \TypesetField{volume}\addcomma{}%
1173 \TypesetField{number}\addpar{}%
1174 \TypesetField{pages}\addcomma{}%
1175 }
1176 \createtype{incollection}{%
1177 \articletitle{title}%
1178 \TypesetField{crossref}\crossref{%
1179 \TypesetField{booktitle}\addbook{}%
1180 \TypesetField{editor}\addeditor{}%
1181 \TypesetField{pages}\addcomma{}%
1182 \TypesetField{publisher}\addcomma{}%
1183 \TypesetField{address}\addcolon{}%
1184 }%
1185 }
1186 \endverbatim
1187
1188 \noindent ... and many more! That's the basic job of a bibliographic
1189 style. Note that we make good use of \tcmd\TypesetField, but not with
1190 the \texttt{title} field, because it is very unlikely to be missing.
1191 Now, give a look at the \texttt{incollection} entry; once the title
1192 is typeset, it reads as follows: call the \tcmd\crossref\ macro on the
1193 value of the \texttt{crossref} field if it has any, otherwise, typeset
1194 the information about the book. And \tcmd\crossref\ is:
1195
1196 \verbatim
1197 \def\crossref#1{%
1198 , in \cite{#1}%
1199 \WriteImmediateInfo{\noexpand\Cite{#1}{main}{}{}}%
1200 }
1201 \endverbatim
1202
1203 \noindent Since the value of the \texttt{crossref} field is an entry key,
1204 we simply \tcmd\cite\ that entry. However, this is not enough; \tcmd\SortList\
1205 can deal with entries if and only if they are cited before it is called; on the
1206 other hand, \tcmd\ReadList, where the cross-reference happens, must appear after
1207 \tcmd\SortList. That's why we pass a \tcmd\Cite\ command to the next compilation;
1208 note that the third argument does nothing.
1209
1210 Thus, supposing the reference `\texttt{Gaddis1994}' has a \texttt{crossref} field to `\texttt{Gass2000}',
1211 \tcmd{\cite\targ{Gaddis1994}} in a document will produce the following in the
1212 bibliography:
1213
1214 \input authoryear
1215 \Cite{Gaddis1994}{main}{}{}
1216 \citation
1217 \SortList{main}
1218 \ReadList{main}
1219 \endcitation
1220
1221 What if we don't want to see the `\texttt{Gass2000}' reference in the bibliography
1222 and instead want something like this:
1223
1224 \citation
1225 \def\EntryKey{gaddis1994}
1226 \RetrieveFieldIn{namenumber}\tempcount
1227 \ReadName\makerefname~(\RetrieveField{year})
1228 `\RetrieveField{title}', in
1229 \def\EntryKey{gass2000}
1230 \RetrieveFieldIn{namenumber}\tempcount
1231 \booktitle{title}, edited by \ReadName\makeedname,
1232 \RetrieveField{publisher}: \RetrieveField{address},
1233 \RetrieveField{year}.
1234 \endcitation
1235
1236 \noindent Then \tcmd\crossref\ should be something like this:
1237
1238 \verbatim
1239 \def\crossref#1{%
1240 \bgroup
1241 \lowercase{\def\EntryKey{#1}}%
1242 \TypesetField{title}\addbook{}%
1243 \TypesetField{editor}\addeditor{}%
1244 \TypesetField{pages}\addcomma{}%
1245 \TypesetField{publisher}\addcomma{}%
1246 \TypesetField{address}\addcolon{}%
1247 \TypesetField{year}\addcomma{}%
1248 \egroup
1249 \WriteImmediateInfo{\noexpand\Cite{#1}{crossref}{}{}}%
1250 }
1251 \endverbatim
1252
1253 \noindent That is: we apply the same macros to a different entry
1254 by redefining \tcmd\EntryKey\ temporarily (hence the group). Note
1255 that this redefinition must happen in \tcmd\lowercase, because there
1256 we're away from \lib's handling of entry keys. Note also that we
1257 still \tcmd\Cite\ the entry in the external file, because the citation
1258 is necessary to retrieve fields in the bibliographic files; however
1259 the entry is added to a secondary list `\texttt{crossref}' that we'll never
1260 sort nor read.
1261
1262 \vskip 0pt plus 1filll
1263 \parfillskip0pt
1264 \noindent\hfill {\it Typeset with Lua\TeX\ v.0.6}\par
1265 \noindent\hfill {\it in Garamond Pro (Robert Slimbach)}\par
1266 \noindent\hfill {\it and Inconsolata (Raph Levien)}\par
1267
1268 \makebookmarks
1269
1270 \BibFile{librarian}
1271 \bye