forked from pkgw/tex-stuff
-
Notifications
You must be signed in to change notification settings - Fork 4
/
pwterse.bst
622 lines (532 loc) · 11.8 KB
/
pwterse.bst
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
36
37
38
39
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
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
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
% Terse bibliography for proposals. Based on bibtex 'abbrv'.
ENTRY {
address
archive
archivePrefix
author
booktitle
chapter
doi
edition
editor
eprint
howpublished
institution
journal
key
month
note
number
organization
pages
primaryClass
publisher
school
series
title
type
url
volume
year
} {} {
label
}
% Basic boolean helpers.
FUNCTION {not}
{ { #0 }
{ #1 }
if$
}
FUNCTION {and}
{ 'skip$
{ pop$ #0 }
if$
}
FUNCTION {or}
{ { pop$ #1 }
'skip$
if$
}
% Sentence-building infrastructure.
INTEGERS { output.state before.all mid.sentence after.sentence }
STRINGS { s t }
FUNCTION {init.state.consts}
{ #0 'before.all :=
#1 'mid.sentence :=
#2 'after.sentence :=
}
FUNCTION {output.nonnull.comma}
% input: stack -1: string (assumed nonempty)
% input: stack -2: string
% output: stack -1: same as on input
% write -2, possibly following it with "," or ".".
% state is mid.sentence when done.
{ 's :=
output.state mid.sentence =
{ ", " * write$ }
{ output.state after.sentence =
{ add.period$ write$
newline$
}
'write$ % <- before.all case
if$
mid.sentence 'output.state :=
}
if$
s
}
FUNCTION {output.nonnull.nocomma}
% as above, except no comma if mid.sentence.
{ 's :=
output.state mid.sentence =
{ " " * write$ }
{ output.state after.sentence =
{ add.period$ write$
newline$
}
'write$ % <- before.all case
if$
mid.sentence 'output.state :=
}
if$
s
}
FUNCTION {output.skipempty.comma}
% input: stack -1: string
% input: stack -2: string
% output: stack -1: same as on input
% Do nothing if -1 is empty. Otherwise, write -2, possibly following it with "," or ".".
% If -1 is not empty, state is mid.sentence when done.
{ duplicate$ empty$
'pop$
'output.nonnull.comma
if$
}
FUNCTION {output.skipempty.nocomma}
% as above, except no comma if mid.sentence
{ duplicate$ empty$
'pop$
'output.nonnull.nocomma
if$
}
FUNCTION {output.check.comma}
% input: stack -1: description of item
% input: stack -2: string (shouldn't be empty; warns if yes)
% input: stack -3: string
% output: stack -1: = input -3
% like output, but warns if empty.
{ 't :=
duplicate$ empty$
{ pop$ "empty " t * " in " * cite$ * warning$ }
'output.nonnull.comma
if$
}
FUNCTION {output.check.nocomma}
% as above, except no comma if mid.sentence
{ 't :=
duplicate$ empty$
{ pop$ "empty " t * " in " * cite$ * warning$ }
'output.nonnull.nocomma
if$
}
FUNCTION {new.sentence}
% stack-agnostic
% set output state to after.sentence, unless it is before.all
{ output.state before.all =
'skip$
{ after.sentence 'output.state := }
if$
}
FUNCTION {begin.entry}
% input: nothing on stack
% output: stack -1: ""
% sets output state to before.all.
{ newline$
"\bibitem{" write$
cite$ write$
"}" write$
newline$
""
before.all 'output.state :=
}
FUNCTION {finish.entry}
% input: stack -1: string
% output: empty stack
{ add.period$
write$
newline$
}
% Text manipulation utilities
FUNCTION {emphasize}
% input: stack -1: string, empty ok
% output: stack -1: input -1 wrapped in \emph{}, or "".
{ duplicate$ empty$
{ pop$ "" }
{ "\emph{" swap$ * "}" * }
if$
}
FUNCTION {tie.or.space.connect}
% input: stack -1: string
% input: stack -2: string
% output: stack -1: (-2) + X + (-1), where X is "~" or " "
% depending on if (-1) is less than 3 characters long.
{ duplicate$ text.length$ #3 <
{ "~" }
{ " " }
if$
swap$ * *
}
INTEGERS { work.strlen }
FUNCTION {string.length}
% input: stack -1: string
% output: stack -1: the length of input -1
{ % Copied from "Taming the BeaST", by Nicolas Markey, Fig 4
#1 'work.strlen :=
{ duplicate$ duplicate$ #1 work.strlen substring$ = not }
{ work.strlen #1 + 'work.strlen := }
while$
pop$ work.strlen
}
% Name formatting
INTEGERS { nameptr namesleft numnames numtrunc }
FUNCTION {format.names}
{ 's :=
#0 'numtrunc :=
#1 'nameptr :=
s num.names$ 'numnames :=
numnames 'namesleft :=
numnames #2 >
{ #1 'numtrunc := }
{}
if$
{ namesleft #0 > }
{ s nameptr
"{vv~}{ll}{~jj}{~f{}}" format.name$
't :=
nameptr #1 >
{
nameptr #1 - numtrunc =
{
#1 'namesleft :=
"others" 't :=
}
{}
if$
namesleft #1 >
{ ", " * t * }
{ s nameptr "{ll}" format.name$ duplicate$ "others" =
{ 't := }
{ pop$ }
if$
t "others" =
{
" \textit{et~al.}" *
}
{ " \& " * t * }
if$
}
if$
}
't
if$
nameptr #1 + 'nameptr :=
namesleft #1 - 'namesleft :=
}
while$
}
FUNCTION {format.authors}
% input: agnostic
% output: stack -1: formatted author names (or "")
{ author empty$
{ "" }
{ author format.names }
if$
}
FUNCTION {format.editors}
% input: agnostic
% output: stack -1: formatted editor names (or "")
{ editor empty$
{ "" }
{ editor format.names
editor num.names$ #1 >
{ ", eds." * }
{ ", ed." * }
if$
}
if$
}
% Other bibliography info formatting
FUNCTION {either.or.check}
{ empty$
'pop$
{ "can't use both " swap$ * " fields in " * cite$ * warning$ }
if$
}
FUNCTION {format.title}
{ title empty$
{ "" }
{ title "t" change.case$ }
if$
}
FUNCTION {format.volume.wordy}
{ volume empty$
{ "" }
{ "volume" volume tie.or.space.connect
series empty$
'skip$
{ " of " * series emphasize * }
if$
"volume and number" number either.or.check
}
if$
}
FUNCTION {format.edition}
{ edition empty$
{ "" }
{ output.state mid.sentence =
{ edition "l" change.case$ " edition" * }
{ edition "t" change.case$ " edition" * }
if$
}
if$
}
INTEGERS { multiresult }
FUNCTION {multi.page.check}
{ 't :=
#0 'multiresult :=
{ multiresult not
t empty$ not
and
}
{ t #1 #1 substring$
duplicate$ "-" =
swap$ duplicate$ "," =
swap$ "+" =
or or
{ #1 'multiresult := }
{ t #2 global.max$ substring$ 't := }
if$
}
while$
multiresult
}
FUNCTION {first.page}
{ 't :=
""
{ t empty$ not t #1 #1 substring$ "-" = not and }
{ t #1 #1 substring$ *
t #2 global.max$ substring$ 't :=
}
while$
% remove possible trailing plus sign
duplicate$ duplicate$ string.length #1 substring$ "+" =
{ duplicate$ string.length #1 - #1 swap$ substring$ }
{ }
if$
}
FUNCTION {format.pages}
{ pages empty$
{ "" }
{ pages first.page }
if$
}
FUNCTION {format.in.ed.booktitle}
{ booktitle empty$
{ "" }
{ editor empty$
{ "in " booktitle emphasize * }
{ "in " format.editors * ", " * booktitle emphasize * }
if$
}
if$
}
FUNCTION {empty.misc.check}
{ author empty$ title empty$ howpublished empty$
month empty$ year empty$ note empty$
and and and and and
key empty$ not and
{ "all relevant fields are empty in " cite$ * warning$ }
'skip$
if$
}
FUNCTION {format.archive}
{ archivePrefix empty$
{ "" }
{ archivePrefix ":" *}
if$
}
FUNCTION {format.primaryClass}
{ primaryClass empty$
{ "" }
{ " [" primaryClass * "]" *}
if$
}
FUNCTION {format.eprint}
% Only print eprint info if no page info and no booktitle info --
% what we're really going for is print the eprint info only if there's
% no "official" reference info to work with.
{ eprint empty$
pages empty$ not
booktitle empty$ not or or
{ "" }
{ archive empty$
{ "\href{http://arxiv.org/abs/" eprint * "}" *
"{\textsf{" * format.archive * eprint *
format.primaryClass * "}}" * }
{ "\href{" archive * "/" * eprint * "}" *
"{\textsf{" * format.archive * eprint *
format.primaryClass * "}}" *
}
if$
}
if$
}
FUNCTION {maybe.doi.link.prepend}
{ % Expects some citation text to be on the stack
doi empty$
{ url empty$
{ }
{ "\href{" url * "}{" * swap$ * }
if$
}
{ "\href{http://dx.doi.org/" doi * "}{" * swap$ * }
if$
}
FUNCTION {maybe.doi.link.end}
{ % Expects some citation text to be on the stack
doi empty$ url empty$ and
{ }
{ "}" * }
if$
}
% Support for the actual items we're going to output.
FUNCTION {article}
{ begin.entry
format.authors "author" output.check.comma
new.sentence
year
maybe.doi.link.prepend "year" output.check.nocomma
journal "journal" output.check.nocomma
volume missing$ % if no volume, assume it's a preprint without full pub info yet.
{ format.eprint output.skipempty.comma }
{ volume output.skipempty.nocomma
pages first.page "page" output.check.nocomma }
if$
maybe.doi.link.end
new.sentence
note output.skipempty.comma
finish.entry
}
FUNCTION {book}
{ begin.entry
author empty$
{ format.editors "author and editor" output.check.comma }
{ format.authors output.nonnull.comma
"author and editor" editor either.or.check
}
if$
new.sentence
year maybe.doi.link.prepend "year" output.check.comma
title emphasize "title" output.check.comma
format.volume.wordy output.skipempty.comma
format.edition output.skipempty.comma
"(" publisher * ")" * "publisher" output.check.nocomma
maybe.doi.link.end
new.sentence
note output.skipempty.comma
finish.entry
}
FUNCTION {incollection}
{ begin.entry
format.authors "author" output.check.comma
new.sentence
year maybe.doi.link.prepend "year" output.check.comma
format.in.ed.booktitle "booktitle" output.check.comma
format.volume.wordy output.skipempty.comma
format.edition output.skipempty.comma
"(" publisher * ")" * "publisher" output.check.nocomma
format.pages output.skipempty.comma
maybe.doi.link.end
new.sentence
note output.skipempty.comma
finish.entry
}
FUNCTION {inproceedings}
{ begin.entry
format.authors "author" output.check.comma
new.sentence
year maybe.doi.link.prepend "year" output.check.comma
format.in.ed.booktitle "booktitle" output.check.comma
format.volume.wordy output.skipempty.comma
format.edition output.skipempty.comma
"(" publisher * ")" * "publisher" output.check.nocomma
format.pages output.skipempty.comma
maybe.doi.link.end
new.sentence
note output.skipempty.comma
finish.entry
}
FUNCTION {conference} { inproceedings }
FUNCTION {misc}
{ begin.entry
format.authors "author" output.check.comma
new.sentence
year maybe.doi.link.prepend output.skipempty.comma
format.title output.skipempty.comma
maybe.doi.link.end
new.sentence
note output.skipempty.comma
finish.entry
empty.misc.check
}
FUNCTION {phdthesis}
{ begin.entry
format.authors "author" output.check.comma
new.sentence
year "year" output.check.comma
title emphasize "title" output.check.comma
"PhD thesis" output.nonnull.comma
school "school" output.check.comma
new.sentence
note output.skipempty.comma
finish.entry
}
FUNCTION {default.type} { misc }
% The "longest label" pass. Not sure if this is relevant at all
% in numbers mode.
STRINGS { longest.label }
INTEGERS { number.label longest.label.width }
FUNCTION {init.longest.label}
{ "" 'longest.label :=
#1 'number.label :=
#0 'longest.label.width :=
}
FUNCTION {longest.label.pass}
{ number.label int.to.str$ 'label :=
number.label #1 + 'number.label :=
label width$ longest.label.width >
{ label 'longest.label :=
label width$ 'longest.label.width :=
}
'skip$
if$
}
% Go, go, go!
READ
EXECUTE {init.longest.label}
ITERATE {longest.label.pass}
FUNCTION {begin.bib}
{ preamble$ empty$
'skip$
{ preamble$ write$ newline$ }
if$
"\begin{thebibliography}{" longest.label * "}" * write$ newline$
}
EXECUTE {begin.bib}
EXECUTE {init.state.consts}
ITERATE {call.type$}
FUNCTION {end.bib}
{ newline$
"\end{thebibliography}" write$ newline$
}
EXECUTE {end.bib}