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\writestatus{loading}{ConTeXt Bibliography Support BibTeX}
36
37\definefilesynonym[bib][obsolete]
38
39\registerctxluafile{bibltra}{}
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\unprotect
189
190\def\biblistname{pubs}
191
192\definelist
193 [pubs]
194
195\setuplist
196 [pubs]
197 [\c!state=\v!start,
198 \c!criterium=\@@pbcriterium,
199 \c!headnumber=\v!always,
200 \c!width=]
201
202\installstructurelistprocessor{pubs:userdata}
203 {\ctxlua{bibtex.hacks.add(structures.lists.uservalue("\currentlist",\currentlistindex,"bibref"),\currentlistindex)}}
204
205\ifdefined\bibtexblock \else \newinteger\bibtexblock \fi \bibtexblock\plusone
206\ifdefined\bibtexcounter \else \newinteger\bibtexcounter \fi
207
208
209
210
211
212
213\protected\def\bibdoifelse#1
214 {\expandafter\def\expandafter\!!stringa\expandafter{#1}
215 \ifempty\!!stringa
216 \expandafter\secondoftwoarguments
217 \else
218 \expandafter\firstoftwoarguments
219 \fi}
220
221\protected\def\bibdoifnot#1
222 {\expandafter\def\expandafter\!!stringa\expandafter{#1}
223 \ifempty\!!stringa
224 \expandafter\firstofoneargument
225 \else
226 \expandafter\gobbleoneargument
227 \fi}
228
229\protected\def\bibdoif#1
230 {\expandafter\def\expandafter\!!stringa\expandafter{#1}
231 \ifempty\!!stringa
232 \expandafter\gobbleoneargument
233 \else
234 \expandafter\firstofoneargument
235 \fi}
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255\newtoks\everysetupbibtex
256
257\protected\def\setupbibtex
258 {\dosingleempty\dosetupbibtex}
259
260\protected\def\dosetupbibtex[#1]
261 {\lettonothing\@@pbdatabase
262 \getparameters[\??pb][#1]
263 \the\everysetupbibtex}
264
265\protected\def\installbibtexsorter#1#2
266 {\setvalue{\??pb:\c!sort:#1}{#2}}
267
268\installbibtexsorter\v!no {no}
269\installbibtexsorter\v!author {au}
270\installbibtexsorter\v!title {ti}
271\installbibtexsorter\v!short {ab}
272\installbibtexsorter\empty {no}
273\installbibtexsorter\s!default{no}
274
275\def\thebibtexsorter{\executeifdefined{\??pb:\c!sort:\@@pbsort}\@@pbsort}
276
277\appendtoks
278 \ifempty\@@pbdatabase\else
279 \doifmode{*\v!first}{\ctxlua{bibtex.hacks.process { style="\thebibtexsorter", database="\@@pbdatabase" }}}
280 \fi
281\to \everysetupbibtex
282
283\setupbibtex
284 [\c!sorttype=\v!cite,
285 \c!sort=no]
286
287
288
289
290
291\newtoks\everysetuppublications
292
293\protected\def\setuppublications
294 {\dosingleargument\dosetuppublications}
295
296\protected\def\dosetuppublications[#1]
297 {\getparameters[\??pb][\c!alternative=,#1]
298 \doifsomething\@@pbalternative
299 {\readsysfile{bibl\@@pbalternative.tex}
300 {\showmessage\m!publications{6}{bibl\@@pbalternative}}
301 {\showmessage\m!publications{1}{bibl\@@pbalternative}}
302 \lettonothing\@@pbalternative}
303 \let\setuppublicationlayout\normalsetuppublicationlayout
304 \getparameters[\??pb][#1]
305 \the\everysetuppublications
306 \ignorespaces}
307
308
309
310
311\setnewconstant\bibtexoncemode\plusone
312
313\appendtoks
314 \doifelse\@@pbmethod\v!local
315 {\bibtexoncemode\plusone}
316 {\bibtexoncemode\plustwo}
317\to \everysetuppublications
318
319
320
321\newif\ifbibcitecompress\bibcitecompresstrue
322
323\def\@@pbinumbercommand{\executeifdefined{\??pb:\c!numbercommand:\@@pbnumbering}\firstofoneargument}
324
325\setvalue{\??pb:\c!numbercommand:\v!yes }#1{#1}
326\setvalue{\??pb:\c!numbercommand:\v!no }#1{}
327\setvalue{\??pb:\c!numbercommand:\v!short}#1{\bibgetvars\currentpublicationkey}
328\setvalue{\??pb:\c!numbercommand:\v!bib }#1{\bibgetvarn\currentpublicationkey}
329
330
331
332
333
334
335\appendtoks
336 \processaction
337 [\@@pbrefcommand]
338 [\s!default=>\edef\@@citedefault{\@@pbrefcommand},
339 \s!unknown=>\edef\@@citedefault{\@@pbrefcommand}]
340\to \everysetuppublications
341
342\protected\def\bibleftnumber#1{#1\hfill}
343
344
345
346
347
348
349
350
351\protected\def\usepublications[#1]
352 {\processcommalist[#1]\dousepublications}
353
354\protected\def\dousepublications#1
355 {\doonlyonce{#1.\f!bibextension}{\dodousepublications{#1}}}
356
357\pushoverloadmode
358
359\protected\def\dodousepublications#1
360 {\enforced\let\par\ignorespaces
361 \ifhmode\kern\zeropoint\fi
362 \pushcatcodetable
363 \setcatcodetable\ctxcatcodes
364 \readfile{#1.\f!bibextension}
365 {\showmessage\m!publications{4}{#1.\f!bibextension}}
366 {\showmessage\m!publications{2}{#1.\f!bibextension}}
367 \popcatcodetable
368 \ifhmode\removeunwantedspaces\fi
369 \enforced\let\par\normalpar}
370
371\popoverloadmode
372
373
374
375
376
377
378
379
380
381
382
383
384\def\publicationlistparameter#1{\csname\??pv:l:#1\endcsname}
385
386\protected\def\setuppublicationlist
387 {\dosingleempty\dosetuppublicationlist}
388
389\protected\def\dosetuppublicationlist[#1]
390 {\getparameters[\??pv:l:][#1]
391 \setuplist[pubs][\c!samplesize={AA99},\c!alternative=a,\c!interaction=,\c!pagenumber=\v!no,#1,\c!command=]}
392
393\protected\def\setuppublicationlayout[#1]#2
394 {\setvalue{\??pv:l:#1}{#2}}
395
396\let\normalsetuppublicationlayout\setuppublicationlayout
397
398\setuppublicationlist
399 [\c!title=,
400 \c!command=\dospecialbibinsert,
401 \c!maybeyear=\v!on]
402
403
404
405
406
407
408\def\bibalternative#1
409 {\csname\??pv\@@currentalternative#1\endcsname}
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428\newtoks\initializebibdefinitions
429
430\protected\def\simplebibdef#1
431 {\expandafter\def\csname bib@#1\endcsname##1
432 {\setvalue{\??pb @#1}{##1}\ignorespaces}
433 \expandafter \appendtoks
434 \expandafter\let\csname insert#1\expandafter\endcsname\csname bibinsert#1\endcsname
435 \to \initializebibdefinitions
436 \expandafter\protected\expandafter\def\csname bibinsert#1\endcsname##1##2##3
437 {\expandafter\bibdoifelse\expandafter{\csname\??pb @#1\endcsname}{##1\csname\??pb @#1\endcsname##2}{##3}}}
438
439\def\bibcommandlist
440 {abstract, annotate, arttitle, assignee, bibnumber, bibtype, biburl, chapter, city,
441 comment, country, day, dayfiled, doi, edition, eprint, howpublished, isbn, issn,
442 issue, journal, keyword, keywords, lastchecked, month, monthfiled, names, nationality,
443 note, notes, organization, pages, pubname, pubyear, revision, series, size, thekey,
444 title, volume, yearfiled}
445
446\processcommacommand[\bibcommandlist]\simplebibdef
447
448\protected\def\bibinsertdoi#1#2#3
449 {\bibdoifelse{\@@pb@doi}{#1\normalexpanded{\bibgotoDOI{\@@pb@thekey}{\@@pb@doi}}#2}{#3}}
450
451\protected\def\bibinsertbiburl#1#2#3
452 {\bibdoifelse{\@@pb@biburl}{#1\normalexpanded{\bibgotoURL{\@@pb@thekey}{\@@pb@biburl}}#2}{#3}}
453
454\protected\def\bibinsertmonth#1#2#3
455 {\bibdoifelse\@@pb@month
456 {#1\doifelsenumber\@@pb@month
457 {\doifelseconversiondefined\@@pbmonthconversion
458 {\convertnumber\@@pbmonthconversion\@@pb@month}{\@@pb@month}}
459 {\@@pb@month}#2}
460 {#3}}
461
462\appendtoks
463 \let\inserturl \bibinsertbiburl
464 \let\inserttype\bibinsertbibtype
465\to\initializebibdefinitions
466
467\protected\def\newbibfield[#1]
468 {\simplebibdef{#1}
469 \edef\bibcommandlist{\bibcommandlist,#1}}
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497\protected\def\docomplexbibdef#1
498 {\dodoubleempty\dodocomplexbibdef[#1]}
499
500\protected\def\dodocomplexbibdef[#1][#2]#3
501 {\doquadrupleempty\dododocomplexbibdef[#1][#2][#3]}
502
503\protected\def\dododocomplexbibdef[#1][#2][#3][#4]#5#6
504 {\expandafter\increment\csname#1@num\endcsname
505 \setevalue{\??pb @#1\csname#1@num\endcsname}{{#3}{#5}{#6}{#4}{#2}}\ignorespaces}
506
507\protected\def\complexbibdef#1
508 {\expandafter\newcounter\csname #1@num\endcsname
509 \expandafter\def\csname bib@#1\endcsname{\docomplexbibdef{#1}}
510 \expandafter \appendtoks
511 \expandafter\let\csname insert#1s\expandafter\endcsname\csname bibinsert#1s\endcsname
512 \to \initializebibdefinitions
513 \expandafter\def\csname bibinsert#1s\endcsname##1##2##3{\specialbibinsert{#1}{\csname #1@num\endcsname}{##1}{\unskip ##2}{##3}}}
514
515\processcommalist[author,artauthor,editor]\complexbibdef
516
517
518
519
520\newinteger\etallimitcounter
521\newinteger\etaldisplaycounter
522\newinteger\todocounter
523
524\protected\def\specialbibinsert#1#2#3#4#5
525 {\bgroup
526 \ifnum#2>\zerocount
527 \etallimitcounter =0\bibalternative{#1etallimit}\relax
528 \etaldisplaycounter=0\bibalternative{#1etaldisplay}\relax
529 \ifnum #2>\etallimitcounter
530 \todocounter\etaldisplaycounter
531
532 \ifnum\todocounter>\etallimitcounter
533 \todocounter\etallimitcounter
534 \fi
535 \else
536 \todocounter#2\relax
537 \fi
538 \ifnum\todocounter>\zerocount
539
540 \lettonothing\templist
541 \dorecurse{#2}
542 {\scratchtoks\doubleexpandafter{\csname\??pb @#1\recurselevel\endcsname}
543 \edef\templist{\ifempty\templist\else\templist,\fi\the\scratchtoks}}
544 #3\publicationlistparameter\c!command{#1}{\todocounter}{\templist}#4\relax
545 \else
546 #5
547 \fi
548 \else
549 #5
550 \fi
551 \egroup}
552
553
554
555
556
557
558
559
560
561\protected\def\doprocessauthoritem#1#2#3
562 {\advanceby\scratchcounter\plusone
563 \ifnum\numexpr\scratchcounter\plusone\relax<#2\relax
564 \publicationlistparameter{#1}#3
565 \ifnum\scratchcounter=#2\relax
566 \ifnum\etallimitcounter<\commalistsize\relax
567 \bibalternative{#1etaltext}
568 \fi
569 \orelse\ifnum\numexpr\scratchcounter\plusone\relax=#2\relax
570 \ifnum\commalistsize>\plustwo
571 \bibalternative\c!finalnamesep
572 \else
573 \bibalternative\c!lastnamesep
574 \fi
575 \else
576 \bibalternative\c!namesep
577 \fi
578 \fi}
579
580\protected\def\dospecialbibinsert#1#2#3
581 {\getcommacommandsize[#3]
582 \scratchcounter\zerocount
583 \processcommacommand[#3]{\doprocessauthoritem{#1}{#2}}}
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601\protected\def\normalauthor#1#2#3#4#5
602 {\bibdoif{#1}{#1\bibalternative\c!firstnamesep}
603 \bibdoif{#2}{#2\bibalternative\c!vonsep}
604 #3
605 \bibdoif{#5}{\bibalternative\c!surnamesep#5\unskip}}
606
607\protected\def\normalshortauthor#1#2#3#4#5
608 {\bibdoif{#4}{#4\bibalternative\c!firstnamesep}
609 \bibdoif{#2}{#2\bibalternative\c!vonsep}
610 #3
611 \bibdoif{#5}{\bibalternative\c!surnamesep#5\unskip}}
612
613\protected\def\invertedauthor#1#2#3#4#5
614 {\bibdoif{#2}{#2\bibalternative\c!vonsep}
615 #3
616 \bibdoif{#5}{\bibalternative\c!juniorsep#5}
617 \bibdoif{#1}{\bibalternative\c!surnamesep#1\unskip}}
618
619\protected\def\invertedshortauthor#1#2#3#4#5
620 {\bibdoif{#2}{#2\bibalternative\c!vonsep}
621 #3
622 \bibdoif{#5}{\bibalternative\c!juniorsep#5}
623 \bibdoif{#4}{\bibalternative\c!surnamesep#4\unskip}}
624
625
626
627
628
629
630\protected\def\clearbibitem#1{\setvalue{\??pb @#1}{}}
631
632\protected\def\clearbibitemtwo#1
633 {
634 \letvalue{#1@num}\!!zerocount}
635
636\protected\def\bibitemdefs#1
637 {\expandafter\let\csname#1\expandafter\endcsname\csname bib@#1\endcsname}
638
639\protected\def\presetbibvariables
640 {\processcommacommand[\bibcommandlist,crossref]\clearbibitem
641 \processcommalist [artauthor,author,editor]\clearbibitemtwo
642 \processcommacommand[\bibcommandlist]\bibitemdefs
643 \processcommalist [artauthor,author,editor,crossref]\bibitemdefs}
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667\pushoverloadmode
668
669\overloaded \protected\def\startpublication
670 {\dosingleempty\dostartpublication}
671
672\overloaded\let\stoppublication\relax
673
674\popoverloadmode
675
676
677
678
679
680
681
682
683
684
685
686
687
688\protected\def\dostartpublication[#1]
689 {\begingroup
690 \doifelseassignment{#1}
691 {\getparameters[\??pb][k=\s!unknown,t=article,n=,s=,a=,y=,o=,u=,#1]}
692 {\getparameters[\??pb][k=#1,t=article,n=,s=,a=,y=,o=,u=]}
693 \ctxlua{bibtex.hacks.register(\!!bs\@@pbk\!!es,\!!bs\@@pbs\!!es)}
694 \catcode\commentasciicode\othercatcode
695 \dodostartpublication}
696
697\protected\def\dodostartpublication#1\stoppublication
698 {\setxvalue{pbd:\@@pbk}##1{\noexpand\ifcase##1\noexpand\or
699 \@@pbk\noexpand\or
700 \@@pba\noexpand\or
701 \@@pby\noexpand\or
702 \@@pbs\noexpand\or
703 \@@pbn\noexpand\or
704 \@@pbt\noexpand\or
705 \@@pbo\noexpand\or
706 \@@pbu\noexpand\or
707 \normalunexpanded{#1}\noexpand\fi}
708 \endgroup
709 \ignorespaces}
710
711\def\bibgetvark#1{\csname pbd:#1\endcsname\plusone }
712\def\bibgetvara#1{\csname pbd:#1\endcsname\plustwo }
713\def\bibgetvary#1{\csname pbd:#1\endcsname\plusthree}
714\def\bibgetvars#1{\csname pbd:#1\endcsname\plusfour }
715\def\bibgetvarn#1{\csname pbd:#1\endcsname\plusfive }
716\def\bibgetvart#1{\csname pbd:#1\endcsname\plussix }
717\def\bibgetvaro#1{\csname pbd:#1\endcsname\plusseven}
718\def\bibgetvaru#1{\csname pbd:#1\endcsname\pluseight}
719\def\bibgetvard#1{\csname pbd:#1\endcsname\plusnine }
720
721\protected\def\doifelsebibreferencefound#1
722 {\preloadbiblist
723 \doifelsedefined{pbd:#1}
724 \firstoftwoarguments
725 {\showmessage\m!publications{5}{#1,\the\inputlineno}\secondoftwoarguments}}
726
727\let\doifbibreferencefoundelse\doifelsebibreferencefound
728
729
730
731
732
733
734
735
736
737
738\protected\def\bib@crossref#1
739 {\setvalue{\??pb @crossref}{#1}\ignorespaces}
740
741\protected\def\bibinsertcrossref#1#2#3
742 {\bibdoifelse\@@pb@crossref{#1\cite[\@@pb@crossref]#2}{#3}}
743
744\let\insertcrossref\gobblethreearguments
745
746\appendtoks\let\insertcrossref\bibinsertcrossref\to\initializebibdefinitions
747
748
749
750
751
752
753\protected\def\doprocessbibtexentry#1{\typesetapublication{#1}}
754
755\protected\def\typesetpubslist
756 {\begingroup
757 \startpacked[\v!blank]
758 \preloadbiblist
759
760 \edef\currentlist{pubs}
761 \ctxlua{bibtex.hacks.reset(\number\bibtexoncemode)}
762 \doifelse{\listparameter\c!criterium}\v!all
763 {\showmessage\m!publications{7}{}
764 \ctxlua{bibtex.hacks.filterall()}}
765 {\doif{\listparameter\c!criterium}\v!cite
766 {\setuplist[pubs][\c!criterium=\v!here]}
767 \strc_lists_place_current
768 {pubs}
769 {\listparameter\c!criterium}
770 {}
771 {\listparameter\c!extras}
772 {\listparameter\c!order}}
773 {}
774 \ctxlua{bibtex.hacks.flush("\@@pbsorttype")}
775 \stoppacked
776 \endgroup}
777
778\newif\ifinpublist
779
780\protected\def\initializepubslist
781 {\def\currentlist{pubs}
782 \edef\@@pbnumbering{\@@pbnumbering}
783 \doifelse\@@pbautohang\v!yes
784 {\ifx\@@pbnumbering\v!short
785 \setbox\scratchbox\hbox{\@@pbnumbercommand{\listparameter\c!samplesize}}
786 \else
787 \doifelse{\listparameter\c!criterium}\v!all
788 {\setbox\scratchbox\hbox{\@@pbnumbercommand{\ctxlua{tex.write{bibtex.hacks.nofregistered()}}}}}
789 {\determinelistcharacteristics[pubs]
790 \setbox\scratchbox\hbox{\@@pbnumbercommand{\structurelistsize}}}
791 \fi
792 \edef\publistnumberbox{\hbox to \the\wd\scratchbox}
793 \normalexpanded{\setuplist[pubs][\c!width=\the\wd\scratchbox,\c!distance=\zeropoint]}
794 \ifx\@@pbnumbering\v!short
795 \def\@@pblimitednumber##1{\publistnumberbox{\@@pbnumbercommand{\bibgetvars\currentpublicationkey}}}
796 \orelse\ifx\@@pbnumbering\v!bib
797 \def\@@pblimitednumber##1{\publistnumberbox{\@@pbnumbercommand{\bibgetvarn\currentpublicationkey}}}
798 \else
799 \def\@@pblimitednumber##1{\publistnumberbox{\@@pbnumbercommand{##1}}}
800 \fi}
801 {\doifelsenothing{\listparameter\c!width}
802 {\let \publistnumberbox \hbox}
803 {\edef\publistnumberbox{\hbox to \listparameter\c!width}}
804 \ifx\@@pbnumbering\v!short
805 \def\@@pblimitednumber##1{\publistnumberbox{\@@pbnumbercommand{\bibgetvars\currentpublicationkey}}}
806 \orelse\ifx\@@pbnumbering\v!bib
807 \def\@@pblimitednumber##1{\publistnumberbox{\@@pbnumbercommand{\bibgetvarn\currentpublicationkey}}}
808 \else
809 \def\@@pblimitednumber##1{\publistnumberbox{\@@pbnumbercommand{##1}}}
810 \fi}
811 \ifx\@@pbnumbering\v!no
812 \setuplist[pubs][\c!numbercommand=,\c!symbol=\v!none,\c!textcommand=\outdented]
813 \else
814 \setuplist[pubs][\c!numbercommand=\@@pblimitednumber]
815 \fi
816 \doifelse{\publicationlistparameter\c!maybeyear}{\v!off}{\def\maybeyear##1{}}{\def\maybeyear##1{##1}}
817 \forgetall}
818
819
820
821\protected\def\completepublications
822 {\dosingleempty\docompletepublications}
823
824\protected\def\docompletepublications[#1]
825 {\begingroup
826 \setuplist[pubs][#1]
827 \edef\currentbibtexsessiontitle{\publicationlistparameter\c!title}
828 \ifempty\currentbibtexsessiontitle
829 \normalexpanded{\startnamedsection[\v!chapter][\c!reference=pubs,\c!title={\headtext{pubs}}]}
830 \else
831 \normalexpanded{\startnamedsection[\v!chapter][\c!reference=pubs,\c!title={\currentbibtexsessiontitle}]}
832 \fi
833 \dodoplacepublications
834 \stopnamedsection
835 \endgroup}
836
837
838
839\def\bibrefprefix{\number\bibtexblock:}
840
841\protected\def\placepublications
842 {\dosingleempty\doplacepublications}
843
844\protected\def\doplacepublications[#1]
845 {\begingroup
846 \setuplist[pubs][#1]
847 \dodoplacepublications
848 \endgroup}
849
850\protected\def\dodoplacepublications
851 {\determinelistcharacteristics[pubs]
852 \initializepubslist
853 \doifnot{\namedlistparameter{pubs}\c!option}\v!continue
854 {\global\bibtexcounter\zerocount}
855 \inpublisttrue
856 \typesetpubslist
857 \inpublistfalse
858 \global\advanceby\bibtexblock\plusone}
859
860
861
862
863
864
865\protected\def\typesetapublication#1
866 {\doifsomething{#1}
867 {\doifelse{\namedlistparameter{pubs}\c!criterium}\v!all
868 {\doplacepublicationindeed{#1}}
869 {\ctxlua{bibtex.hacks.doifalreadyplaced("#1")}
870 {}
871 {\doplacepublicationindeed{#1}}}
872 }}
873
874
875
876
877
878
879\protected\def\doplacepublicationindeed#1
880 {\doifelsebibreferencefound{#1}
881 {\global\advanceby\bibtexcounter\plusone
882 \def\currentpublicationkey{#1}
883 \ctxlua{bibtex.hacks.registerplaced("#1")}
884 \def\currentlist{pubs}
885 \edef\currentlistentrynumber{\number\bibtexcounter}
886 \let\currentlistentrytitle\bibtexpubtext
887 \lettonothing\currentlistentrypagenumber
888 \strc_lists_apply_renderingsetup}
889 {}}
890
891\protected\def\bibtexpubtext
892 {\normalexpanded{\reference[\bibrefprefix\currentpublicationkey]{\number\bibtexcounter}}
893 \strut\dotypesetapublication\currentpublicationkey\strut}
894
895\protected\def\dotypesetapublication#1
896 {\bgroup
897 \the\initializebibdefinitions
898 \def\@@currentalternative{:l:}
899 \presetbibvariables
900 \lettonothing\biblanguage
901 \ignorespaces
902 \bibgetvard{#1}
903 \removeunwantedspaces
904 \ignorespaces
905 \bibalternative{\bibgetvart{#1}}
906 \removeunwantedspaces
907 \egroup}
908
909
910
911\let\maybeyear\gobbleoneargument
912\let\noopsort \gobbleoneargument
913
914
915
916\protected\def\setbiblanguage#1#2{\setvalue{\??pb\s!language#1}{#2}}
917
918\protected\def\lang#1
919 {\edef\biblanguage{#1}
920 \ifcsname\??pb\s!language#1\endcsname
921 \language[\getvalue{\??pb\s!language#1}]
922 \fi
923 \ignorespaces}
924
925
926
927
928
929
930
931
932
933\pushoverloadmode
934
935\protected\def\cite
936 {\strictdoifelsenextoptional\dodocite\dobibref}
937
938\popoverloadmode
939
940\protected\def\dobibref#1
941 {\docite[#1][]}
942
943\protected\def\dodocite[#1]
944 {\strictdoifelsenextoptional{\docite[#1]}{\docite[#1][]}}
945
946\protected\def\docite[#1][#2]
947 {\begingroup
948 \doifelsesomething{#2}
949 {\dowhatevercite{#1}{#2}}
950 {\donumberedcite{#1}}
951 \endgroup}
952
953\protected\def\dowhatevercite#1#2
954 {\processcommalist[#2]\docitation
955 \setupinteraction[\c!style=]
956 \doifelseassignment
957 {#1}
958 {\getparameters[LO][\c!alternative=,\c!extras=,#1]
959 \edef\@@currentalternative{\LOalternative}
960 \ifempty\@@currentalternative
961 \edef\@@currentalternative{\@@citedefault}
962 \fi
963 \ifempty\LOextras
964 \setupcite[\@@currentalternative][#1]
965 \else
966 \expandafter\ifrelax\csname\??pv\@@currentalternative\c!right\endcsname
967
968 \expandafter\lettonothing\csname\??pv\@@currentalternative\c!right\endcsname
969 \fi
970 \expandafter\ifrelax\csname LOright\endcsname
971 \edef\LOextras{{\LOextras\bibalternative\c!right}}
972 \else
973 \edef\LOextras{{\LOextras\LOright}}
974 \fi
975 \normalexpanded{\setupcite[\@@currentalternative][#1,\c!right=\LOextras]}
976 \fi}
977 {\def\@@currentalternative{#1}}
978 \doifelsevalue{@@pv\@@currentalternative\c!compress}\v!no\bibcitecompressfalse\bibcitecompresstrue
979 \getvalue{bib\@@currentalternative ref}[#2]}
980
981\protected\def\donumberedcite#1
982 {\processcommalist[#1]\docitation
983 \setupinteraction[\c!style=]
984 \edef\@@currentalternative{\@@citedefault}
985 \doifelsevalue{@@pv\@@currentalternative\c!compress}\v!no\bibcitecompressfalse\bibcitecompresstrue
986 \getvalue{bib\@@citedefault ref}[#1]}
987
988
989
990\pushoverloadmode
991
992\protected\def\nocite[#1]
993 {\processcommalist[#1]\docitation}
994
995\popoverloadmode
996
997
998
999\permanent\tolerant\protected\def\setupcite[#1]#*[#2]
1000 {\ifparameter#2\or
1001 \def\dodosetupcite##1{\getparameters[\??pv##1][#2]}
1002 \processcommalist[#1]\dodosetupcite
1003 \else
1004 \getparameters[\??pv\@@citedefault][#1]
1005 \fi}
1006
1007
1008
1009\protected\def\getcitedata#1[#2]#*[#3]#*to#4
1010 {\bgroup
1011 \dofetchapublication{#3}
1012 \doifelsedefined{\??pb @bib#2}
1013 {\xdef#4{\getvalue{\??pb @bib#2}}}
1014 {\xdef#4{\getvalue{\??pb @#2}}}
1015 \egroup}
1016
1017\protected\def\dofetchapublication#1
1018 {\def\currentpublicationkey{#1}
1019 \presetbibvariables
1020 \ignorespaces\bibgetvard{#1}}
1021
1022\protected\def\docitation#1
1023 {\iftrialtypesetting \else
1024 \normalexpanded{\writedatatolist[pubs][bibref=#1]}
1025 \fi}
1026
1027\let\addthisref\gobbleoneargument
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060\lettonothing\currentbibauthor
1061
1062\protected\def\ixbibauthoryear#1#2#3#4
1063 {\bgroup
1064 \gdef\ixlastcommand{#4}
1065 \gdef\ixsecondcommand{#3}
1066 \gdef\ixfirstcommand{#2}
1067 \glettonothing\thebibauthors
1068 \glettonothing\thebibyears
1069 \getcommalistsize[#1]
1070 \ifbibcitecompress
1071 \dorecurse\commalistsize{\xdef\thebibyears{\thebibyears,}}
1072 \processcommalist[#1]\docompressbibauthoryear
1073 \else
1074 \processcommalist[#1]\donormalbibauthoryear
1075 \fi
1076 \egroup
1077 \dobibauthoryear}
1078
1079
1080
1081
1082
1083
1084\protected\def\dobibauthoryear
1085 {\scratchcounter\zerocount
1086 \getcommacommandsize[\thebibauthors]
1087 \edef\authorcount{\commalistsize}
1088 \expandafter\processcommalist\expandafter[\thebibauthors]\dodobibauthoryear}
1089
1090\protected\def\dodobibauthoryear#1
1091 {\advanceby\scratchcounter\plusone
1092 \edef\wantednumber{\the\scratchcounter}
1093 \getfromcommacommand[\thebibyears][\wantednumber]
1094 \expandafter\def\expandafter\currentbibyear\expandafter{\commalistelement}
1095 \setcurrentbibauthor{#1}
1096 \ifnum\scratchcounter=\plusone
1097 \ixfirstcommand
1098 \orelse\ifnum \scratchcounter=\authorcount\relax
1099 \ixlastcommand
1100 \else
1101 \ixsecondcommand
1102 \fi}
1103
1104\protected\def\setcurrentbibauthor#1
1105 {\getcommacommandsize[#1]
1106 \ifcase\commalistsize
1107
1108 \lettonothing\currentbibauthor
1109 \or
1110 \def\currentbibauthor{#1}
1111 \or
1112 \normalexpanded{\docurrentbibauthor#1}
1113 \else
1114 \handlemultiplebibauthors{\commalistsize}{#1}
1115 \fi}
1116
1117\newinteger\citescratchcounter
1118
1119\protected\def\handlemultiplebibauthors#1#2
1120 {\citescratchcounter\zerocount
1121 \lettonothing\currentbibauthor
1122 \protected\def\bibprocessauthoritem##1
1123 {\advanceby\citescratchcounter\plusone
1124 \ifnum \citescratchcounter=#1\relax
1125 \edef\currentbibauthor{\currentbibauthor##1}
1126 \orelse\ifnum\numexpr\citescratchcounter\plusone\relax=#1\relax
1127 \edef\currentbibauthor{\currentbibauthor##1\bibalternative{andtext}}
1128 \else
1129 \edef\currentbibauthor{\currentbibauthor##1\bibalternative{namesep}}
1130 \fi}
1131 \processcommalist[#2]\bibprocessauthoritem}
1132
1133\setupcite
1134 [author,authoryear,authoryears]
1135 [\c!namesep={, }]
1136
1137
1138
1139
1140\protected\def\docurrentbibauthor#1,#2
1141 {\doifelseempty{#2}
1142 {\def\currentbibauthor{#1\bibalternative{otherstext}}}
1143 {\expandafter\ifrelax\csname\??pv\@@currentalternative authoretallimit\endcsname
1144 \edef\currentbibauthor{#1\bibalternative{andtext}#2}
1145 \else
1146 \edef\currentbibauthor{#1
1147 \ifcase0\bibalternative{authoretallimit}\relax\or
1148 \bibalternative{otherstext}\else\bibalternative{andtext}#2\fi}
1149 \fi}}
1150
1151
1152
1153
1154\pushoverloadmode
1155
1156
1157
1158
1159
1160 \protected\def\robustaddtocommalist#1#2
1161 {\robustdoifelseinset{#1}#2\donothing{\xdef#2{\ifempty#2\else#2,\fi#1}}}
1162
1163\popoverloadmode
1164
1165
1166
1167
1168
1169
1170\protected\def\donormalbibauthoryear#1
1171 {\def\myauthor{Xxxxxxxxxx}
1172 \def\myyear{0000}
1173 \doifelsebibreferencefound{#1}
1174 {\def\myauthor{{\bibgetvara{#1}}}
1175 \def\myyear {\bibgetvary{#1}}}
1176 {}
1177 \expandafter\doglobal\expandafter\appendtocommalist\expandafter{\myauthor}\thebibauthors
1178 \expandafter\doglobal\expandafter\appendtocommalist\expandafter{\myyear }\thebibyears}
1179
1180
1181
1182
1183
1184
1185
1186\protected\def\docompressbibauthoryear#1
1187 {\def\myauthor{Xxxxxxxxxx}
1188 \def\myyear {0000}
1189 \doifelsebibreferencefound{#1}
1190 {\xdef\myauthor{\bibgetvara{#1}}
1191 \xdef\myyear {\bibgetvary{#1}}}
1192 {}
1193 \ifempty\myauthor\else
1194 \checkifmyauthoralreadyexists
1195 \findmatchingyear
1196 \fi}
1197
1198
1199
1200
1201\newinteger\bibitemcounter
1202\newinteger\bibitemwanted
1203
1204
1205
1206
1207
1208
1209\protected\def\checkifmyauthoralreadyexists
1210 {\doifelseemptyvalue{thebibauthors}
1211 {\global\bibitemwanted \plusone
1212 \global\bibitemcounter\plusone
1213 \xdef\thebibauthors{{\myauthor}}}
1214 {
1215
1216 \expandafter\getcommalistsize\expandafter[\thebibauthors,]
1217 \global\bibitemcounter\numexpr\commalistsize\minusone\relax
1218 \global\bibitemwanted \zerocount
1219 \processcommacommand[\thebibauthors]\docomparemyauthor}}
1220
1221
1222
1223
1224
1225
1226
1227\protected\def\docomparemyauthor#1
1228 {\global\advanceby\bibitemwanted \plusone
1229 \def\mytempc{#1}
1230 \ifx\mytempc\myauthor
1231 \quitcommalist
1232 \orelse\ifnum\bibitemwanted=\bibitemcounter\relax
1233 \global\advanceby\bibitemwanted \plusone
1234 \global\bibitemcounter\bibitemwanted\relax
1235 \expandafter\doglobal\expandafter\robustaddtocommalist\expandafter{{\myauthor}}\thebibauthors
1236 \fi}
1237
1238
1239
1240\protected\def\findmatchingyear
1241 {\edef\wantednumber{\the\bibitemwanted}
1242 \getfromcommacommand[\thebibyears][\wantednumber]
1243 \ifempty\commalistelement
1244 \edef\myyear{{\myyear}}
1245 \else
1246 \edef\myyear{{\commalistelement,\myyear}}
1247 \fi
1248 \edef\newcommalistelement{\myyear}
1249 \doglobal\replaceincommalist \thebibyears \wantednumber}
1250
1251
1252
1253
1254
1255
1256
1257\protected\def\gotobiblink#1[#2]{\doifelsereferencefound{\bibrefprefix#2}{\goto{#1}[\bibrefprefix#2]}{#1}}
1258\protected\def\atbiblink [#1]{\doifelsereferencefound{\bibrefprefix#1}{\at[\bibrefprefix#1]}{#1}}
1259\protected\def\inbiblink [#1]{\doifelsereferencefound{\bibrefprefix#1}{\normalexpanded{\goto{\currentreferencetext}}[\bibrefprefix#1]}{#1}}
1260
1261
1262
1263
1264
1265
1266
1267\protected\def\doifelsebibinteraction
1268 {\iflocation
1269 \edef\test{\bibalternative\c!interaction}
1270 \ifx\test\v!stop
1271 \doubleexpandafter\secondoftwoarguments
1272 \else
1273 \doubleexpandafter\firstoftwoarguments
1274 \fi
1275 \else
1276 \expandafter\secondoftwoarguments
1277 \fi}
1278
1279\let\doifbibinteractionelse\doifelsebibinteraction
1280
1281\protected\def\bibmaybeinteractive#1#2
1282 {\doifelsebibinteraction{\gotobiblink{#2}[#1]}{#2}}
1283
1284\protected\def\bibauthoryearref[#1]
1285 {\ixbibauthoryear{#1}
1286 {\bibmaybeinteractive{#1}{{\currentbibauthor}\bibalternative\c!inbetween
1287 \bibalternative\v!left{\currentbibyear}\bibalternative\v!right}}
1288 {\bibalternative\c!pubsep
1289 \bibmaybeinteractive{#1}{{\currentbibauthor}\bibalternative\c!inbetween
1290 \bibalternative\v!left {\currentbibyear}\bibalternative\v!right}}
1291 {\bibalternative\c!lastpubsep
1292 \bibmaybeinteractive{#1}{{\currentbibauthor}\bibalternative\c!inbetween
1293 \bibalternative\v!left {\currentbibyear}\bibalternative\v!right}}}
1294
1295\protected\def\bibauthoryearsref[#1]
1296 {\bibalternative\v!left
1297 \ixbibauthoryear{#1}
1298 {\bibmaybeinteractive{#1}{{\currentbibauthor}\bibalternative\c!inbetween{\currentbibyear}}}
1299 {\bibalternative\c!pubsep
1300 \bibmaybeinteractive{#1}{{\currentbibauthor}\bibalternative\c!inbetween{\currentbibyear}}}
1301 {\bibalternative\c!lastpubsep
1302 \bibmaybeinteractive{#1}{{\currentbibauthor}\bibalternative\c!inbetween{\currentbibyear}}}
1303 \bibalternative\v!right}
1304
1305\protected\def\bibauthorref[#1]
1306 {\bibalternative\v!left
1307 \ixbibauthoryear{#1}
1308 {\bibmaybeinteractive{#1}{{\currentbibauthor}}}
1309 {\bibalternative\c!pubsep \bibmaybeinteractive{#1}{{\currentbibauthor}}}
1310 {\bibalternative\c!lastpubsep\bibmaybeinteractive{#1}{{\currentbibauthor}}}
1311 \bibalternative\v!right}
1312
1313\protected\def\bibyearref[#1]
1314 {\bibalternative\v!left
1315 \ixbibauthoryear{#1}
1316 {\bibmaybeinteractive{#1}{{\currentbibyear}}}
1317 {\bibalternative\c!pubsep \bibmaybeinteractive{#1}{{\currentbibyear}}}
1318 {\bibalternative\c!lastpubsep\bibmaybeinteractive{#1}{{\currentbibyear}}}
1319 \bibalternative\v!right}
1320
1321
1322
1323
1324
1325
1326
1327\newconditional\firstbibrefsep
1328
1329\protected\def\bibresetrefsep
1330 {\firstbibrefsep\conditionaltrue}
1331
1332\protected\def\bibinsertrefsep
1333 {\ifconditional\firstbibrefsep
1334 \firstbibrefsep\conditionalfalse
1335 \else
1336 \bibalternative\c!pubsep
1337 \fi}
1338
1339\protected\def\bibshortref[#1]
1340 {\bibalternative\v!left
1341 \bibresetrefsep\processcommalist[#1]\dobibshortref
1342 \bibalternative\v!right}
1343
1344\protected\def\dobibshortref#1
1345 {\bibinsertrefsep
1346 \doifelsebibreferencefound{#1}
1347 {\gotobiblink{\bibgetvars{#1}}[#1]}
1348 {}}
1349
1350\protected\def\bibserialref[#1]
1351 {\bibalternative\v!left
1352 \bibresetrefsep\processcommalist[#1]\dobibserialref
1353 \bibalternative\v!right}
1354
1355\protected\def\dobibserialref#1
1356 {\bibinsertrefsep
1357 \doifelsebibreferencefound{#1}
1358 {\gotobiblink{\bibgetvarn{#1}}[#1]}
1359 {}}
1360
1361\protected\def\bibkeyref[#1]
1362 {\bibalternative\v!left
1363 \bibresetrefsep\processcommalist[#1]\dobibkeyref
1364 \bibalternative\v!right}
1365
1366\protected\def\dobibkeyref#1
1367 {\bibinsertrefsep
1368 \gotobiblink{#1}[#1]}
1369
1370\protected\def\bibgotoDOI#1#2
1371 {\doifelsebibinteraction
1372 {\useURL[bibfooDoi#1][#2]
1373 \useURL[bibfoo#1][http:dx.doi.org#2]
1374 \goto{\url[bibfooDoi#1]}[url(bibfoo#1)]}
1375 {\hyphenatedurl{#2}}}
1376
1377\protected\def\bibdoiref[#1]
1378 {\bibalternative\v!left
1379 \bibresetrefsep\processcommalist[#1]\dobibdoiref
1380 \bibalternative\v!right}
1381
1382\protected\def\dobibdoiref#1
1383 {\bibinsertrefsep
1384 \doifelsebibreferencefound{#1}
1385 {\normalexpanded{\bibgotoDOI{#1}{\bibgetvaro{#1}}}}
1386 {}}
1387
1388\protected\def\biburlref[#1]
1389 {\bibalternative\v!left
1390 \bibresetrefsep\processcommalist[#1]\dobiburlref
1391 \bibalternative\v!right}
1392
1393\protected\def\bibgotoURL#1#2
1394 {\doifelsebibinteraction
1395 {\useURL[bibfoo#1][#2]\goto{\url[bibfoo#1]}[url(bibfoo#1)]}
1396 {\hyphenatedurl{#2}}}
1397
1398\protected\def\dobiburlref#1
1399 {\bibinsertrefsep
1400 \doifelsebibreferencefound{#1}
1401 {\normalexpanded{\bibgotoURL{#1}{\bibgetvaru{#1}}}}
1402 {}}
1403
1404\protected\def\bibtyperef[#1]
1405 {\bibalternative\v!left
1406 \bibresetrefsep\processcommalist[#1]\dobibtyperef
1407 \bibalternative\v!right}
1408
1409\protected\def\dobibtyperef#1
1410 {\bibinsertrefsep
1411 \doifelsebibreferencefound{#1}
1412 {\gotobiblink{\bibgetvart{#1}}[#1]}
1413 {}}
1414
1415\protected\def\bibpageref[#1]
1416 {\bibalternative\v!left
1417 \bibresetrefsep\processcommalist[#1]\dobibpageref
1418 \bibalternative\v!right}
1419
1420\protected\def\dobibpageref#1
1421 {\bibinsertrefsep
1422 \doifelsebibinteraction
1423 {\atbiblink[#1]}
1424 {{\referencingfalse\at[#1]}}}
1425
1426\protected\def\bibdataref[#1]
1427 {\bibalternative\v!left
1428 \bibresetrefsep\processcommalist[#1]\dobibdata
1429 \bibalternative\v!right}
1430
1431\protected\def\dobibdata#1
1432 {\bibinsertrefsep
1433 \doifelsebibreferencefound{#1}
1434 {\dotypesetapublication{#1}}
1435 {}}
1436
1437\let\bibnoneref\nocite
1438
1439
1440
1441\protected\def\bibnumref[#1]
1442 {\begingroup
1443 \bibalternative\v!left
1444 \penalty\plustenthousand
1445 \ctxlua{bibtex.hacks.resolve("","\number\bibtexblock","#1")}
1446 \bibalternative\v!right
1447 \endgroup}
1448
1449\protected\def\dowithbibtexnumrefconnector#1#2
1450 {\ifnum#1>\plusone
1451 \ifnum#2>\plusone
1452 \ifnum#2=#1\relax
1453 \bibalternative{lastpubsep}
1454 \else
1455 \bibalternative{pubsep}
1456 \fi
1457 \fi
1458 \fi}
1459
1460\protected\def\dowithbibtexnumref#1#2#3#4#5
1461 {\dowithbibtexnumrefconnector{#1}{#2}
1462 \def\bibrefprefix{#4:}
1463 \inbiblink[#5]}
1464
1465\protected\def\dowithbibtexnumrefrange#1#2#3#4#5#6#7
1466 {\dowithbibtexnumrefconnector{#1}{#2}
1467 \def\bibrefprefix{#4:}
1468 \inbiblink[#5]
1469 \endash
1470 \def\bibrefprefix{#6:}
1471 \inbiblink[#7]}
1472
1473
1474
1475\protected\def\bibauthornumref[#1]
1476 {\getcommalistsize[#1]
1477 \global\bibitemcounter\commalistsize
1478 \bibresetrefsep
1479 \processcommalist[#1]\dobibauthornumref}
1480
1481\protected\def\dobibauthornumref#1
1482 {\bibinsertrefsep
1483 \doifelsebibreferencefound{#1}
1484 {\begingroup
1485 \cite[\c!left=,\c!right=,\c!alternative=\v!author][#1]
1486 \bibalternative\c!inbetween
1487 \cite[num][#1]
1488 \endgroup}
1489 {}}
1490
1491
1492
1493\setuppublications
1494 [\c!monthconversion=,
1495 \c!alternative=apa,
1496 \c!method=\v!global,
1497
1498 \c!criterium=\v!cite,
1499 \c!refcommand=num,
1500 \c!numbercommand=\bibleftnumber]
1501
1502\protected\def\preloadbiblist
1503 {\glet\preloadbiblist\relax
1504 \dousepublications\jobname}
1505
1506
1507
1508
1509\let\ifbibinteractionelse\doifbibinteractionelse
1510
1511\protect \endinput
1512 |