Debian Codegraph @

texmf-dist/bibtex/bst/sort-by-letters/apalike-letters.bst

raw
1 % BibTeX bibliography style `apalike-letters'
2 %% adapted from `apalike' bibliography style (24-Jan-88 version)
3 %% (C) 2006 - Thomas van Oudenhove
4 %% when sorting by letter, write the first letter of author
5 %% or editor - bug with organization...
6 % This style should be used with the `apalike' LaTeX style (apalike.sty).
7 % \cite's come out like "(Jones, 1986)" in the text but there are no labels
8 % in the bibliography, and something like "(1986)" comes out immediately
9 % after the author. Author (and editor) names appear as last name, comma,
10 % initials. A `year' field is required for every entry, and so is either
11 % an author (or in some cases, an editor) field or a key field.
12 %
13 % Editorial note:
14 % Many journals require a style like `apalike', but I strongly, strongly,
15 % strongly recommend that you not use it if you have a choice---use something
16 % like `plain' instead. Mary-Claire van Leunen (A Handbook for Scholars,
17 % Knopf, 1979) argues convincingly that a style like `plain' encourages better
18 % writing than one like `apalike'. Furthermore the strongest arguments for
19 % using an author-date style like `apalike'---that it's "the most practical"
20 % (The Chicago Manual of Style, University of Chicago Press, thirteenth
21 % edition, 1982, pages 400--401)---fall flat on their face with the new
22 % computer-typesetting technology. For instance page 401 anachronistically
23 % states "The chief disadvantage of [a style like `plain'] is that additions
24 % or deletions cannot be made after the manuscript is typed without changing
25 % numbers in both text references and list." LaTeX sidesteps the disadvantage.
26
27 ENTRY
28 { address
29 author
30 booktitle
31 chapter
32 edition
33 editor
34 howpublished
35 institution
36 journal
37 key
38 % month not used in apalike
39 note
40 number
41 organization
42 pages
43 publisher
44 school
45 series
46 title
47 type
48 volume
49 year
50 }
51 {}
52 { label extra.label sort.label }
53
54 INTEGERS { output.state before.all mid.sentence after.sentence after.block }
55
56 FUNCTION {init.state.consts}
57 { #0 'before.all :=
58 #1 'mid.sentence :=
59 #2 'after.sentence :=
60 #3 'after.block :=
61 }
62
63 STRINGS { s t cur.letter first.letter }
64 INTEGERS { first.letter.place first.letter.ascii }
65
66 FUNCTION {output.nonnull}
67 { 's :=
68 output.state mid.sentence =
69 { ", " * write$ }
70 { output.state after.block =
71 { add.period$ write$
72 newline$
73 "\newblock " write$
74 }
75 { output.state before.all =
76 'write$
77 { add.period$ " " * write$ }
78 if$
79 }
80 if$
81 mid.sentence 'output.state :=
82 }
83 if$
84 s
85 }
86
87 FUNCTION {output}
88 { duplicate$ empty$
89 'pop$
90 'output.nonnull
91 if$
92 }
93
94 FUNCTION {output.check}
95 { 't :=
96 duplicate$ empty$
97 { pop$ "empty " t * " in " * cite$ * warning$ }
98 'output.nonnull
99 if$
100 }
101
102 % apalike needs this function because
103 % the year has special punctuation;
104 % apalike ignores the month
105 FUNCTION {output.year.check}
106 { year empty$
107 { "empty year in " cite$ * warning$ }
108 { write$
109 " (" year * extra.label * ")" *
110 mid.sentence 'output.state :=
111 }
112 if$
113 }
114
115 FUNCTION {output.letter}
116 { first.letter cur.letter =
117 { skip$ }
118 { newline$
119 "\alphabibitem{" first.letter * "}" * write$
120 newline$
121 first.letter 'cur.letter := }
122 if$
123 cur.letter "\" =
124 { first.letter 'cur.letter := }
125 { skip$ }
126 if$
127 }
128
129 FUNCTION {output.bibitem}
130 { newline$
131 "\bibitem[" write$
132 label write$
133 "]{" write$
134 cite$ write$
135 "}" write$
136 newline$
137 ""
138 before.all 'output.state :=
139 }
140
141 FUNCTION {fin.entry}
142 { add.period$
143 write$
144 newline$
145 }
146
147 FUNCTION {new.block}
148 { output.state before.all =
149 'skip$
150 { after.block 'output.state := }
151 if$
152 }
153
154 FUNCTION {new.sentence}
155 { output.state after.block =
156 'skip$
157 { output.state before.all =
158 'skip$
159 { after.sentence 'output.state := }
160 if$
161 }
162 if$
163 }
164
165 FUNCTION {not}
166 { { #0 }
167 { #1 }
168 if$
169 }
170
171 FUNCTION {and}
172 { 'skip$
173 { pop$ #0 }
174 if$
175 }
176
177 FUNCTION {or}
178 { { pop$ #1 }
179 'skip$
180 if$
181 }
182
183 FUNCTION {new.block.checkb}
184 { empty$
185 swap$ empty$
186 and
187 'skip$
188 'new.block
189 if$
190 }
191
192 FUNCTION {field.or.null}
193 { duplicate$ empty$
194 { pop$ "" }
195 'skip$
196 if$
197 }
198
199 FUNCTION {emphasize}
200 { duplicate$ empty$
201 { pop$ "" }
202 { "{\em " swap$ * "}" * }
203 if$
204 }
205
206 FUNCTION { author.find.first.letter }
207 { author #1 "{vv }{ll }{ff }, {jj }" format.name$ "u" change.case$
208 purify$ first.letter.place #1 substring$ 'first.letter :=
209 first.letter chr.to.int$ 'first.letter.ascii :=
210 }
211
212 FUNCTION { editor.find.first.letter }
213 { editor #1 "{vv }{ll }{ff }, {jj }" format.name$ "u" change.case$
214 purify$ first.letter.place #1 substring$ 'first.letter :=
215 first.letter chr.to.int$ 'first.letter.ascii :=
216 }
217
218 FUNCTION { organization.find.first.letter }
219 { organization #1 "{vv }{ll }{ff }, {jj }" format.name$ "u" change.case$
220 purify$ first.letter.place #1 substring$ 'first.letter :=
221 first.letter chr.to.int$ 'first.letter.ascii :=
222 }
223
224 FUNCTION { find.firstletter }
225 { author empty$
226 { editor empty$
227 % { organization empty$
228 { "Nor author, editor neither organization for entry " cite$ * warning$ }
229 % { organization.find.first.letter
230 % { first.letter.ascii #64 > first.letter.ascii #91 < and
231 % first.letter.ascii #96 > first.letter.ascii #123 < and or not }
232 % { first.letter.place #1 + 'first.letter.place :=
233 % organization.find.first.letter }
234 % while$ }
235 % if$ }
236 { editor.find.first.letter
237 { first.letter.ascii #64 > first.letter.ascii #91 < and
238 first.letter.ascii #96 > first.letter.ascii #123 < and or not }
239 { first.letter.place #1 + 'first.letter.place :=
240 editor.find.first.letter }
241 while$
242 }
243 if$
244 }
245 { author.find.first.letter
246 { first.letter.ascii #64 > first.letter.ascii #91 < and
247 first.letter.ascii #96 > first.letter.ascii #123 < and or not }
248 { first.letter.place #1 + 'first.letter.place :=
249 author.find.first.letter }
250 while$
251 }
252 if$
253 #1 'first.letter.place :=
254 }
255
256 INTEGERS { nameptr namesleft numnames }
257
258 FUNCTION {format.names}
259 { 's :=
260 #1 'nameptr :=
261 s num.names$ 'numnames :=
262 numnames 'namesleft :=
263 { namesleft #0 > }
264 { s nameptr "{vv~}{ll}{, jj}{, f.}" format.name$ 't := % last name first
265 nameptr #1 >
266 { namesleft #1 >
267 { ", " * t * }
268 { numnames #2 >
269 { "," * }
270 'skip$
271 if$
272 t "others" =
273 { " et~al." * }
274 { " and " * t * }
275 if$
276 }
277 if$
278 }
279 't
280 if$
281 nameptr #1 + 'nameptr :=
282 namesleft #1 - 'namesleft :=
283 }
284 while$
285 }
286
287 FUNCTION {format.authors}
288 { author empty$
289 { "" }
290 { author format.names }
291 if$
292 }
293
294 FUNCTION {format.key} % this function is just for apalike
295 { empty$
296 { key field.or.null }
297 { "" }
298 if$
299 }
300
301 FUNCTION {format.editors}
302 { editor empty$
303 { "" }
304 { editor format.names
305 editor num.names$ #1 >
306 { ", editors" * }
307 { ", editor" * }
308 if$
309 }
310 if$
311 }
312
313 FUNCTION {format.title}
314 { title empty$
315 { "" }
316 { title "t" change.case$ }
317 if$
318 }
319
320 FUNCTION {n.dashify}
321 { 't :=
322 ""
323 { t empty$ not }
324 { t #1 #1 substring$ "-" =
325 { t #1 #2 substring$ "--" = not
326 { "--" *
327 t #2 global.max$ substring$ 't :=
328 }
329 { { t #1 #1 substring$ "-" = }
330 { "-" *
331 t #2 global.max$ substring$ 't :=
332 }
333 while$
334 }
335 if$
336 }
337 { t #1 #1 substring$ *
338 t #2 global.max$ substring$ 't :=
339 }
340 if$
341 }
342 while$
343 }
344
345 FUNCTION {format.btitle}
346 { title emphasize
347 }
348
349 FUNCTION {tie.or.space.connect}
350 { duplicate$ text.length$ #3 <
351 { "~" }
352 { " " }
353 if$
354 swap$ * *
355 }
356
357 FUNCTION {either.or.check}
358 { empty$
359 'pop$
360 { "can't use both " swap$ * " fields in " * cite$ * warning$ }
361 if$
362 }
363
364 FUNCTION {format.bvolume}
365 { volume empty$
366 { "" }
367 { "volume" volume tie.or.space.connect
368 series empty$
369 'skip$
370 { " of " * series emphasize * }
371 if$
372 "volume and number" number either.or.check
373 }
374 if$
375 }
376
377 FUNCTION {format.number.series}
378 { volume empty$
379 { number empty$
380 { series field.or.null }
381 { output.state mid.sentence =
382 { "number" }
383 { "Number" }
384 if$
385 number tie.or.space.connect
386 series empty$
387 { "there's a number but no series in " cite$ * warning$ }
388 { " in " * series * }
389 if$
390 }
391 if$
392 }
393 { "" }
394 if$
395 }
396
397 FUNCTION {format.edition}
398 { edition empty$
399 { "" }
400 { output.state mid.sentence =
401 { edition "l" change.case$ " edition" * }
402 { edition "t" change.case$ " edition" * }
403 if$
404 }
405 if$
406 }
407
408 INTEGERS { multiresult }
409
410 FUNCTION {multi.page.check}
411 { 't :=
412 #0 'multiresult :=
413 { multiresult not
414 t empty$ not
415 and
416 }
417 { t #1 #1 substring$
418 duplicate$ "-" =
419 swap$ duplicate$ "," =
420 swap$ "+" =
421 or or
422 { #1 'multiresult := }
423 { t #2 global.max$ substring$ 't := }
424 if$
425 }
426 while$
427 multiresult
428 }
429
430 FUNCTION {format.pages}
431 { pages empty$
432 { "" }
433 { pages multi.page.check
434 { "pages" pages n.dashify tie.or.space.connect }
435 { "page" pages tie.or.space.connect }
436 if$
437 }
438 if$
439 }
440
441 FUNCTION {format.vol.num.pages}
442 { volume field.or.null
443 number empty$
444 'skip$
445 { "(" number * ")" * *
446 volume empty$
447 { "there's a number but no volume in " cite$ * warning$ }
448 'skip$
449 if$
450 }
451 if$
452 pages empty$
453 'skip$
454 { duplicate$ empty$
455 { pop$ format.pages }
456 { ":" * pages n.dashify * }
457 if$
458 }
459 if$
460 }
461
462 FUNCTION {format.chapter.pages}
463 { chapter empty$
464 'format.pages
465 { type empty$
466 { "chapter" }
467 { type "l" change.case$ }
468 if$
469 chapter tie.or.space.connect
470 pages empty$
471 'skip$
472 { ", " * format.pages * }
473 if$
474 }
475 if$
476 }
477
478 FUNCTION {format.in.ed.booktitle}
479 { booktitle empty$
480 { "" }
481 { editor empty$
482 { "In " booktitle emphasize * }
483 { "In " format.editors * ", " * booktitle emphasize * }
484 if$
485 }
486 if$
487 }
488
489 FUNCTION {format.thesis.type}
490 { type empty$
491 'skip$
492 { pop$
493 type "t" change.case$
494 }
495 if$
496 }
497
498 FUNCTION {format.tr.number}
499 { type empty$
500 { "Technical Report" }
501 'type
502 if$
503 number empty$
504 { "t" change.case$ }
505 { number tie.or.space.connect }
506 if$
507 }
508
509 FUNCTION {format.article.crossref}
510 { "In" % this is for apalike
511 " \cite{" * crossref * "}" *
512 }
513
514 FUNCTION {format.book.crossref}
515 { volume empty$
516 { "empty volume in " cite$ * "'s crossref of " * crossref * warning$
517 "In "
518 }
519 { "Volume" volume tie.or.space.connect
520 " of " *
521 }
522 if$
523 "\cite{" * crossref * "}" * % this is for apalike
524 }
525
526 FUNCTION {format.incoll.inproc.crossref}
527 { "In" % this is for apalike
528 " \cite{" * crossref * "}" *
529 }
530
531 FUNCTION {article}
532 { find.firstletter
533 output.letter
534 output.bibitem
535 format.authors "author" output.check
536 author format.key output % special for
537 output.year.check % apalike
538 new.block
539 format.title "title" output.check
540 new.block
541 crossref missing$
542 { journal emphasize "journal" output.check
543 format.vol.num.pages output
544 }
545 { format.article.crossref output.nonnull
546 format.pages output
547 }
548 if$
549 new.block
550 note output
551 fin.entry
552 }
553
554 FUNCTION {book}
555 { find.firstletter
556 output.letter
557 output.bibitem
558 author empty$
559 { format.editors "author and editor" output.check
560 editor format.key output
561 }
562 { format.authors output.nonnull
563 crossref missing$
564 { "author and editor" editor either.or.check }
565 'skip$
566 if$
567 }
568 if$
569 output.year.check % special for apalike
570 new.block
571 format.btitle "title" output.check
572 crossref missing$
573 { format.bvolume output
574 new.block
575 format.number.series output
576 new.sentence
577 publisher "publisher" output.check
578 address output
579 }
580 { new.block
581 format.book.crossref output.nonnull
582 }
583 if$
584 format.edition output
585 new.block
586 note output
587 fin.entry
588 }
589
590 FUNCTION {booklet}
591 { find.firstletter
592 output.letter
593 output.bibitem
594 format.authors output
595 author format.key output % special for
596 output.year.check % apalike
597 new.block
598 format.title "title" output.check
599 new.block
600 howpublished output
601 address output
602 new.block
603 note output
604 fin.entry
605 }
606
607 FUNCTION {inbook}
608 { find.firstletter
609 output.letter
610 output.bibitem
611 author empty$
612 { format.editors "author and editor" output.check
613 editor format.key output
614 }
615 { format.authors output.nonnull
616 crossref missing$
617 { "author and editor" editor either.or.check }
618 'skip$
619 if$
620 }
621 if$
622 output.year.check % special for apalike
623 new.block
624 format.btitle "title" output.check
625 crossref missing$
626 { format.bvolume output
627 format.chapter.pages "chapter and pages" output.check
628 new.block
629 format.number.series output
630 new.sentence
631 publisher "publisher" output.check
632 address output
633 }
634 { format.chapter.pages "chapter and pages" output.check
635 new.block
636 format.book.crossref output.nonnull
637 }
638 if$
639 format.edition output
640 new.block
641 note output
642 fin.entry
643 }
644
645 FUNCTION {incollection}
646 { find.firstletter
647 output.letter
648 output.bibitem
649 format.authors "author" output.check
650 author format.key output % special for
651 output.year.check % apalike
652 new.block
653 format.title "title" output.check
654 new.block
655 crossref missing$
656 { format.in.ed.booktitle "booktitle" output.check
657 format.bvolume output
658 format.number.series output
659 format.chapter.pages output
660 new.sentence
661 publisher "publisher" output.check
662 address output
663 format.edition output
664 }
665 { format.incoll.inproc.crossref output.nonnull
666 format.chapter.pages output
667 }
668 if$
669 new.block
670 note output
671 fin.entry
672 }
673
674 FUNCTION {inproceedings}
675 { find.firstletter
676 output.letter
677 output.bibitem
678 format.authors "author" output.check
679 author format.key output % special for
680 output.year.check % apalike
681 new.block
682 format.title "title" output.check
683 new.block
684 crossref missing$
685 { format.in.ed.booktitle "booktitle" output.check
686 format.bvolume output
687 format.number.series output
688 format.pages output
689 address output % for apalike
690 new.sentence % there's no year
691 organization output % here so things
692 publisher output % are simpler
693 }
694 { format.incoll.inproc.crossref output.nonnull
695 format.pages output
696 }
697 if$
698 new.block
699 note output
700 fin.entry
701 }
702
703 FUNCTION {conference} { inproceedings }
704
705 FUNCTION {manual}
706 { find.firstletter
707 output.letter
708 output.bibitem
709 format.authors output
710 author format.key output % special for
711 output.year.check % apalike
712 new.block
713 format.btitle "title" output.check
714 organization address new.block.checkb
715 organization output
716 address output
717 format.edition output
718 new.block
719 note output
720 fin.entry
721 }
722
723 FUNCTION {mastersthesis}
724 { find.firstletter
725 output.letter
726 output.bibitem
727 format.authors "author" output.check
728 author format.key output % special for
729 output.year.check % apalike
730 new.block
731 format.title "title" output.check
732 new.block
733 "Master's thesis" format.thesis.type output.nonnull
734 school "school" output.check
735 address output
736 new.block
737 note output
738 fin.entry
739 }
740
741 FUNCTION {misc}
742 { find.firstletter
743 output.letter
744 output.bibitem
745 format.authors output
746 author format.key output % special for
747 output.year.check % apalike
748 new.block
749 format.title output
750 new.block
751 howpublished output
752 new.block
753 note output
754 fin.entry
755 }
756
757 FUNCTION {phdthesis}
758 { find.firstletter
759 output.letter
760 output.bibitem
761 format.authors "author" output.check
762 author format.key output % special for
763 output.year.check % apalike
764 new.block
765 format.btitle "title" output.check
766 new.block
767 "PhD thesis" format.thesis.type output.nonnull
768 school "school" output.check
769 address output
770 new.block
771 note output
772 fin.entry
773 }
774
775 FUNCTION {proceedings}
776 { find.firstletter
777 output.letter
778 output.bibitem
779 format.editors output
780 editor format.key output % special for
781 output.year.check % apalike
782 new.block
783 format.btitle "title" output.check
784 format.bvolume output
785 format.number.series output
786 address output % for apalike
787 new.sentence % we always output
788 organization output % a nonempty organization
789 publisher output % here
790 new.block
791 note output
792 fin.entry
793 }
794
795 FUNCTION {techreport}
796 { find.firstletter
797 output.letter
798 output.bibitem
799 format.authors "author" output.check
800 author format.key output % special for
801 output.year.check % apalike
802 new.block
803 format.title "title" output.check
804 new.block
805 format.tr.number output.nonnull
806 institution "institution" output.check
807 address output
808 new.block
809 note output
810 fin.entry
811 }
812
813 FUNCTION {unpublished}
814 { find.firstletter
815 output.letter
816 output.bibitem
817 format.authors "author" output.check
818 author format.key output % special for
819 output.year.check % apalike
820 new.block
821 format.title "title" output.check
822 new.block
823 note "note" output.check
824 fin.entry
825 }
826
827 FUNCTION {default.type} { misc }
828
829 MACRO {jan} {"January"}
830
831 MACRO {feb} {"February"}
832
833 MACRO {mar} {"March"}
834
835 MACRO {apr} {"April"}
836
837 MACRO {may} {"May"}
838
839 MACRO {jun} {"June"}
840
841 MACRO {jul} {"July"}
842
843 MACRO {aug} {"August"}
844
845 MACRO {sep} {"September"}
846
847 MACRO {oct} {"October"}
848
849 MACRO {nov} {"November"}
850
851 MACRO {dec} {"December"}
852
853 MACRO {acmcs} {"ACM Computing Surveys"}
854
855 MACRO {acta} {"Acta Informatica"}
856
857 MACRO {cacm} {"Communications of the ACM"}
858
859 MACRO {ibmjrd} {"IBM Journal of Research and Development"}
860
861 MACRO {ibmsj} {"IBM Systems Journal"}
862
863 MACRO {ieeese} {"IEEE Transactions on Software Engineering"}
864
865 MACRO {ieeetc} {"IEEE Transactions on Computers"}
866
867 MACRO {ieeetcad}
868 {"IEEE Transactions on Computer-Aided Design of Integrated Circuits"}
869
870 MACRO {ipl} {"Information Processing Letters"}
871
872 MACRO {jacm} {"Journal of the ACM"}
873
874 MACRO {jcss} {"Journal of Computer and System Sciences"}
875
876 MACRO {scp} {"Science of Computer Programming"}
877
878 MACRO {sicomp} {"SIAM Journal on Computing"}
879
880 MACRO {tocs} {"ACM Transactions on Computer Systems"}
881
882 MACRO {tods} {"ACM Transactions on Database Systems"}
883
884 MACRO {tog} {"ACM Transactions on Graphics"}
885
886 MACRO {toms} {"ACM Transactions on Mathematical Software"}
887
888 MACRO {toois} {"ACM Transactions on Office Information Systems"}
889
890 MACRO {toplas} {"ACM Transactions on Programming Languages and Systems"}
891
892 MACRO {tcs} {"Theoretical Computer Science"}
893
894 READ
895
896 FUNCTION {sortify}
897 { purify$
898 "l" change.case$
899 }
900
901 INTEGERS { len }
902
903 FUNCTION {chop.word}
904 { 's :=
905 'len :=
906 s #1 len substring$ =
907 { s len #1 + global.max$ substring$ }
908 's
909 if$
910 }
911
912 % There are three apalike cases: one person (Jones),
913 % two (Jones and de~Bruijn), and more (Jones et~al.).
914 % This function is much like format.crossref.editors.
915 %
916 FUNCTION {format.lab.names}
917 { 's :=
918 s #1 "{vv~}{ll}" format.name$
919 s num.names$ duplicate$
920 #2 >
921 { pop$ " et~al." * }
922 { #2 <
923 'skip$
924 { s #2 "{ff }{vv }{ll}{ jj}" format.name$ "others" =
925 { " et~al." * }
926 { " and " * s #2 "{vv~}{ll}" format.name$ * }
927 if$
928 }
929 if$
930 }
931 if$
932 }
933
934 FUNCTION {author.key.label}
935 { author empty$
936 { key empty$
937 { cite$ #1 #3 substring$ }
938 'key % apalike uses the whole key
939 if$
940 }
941 { author format.lab.names }
942 if$
943 }
944
945 FUNCTION {author.editor.key.label}
946 { author empty$
947 { editor empty$
948 { key empty$
949 { cite$ #1 #3 substring$ }
950 'key % apalike uses the whole key
951 if$
952 }
953 { editor format.lab.names }
954 if$
955 }
956 { author format.lab.names }
957 if$
958 }
959
960 FUNCTION {editor.key.label}
961 { editor empty$
962 { key empty$
963 { cite$ #1 #3 substring$ }
964 'key % apalike uses the whole key, no organization
965 if$
966 }
967 { editor format.lab.names }
968 if$
969 }
970
971 FUNCTION {calc.label}
972 { type$ "book" =
973 type$ "inbook" =
974 or
975 'author.editor.key.label
976 { type$ "proceedings" =
977 'editor.key.label % apalike ignores organization
978 'author.key.label % for labeling and sorting
979 if$
980 }
981 if$
982 ", " % these three lines are
983 * % for apalike, which
984 year field.or.null purify$ #-1 #4 substring$ % uses all four digits
985 *
986 'label :=
987 }
988
989 FUNCTION {sort.format.names}
990 { 's :=
991 #1 'nameptr :=
992 ""
993 s num.names$ 'numnames :=
994 numnames 'namesleft :=
995 { namesleft #0 > }
996 { nameptr #1 >
997 { " " * }
998 'skip$
999 if$ % apalike uses initials
1000 s nameptr "{vv{ } }{ll{ }}{ f{ }}{ jj{ }}" format.name$ 't := % <= here
1001 nameptr numnames = t "others" = and
1002 { "et al" * }
1003 { t sortify * }
1004 if$
1005 nameptr #1 + 'nameptr :=
1006 namesleft #1 - 'namesleft :=
1007 }
1008 while$
1009 }
1010
1011 FUNCTION {sort.format.title}
1012 { 't :=
1013 "A " #2
1014 "An " #3
1015 "The " #4 t chop.word
1016 chop.word
1017 chop.word
1018 sortify
1019 #1 global.max$ substring$
1020 }
1021
1022 FUNCTION {author.sort}
1023 { author empty$
1024 { key empty$
1025 { "to sort, need author or key in " cite$ * warning$
1026 ""
1027 }
1028 { key sortify }
1029 if$
1030 }
1031 { author sort.format.names }
1032 if$
1033 }
1034
1035 FUNCTION {author.editor.sort}
1036 { author empty$
1037 { editor empty$
1038 { key empty$
1039 { "to sort, need author, editor, or key in " cite$ * warning$
1040 ""
1041 }
1042 { key sortify }
1043 if$
1044 }
1045 { editor sort.format.names }
1046 if$
1047 }
1048 { author sort.format.names }
1049 if$
1050 }
1051
1052 FUNCTION {editor.sort}
1053 { editor empty$
1054 { key empty$
1055 { "to sort, need editor or key in " cite$ * warning$
1056 ""
1057 }
1058 { key sortify }
1059 if$
1060 }
1061 { editor sort.format.names }
1062 if$
1063 }
1064
1065 % apalike uses two sorting passes; the first one sets the
1066 % labels so that the `a's, `b's, etc. can be computed;
1067 % the second pass puts the references in "correct" order.
1068 % The presort function is for the first pass. It computes
1069 % label, sort.label, and title, and then concatenates.
1070 FUNCTION {presort}
1071 { calc.label
1072 label sortify
1073 " "
1074 *
1075 type$ "book" =
1076 type$ "inbook" =
1077 or
1078 'author.editor.sort
1079 { type$ "proceedings" =
1080 'editor.sort
1081 'author.sort
1082 if$
1083 }
1084 if$
1085 #1 entry.max$ substring$ % for
1086 'sort.label := % apalike
1087 sort.label % style
1088 *
1089 " "
1090 *
1091 title field.or.null
1092 sort.format.title
1093 *
1094 #1 entry.max$ substring$
1095 'sort.key$ :=
1096 }
1097
1098 ITERATE {presort}
1099
1100 SORT % by label, sort.label, title---for final label calculation
1101
1102 STRINGS { last.label next.extra } % apalike labels are only for the text;
1103
1104 INTEGERS { last.extra.num } % there are none in the bibliography
1105
1106 FUNCTION {initialize.extra.label.stuff} % and hence there is no `longest.label'
1107 { #0 int.to.chr$ 'last.label :=
1108 "\" 'cur.letter :=
1109 #1 'first.letter.place :=
1110 "" 'next.extra :=
1111 #0 'last.extra.num :=
1112 }
1113
1114 FUNCTION { def.alphabibitem }
1115 { "\def\alphabibitem#1{%" write$ newline$
1116 "\expandafter\ifx\csname firstalphabibitem\endcsname" write$ newline$
1117 "\relax\def\firstalphabibitem{}" write$ newline$
1118 "\else\expandafter" write$ newline$
1119 "\ifx\csname alphabibitemskip\endcsname" write$ newline$
1120 "\relax\bigskip" write$ newline$
1121 "\else\alphabibitemskip" write$ newline$
1122 "\fi" write$ newline$
1123 "\fi" write$ newline$
1124 "\penalty-200\expandafter" write$ newline$
1125 "\ifx\csname alphabibitemlabel\endcsname" write$ newline$
1126 "\relax\expandafter" write$ newline$
1127 "\ifx\csname alphabibitemcontent\endcsname\relax" write$ newline$
1128 "\item[\LARGE\bfseries\MakeUppercase{#1}]" write$ newline$
1129 "\hfill\vskip 1ex\hrule\medskip" write$ newline$
1130 "\else\item[\Large\bfseries\MakeUppercase{#1}]" write$ newline$
1131 "\alphabibitemcontent{\MakeUppercase{#1}}%" write$ newline$
1132 "\fi" write$ newline$
1133 "\else\expandafter" write$ newline$
1134 "\ifx\csname alphabibitemcontent\endcsname\relax" write$ newline$
1135 "\item[\alphabibitemlabel{\MakeUppercase{#1}}]" write$ newline$
1136 "\vskip 1ex\hrule\medskip" write$ newline$
1137 "\else\item[\alphabibitemlabel{\MakeUppercase{#1}}]" write$ newline$
1138 "\alphabibitemcontent{\MakeUppercase{#1}}%" write$ newline$
1139 "\fi" write$ newline$
1140 "\fi}" write$ newline$
1141 newline$
1142 }
1143
1144 FUNCTION {forward.pass}
1145 { last.label label =
1146 { last.extra.num #1 + 'last.extra.num :=
1147 last.extra.num int.to.chr$ 'extra.label :=
1148 }
1149 { "a" chr.to.int$ 'last.extra.num :=
1150 "" 'extra.label :=
1151 label 'last.label :=
1152 }
1153 if$
1154 }
1155
1156 FUNCTION {reverse.pass}
1157 { next.extra "b" =
1158 { "a" 'extra.label := }
1159 'skip$
1160 if$
1161 label extra.label * 'label :=
1162 extra.label 'next.extra :=
1163 }
1164
1165 EXECUTE {initialize.extra.label.stuff}
1166
1167 ITERATE {forward.pass}
1168
1169 REVERSE {reverse.pass}
1170
1171 % Now that the label is right we sort for real,
1172 % on sort.label then year then title. This is
1173 % for the second sorting pass.
1174 FUNCTION {bib.sort.order}
1175 { sort.label
1176 " "
1177 *
1178 year field.or.null sortify
1179 *
1180 " "
1181 *
1182 title field.or.null
1183 sort.format.title
1184 *
1185 #1 entry.max$ substring$
1186 'sort.key$ :=
1187 }
1188
1189 ITERATE {bib.sort.order}
1190
1191 SORT % by sort.label, year, title---giving final bibliography order
1192
1193 FUNCTION {begin.bib}
1194 { preamble$ empty$ % no \etalchar in apalike
1195 'skip$
1196 { preamble$ write$ newline$ }
1197 if$
1198 def.alphabibitem
1199 "\begin{thebibliography}{}" write$ newline$ % no labels in apalike
1200 }
1201
1202 EXECUTE {begin.bib}
1203
1204 EXECUTE {init.state.consts}
1205
1206 ITERATE {call.type$}
1207
1208 FUNCTION {end.bib}
1209 { newline$
1210 "\end{thebibliography}" write$ newline$
1211 }
1212
1213 EXECUTE {end.bib}