Debian Codegraph @

texmf-dist/source/bibtex/gbt7714/gbt7714-bst.dtx

raw
1 % GB/T 7714 BibTeX Style
2 % https://github.com/zepinglee/gbt7714-bibtex-style
3 %
4 % Copyright (C) 2016-2026 by Zeping Lee <zepinglee AT gmail DOT com>
5 %
6 % This file may be distributed and/or modified under the
7 % conditions of the LaTeX Project Public License, either version 1.3c
8 % of this license or (at your option) any later version.
9 % The latest version of this license is in
10 % https://www.latex-project.org/lppl.txt
11 % and version 1.3c or later is part of all distributions of LaTeX
12 % version 2008 or later.
13 %
14 % \begin{macrocode}
15 INTEGERS {
16 control.convert.punct
17 control.max.bib.names
18 control.min.bib.names
19 control.max.cite.names
20 control.min.cite.names
21 control.uppercase.family
22 control.initialize.with.hyphen
23 control.check.pinyin
24 control.initialize.pinyin
25 control.cite.final.and
26 control.bib.final.and
27 control.space.before.et.al
28 control.year.before.title
29 control.sentence.case.title
30 control.sentence.case.journal
31 control.sentence.case.booktitle
32 control.link.title
33 control.article.title
34 control.patent.country
35 control.entry.type.id
36 control.space.before.type.id
37 control.entry.medium.id
38 control.slash
39 control.in
40 control.emph.booktitle
41 control.emph.journal
42 control.short.journal
43 control.journal.dots
44 control.link.journal
45 control.bold.volume
46 control.unknown.publisher
47 control.space.before.pages
48 control.page.ranges
49 control.urldate
50 control.url
51 control.doi
52 control.cstr
53 control.eprint
54 control.note
55 control.end.dot
56 control.capitalize.subtitle
57 control.warn.empty.field
58 %<*authoryear>
59 lang.zh.order
60 lang.ja.order
61 lang.en.order
62 lang.ru.order
63 lang.other.order
64 %</authoryear>
65 }
66
67 STRINGS {
68 control.bib.punct
69 control.cite.lang
70 control.name.year.delim
71 control.page.range.delim
72 }
73
74 % \end{macrocode}
75 %
76 % 下面每个变量若被设为 |#1| 则启用该项,若被设为 |#0| 则不启用。
77 % 默认的值是严格遵循国标的配置。
78 % \begin{macrocode}
79 FUNCTION {load.config}
80 {
81 % \end{macrocode}
82 %
83 % TODO: v3.0.0 将 2015、2005 版默认值改为 GB。
84 % \begin{macrocode}
85 %<*!(2015|2005|halfwidth|thu|ucas|ustc)>
86 "GB" 'control.bib.punct := % GB / half / bylanguage
87 %</!(2015|2005|halfwidth|thu|ucas|ustc)>
88 %<*2015|2005|halfwidth|thu|ucas|ustc>
89 "half" 'control.bib.punct := % GB / half / bylanguage
90 %</2015|2005|halfwidth|thu|ucas|ustc>
91 % \end{macrocode}
92 %
93 % 控制是否转换标题内部的标点。
94 % \begin{macrocode}
95 #1 'control.convert.punct :=
96 % \end{macrocode}
97 %
98 % 姓名的数量超过 |control.max.bib.names| 时,只著录前 |control.min.bib.names| 个,
99 % 其后加“,等”或与之相应的词。
100 % \begin{macrocode}
101 #3 'control.max.bib.names :=
102 #3 'control.min.bib.names :=
103 %<*!ucas>
104 #1 'control.max.cite.names :=
105 #1 'control.min.cite.names :=
106 %</!ucas>
107 %<*ucas>
108 #2 'control.max.cite.names :=
109 #1 'control.min.cite.names :=
110 %</ucas>
111 % \end{macrocode}
112 %
113 % \begin{macrocode}
114 #0 'control.bib.final.and :=
115 #1 'control.cite.final.and :=
116 % \end{macrocode}
117 %
118 % \begin{macrocode}
119 #1 'control.space.before.et.al :=
120 % \end{macrocode}
121 %
122 % 英文姓名转为全大写:
123 % \begin{macrocode}
124 %<*!(2005|2015)|thu|ustc>
125 #0 'control.uppercase.family :=
126 %</!(2005|2015)|thu|ustc>
127 %<*(2005|2015)&!(thu|ustc)>
128 #1 'control.uppercase.family :=
129 %</(2005|2015)&!(thu|ustc)>
130 % \end{macrocode}
131 %
132 % 名字缩写时是否保留连字符:
133 % \begin{macrocode}
134 %<*!(2005|2015)>
135 #1 'control.initialize.with.hyphen :=
136 %</!(2005|2015)>
137 %<*(2005|2015)>
138 #0 'control.initialize.with.hyphen :=
139 %</(2005|2015)>
140 % \end{macrocode}
141 %
142 % 检查姓名是否为拼音:
143 % \begin{macrocode}
144 #1 'control.check.pinyin :=
145 % \end{macrocode}
146 %
147 % 控制用汉语拼音书写的人名是否缩写。
148 % \begin{macrocode}
149 %<*!(2005|2015)>
150 #0 'control.initialize.pinyin :=
151 %</!(2005|2015)>
152 %<*2005|2015>
153 #1 'control.initialize.pinyin :=
154 %</2005|2015>
155 % \end{macrocode}
156 %
157 % 使用 TeX 宏输出“和”、“等”
158 % \begin{macrocode}
159 %<*!ucas>
160 "byentry" 'control.cite.lang := % byentry / chinese / english / macro
161 %</!ucas>
162 %<*ucas>
163 "macro" 'control.cite.lang := % byentry / chinese / english / macro
164 %</ucas>
165 % \end{macrocode}
166 %
167 % 将年份置于著者后面(著者-出版年制默认)
168 % \begin{macrocode}
169 %<*numeric|ucas>
170 #0 'control.year.before.title :=
171 %</numeric|ucas>
172 %<*authoryear&!ucas>
173 #1 'control.year.before.title :=
174 %</authoryear&!ucas>
175 % \end{macrocode}
176 %
177 % 采用著者-出版年制时,作者姓名与年份之间使用句点连接:
178 % \begin{macrocode}
179 %<*numeric>
180 "period" 'control.name.year.delim := % comma / period
181 %</numeric>
182 %<*authoryear>
183 %<*!2005>
184 "comma" 'control.name.year.delim := % comma / period
185 %</!2005>
186 %<*2005>
187 "period" 'control.name.year.delim := % comma / period
188 %</2005>
189 %</authoryear>
190 % \end{macrocode}
191 %
192 % 英文标题转为 sentence case (句首字母大写,其余小写):
193 % \begin{macrocode}
194 #1 'control.sentence.case.title :=
195 #1 'control.sentence.case.booktitle :=
196 %<*!(2005|2015)|thu|ustc>
197 #0 'control.sentence.case.journal :=
198 %</!(2005|2015)|thu|ustc>
199 % TODO: v3.0.0 set this to #1 after implementation of GB/T 7714-2025
200 %<*(2005|2015)&!(thu|ustc)>
201 #0 'control.sentence.case.journal :=
202 %</(2005|2015)&!(thu|ustc)>
203 % \end{macrocode}
204 %
205 % Sentence case 的标题在冒号后是否大写:
206 % \begin{macrocode}
207 #0 'control.capitalize.subtitle :=
208 % \end{macrocode}
209 %
210 % 在标题添加超链接:
211 % \begin{macrocode}
212 #0 'control.link.title :=
213 % \end{macrocode}
214 %
215 % 期刊是否含标题(参考 \pkg{bilatex-phys} 的选项),此选项也适用于 @incollection,
216 % @inproceedings, @patent 的标题,它们的处理方式相同。
217 % \begin{macrocode}
218 #1 'control.article.title :=
219 % \end{macrocode}
220 %
221 % 专利题名是否含专利国别
222 % \begin{macrocode}
223 %<*!(2005|thu)>
224 #0 'control.patent.country :=
225 %</!(2005|thu)>
226 %<*(2005|thu)>
227 #1 'control.patent.country :=
228 %</(2005|thu)>
229 % \end{macrocode}
230 %
231 % 控制是否著录类型标识(比如“[M/OL],含文献载体标识):
232 % \begin{macrocode}
233 #1 'control.entry.type.id :=
234 % \end{macrocode}
235 %
236 % 题名与文献类型标识的分隔符。
237 % \begin{macrocode}
238 #0 'control.space.before.type.id :=
239 % \end{macrocode}
240 %
241 % 是否显示文献载体标识(比如“/OL“):
242 % \begin{macrocode}
243 #1 'control.entry.medium.id :=
244 % \end{macrocode}
245 %
246 % 使用“//”表示析出文献
247 % \begin{macrocode}
248 #1 'control.slash :=
249 % \end{macrocode}
250 %
251 % 控制是否使用”In:”和“见”。
252 % \begin{macrocode}
253 #0 'control.in :=
254 % \end{macrocode}
255 %
256 % 书名使用斜体:
257 % \begin{macrocode}
258 %<*!italic-book-title>
259 #0 'control.emph.booktitle :=
260 %</!italic-book-title>
261 %<*italic-book-title>
262 #1 'control.emph.booktitle :=
263 %</italic-book-title>
264 % \end{macrocode}
265 %
266 % 期刊名使用斜体:
267 % \begin{macrocode}
268 #0 'control.emph.journal :=
269 % \end{macrocode}
270 %
271 % 期刊名使用缩写:
272 % \begin{macrocode}
273 #0 'control.short.journal :=
274 % \end{macrocode}
275 %
276 % 刊名缩写是否去除缩写点:
277 % \begin{macrocode}
278 #0 'control.journal.dots :=
279 % \end{macrocode}
280 %
281 % 在期刊题名添加超链接:
282 % \begin{macrocode}
283 #0 'control.link.journal :=
284 % \end{macrocode}
285 %
286 % 期刊的卷使用粗体:
287 % \begin{macrocode}
288 #0 'control.bold.volume :=
289 % \end{macrocode}
290 %
291 % 无出版地或出版者时,著录“出版地不详”,“出版者不详”,“S.l.” 或 “s.n.”:
292 % \begin{macrocode}
293 #0 'control.unknown.publisher :=
294 % \end{macrocode}
295 %
296 % 页码与前面的冒号之间是否有空格:
297 % \begin{macrocode}
298 #1 'control.space.before.pages :=
299 % \end{macrocode}
300 %
301 % 页码是否只含起始页:
302 % \begin{macrocode}
303 #1 'control.page.ranges :=
304 % \end{macrocode}
305 %
306 % 起止页码中的连接号:
307 % \begin{macrocode}
308 "-" 'control.page.range.delim :=
309 % \end{macrocode}
310 %
311 % 是否著录非电子文献的引用日期:
312 % \begin{macrocode}
313 #1 'control.urldate :=
314 % \end{macrocode}
315 %
316 % 是否著录 URL:
317 % \begin{macrocode}
318 %<*!(ustc)>
319 #1 'control.url :=
320 %</!(ustc)>
321 %<*ustc>
322 #0 'control.url :=
323 %</ustc>
324 % \end{macrocode}
325 %
326 % 是否著录 DOI:
327 % \begin{macrocode}
328 %<*!(2005|ustc)>
329 #1 'control.doi :=
330 %</!(2005|ustc)>
331 %<*2005|ustc>
332 #0 'control.doi :=
333 %</2005|ustc>
334 % \end{macrocode}
335 %
336 % 是否著录 CSTR:
337 % \begin{macrocode}
338 %<*!(2005|2015)>
339 #1 'control.cstr :=
340 %</!(2005|2015)>
341 %<*2005|2015>
342 #0 'control.cstr :=
343 %</2005|2015>
344 % \end{macrocode}
345 %
346 % 是否著录预印本的标识符 eprint(“arXiv:1112.6136”的编号部分。
347 % \begin{macrocode}
348 #0 'control.eprint :=
349 % \end{macrocode}
350 %
351 % 在每一条文献最后输出注释(note)的内容:
352 % \begin{macrocode}
353 #0 'control.note :=
354 % \end{macrocode}
355 %
356 % 结尾加句点
357 % \begin{macrocode}
358 #1 'control.end.dot :=
359 % \end{macrocode}
360 %
361 % 是否警告缺失的字段。
362 % \begin{macrocode}
363 #1 'control.warn.empty.field :=
364 % \end{macrocode}
365 %
366 % 参考文献表按照“著者-出版年”组织时,各个文种的顺序:
367 % \begin{macrocode}
368 %<*authoryear>
369 #1 'lang.zh.order :=
370 #2 'lang.ja.order :=
371 #3 'lang.en.order :=
372 #4 'lang.ru.order :=
373 #5 'lang.other.order :=
374 %</authoryear>
375 }
376
377 % \end{macrocode}
378 %
379 %
380 % \subsection{The ENTRY declaration}
381 %
382 % Like Scribe's (according to pages 231-2 of the April '84 edition),
383 % but no fullauthor or editors fields because BibTeX does name handling.
384 % The annote field is commented out here because this family doesn't
385 % include an annotated bibliography style. And in addition to the fields
386 % listed here, BibTeX has a built-in crossref field, explained later.
387 % \begin{macrocode}
388 ENTRY
389 { address
390 archiveprefix
391 author
392 bookauthor
393 booksubtitle
394 booktitle
395 booktitleaddon
396 country % 专利国别
397 cstr
398 date
399 dimensions
400 doi
401 edition
402 editor
403 eid
404 entrymediumid
405 entrysubtype
406 entrytypeid
407 eventtitle
408 eprint
409 eprinttype
410 holder
411 howpublished
412 institution
413 journal
414 journalsubtitle
415 journaltitle
416 journaltitleaddon
417 key
418 langid
419 language
420 location
421 mainsubtitle
422 maintitle
423 maintitleaddon
424 mark
425 medium
426 nationality % 专利国别,兼容 IEEEtran.bst
427 note
428 number
429 organization
430 pages
431 publisher
432 scale
433 school
434 series
435 shortjournal
436 subtitle
437 title
438 titleaddon
439 translator
440 url
441 urldate
442 version
443 volume
444 year
445 CTL_bib_punct
446 CTL_convert_punct
447 CTL_max_bib_names
448 CTL_min_bib_names
449 CTL_max_cite_names
450 CTL_min_cite_names
451 CTL_uppercase_family
452 CTL_initialize_with_hyphen
453 CTL_check_pinyin
454 CTL_initialize_pinyin
455 CTL_bib_final_and
456 CTL_cite_final_and
457 CTL_cite_lang
458 CTL_space_before_et_al
459 CTL_year_before_title
460 CTL_name_year_delim
461 CTL_sentence_case
462 CTL_sentence_case_title
463 CTL_sentence_case_booktitle
464 CTL_sentence_case_journal
465 CTL_capitalize_subtitle
466 CTL_link_title
467 CTL_article_title
468 CTL_patent_country
469 CTL_entry_type_id
470 CTL_space_before_type_id
471 CTL_entry_medium_id
472 CTL_slash
473 CTL_in
474 CTL_emph_booktitle
475 CTL_emph_journal
476 CTL_short_journal
477 CTL_journal_dots
478 CTL_link_journal
479 CTL_bold_volume
480 CTL_unknown_publisher
481 CTL_space_before_pages
482 CTL_page_ranges
483 CTL_page_range_delim
484 CTL_urldate
485 CTL_url
486 CTL_doi
487 CTL_eprint
488 CTL_note
489 CTL_end_dot
490 CTL_warn_empty_field
491 }
492 { entry.lang is.lang.cjk entry.numbered require.url }
493 % \end{macrocode}
494 %
495 % These string entry variables are used to form the citation label.
496 % In a storage pinch, sort.label can be easily computed on the fly.
497 % \begin{macrocode}
498 { label extra.label sort.label short.list entry.type.id entry.eprint entry.url }
499
500 % \end{macrocode}
501 %
502 %
503 % \subsection{Entry functions}
504 %
505 % Each entry function starts by calling output.bibitem, to write the
506 % |\bibitem| and its arguments to the .BBL file. Then the various fields
507 % are formatted and printed by output or output.check. Those functions
508 % handle the writing of separators (commas, periods, |\newblock|'s),
509 % taking care not to do so when they are passed a null string.
510 % Finally, fin.entry is called to add the final period and finish the
511 % entry.
512 %
513 % A bibliographic reference is formatted into a number of `blocks':
514 % in the open format, a block begins on a new line and subsequent
515 % lines of the block are indented. A block may contain more than
516 % one sentence (well, not a grammatical sentence, but something to
517 % be ended with a sentence ending period). The entry functions should
518 % call new.block whenever a block other than the first is about to be
519 % started. They should call new.sentence whenever a new sentence is
520 % to be started. The output functions will ensure that if two
521 % new.sentence's occur without any non-null string being output between
522 % them then there won't be two periods output. Similarly for two
523 % successive new.block's.
524 %
525 % The output routines don't write their argument immediately.
526 % Instead, by convention, that argument is saved on the stack to be
527 % output next time (when we'll know what separator needs to come
528 % after it). Meanwhile, the output routine has to pop the pending
529 % output off the stack, append any needed separator, and write it.
530 %
531 % To tell which separator is needed, we maintain an output.state.
532 % It will be one of these values:
533 % before.all just after the |\bibitem|
534 % mid.sentence in the middle of a sentence: comma needed
535 % if more sentence is output
536 % after.sentence just after a sentence: period needed
537 % after.block just after a block (and sentence):
538 % period and |\newblock| needed.
539 % Note: These styles don't use after.sentence
540 %
541 % VAR: output.state : INTEGER -- state variable for output
542 %
543 % The output.nonnull function saves its argument (assumed to be nonnull)
544 % on the stack, and writes the old saved value followed by any needed
545 % separator. The ordering of the tests is decreasing frequency of
546 % occurrence.
547 %
548 % \begin{pseudocode}
549 % output.nonnull(s) ==
550 % BEGIN
551 % s := argument on stack
552 % if output.state = mid.sentence then
553 % write$(pop() * ", ")
554 % -- "pop" isn't a function: just use stack top
555 % else
556 % if output.state = after.block then
557 % write$(add.period$(pop()))
558 % newline$
559 % write$("\newblock ")
560 % else
561 % if output.state = before.all then
562 % write$(pop())
563 % else -- output.state should be after.sentence
564 % write$(add.period$(pop()) * " ")
565 % fi
566 % fi
567 % output.state := mid.sentence
568 % fi
569 % push s on stack
570 % END
571 % \end{pseudocode}
572 %
573 % The output function calls output.nonnull if its argument is non-empty;
574 % its argument may be a missing field (thus, not necessarily a string)
575 %
576 % \begin{pseudocode}
577 % output(s) ==
578 % BEGIN
579 % if not empty$(s) then output.nonnull(s)
580 % fi
581 % END
582 % \end{pseudocode}
583 %
584 % The output.check function is the same as the output function except that, if
585 % necessary, output.check warns the user that the t field shouldn't be empty
586 % (this is because it probably won't be a good reference without the field;
587 % the entry functions try to make the formatting look reasonable even when
588 % such fields are empty).
589 %
590 % \begin{pseudocode}
591 % output.check(s,t) ==
592 % BEGIN
593 % if empty$(s) then
594 % warning$("empty " * t * " in " * cite$)
595 % else output.nonnull(s)
596 % fi
597 % END
598 % \end{pseudocode}
599 %
600 % The output.bibitem function writes the |\bibitem| for the current entry
601 % (the label should already have been set up), and sets up the separator
602 % state for the output functions. And, it leaves a string on the stack
603 % as per the output convention.
604 %
605 % \begin{pseudocode}
606 % output.bibitem ==
607 % BEGIN
608 % newline$
609 % write$("\bibitem[") % for alphabetic labels,
610 % write$(label) % these three lines
611 % write$("]{") % are used
612 % write$("\bibitem{") % this line for numeric labels
613 % write$(cite$)
614 % write$("}")
615 % push "" on stack
616 % output.state := before.all
617 % END
618 % \end{pseudocode}
619 %
620 % The fin.entry function finishes off an entry by adding a period to the
621 % string remaining on the stack. If the state is still before.all
622 % then nothing was produced for this entry, so the result will look bad,
623 % but the user deserves it. (We don't omit the whole entry because the
624 % entry was cited, and a bibitem is needed to define the citation label.)
625 %
626 % \begin{pseudocode}
627 % fin.entry ==
628 % BEGIN
629 % write$(add.period$(pop()))
630 % newline$
631 % END
632 % \end{pseudocode}
633 %
634 % The new.block function prepares for a new block to be output, and
635 % new.sentence prepares for a new sentence.
636 %
637 % \begin{pseudocode}
638 % new.block ==
639 % BEGIN
640 % if output.state <> before.all then
641 % output.state := after.block
642 % fi
643 % END
644 % \end{pseudocode}
645 %
646 % \begin{pseudocode}
647 % new.sentence ==
648 % BEGIN
649 % if output.state <> after.block then
650 % if output.state <> before.all then
651 % output.state := after.sentence
652 % fi
653 % fi
654 % END
655 % \end{pseudocode}
656 % \begin{macrocode}
657 INTEGERS { output.state before.all mid.sentence after.sentence after.block after.punct }
658
659 INTEGERS { lang.zh lang.ja lang.ko lang.en lang.ru lang.other }
660
661 INTEGERS { charptr len }
662
663 STRINGS { pinyin.table }
664
665 FUNCTION {init.state.consts}
666 { #0 'before.all :=
667 #1 'mid.sentence :=
668 #2 'after.sentence :=
669 #3 'after.block :=
670 #4 'after.punct :=
671 #3 'lang.zh :=
672 #4 'lang.ja :=
673 #5 'lang.ko :=
674 #1 'lang.en :=
675 #2 'lang.ru :=
676 #0 'lang.other :=
677 " a ai an ang ao "
678 "ba bai ban bang bao bei ben beng bi bian biao bie bin bing bo bu " *
679 "ca cai can cang cao ce cen ceng cha chai chan chang chao che chen cheng chi chong chou chu chuai chuan chuang chui chun chuo ci cong cou cu cuan cui cun cuo " *
680 "da dai dan dang dao de dei deng di dia dian diao die ding diu dong dou du duan dui dun duo " *
681 "e ei en eng er " *
682 "fa fan fang fei fen feng fo fou fu " *
683 "ga gai gan gang gao ge gei gen geng gong gou gu gua guai guan guang gui gun guo " *
684 "ha hai han hang hao he hei hen heng hong hou hu hua huai huan huang hui hun huo " *
685 "ji jia jian jiang jiao jie jin jing jiong jiu ju juan jue jun " *
686 "ka kai kan kang kao ke ken keng kong kou ku kua kuai kuan kuang kui kun kuo " *
687 "la lai lan lang lao le lei leng li lia lian liang liao lie lin ling liu long lou lu luan lun luo lü lüe lyu lyue " *
688 "ma mai man mang mao me mei men meng mi mian miao mie min ming miu mo mou mu " *
689 "na nai nan nang nao ne nei nen neng ni nian niang niao nie nin ning niu nong nu nuan nuo nü nüe nyu nyue " *
690 "o ou " *
691 "pa pai pan pang pao pei pen peng pi pian piao pie pin ping po pou pu " *
692 "qi qia qian qiang qiao qie qin qing qiong qiu qu quan que qun " *
693 "ran rang rao re ren reng ri rong rou ru ruan rui run ruo " *
694 "sa sai san sang sao se sen seng sha shai shan shang shao she shei shen sheng shi shou shu shua shuai shuan shuang shui shun shuo si song sou su suan sui sun suo " *
695 "ta tai tan tang tao te teng ti tian tiao tie ting tong tou tu tuan tui tun tuo " *
696 "wa wai wan wang wei wen weng wo wu " *
697 "xi xia xian xiang xiao xie xin xing xiong xiu xu xuan xue xun " *
698 "ya yan yang yao ye yi yin ying yong you yu yuan yue yun " *
699 "za zai zan zang zao ze zei zen zeng zha zhai zhan zhang zhao zhe zhei zhen zheng zhi zhong zhou zhu zhua zhuai zhuan zhuang zhui zhun zhuo zi zong zou zu zuan zui zun zuo " *
700 'pinyin.table :=
701 %<*deprecated>
702 %<*numeric>
703 "The style name 'gbt7714-numerical' is deprecated. Use 'gbt7714-numeric' instead." warning$
704 %</numeric>
705 %<*authoryear>
706 "The style name 'gbt7714-author-year' is deprecated. Use 'gbt7714-authoryear' instead." warning$
707 %</authoryear>
708 %</deprecated>
709 }
710
711 % \end{macrocode}
712 %
713 % 下面是一些常量的定义
714 % \begin{macrocode}
715 FUNCTION {bbl.anonymous}
716 { entry.lang lang.zh =
717 { "佚名" }
718 { "Anon" }
719 if$
720 }
721
722 FUNCTION {bbl.no.date}
723 { entry.lang lang.zh =
724 { "无日期" }
725 { "n.d." }
726 if$
727 }
728
729 FUNCTION {space.precedes.et.al}
730 { is.lang.cjk
731 { control.space.before.et.al
732 { "\ " }
733 { "" }
734 if$
735 }
736 { " " }
737 if$
738 }
739
740 FUNCTION {bbl.and}
741 { entry.lang lang.zh =
742 { "和" }
743 { entry.lang lang.ja =
744 { "と" }
745 { entry.lang lang.ru =
746 { "и" }
747 { "and" }
748 if$
749 }
750 if$
751 }
752 if$
753 }
754
755 FUNCTION {bbl.et.al}
756 { entry.lang lang.zh =
757 { "等" }
758 { entry.lang lang.ja =
759 { "ほか" }
760 { entry.lang lang.ru =
761 { "и~др." }
762 { "et~al." }
763 if$
764 }
765 if$
766 }
767 if$
768 }
769
770 FUNCTION {cite.and}
771 { control.cite.lang "byentry" =
772 'bbl.and
773 { control.cite.lang "macro" =
774 { "{\biband}" }
775 { control.cite.lang "chinese" =
776 { "和" }
777 { "and" }
778 if$
779 }
780 if$
781 }
782 if$
783 }
784
785 FUNCTION {cite.et.al}
786 { control.cite.lang "byentry" =
787 { bbl.et.al }
788 { control.cite.lang "macro" =
789 { "{\bibetal}" }
790 { control.cite.lang "chinese" =
791 { "等" }
792 { "et~al." }
793 if$
794 }
795 if$
796 }
797 if$
798 }
799
800 FUNCTION {bbl.in}
801 { entry.lang lang.zh =
802 { "见" }
803 { "In" }
804 if$
805 }
806
807 FUNCTION {bbl.translator}
808 { entry.lang lang.zh =
809 { "译" }
810 { "trans." }
811 if$
812 }
813
814 %<*!2005>
815 FUNCTION {bbl.wide.space} { "\quad " }
816 %</!2005>
817 %<*2005>
818 FUNCTION {bbl.wide.space} { "\ " }
819 %</2005>
820
821 FUNCTION {bbl.edition}
822 { entry.lang lang.zh =
823 { "版" }
824 { entry.lang lang.ja =
825 { "版" }
826 { entry.lang lang.ru =
827 { "изд." }
828 { "ed." }
829 if$
830 }
831 if$
832 }
833 if$
834 }
835
836 FUNCTION {bbl.double.slash} { "//\allowbreak" }
837
838 FUNCTION {bbl.sine.loco}
839 { entry.lang lang.zh =
840 { "出版地不详" }
841 { "S.l." }
842 if$
843 }
844
845 FUNCTION {bbl.sine.nomine}
846 { entry.lang lang.zh =
847 { "出版者不详" }
848 { "s.n." }
849 if$
850 }
851
852 FUNCTION {bbl.sine.loco.sine.nomine}
853 { entry.lang lang.zh =
854 { "出版地不详: 出版者不详" }
855 { "S.l.: s.n." }
856 if$
857 }
858
859 FUNCTION {default.self.tokens} { ":,-'–—?.!" }
860
861 FUNCTION {latin.upper} { "ÀÁÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞŸĀĂĄĆĈĊČĎĐĒĔĖĘĚĜĞĠĢĤĦĨĪĬĮİIĴĶĹĻĽĿŁŃŅŇŊŌŎŐŒŔŖŘŚŜŞŠŢŤŦŨŪŬŮŰŲŴŶŸŹŻŽ" }
862
863 FUNCTION {latin.lower} { "àáãäåæçèéêëìíîïðñòóôõöøùúûüýþÿāăąćĉċčďđēĕėęěĝğġģĥħĩīĭįiıĵķĺļľŀłńņňŋōŏőœŕŗřśŝşšţťŧũūŭůűųŵŷÿźżž" }
864
865 FUNCTION {range.delimiters} { "-–—~" }
866
867 % \end{macrocode}
868 %
869 % These three functions pop one or two (integer) arguments from the stack
870 % and push a single one, either 0 or 1.
871 % The |'skip$| in the `and' and `or' functions are used because
872 % the corresponding |if$| would be idempotent
873 % \begin{macrocode}
874 FUNCTION {not}
875 { { #0 }
876 { #1 }
877 if$
878 }
879
880 FUNCTION {and}
881 { 'skip$
882 { pop$ #0 }
883 if$
884 }
885
886 FUNCTION {or}
887 { { pop$ #1 }
888 'skip$
889 if$
890 }
891
892 FUNCTION {string.length}
893 { #0 swap$
894 { duplicate$ "" = not }
895 { swap$ #1 + swap$
896 #2 global.max$ substring$
897 }
898 while$
899 pop$
900 }
901
902 STRINGS { x y }
903
904 STRINGS { replace find text }
905
906 % The "X Y contains" function checks if string Y is contained in X.
907 % Although we only need to check if Y is at the beginning of X,
908 % it makes no practical difference, so just use it as-is.
909 FUNCTION {contains}
910 { 'find :=
911 'text :=
912 find string.length 'len :=
913 text string.length len - #1 + 'charptr :=
914 { charptr #0 >
915 text charptr len substring$ find = not
916 and
917 }
918 { charptr #1 - 'charptr := }
919 while$
920 charptr #0 >
921 }
922
923 % \end{macrocode}
924 %
925 % the variables s and t are temporary string holders
926 % \begin{macrocode}
927 STRINGS { s t }
928
929 FUNCTION {add.period}
930 { "bylanguage" control.bib.punct =
931 { is.lang.cjk
932 { "." * }
933 'add.period$
934 if$
935 }
936 'add.period$
937 if$
938 }
939
940 FUNCTION {after.period.space}
941 { is.lang.cjk
942 "bylanguage" control.bib.punct = and
943 { "" }
944 { " " }
945 if$
946 }
947
948 FUNCTION {add.comma}
949 { "bylanguage" control.bib.punct =
950 is.lang.cjk and
951 "GB" control.bib.punct = or
952 { "," * }
953 { ", " * }
954 if$
955 }
956
957 FUNCTION {add.colon}
958 { "bylanguage" control.bib.punct =
959 is.lang.cjk and
960 "GB" control.bib.punct = or
961 { ":" * }
962 { ": " * }
963 if$
964 }
965
966 FUNCTION {add.colon.by.language}
967 { is.lang.cjk
968 { ":" * }
969 { ": " * }
970 if$
971 }
972
973 FUNCTION {bbl.pages.colon}
974 { "bylanguage" control.bib.punct =
975 is.lang.cjk and
976 "GB" control.bib.punct = or
977 { ":" }
978 { control.space.before.pages
979 { ": " }
980 { ":\allowbreak " }
981 if$
982 }
983 if$
984 }
985
986 FUNCTION {make.parentheses}
987 { "bylanguage" control.bib.punct =
988 is.lang.cjk and
989 "GB" control.bib.punct = or
990 { "(" swap$ * ")" * }
991 { "(" swap$ * ")" * }
992 if$
993 }
994
995 FUNCTION {make.brackets}
996 { "[" swap$ * "]" *
997 }
998
999 INTEGERS { find_length }
1000 FUNCTION { find.replace }
1001 { 'replace :=
1002 'find :=
1003 'text :=
1004 find string.length 'find_length :=
1005 ""
1006 { text empty$ not }
1007 { text #1 find_length substring$ find =
1008 { replace *
1009 text #1 find_length + global.max$ substring$ 'text :=
1010 }
1011 { text #1 #1 substring$ *
1012 text #2 global.max$ substring$ 'text :=
1013 }
1014 if$
1015 }
1016 while$
1017 }
1018
1019 FUNCTION {convert.fullwidth.punctuations}
1020 { ", " "," find.replace
1021 ": " ":" find.replace
1022 "; " ";" find.replace
1023 "! " "!" find.replace
1024 "!" "!" find.replace
1025 "? " "?" find.replace
1026 "?" "?" find.replace
1027 " (" "(" find.replace
1028 "(" "(" find.replace
1029 ") " ")" find.replace
1030 ")" ")" find.replace
1031 }
1032
1033 FUNCTION {convert.halfwidth.punctuations}
1034 { "." ". " find.replace
1035 "," ", " find.replace
1036 ":" ": " find.replace
1037 ";" "; " find.replace
1038 "!" "! " find.replace
1039 "?" "? " find.replace
1040 "(" " (" find.replace
1041 ")." ")." find.replace
1042 ")," ")," find.replace
1043 "):" "):" find.replace
1044 ");" ");" find.replace
1045 ")}" ")}" find.replace
1046 ")" ") " find.replace
1047 % Strip leading and trailing spaces
1048 duplicate$ #1 #1 substring$ " " =
1049 { #2 global.max$ substring$ }
1050 'skip$
1051 if$
1052 duplicate$ #-1 #1 substring$ " " =
1053 { duplicate$ string.length #1 - #1 swap$ substring$ }
1054 'skip$
1055 if$
1056 }
1057
1058 FUNCTION {convert.punctuations}
1059 { "GB" control.bib.punct =
1060 { "." ". " find.replace
1061 convert.fullwidth.punctuations
1062 }
1063 { "half" control.bib.punct =
1064 { convert.halfwidth.punctuations }
1065 { "bylanguage" control.bib.punct =
1066 { is.lang.cjk
1067 { ". " "." find.replace
1068 convert.fullwidth.punctuations
1069 }
1070 { convert.halfwidth.punctuations }
1071 if$
1072 }
1073 'skip$
1074 if$
1075 }
1076 if$
1077 }
1078 if$
1079 }
1080
1081 FUNCTION {format.punctuations}
1082 { control.convert.punct
1083 'convert.punctuations
1084 'skip$
1085 if$
1086 is.lang.cjk
1087 { "---" "—" find.replace
1088 "--" "—" find.replace
1089 }
1090 { "“" "``" find.replace
1091 "”" "''" find.replace
1092 "‘" "`" find.replace
1093 "’" "'" find.replace
1094 "—" "---" find.replace
1095 "–" "--" find.replace
1096 }
1097 if$
1098 }
1099
1100 STRINGS { output.punct }
1101
1102 % \end{macrocode}
1103 %
1104 % This is similar to biblatex's \setunit.
1105 % \begin{macrocode}
1106 FUNCTION {set.punct}
1107 { output.state mid.sentence =
1108 output.state after.punct = or
1109 { 'output.punct :=
1110 after.punct 'output.state :=
1111 }
1112 'pop$
1113 if$
1114 }
1115
1116 FUNCTION {output.nonnull}
1117 { 's :=
1118 output.state mid.sentence =
1119 { add.comma write$ }
1120 { output.state after.block =
1121 { add.period write$
1122 newline$
1123 "\newblock " write$
1124 }
1125 { output.state before.all =
1126 'write$
1127 { output.state after.punct =
1128 { output.punct * write$ }
1129 { add.period after.period.space * write$ }
1130 if$
1131 }
1132 if$
1133 }
1134 if$
1135 mid.sentence 'output.state :=
1136 }
1137 if$
1138 s
1139 }
1140
1141 FUNCTION {output}
1142 { duplicate$ empty$
1143 'pop$
1144 'output.nonnull
1145 if$
1146 }
1147
1148 FUNCTION {output.check}
1149 { 't :=
1150 duplicate$ empty$
1151 { pop$
1152 control.warn.empty.field
1153 { "empty " t * " in " * cite$ * warning$ }
1154 'skip$
1155 if$
1156 }
1157 'output.nonnull
1158 if$
1159 }
1160
1161 % \end{macrocode}
1162 %
1163 % This function finishes all entries.
1164 %
1165 % \begin{macrocode}
1166 FUNCTION {fin.entry}
1167 { control.end.dot
1168 'add.period
1169 'skip$
1170 if$
1171 write$
1172 newline$
1173 }
1174
1175 FUNCTION {new.block}
1176 { output.state before.all =
1177 'skip$
1178 { after.block 'output.state := }
1179 if$
1180 }
1181
1182 FUNCTION {new.sentence}
1183 { output.state after.block =
1184 'skip$
1185 { output.state before.all =
1186 'skip$
1187 { after.sentence 'output.state := }
1188 if$
1189 }
1190 if$
1191 }
1192
1193 FUNCTION {new.slash}
1194 { output.state before.all =
1195 'skip$
1196 { control.slash
1197 { bbl.double.slash * write$
1198 newline$
1199 ""
1200 before.all 'output.state :=
1201 }
1202 { new.block }
1203 if$
1204 }
1205 if$
1206 }
1207
1208 % \end{macrocode}
1209 %
1210 % Sometimes we begin a new block only if the block will be big enough. The
1211 % new.block.checka function issues a new.block if its argument is nonempty;
1212 % new.block.checkb does the same if either of its TWO arguments is nonempty.
1213 % \begin{macrocode}
1214 FUNCTION {new.block.checka}
1215 { empty$
1216 'skip$
1217 'new.block
1218 if$
1219 }
1220
1221 FUNCTION {new.block.checkb}
1222 { empty$
1223 swap$ empty$
1224 and
1225 'skip$
1226 'new.block
1227 if$
1228 }
1229
1230 % \end{macrocode}
1231 %
1232 % The new.sentence.check functions are analogous.
1233 % \begin{macrocode}
1234 FUNCTION {new.sentence.checka}
1235 { empty$
1236 'skip$
1237 'new.sentence
1238 if$
1239 }
1240
1241 FUNCTION {new.sentence.checkb}
1242 { empty$
1243 swap$ empty$
1244 and
1245 'skip$
1246 'new.sentence
1247 if$
1248 }
1249
1250 % \end{macrocode}
1251 %
1252 % In order to support UTF-8 encoding, we need some auxiliary functions. Below
1253 % are a series of such functions. We try to make functions loosely-coupled as
1254 % much as possible. Where the use of variables is inevitable in functions, we
1255 % generally assume it is the caller's responsibility to save and restore those
1256 % variables. Exceptions are made for some unary functions, where it is
1257 % convenient for the callee to do so.
1258 % \begin{macrocode}
1259 INTEGERS { a b }
1260
1261 % \end{macrocode}
1262 %
1263 % Function |is.int.in.range| takes a codepoint and two integers and check if the
1264 % codepoint is between these two integers (inclusive).
1265 % \begin{macrocode}
1266 % codepoint: int, a: int, b: int -> bool
1267 % variable used: b
1268 FUNCTION {is.int.in.range}
1269 { 'b :=
1270 #1 +
1271 b >
1272 { #1 - b < }
1273 { pop$ #0 }
1274 if$
1275 }
1276
1277 % \end{macrocode}
1278 %
1279 % Function |mult.power2| takes two integers and returns \(2^nm\).
1280 % \begin{macrocode}
1281 % m: int, n: int -> int
1282 FUNCTION {mult.power2}
1283 { { duplicate$ #0 > }
1284 { swap$
1285 duplicate$ +
1286 swap$ #1 -
1287 }
1288 while$
1289 pop$
1290 }
1291
1292 % \end{macrocode}
1293 %
1294 % Function |find.match.brace| takes two strings, the first of which is assumed
1295 % to be |"{"|, and find the matching brace in the second string. It returns a
1296 % token (or subtoken) and the rest of the string after the matching brace. When
1297 % braces are unmatched, it issues a warning and complete the brace
1298 % automatically, following the convention of the original \BibTeX{}.
1299 % \begin{macrocode}
1300 % "{", str -> subtoken: str, rest: str
1301 % variables used: s, t
1302 FUNCTION {find.match.brace}
1303 { 's :=
1304 't :=
1305 #1
1306 { duplicate$ #0 >
1307 s empty$ not and }
1308 { s #1 #1 substring$ "{" =
1309 { #1 + }
1310 { s #1 #1 substring$ "}" =
1311 { #1 - }
1312 'skip$
1313 if$
1314 }
1315 if$
1316 t s #1 #1 substring$ * 't :=
1317 s #2 global.max$ substring$ 's :=
1318 }
1319 while$
1320
1321 duplicate$ #0 >
1322 { "Unbalanced brace(s): one or more closing braces are missing" warning$
1323 { duplicate$ #0 > }
1324 { t "}" * 't :=
1325 #1 -
1326 }
1327 while$
1328 }
1329 'skip$
1330 if$
1331 pop$
1332
1333 t
1334 s
1335 }
1336
1337 % \end{macrocode}
1338 %
1339 % Function |split.first.char.from.str| takes a UTF-8 string and return
1340 % the first UTF-8 character and the rest of the string in reverse order.
1341 % \begin{macrocode}
1342 % str -> str, char
1343 FUNCTION {split.first.char.from.str}
1344 { duplicate$ "" =
1345 { "split.first.char.from.str: Trying to split an empty string!" warning$
1346 ""
1347 }
1348 { duplicate$ #1 #1 substring$ chr.to.int$ #128 <
1349 { duplicate$ #1 #1 substring$ swap$
1350 #2 global.max$ substring$ swap$
1351 }
1352 { duplicate$ #1 #1 substring$ chr.to.int$ #224 <
1353 { duplicate$ #1 #2 substring$ swap$
1354 #3 global.max$ substring$ swap$
1355 }
1356 { duplicate$ #1 #1 substring$ chr.to.int$ #240 <
1357 { duplicate$ #1 #3 substring$ swap$
1358 #4 global.max$ substring$ swap$
1359 }
1360 { duplicate$ #1 #4 substring$ swap$
1361 #5 global.max$ substring$ swap$
1362 }
1363 if$
1364 }
1365 if$
1366 }
1367 if$
1368 }
1369 if$
1370 }
1371
1372 % \end{macrocode}
1373 %
1374 % Function |get.first.char.from.str| takes a UTF-8 string and return the
1375 % first UTF-8 character.
1376 % \begin{macrocode}
1377 % str -> char
1378 FUNCTION {get.first.char.from.str}
1379 { split.first.char.from.str swap$ pop$ }
1380
1381 % \end{macrocode}
1382 %
1383 % Function |split.first.tex.char.from.str| is like
1384 % |split.first.char.from.str|. It takes a UTF-8 string and return the
1385 % first UTF-8 character or first \TeX group and the rest of string in
1386 % reverse order.
1387 % \begin{macrocode}
1388 % str -> rest: str, texchar
1389 FUNCTION {split.first.tex.char.from.str}
1390 { duplicate$ #1 #1 substring$ "{" =
1391 { split.first.char.from.str swap$
1392 find.match.brace swap$
1393 }
1394 'split.first.char.from.str
1395 if$
1396 }
1397
1398 % \end{macrocode}
1399 %
1400 % Function |char.to.unicode| takes a UTF-8 character and returns its
1401 % codepoint in Unicode. It issues a warning and returns \(-1\) if the
1402 % presumed character is an empty string. For other invalid input, the
1403 % behavior is undefined.
1404 % \begin{macrocode}
1405 % char -> int
1406 FUNCTION {char.to.unicode}
1407 { duplicate$ #4 #1 substring$ "" =
1408 { duplicate$ #3 #1 substring$ "" =
1409 { duplicate$ #2 #1 substring$ "" =
1410 { duplicate$ "" =
1411 { "Empty string is not a char!" warning$
1412 pop$ #-1
1413 }
1414 { #1 #1 substring$ chr.to.int$ }
1415 if$
1416 }
1417 { duplicate$ #2 #1 substring$ chr.to.int$ #128 - swap$
1418 #1 #1 substring$ chr.to.int$ #192 -
1419 #6 mult.power2 +
1420 }
1421 if$
1422 }
1423 { duplicate$ #3 #1 substring$ chr.to.int$ #128 - swap$
1424 duplicate$ #2 #1 substring$ chr.to.int$ #128 - swap$
1425 #1 #1 substring$ chr.to.int$ #224 -
1426 #6 mult.power2 +
1427 #6 mult.power2 +
1428 }
1429 if$
1430 }
1431 { duplicate$ #4 #1 substring$ chr.to.int$ #128 - swap$
1432 duplicate$ #3 #1 substring$ chr.to.int$ #128 - swap$
1433 duplicate$ #2 #1 substring$ chr.to.int$ #128 - swap$
1434 #1 #1 substring$ chr.to.int$ #240 -
1435 #6 mult.power2 +
1436 #6 mult.power2 +
1437 #6 mult.power2 +
1438 }
1439 if$
1440 }
1441
1442 % \end{macrocode}
1443 %
1444 % Function |is.char.in.str| takes a string and a UTF-8 character. It
1445 % checks whether the character is in the string. It issues a warning
1446 % and returns \(0\) if the presumed character is an empty string. It
1447 % also returns \(0\) if the string itself is empty. For other input,
1448 % the behavior is undefined.
1449 % \begin{macrocode}
1450 % str, char -> bool
1451 % variable used: t
1452 FUNCTION {is.char.in.str}
1453 { 't :=
1454 t "" =
1455 { "is.char.in.str: Empty string is not a char!" warning$ }
1456 'skip$
1457 if$
1458
1459 #0 swap$
1460 { duplicate$ "" = not }
1461 { split.first.char.from.str t =
1462 { pop$ pop$ #1 "" }
1463 'skip$
1464 if$
1465 }
1466 while$
1467 pop$
1468 }
1469
1470 % \end{macrocode}
1471 %
1472 % Function |is.upper.ascii| takes a UTF-8 character and checks whether
1473 % it is an uppercase ASCII letter.
1474 % \begin{macrocode}
1475 % char -> bool
1476 % variable used: b
1477 FUNCTION {is.upper.ascii}
1478 { char.to.unicode #65 swap$ #90 swap$ is.int.in.range }
1479
1480 % \end{macrocode}
1481 %
1482 % Function |is.upper| takes a UTF-8 character and checks whether it is
1483 % uppercase in the range from |U+0000| to |U+017F|.
1484 % \begin{macrocode}
1485 % char -> bool
1486 % variable used: b
1487 FUNCTION {is.upper}
1488 { duplicate$ is.upper.ascii
1489 { pop$ #1 }
1490 { latin.upper swap$ is.char.in.str }
1491 if$
1492 }
1493
1494 % \end{macrocode}
1495 %
1496 % Function |is.lower.ascii| takes a UTF-8 character and checks whether
1497 % it is a lowercase ASCII letter.
1498 % \begin{macrocode}
1499 % char -> bool
1500 % variable used: b
1501 FUNCTION {is.lower.ascii}
1502 { char.to.unicode #97 swap$ #122 swap$ is.int.in.range }
1503
1504 % \end{macrocode}
1505 %
1506 % Function |is.upper| takes a UTF-8 character and checks whether it is
1507 % lowercase in the range from |U+0000| to |U+017F|.
1508 % \begin{macrocode}
1509 % char -> bool
1510 % variable used: b
1511 FUNCTION {is.lower}
1512 { duplicate$ is.lower.ascii
1513 { pop$ #1 }
1514 { latin.lower swap$ is.char.in.str }
1515 if$
1516 }
1517
1518 % \end{macrocode}
1519 %
1520 % Function |is.printable.ascii| takes a UTF-8 character and checks
1521 % whether it is a printable ASCII character.
1522 % \begin{macrocode}
1523 % char -> bool
1524 % variable used: b
1525 FUNCTION {is.printable.ascii}
1526 { char.to.unicode #32 swap$ #126 swap$ is.int.in.range }
1527
1528 % \end{macrocode}
1529 %
1530 % Function |is.letter.ascii| takes a UTF-8 character and checks
1531 % whether it is an ASCII letter.
1532 % \begin{macrocode}
1533 % char -> bool
1534 % variable used: b
1535 FUNCTION {is.letter.ascii}
1536 { duplicate$ is.upper.ascii swap$ is.lower.ascii or }
1537
1538 % \end{macrocode}
1539 %
1540 % Function |is.symbol.ascii| takes a UTF-8 character and checks whether
1541 % it is a printable ASCII character but not an ASCII letter.
1542 % \begin{macrocode}
1543 % char -> bool
1544 % variable used: b
1545 FUNCTION {is.symbol.ascii}
1546 { duplicate$ is.printable.ascii swap$ is.letter.ascii not and }
1547
1548 % \end{macrocode}
1549 %
1550 % Function |is.all.lower| takes a string and checks whether every
1551 % character in it is lowercase in the range from |U+0000| to |U+017F|.
1552 % \begin{macrocode}
1553 % str -> bool
1554 % variable used: b
1555 % return true if str is empty
1556 FUNCTION {is.all.lower}
1557 { #1 swap$
1558 { duplicate$ "" = not }
1559 { split.first.char.from.str is.lower
1560 'skip$
1561 { pop$ pop$ #0 "" }
1562 if$
1563 }
1564 while$
1565 pop$
1566 }
1567
1568 % str -> bool
1569 % variable used: b
1570 FUNCTION {is.tex.str.in.title.case}
1571 { duplicate$ "" =
1572 { pop$ #0 }
1573 { split.first.tex.char.from.str purify$
1574 duplicate$ "" =
1575 { pop$ pop$ #0 }
1576 { split.first.char.from.str is.upper
1577 { duplicate$ "" = % single-letter word
1578 { pop$ pop$ #1 }
1579 { duplicate$ is.all.lower
1580 { empty$
1581 { duplicate$ "" =
1582 { pop$ #0 }
1583 'is.all.lower
1584 if$
1585 }
1586 'is.all.lower
1587 if$
1588 }
1589 { pop$ pop$ #0 }
1590 if$
1591 }
1592 if$
1593 }
1594 { pop$ pop$ #0}
1595 if$
1596 }
1597 if$
1598 }
1599 if$
1600 }
1601
1602 % char, int -> bool
1603 % variables used: t, b
1604 FUNCTION {is.in.inter.token.chars}
1605 { duplicate$ #0 =
1606 { pop$ " " = }
1607 { #1 =
1608 { " " range.delimiters * swap$ is.char.in.str }
1609 'is.letter.ascii
1610 if$
1611 }
1612 if$
1613 }
1614
1615 % str, int -> intertoken: str, rest: str
1616 % variable used: t, b
1617 FUNCTION {skip.inter.token.chars.by}
1618 { 'b :=
1619 't :=
1620
1621 "" t
1622 { duplicate$ "" = not }
1623 { split.first.char.from.str
1624 duplicate$ b is.in.inter.token.chars
1625 { swap$ 't := * t }
1626 { swap$ * 't := "" }
1627 if$
1628 }
1629 while$
1630
1631 pop$ t
1632 }
1633
1634 % str -> intertoken: str, rest: str
1635 % variable used: t, b
1636 FUNCTION {skip.inter.token.chars}
1637 { #0 skip.inter.token.chars.by }
1638
1639 % str -> intertoken: str, rest: str
1640 % variable used: t, b
1641 FUNCTION {skip.inter.token.command}
1642 { duplicate$ "" =
1643 { "" }
1644 { duplicate$ #1 #1 substring$ is.symbol.ascii
1645 { split.first.char.from.str swap$ }
1646 { #2 skip.inter.token.chars.by }
1647 if$
1648 }
1649 if$
1650 }
1651
1652 % cmdstr -> cmdstr
1653 FUNCTION {is.special.char.command}
1654 { #2 global.max$ substring$ skip.inter.token.command
1655 empty$
1656 'skip$
1657 { "is.special.char.command: cmdstr has extra components!" warning$ }
1658 if$
1659
1660 duplicate$ duplicate$ duplicate$ duplicate$ duplicate$ duplicate$
1661 "oOlLij" swap$ is.char.in.str
1662 swap$ "oe" = or
1663 swap$ "OE" = or
1664 swap$ "ae" = or
1665 swap$ "AE" = or
1666 swap$ "aa" = or
1667 swap$ "AA" = or
1668 }
1669
1670 % str, str, char -> char
1671 % variable used: t
1672 FUNCTION {map.char}
1673 { 't :=
1674 split.first.char.from.str
1675 { swap$ duplicate$ "" = not }
1676 { swap$ t =
1677 { pop$ "" t }
1678 { swap$ split.first.char.from.str pop$ swap$
1679 split.first.char.from.str
1680 }
1681 if$
1682 }
1683 while$
1684 pop$ t =
1685 'get.first.char.from.str
1686 { pop$ t }
1687 if$
1688 }
1689
1690 % char -> char
1691 % variables used: t, b
1692 FUNCTION {to.lower}
1693 { duplicate$ is.upper.ascii
1694 { chr.to.int$ #32 + int.to.chr$ }
1695 { latin.lower swap$ latin.upper swap$ map.char }
1696 if$
1697 }
1698
1699 % char -> char
1700 % variables used: t, b
1701 FUNCTION {to.upper}
1702 { duplicate$ is.lower.ascii
1703 { chr.to.int$ #32 - int.to.chr$ }
1704 { latin.upper swap$ latin.lower swap$ map.char }
1705 if$
1706 }
1707
1708 % str -> str
1709 % variables used: t, b
1710 FUNCTION {all.to.lower}
1711 { "" swap$
1712 { duplicate$ empty$ not }
1713 { split.first.char.from.str to.lower swap$ 't := * t }
1714 while$
1715 *
1716 }
1717
1718 % texchar -> texchar
1719 % variables used: t, b
1720 FUNCTION {command.to.lower}
1721 { duplicate$ "" =
1722 { "command.to.lower: Empty string is not a texchar!" warning$ }
1723 { duplicate$ #1 #1 substring$ #92 int.to.chr$ =
1724 { duplicate$ is.special.char.command
1725 'all.to.lower
1726 'skip$
1727 if$
1728 }
1729 'to.lower
1730 if$
1731 }
1732 if$
1733 }
1734
1735 % texchar -> texchar
1736 % variables used: t, b
1737 FUNCTION {tex.to.lower}
1738 { duplicate$ #1 #2 substring$ "{" #92 int.to.chr$ * =
1739 { "" swap$
1740 { duplicate$ "" = not }
1741 { split.first.char.from.str
1742 duplicate$ #92 int.to.chr$ =
1743 { swap$ skip.inter.token.command 't := * t
1744 swap$ command.to.lower
1745 }
1746 'to.lower
1747 if$
1748 swap$ 't := * t
1749 }
1750 while$
1751 pop$
1752 }
1753 { duplicate$ #1 #1 substring$ "{" =
1754 { split.first.char.from.str swap$ find.match.brace pop$ }
1755 'command.to.lower
1756 if$
1757 }
1758 if$
1759 }
1760
1761 % str -> str
1762 % variables used: t, b
1763 FUNCTION {all.to.upper}
1764 { "" swap$
1765 { duplicate$ empty$ not }
1766 { split.first.char.from.str to.upper swap$ 't := * t }
1767 while$
1768 *
1769 }
1770
1771 % texchar -> texchar
1772 % variables used: t, b
1773 FUNCTION {command.to.upper}
1774 { duplicate$ "" =
1775 { "command.to.lower: Empty string is not a texchar!" warning$ }
1776 { duplicate$ #1 #1 substring$ #92 int.to.chr$ =
1777 { duplicate$ is.special.char.command
1778 'all.to.upper
1779 'skip$
1780 if$
1781 }
1782 'to.upper
1783 if$
1784 }
1785 if$
1786 }
1787
1788 % texchar -> texchar
1789 % variables used: t, b
1790 FUNCTION {tex.to.upper}
1791 { duplicate$ #1 #2 substring$ "{" #92 int.to.chr$ * =
1792 { "" swap$
1793 { duplicate$ "" = not }
1794 { split.first.char.from.str
1795 duplicate$ #92 int.to.chr$ =
1796 { swap$ skip.inter.token.command 't := * t
1797 swap$ command.to.upper
1798 }
1799 'to.upper
1800 if$
1801 swap$ 't := * t
1802 }
1803 while$
1804 pop$
1805 }
1806 { duplicate$ #1 #1 substring$ "{" =
1807 { split.first.char.from.str swap$ find.match.brace pop$ }
1808 'command.to.upper
1809 if$
1810 }
1811 if$
1812 }
1813
1814 % texstr -> texstr
1815 % variable used: t, b
1816 FUNCTION {lower.token.if.in.title.case}
1817 { duplicate$ is.tex.str.in.title.case
1818 { split.first.tex.char.from.str tex.to.lower swap$ * }
1819 'skip$
1820 if$
1821 }
1822
1823 % int -> str
1824 FUNCTION {self.tokens}
1825 { #0 =
1826 'default.self.tokens
1827 'range.delimiters
1828 if$
1829 }
1830
1831 % str, int -> token: str, rest: str
1832 % variables used: s, t, b
1833 FUNCTION {tokenize.by}
1834 { 'b :=
1835 's :=
1836
1837 s "" =
1838 { "" "" }
1839 { s split.first.char.from.str
1840 duplicate$ b self.tokens swap$ is.char.in.str
1841 'swap$
1842 { duplicate$ #92 int.to.chr$ =
1843 { swap$ skip.inter.token.command 's := * s }
1844 { pop$ pop$ "" s
1845 { duplicate$ "" = not }
1846 { split.first.char.from.str
1847 duplicate$ "\ " b self.tokens * swap$ is.char.in.str
1848 { pop$ pop$ "" }
1849 { duplicate$ "{" =
1850 { swap$ find.match.brace }
1851 'swap$
1852 if$
1853 's := * s
1854 }
1855 if$
1856 }
1857 while$
1858 pop$ s
1859 }
1860 if$
1861 }
1862 if$
1863 }
1864 if$
1865 }
1866
1867 % str -> str
1868 % variables used: s, t, b
1869 FUNCTION {tokenize}
1870 { #0 tokenize.by }
1871
1872 % str -> str
1873 % variables used: s, t, b
1874 FUNCTION {smart.sentence.case}
1875 { tokenize 's :=
1876
1877 { s "" = not }
1878 { s skip.inter.token.chars 's := * s
1879 tokenize swap$
1880 duplicate$ ":" =
1881 { swap$ 's := *
1882 s skip.inter.token.chars 's := * s
1883 tokenize swap$
1884 control.capitalize.subtitle
1885 'skip$
1886 { lower.token.if.in.title.case }
1887 if$
1888 }
1889 'lower.token.if.in.title.case
1890 if$
1891 swap$ 's := *
1892 }
1893 while$
1894 }
1895
1896 % str -> str
1897 % variables used: s, t, b
1898 FUNCTION {smart.upper.case}
1899 { s swap$ t swap$
1900
1901 "" swap$
1902 { duplicate$ "" = not }
1903 { tokenize swap$
1904 duplicate$ #1 #1 substring$ #92 int.to.chr$ =
1905 'command.to.upper
1906 { "" swap$
1907 { duplicate$ "" = not }
1908 { split.first.tex.char.from.str tex.to.upper
1909 swap$ 't := * t
1910 }
1911 while$
1912 pop$
1913 }
1914 if$
1915 swap$ 't := * t
1916 skip.inter.token.chars 't := * t
1917 }
1918 while$
1919 pop$
1920
1921 swap$ 't :=
1922 swap$ 's :=
1923 }
1924
1925 % \end{macrocode}
1926 %
1927 %
1928 % \subsection{Formatting chunks}
1929 %
1930 % Here are some functions for formatting chunks of an entry.
1931 % By convention they either produce a string that can be followed by
1932 % a comma or period (using |add.period$|, so it is OK to end in a period),
1933 % or they produce the null string.
1934 %
1935 % A useful utility is the field.or.null function, which checks if the
1936 % argument is the result of pushing a `missing' field (one for which no
1937 % assignment was made when the current entry was read in from the database)
1938 % or the result of pushing a string having no non-white-space characters.
1939 % It returns the null string if so, otherwise it returns the field string.
1940 % Its main (but not only) purpose is to guarantee that what's left on the
1941 % stack is a string rather than a missing field.
1942 %
1943 % \begin{pseudocode}
1944 % field.or.null(s) ==
1945 % BEGIN
1946 % if empty$(s) then return ""
1947 % else return s
1948 % END
1949 % \end{pseudocode}
1950 %
1951 % Another helper function is emphasize, which returns the argument emphasized,
1952 % if that is non-empty, otherwise it returns the null string. Italic
1953 % corrections aren't used, so this function should be used when punctuation
1954 % will follow the result.
1955 %
1956 % \begin{pseudocode}
1957 % emphasize(s) ==
1958 % BEGIN
1959 % if empty$(s) then return ""
1960 % else return "{\em " * s * "}"
1961 % \end{pseudocode}
1962 %
1963 % The `pop\$' in this function gets rid of the duplicate `empty' value and
1964 % the `skip\$' returns the duplicate field value
1965 % \begin{macrocode}
1966 FUNCTION {field.or.null}
1967 { duplicate$ empty$
1968 { pop$ "" }
1969 'skip$
1970 if$
1971 }
1972
1973 FUNCTION {emphasize}
1974 { duplicate$ empty$
1975 { pop$ "" }
1976 { "\emph{" swap$ * "}" * }
1977 if$
1978 }
1979
1980 FUNCTION {emphasize.book.title}
1981 { control.emph.booktitle
1982 is.lang.cjk not and
1983 'emphasize
1984 'skip$
1985 if$
1986 }
1987
1988 % \end{macrocode}
1989 %
1990 % \subsubsection{Detect Language}
1991 % \begin{macrocode}
1992 INTEGERS { codepoint tmp.lang }
1993
1994 FUNCTION {get.codepoint.lang}
1995 { 'codepoint :=
1996 codepoint #128 <
1997 { codepoint #64 > codepoint #91 < and codepoint #96 > codepoint #123 < and or
1998 { lang.en }
1999 { lang.other }
2000 if$
2001 }
2002 % \end{macrocode}
2003 % 俄文西里尔字母:U+0400 到 U+052F,1024--1328。
2004 % \begin{macrocode}
2005 { codepoint #1023 > codepoint #1328 < and
2006 { lang.ru }
2007 % \end{macrocode}
2008 % CJK Unified Ideographs: U+4E00--U+9FFF; 19968--40959.
2009 % \begin{macrocode}
2010 { codepoint #19967 > codepoint #40960 < and
2011 { lang.zh }
2012 % \end{macrocode}
2013 % CJK Unified Ideographs Extension A: U+3400--U+4DBF; 13312--19903.
2014 % \begin{macrocode}
2015 { codepoint #13311 > codepoint #19904 < and
2016 { lang.zh }
2017 % \end{macrocode}
2018 % 日语假名:U+3040--U+30FF, 12352--12543.
2019 % \begin{macrocode}
2020 { codepoint #12351 > codepoint #12544 < and
2021 { lang.ja }
2022 % \end{macrocode}
2023 % 韩语谚文音节:U+AC00--U+D7AF, 44032--55215.
2024 % \begin{macrocode}
2025 { codepoint #44031 > codepoint #55216 < and
2026 { lang.ko }
2027 { lang.other }
2028 if$
2029 }
2030 if$
2031 }
2032 if$
2033 }
2034 if$
2035 }
2036 if$
2037 }
2038 if$
2039 }
2040
2041 FUNCTION {get.str.lang}
2042 { lang.other 'tmp.lang :=
2043 { duplicate$ empty$ not }
2044 { split.first.char.from.str
2045 char.to.unicode
2046 get.codepoint.lang
2047 duplicate$ tmp.lang >
2048 { 'tmp.lang := }
2049 'pop$
2050 if$
2051 }
2052 while$
2053 duplicate$ empty$
2054 { pop$ }
2055 { "non-empty string " quote$ swap$ * quote$ " left" warning$ }
2056 if$
2057 tmp.lang
2058 }
2059
2060 FUNCTION {check.entry.lang}
2061 { title field.or.null
2062 duplicate$ empty$
2063 { author field.or.null * }
2064 'skip$
2065 if$
2066 duplicate$ empty$
2067 { journal field.or.null * }
2068 'skip$
2069 if$
2070 duplicate$ empty$
2071 { journaltitle field.or.null * }
2072 'skip$
2073 if$
2074 duplicate$ empty$
2075 { booktitle field.or.null * }
2076 'skip$
2077 if$
2078 duplicate$ empty$
2079 { address field.or.null * }
2080 'skip$
2081 if$
2082 duplicate$ empty$
2083 { location field.or.null * }
2084 'skip$
2085 if$
2086 duplicate$ empty$
2087 { publisher field.or.null * }
2088 'skip$
2089 if$
2090 get.str.lang
2091 }
2092
2093 FUNCTION {set.entry.lang}
2094 { langid empty$
2095 { language empty$
2096 { "" }
2097 { language }
2098 if$
2099 }
2100 { langid }
2101 if$
2102 "l" change.case$
2103 's :=
2104 s empty$
2105 { check.entry.lang }
2106 { s "english" = s "american" = or s "british" = or
2107 { lang.en }
2108 { s "chinese" =
2109 { lang.zh }
2110 { s "japanese" =
2111 { lang.ja }
2112 { s "korean" =
2113 { lang.ko }
2114 { s "russian" =
2115 { lang.ru }
2116 { lang.other }
2117 if$
2118 }
2119 if$
2120 }
2121 if$
2122 }
2123 if$
2124 }
2125 if$
2126 }
2127 if$
2128 'entry.lang :=
2129 #0 'is.lang.cjk :=
2130 entry.lang lang.zh =
2131 entry.lang lang.ja = or
2132 entry.lang lang.ko = or
2133 { #1 'is.lang.cjk := }
2134 'skip$
2135 if$
2136 }
2137
2138 FUNCTION {set.entry.numbered}
2139 { type$ "archive" =
2140 type$ "letter" = or
2141 type$ "legislation" = or
2142 type$ "patent" = or
2143 type$ "regulation" = or
2144 type$ "report" = or
2145 %<*2005|2015>
2146 type$ "standard" = or
2147 %</2005|2015>
2148 type$ "techreport" = or
2149 { #1 'entry.numbered := }
2150 { #0 'entry.numbered := }
2151 if$
2152 }
2153
2154 % \end{macrocode}
2155 %
2156 % \subsubsection{Format names}
2157 %
2158 % The format.names function formats the argument (which should be in
2159 % BibTeX name format) into "First Von Last, Junior", separated by commas
2160 % and with an "and" before the last (but ending with "et~al." if the last
2161 % of multiple authors is "others"). This function's argument should always
2162 % contain at least one name.
2163 %
2164 % \begin{pseudocode}
2165 % VAR: nameptr, namesleft, numnames: INTEGER
2166 % pseudoVAR: nameresult: STRING (it's what's accumulated on the stack)
2167 %
2168 % format.names(s) ==
2169 % BEGIN
2170 % nameptr := 1
2171 % numnames := num.names$(s)
2172 % namesleft := numnames
2173 % while namesleft > 0
2174 % do
2175 % % for full names:
2176 % t := format.name$(s, nameptr, "{ff~}{vv~}{ll}{, jj}")
2177 % % for abbreviated first names:
2178 % t := format.name$(s, nameptr, "{f.~}{vv~}{ll}{, jj}")
2179 % if nameptr > 1 then
2180 % if namesleft > 1 then nameresult := nameresult * ", " * t
2181 % else if numnames > 2
2182 % then nameresult := nameresult * ","
2183 % fi
2184 % if t = "others"
2185 % then nameresult := nameresult * " et~al."
2186 % else nameresult := nameresult * " and " * t
2187 % fi
2188 % fi
2189 % else nameresult := t
2190 % fi
2191 % nameptr := nameptr + 1
2192 % namesleft := namesleft - 1
2193 % od
2194 % return nameresult
2195 % END
2196 % \end{pseudocode}
2197 %
2198 % The format.authors function returns the result of format.names(author)
2199 % if the author is present, or else it returns the null string
2200 %
2201 % \begin{pseudocode}
2202 % format.authors ==
2203 % BEGIN
2204 % if empty$(author) then return ""
2205 % else return format.names(author)
2206 % fi
2207 % END
2208 % \end{pseudocode}
2209 %
2210 % Format.editors is like format.authors, but it uses the editor field,
2211 % and appends ", editor" or ", editors"
2212 %
2213 % \begin{pseudocode}
2214 % format.editors ==
2215 % BEGIN
2216 % if empty$(editor) then return ""
2217 % else
2218 % if num.names$(editor) > 1 then
2219 % return format.names(editor) * ", editors"
2220 % else
2221 % return format.names(editor) * ", editor"
2222 % fi
2223 % fi
2224 % END
2225 % \end{pseudocode}
2226 %
2227 % Other formatting functions are similar, so no "comment version" will be
2228 % given for them.
2229 % \begin{macrocode}
2230 INTEGERS { nameptr namesleft numnames name.lang }
2231
2232 FUNCTION {is.lowercase.word}
2233 { #1
2234 { #0 > }
2235 { duplicate$ #1 #1 substring$ chr.to.int$
2236 duplicate$ #96 >
2237 swap$ #123 <
2238 and
2239 { #2 global.max$ substring$
2240 duplicate$ empty$
2241 { #0 }
2242 { #1 }
2243 if$
2244 }
2245 { #0 }
2246 if$
2247 }
2248 while$
2249 empty$
2250 }
2251
2252 % Assume already changed to lowercase
2253 FUNCTION {is.single.pinyin}
2254 { " " swap$ * " " *
2255 pinyin.table swap$ contains
2256 }
2257
2258 % Assume already changed to lowercase
2259 FUNCTION {is.single.pinyin.word}
2260 { duplicate$ is.lowercase.word
2261 'is.single.pinyin
2262 { pop$ #0 }
2263 if$
2264 }
2265
2266 % Check if the word is pinyin of one or two characters.
2267 % Assume already changed to lowercase.
2268 % This function is extremely slow, so it should be used only when necessary.
2269 FUNCTION {is.double.pinyin}
2270 { duplicate$ string.length 'a :=
2271 #1
2272 { a #0 > and }
2273 { duplicate$ #1 a substring$ is.single.pinyin
2274 { duplicate$ a #1 + global.max$ substring$
2275 duplicate$ empty$
2276 { pop$ #0 }
2277 { is.single.pinyin
2278 { #0 }
2279 { a #1 - 'a :=
2280 #1
2281 }
2282 if$
2283 }
2284 if$
2285 }
2286 { a #1 - 'a :=
2287 #1
2288 }
2289 if$
2290 }
2291 while$
2292 't :=
2293 t #1 #1 substring$
2294 t a #1 + #1 substring$
2295 duplicate$ empty$
2296 'pop$
2297 { " " swap$ * * }
2298 if$
2299 't :=
2300 a #0 >
2301 }
2302
2303 FUNCTION {is.double.pinyin.word}
2304 { duplicate$ is.lowercase.word
2305 'is.double.pinyin
2306 { pop$ #0 }
2307 if$
2308 }
2309
2310 FUNCTION {extract.before}
2311 { 'find :=
2312 'text :=
2313 find string.length 'find_length :=
2314 ""
2315 { text empty$ not }
2316 { text #1 find_length substring$ find =
2317 { "" 'text := }
2318 { text #1 #1 substring$ *
2319 text #2 global.max$ substring$ 'text :=
2320 }
2321 if$
2322 }
2323 while$
2324 }
2325
2326 FUNCTION {extract.after}
2327 { 'find :=
2328 'text :=
2329 find string.length 'find_length :=
2330 ""
2331 { text empty$ not }
2332 { text #1 find_length substring$ find =
2333 { text find_length #1 + global.max$ substring$ *
2334 "" 'text :=
2335 }
2336 { text #2 global.max$ substring$ 'text := }
2337 if$
2338 }
2339 while$
2340 }
2341
2342 FUNCTION {format.western.given.name}
2343 { s nameptr "{ f.}" format.name$
2344 control.initialize.with.hyphen
2345 'skip$
2346 { duplicate$ "-" contains
2347 { "-" " " find.replace
2348 "u" change.case$
2349 }
2350 'skip$
2351 if$
2352 }
2353 if$
2354 s nameptr "{, jj}" format.name$ *
2355 "." "" find.replace
2356 }
2357
2358 FUNCTION {is.family.name.pinyin}
2359 { s nameptr "{ll}" format.name$
2360 duplicate$ empty$
2361 { pop$ #0 }
2362 { "l" change.case$
2363 duplicate$ "-" contains
2364 { duplicate$ "-" extract.before is.single.pinyin.word
2365 { "-" extract.after is.single.pinyin.word }
2366 { pop$ #0 }
2367 if$
2368 }
2369 { % 这个函数实在太慢了
2370 % is.double.pinyin
2371 is.single.pinyin.word
2372 }
2373 if$
2374 }
2375 if$
2376 }
2377
2378 FUNCTION {is.given.name.pinyin}
2379 { s nameptr "{ff}" format.name$
2380 duplicate$ empty$
2381 { pop$ #0 }
2382 { "l" change.case$
2383 "’" "'" find.replace
2384 duplicate$ "'" contains
2385 { duplicate$ "'" extract.before
2386 duplicate$ #1 #1 substring$ 't :=
2387 is.single.pinyin.word
2388 { "'" extract.after
2389 duplicate$ #1 #1 substring$ t " " * swap$ * 't :=
2390 is.single.pinyin.word
2391 }
2392 { pop$ #0 }
2393 if$
2394 }
2395 'is.double.pinyin.word
2396 if$
2397 }
2398 if$
2399 }
2400
2401 FUNCTION {is.name.pinyin}
2402 { s nameptr "{vv}{jj}" format.name$ empty$
2403 { is.family.name.pinyin
2404 'is.given.name.pinyin
2405 { #0 }
2406 if$
2407 }
2408 { #0 }
2409 if$
2410 }
2411
2412 FUNCTION {format.latin.name}
2413 { s nameptr "{vv~}{ll}" format.name$
2414 control.uppercase.family
2415 'smart.upper.case
2416 'skip$
2417 if$
2418 control.check.pinyin
2419 { is.name.pinyin
2420 { control.initialize.pinyin
2421 { " " t "u" change.case$ * }
2422 { s nameptr "{ ff}" format.name$ }
2423 if$
2424 }
2425 { format.western.given.name }
2426 if$
2427 }
2428 { format.western.given.name }
2429 if$
2430 *
2431 }
2432
2433 FUNCTION {format.name}
2434 { s nameptr "{vv~}{ll}{,~ff}{, jj}" format.name$
2435 get.str.lang
2436 duplicate$
2437 duplicate$ lang.zh = swap$ lang.ja = or
2438 { pop$
2439 s nameptr "{vv~}{ll}" format.name$
2440 s nameptr "{ff}{, jj}" format.name$
2441 duplicate$ get.str.lang
2442 duplicate$ lang.zh = swap$ lang.ja = or
2443 { * }
2444 { pop$ }
2445 if$
2446 }
2447 { lang.ru =
2448 { s nameptr "{vv~}{ll}" format.name$
2449 s nameptr "{ff}{, jj}" format.name$
2450 "." "" find.replace
2451 duplicate$ empty$
2452 'pop$
2453 { " " swap$ * * }
2454 if$
2455 }
2456 { format.latin.name }
2457 if$
2458 }
2459 if$
2460 }
2461
2462 FUNCTION {inter.word.space}
2463 { is.lang.cjk
2464 { "" }
2465 { " " }
2466 if$
2467 }
2468
2469 FUNCTION {format.names}
2470 { 's :=
2471 #1 'nameptr :=
2472 s num.names$ 'numnames :=
2473 numnames 'namesleft :=
2474 { namesleft #0 > }
2475 { format.name 't :=
2476 nameptr #1 >
2477 { numnames control.max.bib.names >
2478 nameptr control.min.bib.names > and
2479 { "others" 't :=
2480 #1 'namesleft :=
2481 }
2482 'skip$
2483 if$
2484 namesleft #1 >
2485 { add.comma t * }
2486 { t "l" change.case$ "others" =
2487 { nameptr #2 >
2488 { add.comma }
2489 { inter.word.space * }
2490 if$
2491 bbl.et.al *
2492 }
2493 { control.bib.final.and
2494 { is.lang.cjk not nameptr #2 > and
2495 { add.comma }
2496 { inter.word.space * }
2497 if$
2498 bbl.and * inter.word.space *
2499 }
2500 { add.comma }
2501 if$
2502 t *
2503 }
2504 if$
2505 }
2506 if$
2507 }
2508 't
2509 if$
2510 nameptr #1 + 'nameptr :=
2511 namesleft #1 - 'namesleft :=
2512 }
2513 while$
2514 format.punctuations
2515 }
2516
2517 FUNCTION {warn.empty.field}
2518 { control.warn.empty.field
2519 { "empty " swap$ * " in " * cite$ * warning$ }
2520 'pop$
2521 if$
2522 }
2523
2524 FUNCTION {format.anonymous}
2525 {
2526 %<*authoryear>
2527 bbl.anonymous
2528 %</authoryear>
2529 %<*numeric>
2530 ""
2531 %</numeric>
2532 }
2533
2534 FUNCTION {format.authors}
2535 { author empty$
2536 { "author" warn.empty.field
2537 format.anonymous
2538 }
2539 { author format.names }
2540 if$
2541 }
2542
2543 FUNCTION {format.editors}
2544 { editor empty$
2545 { "editor" warn.empty.field
2546 format.anonymous
2547 }
2548 { editor format.names }
2549 if$
2550 }
2551
2552 FUNCTION {format.authors.editors}
2553 { author empty$
2554 { editor empty$
2555 { "author and editor" warn.empty.field
2556 format.anonymous
2557 }
2558 { editor format.names }
2559 if$
2560 }
2561 { author format.names }
2562 if$
2563 }
2564
2565 FUNCTION {format.translators}
2566 { translator empty$
2567 { "" }
2568 { translator format.names
2569 add.comma bbl.translator *
2570 }
2571 if$
2572 }
2573
2574 FUNCTION {format.lab.name}
2575 { s nameptr "{vv~}{ll}{,~ff}{, jj}" format.name$
2576 get.str.lang
2577 duplicate$ lang.zh =
2578 swap$ lang.ja = or
2579 { s nameptr "{vv~}{ll}" format.name$
2580 s nameptr "{ff}{, jj}" format.name$
2581 duplicate$ get.str.lang
2582 duplicate$ lang.zh = swap$ lang.ja = or
2583 { * }
2584 'pop$
2585 if$
2586 }
2587 { s nameptr "{vv~}{ll}" format.name$ }
2588 if$
2589 }
2590
2591 FUNCTION {format.full.names}
2592 { 's :=
2593 #1 'nameptr :=
2594 s num.names$ 'numnames :=
2595 numnames 'namesleft :=
2596 { namesleft #0 > }
2597 { format.lab.name 't :=
2598 nameptr #1 >
2599 { namesleft #1 >
2600 { add.comma t * }
2601 { t "l" change.case$ "others" =
2602 { nameptr #2 >
2603 { add.comma }
2604 { inter.word.space * }
2605 if$
2606 cite.et.al *
2607 }
2608 { control.cite.final.and
2609 { is.lang.cjk not nameptr #2 > and
2610 { add.comma }
2611 { inter.word.space * }
2612 if$
2613 cite.and * inter.word.space *
2614 }
2615 { add.comma }
2616 if$
2617 t *
2618 }
2619 if$
2620 }
2621 if$
2622 }
2623 't
2624 if$
2625 nameptr #1 + 'nameptr :=
2626 namesleft #1 - 'namesleft :=
2627 }
2628 while$
2629 format.punctuations
2630 }
2631
2632 FUNCTION {author.editor.full}
2633 { author empty$
2634 { editor empty$
2635 { "" }
2636 { editor format.full.names }
2637 if$
2638 }
2639 { author format.full.names }
2640 if$
2641 }
2642
2643 FUNCTION {author.full}
2644 { author empty$
2645 { "" }
2646 { author format.full.names }
2647 if$
2648 }
2649
2650 FUNCTION {editor.full}
2651 { editor empty$
2652 { "" }
2653 { editor format.full.names }
2654 if$
2655 }
2656
2657 FUNCTION {holder.author.full}
2658 { holder empty$
2659 { author empty$
2660 { "" }
2661 { author format.full.names }
2662 if$
2663 }
2664 { holder format.full.names }
2665 if$
2666 }
2667
2668 FUNCTION {make.full.names}
2669 { type$ "book" =
2670 type$ "inbook" = booktitle empty$ not and
2671 or
2672 'author.editor.full
2673 { type$ "collection" =
2674 type$ "proceedings" =
2675 or
2676 'editor.full
2677 { type$ "patent" =
2678 'holder.author.full
2679 'author.full
2680 if$
2681 }
2682 if$
2683 }
2684 if$
2685 }
2686
2687 FUNCTION {output.bibitem}
2688 { newline$
2689 "\bibitem[" write$
2690 label ")" *
2691 make.full.names duplicate$ short.list =
2692 { pop$ }
2693 { duplicate$ "]" contains
2694 { "{" swap$ * "}" * }
2695 'skip$
2696 if$
2697 *
2698 }
2699 if$
2700 "]{" * write$
2701 cite$ write$
2702 "}" write$
2703 newline$
2704 ""
2705 before.all 'output.state :=
2706 }
2707
2708 % \end{macrocode}
2709 %
2710 % \subsubsection{Format title}
2711 %
2712 % The |format.title| function is used for non-book-like titles.
2713 % For most styles we convert to lowercase (except for the very first letter,
2714 % and except for the first one after a colon (followed by whitespace)),
2715 % and hope the user has brace-surrounded words that need to stay capitalized;
2716 % for some styles, however, we leave it as it is in the database.
2717 % \begin{macrocode}
2718 FUNCTION {format.title.subtitle.titleaddon}
2719 { title empty$
2720 { "" }
2721 { title
2722 subtitle empty$
2723 'skip$
2724 { add.colon.by.language subtitle * }
2725 if$
2726 titleaddon empty$
2727 'skip$
2728 { add.colon.by.language titleaddon * }
2729 if$
2730 }
2731 if$
2732 }
2733
2734 % 只有英文转为 sentence case,
2735 % 其他语言通常不使用 title case,所以应按照 sentence case 保存,
2736 % 不需要转为 sentence case。
2737 FUNCTION {change.sentence.case}
2738 { entry.lang lang.en =
2739 'smart.sentence.case
2740 'skip$
2741 if$
2742 }
2743
2744 FUNCTION {add.link}
2745 { url empty$ not
2746 { "\href{" url * "}{" * swap$ * "}" * }
2747 { doi empty$ not
2748 { "\href{https://doi.org/" doi * "}{" * swap$ * "}" * }
2749 'skip$
2750 if$
2751 }
2752 if$
2753 }
2754
2755 FUNCTION {format.tr.number}
2756 { ""
2757 number empty$
2758 'skip$
2759 { type$ "patent" = control.patent.country and
2760 { country empty$ not
2761 { country * }
2762 { nationality empty$ not
2763 { nationality * }
2764 { address empty$ not
2765 { address * }
2766 { location empty$ not
2767 { location * }
2768 { "" }
2769 { entry.lang lang.zh =
2770 { "中国" * }
2771 'skip$
2772 if$
2773 }
2774 if$
2775 }
2776 if$
2777 }
2778 if$
2779 }
2780 if$
2781 }
2782 'skip$
2783 if$
2784 duplicate$ empty$
2785 'skip$
2786 'add.comma
2787 if$
2788 number
2789 duplicate$ get.str.lang lang.zh =
2790 'format.punctuations
2791 'skip$
2792 if$
2793 *
2794 }
2795 if$
2796 }
2797
2798 FUNCTION {entry.has.url.or.doi}
2799 { control.url require.url or entry.url empty$ not and
2800 doi empty$ not cstr empty$ not or
2801 control.doi control.url or require.url or and
2802 or
2803 }
2804
2805 FUNCTION {format.entry.type.id}
2806 { control.entry.type.id
2807 { entry.type.id
2808 control.entry.medium.id
2809 { entrymediumid empty$
2810 { medium empty$
2811 { entry.has.url.or.doi
2812 type$ "online" = or
2813 type$ "webpage" = or
2814 { "/OL" * }
2815 'skip$
2816 if$
2817 }
2818 { "The field 'medium' for entry medium ID is deprecated. Use 'entrymediumid' instead." warning$
2819 "/" * medium *
2820 }
2821 if$
2822 }
2823 { "/" * entrymediumid * }
2824 if$
2825 }
2826 'skip$
2827 if$
2828 make.brackets
2829 control.space.before.type.id
2830 { " " }
2831 { "\allowbreak" }
2832 if$
2833 swap$ *
2834 }
2835 { "" }
2836 if$
2837 }
2838
2839 FUNCTION {format.title}
2840 { title empty$
2841 { "" }
2842 { format.title.subtitle.titleaddon
2843 control.sentence.case.title
2844 'change.sentence.case
2845 'skip$
2846 if$
2847 format.punctuations
2848 control.link.title
2849 'add.link
2850 'skip$
2851 if$
2852 entry.numbered number empty$ not and
2853 { add.colon
2854 format.tr.number *
2855 }
2856 'skip$
2857 if$
2858 format.entry.type.id *
2859 }
2860 if$
2861 }
2862
2863 % \end{macrocode}
2864 %
2865 % For several functions we'll need to connect two strings with a
2866 % tie (|~|) if the second one isn't very long (fewer than 3 characters).
2867 % The tie.or.space.connect function does that. It concatenates the two
2868 % strings on top of the stack, along with either a tie or space between
2869 % them, and puts this concatenation back onto the stack:
2870 %
2871 % \begin{pseudocode}
2872 % tie.or.space.connect(str1,str2) ==
2873 % BEGIN
2874 % if text.length$(str2) < 3
2875 % then return the concatenation of str1, "~", and str2
2876 % else return the concatenation of str1, " ", and str2
2877 % END
2878 % \end{pseudocode}
2879 % \begin{macrocode}
2880 FUNCTION {tie.or.space.connect}
2881 { duplicate$ text.length$ #3 <
2882 { "~" }
2883 { " " }
2884 if$
2885 swap$ * *
2886 }
2887
2888 % \end{macrocode}
2889 %
2890 % The either.or.check function complains if both fields or an either-or pair
2891 % are nonempty.
2892 %
2893 % \begin{pseudocode}
2894 % either.or.check(t,s) ==
2895 % BEGIN
2896 % if empty$(s) then
2897 % warning$(can't use both " * t * " fields in " * cite$)
2898 % fi
2899 % END
2900 % \end{pseudocode}
2901 % \begin{macrocode}
2902 FUNCTION {either.or.check}
2903 { empty$
2904 'pop$
2905 { "can't use both " swap$ * " fields in " * cite$ * warning$ }
2906 if$
2907 }
2908
2909 % \end{macrocode}
2910 %
2911 % The format.bvolume function is for formatting the volume and perhaps
2912 % series name of a multivolume work. If both a volume and a series field
2913 % are there, we assume the series field is the title of the whole multivolume
2914 % work (the title field should be the title of the thing being referred to),
2915 % and we add an "of <series>". This function is called in mid-sentence.
2916 %
2917 % The format.number.series function is for formatting the series name
2918 % and perhaps number of a work in a series. This function is similar to
2919 % format.bvolume, although for this one the series must exist (and the
2920 % volume must not exist). If the number field is empty we output either
2921 % the series field unchanged if it exists or else the null string.
2922 % If both the number and series fields are there we assume the series field
2923 % gives the name of the whole series (the title field should be the title
2924 % of the work being one referred to), and we add an "in <series>".
2925 % We capitalize Number when this function is used at the beginning of a block.
2926 % \begin{macrocode}
2927 FUNCTION {is.digit}
2928 { duplicate$ empty$
2929 { pop$ #0 }
2930 { chr.to.int$
2931 duplicate$ "0" chr.to.int$ <
2932 { pop$ #0 }
2933 { "9" chr.to.int$ >
2934 { #0 }
2935 { #1 }
2936 if$
2937 }
2938 if$
2939 }
2940 if$
2941 }
2942
2943 FUNCTION {is.number}
2944 { #1
2945 { #0 > }
2946 { duplicate$ #1 #1 substring$ chr.to.int$
2947 duplicate$ #47 >
2948 swap$ #58 <
2949 and
2950 { #2 global.max$ substring$
2951 duplicate$ empty$
2952 { #0 }
2953 { #1 }
2954 if$
2955 }
2956 { #0 }
2957 if$
2958 }
2959 while$
2960 empty$
2961 }
2962
2963 FUNCTION {format.bvolume}
2964 { volume empty$
2965 { "" }
2966 { volume is.number
2967 { entry.lang lang.zh =
2968 { "第" volume tie.or.space.connect " 卷" * }
2969 { entry.lang lang.ko =
2970 { "제" volume tie.or.space.connect " 권" * }
2971 { "v." volume * }
2972 if$
2973 }
2974 if$
2975 }
2976 { volume }
2977 if$
2978 }
2979 if$
2980 }
2981
2982 FUNCTION {format.maintitle}
2983 { maintitle empty$
2984 { "" }
2985 { mainsubtitle empty$
2986 'skip$
2987 { add.colon.by.language mainsubtitle * }
2988 if$
2989 maintitleaddon empty$
2990 'skip$
2991 { add.colon.by.language maintitleaddon * }
2992 if$
2993 }
2994 if$
2995 }
2996
2997 FUNCTION {format.maintitle.volume}
2998 { maintitle empty$
2999 { "" }
3000 { maintitle
3001 volume empty$
3002 'skip$
3003 { add.colon.by.language
3004 format.bvolume *
3005 }
3006 if$
3007 }
3008 if$
3009 }
3010
3011 FUNCTION {format.title.volume}
3012 { title empty$
3013 { "" }
3014 { format.title.subtitle.titleaddon
3015 volume empty$
3016 'skip$
3017 { add.colon.by.language
3018 format.bvolume *
3019 }
3020 if$
3021 }
3022 if$
3023 }
3024
3025 FUNCTION {format.series.volume}
3026 { series empty$
3027 { "" }
3028 { series
3029 volume empty$
3030 'skip$
3031 { add.colon.by.language
3032 format.bvolume *
3033 }
3034 if$
3035 }
3036 if$
3037 }
3038
3039 FUNCTION {format.btitle}
3040 { maintitle empty$
3041 { series empty$
3042 { format.title.volume }
3043 { volume empty$
3044 { format.title.volume }
3045 { format.series.volume
3046 entry.numbered
3047 'skip$
3048 { "volume and number" number either.or.check }
3049 if$
3050 bbl.wide.space *
3051 format.title.subtitle.titleaddon
3052 *
3053 }
3054 if$
3055 }
3056 if$
3057 }
3058 { volume empty$
3059 { format.maintitle
3060 add.colon.by.language
3061 format.title.subtitle.titleaddon *
3062 }
3063 { format.maintitle.volume
3064 bbl.wide.space *
3065 format.title.subtitle.titleaddon
3066 *
3067 }
3068 if$
3069 }
3070 if$
3071 duplicate$ empty$
3072 'skip$
3073 { control.sentence.case.title
3074 'change.sentence.case
3075 'skip$
3076 if$
3077 format.punctuations
3078 emphasize.book.title
3079 control.link.title
3080 'add.link
3081 'skip$
3082 if$
3083 entry.numbered number empty$ not and
3084 { add.colon format.tr.number * }
3085 'skip$
3086 if$
3087 type$ "map" =
3088 scale empty$ not and
3089 { add.period
3090 duplicate$ #-1 #1 substring$ "." =
3091 { " " * }
3092 'skip$
3093 if$
3094 scale *
3095 }
3096 'skip$
3097 if$
3098 format.entry.type.id *
3099 }
3100 if$
3101 }
3102
3103 % \end{macrocode}
3104 %
3105 % \begin{macrocode}
3106 FUNCTION {format.booktitle}
3107 { booktitle empty$
3108 { "" }
3109 { booktitle
3110 control.sentence.case.booktitle
3111 'change.sentence.case
3112 'skip$
3113 if$
3114 booksubtitle empty$
3115 'skip$
3116 { add.colon
3117 booksubtitle
3118 control.sentence.case.booktitle
3119 { "l" change.case$ }
3120 'skip$
3121 if$
3122 *
3123 }
3124 if$
3125 emphasize.book.title
3126 booktitleaddon empty$
3127 'skip$
3128 { add.colon
3129 booktitleaddon
3130 control.sentence.case.booktitle
3131 { "l" change.case$ }
3132 'skip$
3133 if$
3134 *
3135 }
3136 if$
3137 format.punctuations
3138 }
3139 if$
3140 }
3141
3142 FUNCTION {format.series.volume.booktitle}
3143 { series empty$
3144 { maintitle empty$
3145 { format.booktitle
3146 volume empty$
3147 'skip$
3148 { add.colon
3149 format.bvolume *
3150 }
3151 if$
3152 }
3153 { format.maintitle.volume
3154 bbl.wide.space *
3155 format.booktitle *
3156 }
3157 if$
3158 }
3159 { volume empty$
3160 { format.booktitle }
3161 { format.series.volume
3162 bbl.wide.space *
3163 format.booktitle *
3164 }
3165 if$
3166 }
3167 if$
3168 }
3169
3170 FUNCTION {format.in.ed.booktitle}
3171 { booktitle empty$
3172 { "" }
3173 { control.in
3174 { bbl.in add.colon }
3175 { "" }
3176 if$
3177 editor empty$
3178 'skip$
3179 { format.editors * output new.block "" }
3180 if$
3181 format.series.volume.booktitle *
3182 }
3183 if$
3184 }
3185
3186 FUNCTION {remove.dots}
3187 { 's :=
3188 ""
3189 { s empty$ not }
3190 { s #1 #1 substring$
3191 duplicate$ "." =
3192 'pop$
3193 { * }
3194 if$
3195 s #2 global.max$ substring$ 's :=
3196 }
3197 while$
3198 }
3199
3200 FUNCTION {format.journal.title}
3201 { journal empty$
3202 { journaltitle empty$
3203 { "" }
3204 { journaltitle }
3205 if$
3206 }
3207 { journal }
3208 if$
3209 journalsubtitle empty$
3210 'skip$
3211 { duplicate$ empty$
3212 'skip$
3213 'add.colon.by.language
3214 if$
3215 journalsubtitle *
3216 }
3217 if$
3218 journaltitleaddon empty$
3219 'skip$
3220 { duplicate$ empty$
3221 'skip$
3222 'add.colon.by.language
3223 if$
3224 journaltitleaddon *
3225 }
3226 if$
3227 control.sentence.case.journal
3228 'change.sentence.case
3229 'skip$
3230 if$
3231 }
3232
3233 FUNCTION {format.short.journal}
3234 { shortjournal empty$
3235 { format.journal.title
3236 duplicate$ field.or.null " " contains % The journal title is not a single word
3237 is.lang.cjk not and
3238 { "shortjournal" warn.empty.field }
3239 'skip$
3240 if$
3241 }
3242 { shortjournal
3243 control.journal.dots
3244 'skip$
3245 'remove.dots
3246 if$
3247 }
3248 if$
3249 }
3250
3251 FUNCTION {get.journal.title}
3252 { control.short.journal
3253 'format.short.journal
3254 { format.journal.title
3255 duplicate$ empty$
3256 { shortjournal empty$
3257 { "journal" warn.empty.field }
3258 { pop$ format.short.journal }
3259 if$
3260 }
3261 { shortjournal empty$ control.journal.dots not and
3262 'remove.dots
3263 { duplicate$ shortjournal = control.journal.dots not and
3264 'remove.dots
3265 'skip$
3266 if$
3267 }
3268 if$
3269 }
3270 if$
3271 }
3272 if$
3273 }
3274
3275 FUNCTION {check.arxiv.preprint}
3276 { "l" change.case$
3277 duplicate$ #1 #5 substring$ "arxiv" =
3278 { 'x :=
3279 "arxiv:" 'y :=
3280 y text.length$ 'len :=
3281 x text.length$ len - #1 + 'charptr :=
3282 { charptr #0 >
3283 x charptr len substring$ y = not
3284 and
3285 }
3286 { charptr #1 - 'charptr := }
3287 while$
3288 charptr #0 >
3289 { x charptr #6 + global.max$ substring$ 'x :=
3290 x string.length #1 + 'len :=
3291 #1 'charptr :=
3292 { charptr len <
3293 x charptr #1 substring$ " " = not and
3294 x charptr #1 substring$ "[" = not and
3295 }
3296 { charptr #1 + 'charptr := }
3297 while$
3298 x #1 charptr substring$
3299 duplicate$ empty$
3300 'pop$
3301 { "\url{https://arxiv.org/abs/" swap$ * "}" * 'entry.url := }
3302 if$
3303 }
3304 'skip$
3305 if$
3306 #1
3307 }
3308 { pop$ #0 }
3309 if$
3310 }
3311
3312 FUNCTION {format.journal}
3313 { get.journal.title
3314 duplicate$ empty$
3315 'skip$
3316 { format.punctuations
3317 control.emph.journal is.lang.cjk not and
3318 'emphasize
3319 'skip$
3320 if$
3321 }
3322 if$
3323 }
3324
3325 % \end{macrocode}
3326 %
3327 % \subsubsection{Format entry type mark}
3328 %
3329 % \begin{macrocode}
3330 FUNCTION {set.entry.type.id}
3331 { entry.type.id empty$
3332 { entrytypeid empty$
3333 { entrysubtype empty$
3334 { mark empty$
3335 { 'entry.type.id := }
3336 { pop$
3337 "The field 'mark' for entry type ID is deprecated. Use 'entrytypeid' instead." warning$
3338 mark 'entry.type.id :=
3339 }
3340 if$
3341 }
3342 { entrysubtype "newspaper" =
3343 { pop$ "N" 'entry.type.id := }
3344 { entrysubtype "inproceedings" =
3345 { pop$ "C" 'entry.type.id := }
3346 { entrysubtype "report" =
3347 { pop$ "R" 'entry.type.id := }
3348 { entrysubtype "techreport" =
3349 { pop$ "R" 'entry.type.id := }
3350 { entrysubtype "standard" =
3351 { pop$ "S" 'entry.type.id := }
3352 { entrysubtype "patent" =
3353 { pop$ "P" 'entry.type.id := }
3354 { entrysubtype "dataset" =
3355 { pop$ "DS" 'entry.type.id := }
3356 { 'entry.type.id := }
3357 if$
3358 }
3359 if$
3360 }
3361 if$
3362 }
3363 if$
3364 }
3365 if$
3366 }
3367 if$
3368 }
3369 if$
3370 }
3371 if$
3372 }
3373 { pop$ entrytypeid 'entry.type.id := }
3374 if$
3375 }
3376 'pop$
3377 if$
3378 }
3379
3380 % \end{macrocode}
3381 %
3382 % \subsubsection{Format edition}
3383 %
3384 % The format.edition function appends " edition" to the edition, if present.
3385 % We lowercase the edition (it should be something like "Third"), because
3386 % this doesn't start a sentence.
3387 % \begin{macrocode}
3388 FUNCTION {num.to.ordinal}
3389 { is.lang.cjk
3390 'skip$
3391 { duplicate$ #-2 #1 substring$ "1" =
3392 { "th" * }
3393 { duplicate$ #-1 #1 substring$ "1" =
3394 { "st" * }
3395 { duplicate$ #-1 #1 substring$ "2" =
3396 { "nd" * }
3397 { duplicate$ #-1 #1 substring$ "3" =
3398 { "rd" * }
3399 { "th" * }
3400 if$
3401 }
3402 if$
3403 }
3404 if$
3405 }
3406 if$
3407 }
3408 if$
3409 }
3410
3411
3412 % If the string on the top of the stack begins with a number,
3413 % (e.g., 11th) then replace the string with the leading number
3414 % it contains. Otherwise retain the string as-is. s holds the
3415 % extracted number, t holds the part of the string that remains
3416 % to be scanned.
3417 FUNCTION {extract.num}
3418 { duplicate$ 't :=
3419 "" 's :=
3420 { t empty$ not }
3421 { t #1 #1 substring$
3422 t #2 global.max$ substring$ 't :=
3423 duplicate$ is.digit
3424 { s swap$ * 's := }
3425 { pop$ "" 't := }
3426 if$
3427 }
3428 while$
3429 s empty$
3430 'skip$
3431 { pop$ s }
3432 if$
3433 }
3434
3435 % Converts the word number string on the top of the stack to
3436 % Arabic string form. Will be successful up to "tenth".
3437 FUNCTION {word.to.num}
3438 { duplicate$ "l" change.case$ 's :=
3439 s "first" =
3440 { pop$ "1" }
3441 'skip$
3442 if$
3443 s "second" =
3444 { pop$ "2" }
3445 'skip$
3446 if$
3447 s "third" =
3448 { pop$ "3" }
3449 'skip$
3450 if$
3451 s "fourth" =
3452 { pop$ "4" }
3453 'skip$
3454 if$
3455 s "fifth" =
3456 { pop$ "5" }
3457 'skip$
3458 if$
3459 s "sixth" =
3460 { pop$ "6" }
3461 'skip$
3462 if$
3463 s "seventh" =
3464 { pop$ "7" }
3465 'skip$
3466 if$
3467 s "eighth" =
3468 { pop$ "8" }
3469 'skip$
3470 if$
3471 s "ninth" =
3472 { pop$ "9" }
3473 'skip$
3474 if$
3475 s "tenth" =
3476 { pop$ "10" }
3477 'skip$
3478 if$
3479 s "revised edition" =
3480 { pop$ "Rev. ed." }
3481 'skip$
3482 if$
3483 s "revised ed." =
3484 { pop$ "Rev. ed." }
3485 'skip$
3486 if$
3487 s "revised" =
3488 { pop$ "Rev. ed." }
3489 'skip$
3490 if$
3491 s "rev." =
3492 { pop$ "Rev. ed." }
3493 'skip$
3494 if$
3495 s "修订版" =
3496 { pop$ "修订版" }
3497 'skip$
3498 if$
3499 s "修订" =
3500 { pop$ "修订版" }
3501 'skip$
3502 if$
3503 }
3504
3505
3506 FUNCTION {format.edition}
3507 { edition empty$
3508 { "" }
3509 { edition
3510 duplicate$ #1 #1 substring$ is.digit
3511 'extract.num
3512 'word.to.num
3513 if$
3514 duplicate$ "1" =
3515 { pop$ "" }
3516 { duplicate$ #1 #1 substring$ is.digit
3517 { num.to.ordinal
3518 " " * bbl.edition *
3519 }
3520 'skip$
3521 if$
3522 }
3523 if$
3524 }
3525 if$
3526 }
3527
3528 FUNCTION {format.version}
3529 { version empty$
3530 { "" }
3531 { version #1 #1 substring$
3532 duplicate$ "V" =
3533 { pop$ version }
3534 { "v" =
3535 { "V" version #2 global.max$ substring$ * }
3536 { "V" version * }
3537 if$
3538 }
3539 if$
3540 }
3541 if$
3542 }
3543
3544 % \end{macrocode}
3545 %
3546 % \subsubsection{Format publishing items}
3547 %
3548 % 出版地址和出版社会有 “[S.l.: s.n.]” 的情况,所以必须一起处理。
3549 % \begin{macrocode}
3550 FUNCTION {format.publisher}
3551 { publisher empty$
3552 { institution empty$
3553 { school empty$
3554 { "" }
3555 { school }
3556 if$
3557 }
3558 { institution }
3559 if$
3560 }
3561 { publisher }
3562 if$
3563 format.punctuations
3564 }
3565
3566 FUNCTION {format.address.publisher}
3567 { address empty$
3568 { location empty$
3569 { "" }
3570 { location }
3571 if$
3572 }
3573 { address }
3574 if$
3575 format.punctuations
3576 duplicate$ empty$ not
3577 { format.publisher empty$ not
3578 { add.colon format.publisher * }
3579 { entry.has.url.or.doi not control.unknown.publisher and
3580 { add.colon bbl.sine.nomine make.brackets * }
3581 'skip$
3582 if$
3583 }
3584 if$
3585 }
3586 { pop$
3587 entry.has.url.or.doi not control.unknown.publisher and
3588 { format.publisher empty$ not
3589 { bbl.sine.loco make.brackets add.colon format.publisher * }
3590 { bbl.sine.loco.sine.nomine make.brackets }
3591 if$
3592 }
3593 { format.publisher empty$ not
3594 { format.publisher }
3595 { "" }
3596 if$
3597 }
3598 if$
3599 }
3600 if$
3601 }
3602
3603 FUNCTION {format.eventtitle}
3604 { eventtitle empty$
3605 { "" }
3606 { eventtitle format.punctuations }
3607 if$
3608 }
3609
3610 % \end{macrocode}
3611 %
3612 % \subsubsection{Format date}
3613 %
3614 % The format.date function is for the month and year, but we give a warning if
3615 % there's an empty year but the month is there, and we return the empty string
3616 % if they're both empty.
3617 %
3618 % 期刊需要著录起止范围,其中年份使用“/”分隔,卷和期使用“--”分隔。
3619 % 版本 v2.0.2 前的年份也使用“--”分隔,仅提供兼容性,不再推荐。
3620 % \begin{macrocode}
3621 FUNCTION {normalize.year.dash}
3622 {
3623 %<*!(2005|2015)>
3624 "bylanguage" control.bib.punct =
3625 is.lang.cjk and
3626 "GB" control.bib.punct = or
3627 { "---" "—" find.replace
3628 "--" "—" find.replace
3629 "–" "—" find.replace
3630 "-" "—" find.replace
3631 }
3632 { "---" "-" find.replace
3633 "--" "-" find.replace
3634 "–" "-" find.replace
3635 "—" "-" find.replace
3636 }
3637 if$
3638 %</!(2005|2015)>
3639 %<*2005|2015>
3640 "---" "-" find.replace
3641 "--" "-" find.replace
3642 "–" "-" find.replace
3643 "—" "-" find.replace
3644 %</2005|2015>
3645 }
3646
3647 FUNCTION {format.date}
3648 { year empty$
3649 { date empty$
3650 { entry.has.url.or.doi
3651 { "" }
3652 { "year" warn.empty.field
3653 urldate empty$
3654 { "" }
3655 { urldate "-" extract.before extra.label * make.brackets }
3656 if$
3657 }
3658 if$
3659 }
3660 { date "/" extract.before "-" extract.before
3661 date "/" contains
3662 { "-" normalize.year.dash *
3663 date "/" extract.after "-" extract.before *
3664 }
3665 'skip$
3666 if$
3667 extra.label *
3668 }
3669 if$
3670 }
3671 { year normalize.year.dash
3672 extra.label *
3673 }
3674 if$
3675 %<*authoryear>
3676 control.year.before.title
3677 { pop$ "" }
3678 'skip$
3679 if$
3680 %</authoryear>
3681 }
3682
3683 % \end{macrocode}
3684 %
3685 % 专利和报纸都是使用完整日期
3686 % \begin{macrocode}
3687 FUNCTION {format.full.date}
3688 { date empty$
3689 { year }
3690 { control.year.before.title
3691 { date }
3692 { date #1 #4 substring$
3693 extra.label *
3694 date #5 global.max$ substring$ *
3695 }
3696 if$
3697 }
3698 if$
3699 }
3700
3701 % \end{macrocode}
3702 %
3703 % 正文中的引用标注的出版年,若为空则显示“无日期”或“n.d.”,需要带消歧的小写字后缀。
3704 % \begin{macrocode}
3705 FUNCTION {format.lab.date}
3706 { year empty$
3707 { date empty$
3708 { urldate empty$
3709 { bbl.no.date
3710 extra.label empty$
3711 'skip$
3712 { "-" * extra.label *}
3713 if$
3714 }
3715 { urldate "-" extract.before extra.label * make.brackets }
3716 if$
3717 }
3718 { date "/" extract.before "-" extract.before
3719 date "/" contains
3720 { "-" normalize.year.dash *
3721 date "/" extract.after "-" extract.before *
3722 }
3723 'skip$
3724 if$
3725 extra.label *
3726 }
3727 if$
3728 }
3729 { year normalize.year.dash extra.label * }
3730 if$
3731 }
3732
3733 % \end{macrocode}
3734 %
3735 % 著者-出版年制的出版年应置于题名前、著者姓名后。
3736 % 需要根据以下选项控制格式:
3737 % - \opt{control.year.before.title} 出版年是否置于题名前;
3738 % - \opt{control.name.year.delim} 著者姓名与出版年之间的分隔符;
3739 % \begin{macrocode}
3740 %<*authoryear>
3741 FUNCTION {format.date.before.title}
3742 { control.year.before.title
3743 { "period" control.name.year.delim =
3744 'new.sentence
3745 'skip$
3746 if$
3747 format.lab.date
3748 }
3749 { "" }
3750 if$
3751 }
3752
3753 %</authoryear>
3754 % \end{macrocode}
3755 %
3756 % 7.6 创建/发布或修改日期、引用日期
3757 % \begin{macrocode}
3758 FUNCTION {format.creation.modification.date}
3759 { date empty$
3760 {
3761 %<*2025>
3762 year empty$
3763 { "" }
3764 { year}
3765 if$
3766 %</2025>
3767 %<*!2025>
3768 ""
3769 %</!2025>
3770 }
3771 { date }
3772 if$
3773 duplicate$ empty$
3774 'skip$
3775 { make.parentheses
3776 "\allowbreak " swap$ *
3777 }
3778 if$
3779 }
3780
3781 % \end{macrocode}
3782 %
3783 % 2025 版的引用日期对于以下文献类型是必备:网站、网页、数据集、预印本类型,
3784 % 其余类型不需要著录。
3785 % 2005、2015 版只有电子资源著录 URL/DOI 时才著录引用日期。
3786 % \begin{macrocode}
3787 FUNCTION {format.urldate}
3788 {
3789 %<*2025>
3790 control.urldate urldate empty$ not and
3791 %</2025>
3792 %<*!2025>
3793 entry.has.url.or.doi
3794 control.urldate urldate empty$ not and and
3795 %</!2025>
3796 { "\allowbreak" urldate make.brackets * }
3797 { "" }
3798 if$
3799 }
3800
3801 % \end{macrocode}
3802 %
3803 % \subsubsection{Format pages}
3804 %
3805 % By default, BibTeX sets the global integer variable |global.max$| to the BibTeX
3806 % constant |glob_str_size|, the maximum length of a global string variable.
3807 % Analogously, BibTeX sets the global integer variable |entry.max$| to
3808 % |ent_str_size|, the maximum length of an entry string variable.
3809 % The style designer may change these if necessary (but this is unlikely)
3810 %
3811 % The n.dashify function makes each single |`-'| in a string a double |`--'|
3812 % if it's not already
3813 %
3814 % \begin{pseudocode}
3815 % pseudoVAR: pageresult: STRING (it's what's accumulated on the stack)
3816 %
3817 % n.dashify(s) ==
3818 % BEGIN
3819 % t := s
3820 % pageresult := ""
3821 % while (not empty$(t))
3822 % do
3823 % if (first character of t = "-")
3824 % then
3825 % if (next character isn't)
3826 % then
3827 % pageresult := pageresult * "--"
3828 % t := t with the "-" removed
3829 % else
3830 % while (first character of t = "-")
3831 % do
3832 % pageresult := pageresult * "-"
3833 % t := t with the "-" removed
3834 % od
3835 % fi
3836 % else
3837 % pageresult := pageresult * the first character
3838 % t := t with the first character removed
3839 % fi
3840 % od
3841 % return pageresult
3842 % END
3843 % \end{pseudocode}
3844 %
3845 % 国标里页码范围的连接号使用 hyphen,需要将 dash 转为 hyphen。
3846 % \begin{macrocode}
3847 % str -> str
3848 % variable used: s, t, b
3849 FUNCTION {normalize.page.range}
3850 { "" swap$
3851 { duplicate$ empty$ not }
3852 { #1 skip.inter.token.chars.by 't :=
3853 empty$
3854 { "" }
3855 'control.page.range.delim
3856 if$
3857 * t
3858 #1 tokenize.by 't :=
3859 * t
3860 }
3861 while$
3862 pop$
3863 }
3864
3865 % \end{macrocode}
3866 %
3867 % This function doesn't begin a sentence so "pages" isn't capitalized.
3868 % Other functions that use this should keep that in mind.
3869 % \begin{macrocode}
3870 FUNCTION {format.pages}
3871 { pages empty$
3872 { "" }
3873 { pages
3874 control.page.ranges
3875 'normalize.page.range
3876 { #1 tokenize.by pop$ }
3877 if$
3878 }
3879 if$
3880 }
3881
3882 FUNCTION {format.dimensions}
3883 { dimensions empty$
3884 { "" }
3885 { dimensions
3886 "x" "$\times$" find.replace
3887 "×" "$\times$" find.replace
3888 }
3889 if$
3890 }
3891
3892 % \end{macrocode}
3893 %
3894 % The |format.vol.num.pages| function is for the volume, number, and page range
3895 % of a journal article. We use the format: vol(number):pages, with some
3896 % variations for empty fields. This doesn't begin a sentence.
3897 %
3898 % 报纸在卷号缺失时,期号与前面的日期直接相连,所以必须拆开输出。
3899 % \begin{macrocode}
3900 FUNCTION {format.journal.volume}
3901 { volume empty$
3902 { "" }
3903 { control.bold.volume
3904 { "\textbf{" volume * "}" * }
3905 { volume }
3906 if$
3907 }
3908 if$
3909 }
3910
3911 FUNCTION {format.journal.number}
3912 { number empty$
3913 { "" }
3914 { "\allowbreak " number make.parentheses * }
3915 if$
3916 }
3917
3918 FUNCTION {format.journal.pages}
3919 { pages empty$
3920 { eid empty$
3921 { "" }
3922 { eid }
3923 if$
3924 }
3925 { format.pages }
3926 if$
3927 }
3928
3929 FUNCTION {format.newspaper.pages}
3930 { pages empty$
3931 { "" }
3932 { "\allowbreak " format.pages make.parentheses * }
3933 if$
3934 }
3935
3936 % \end{macrocode}
3937 %
3938 % \subsubsection{Format url and doi}
3939 %
3940 % 传统的 \BibTeX{} 习惯使用 howpublished 著录 url,这里提供支持。
3941 % \begin{macrocode}
3942 FUNCTION {check.electronic}
3943 { entry.url empty$
3944 { url empty$
3945 { howpublished field.or.null #1 #5 substring$ "\url{" =
3946 { howpublished 'entry.url := }
3947 { note field.or.null #1 #5 substring$ "\url{" =
3948 { note "}" extract.before "}" * 'entry.url := }
3949 'skip$
3950 if$
3951 }
3952 if$
3953 }
3954 { "\url{" url * "}" * 'entry.url := }
3955 if$
3956 }
3957 'skip$
3958 if$
3959 }
3960
3961 FUNCTION {format.url}
3962 { control.url require.url or
3963 { entry.url empty$
3964 { control.doi not require.url or
3965 { cstr empty$
3966 { doi empty$
3967 'skip$
3968 { "\url{https://doi.org/" doi * "}" * 'entry.url := }
3969 if$
3970 }
3971 { "\url{https://cstr.cn/" cstr * "}" * 'entry.url := }
3972 if$
3973 }
3974 'skip$
3975 if$
3976 }
3977 'skip$
3978 if$
3979 entry.url empty$
3980 { "" }
3981 { new.block
3982 entry.url
3983 }
3984 if$
3985 }
3986 { "" }
3987 if$
3988 }
3989
3990 % \end{macrocode}
3991 %
3992 % 需要检测 DOI 是否已经包含在 URL 中。
3993 % \begin{macrocode}
3994 FUNCTION {either.or}
3995 { swap$
3996 duplicate$ empty$
3997 { pop$
3998 duplicate$ empty$
3999 { pop$ "" }
4000 'skip$
4001 if$
4002 }
4003 { swap$ pop$ }
4004 if$
4005 }
4006
4007 FUNCTION {format.doi}
4008 { control.doi
4009 { control.cstr not cstr empty$ or
4010 { doi empty$
4011 { "" }
4012 { control.url require.url or
4013 entry.url doi contains and
4014 { "" }
4015 { new.block "DOI:\doi{" doi * "}" * }
4016 if$
4017 }
4018 if$
4019 }
4020 { control.url require.url or
4021 entry.url cstr contains and
4022 { "" }
4023 { new.block "CSTR:\cstr{" cstr * "}" * }
4024 if$
4025 }
4026 if$
4027 }
4028 { "" }
4029 if$
4030 }
4031
4032 FUNCTION {format.eprint}
4033 { archiveprefix eprinttype either.or
4034 duplicate$ empty$
4035 { pop$
4036 journal journaltitle either.or shortjournal either.or
4037 "l" change.case$ #1 #5 substring$ "arxiv" =
4038 { "arXiv" }
4039 { "" }
4040 if$
4041 }
4042 { duplicate$ "arxiv" =
4043 { pop$ "arXiv" }
4044 { duplicate$ "pubmed" =
4045 { pop$ "PubMed" }
4046 'skip$
4047 if$
4048 }
4049 if$
4050 }
4051 if$
4052 entry.url empty$
4053 { duplicate$ "l" change.case$ "arxiv" = entry.eprint empty$ not and
4054 { "\url{https://arxiv.org/abs/" entry.eprint * "}" * 'entry.url := }
4055 'skip$
4056 if$
4057 }
4058 'skip$
4059 if$
4060 control.eprint eprint empty$ not and
4061 { duplicate$ empty$
4062 'skip$
4063 { ":" * }
4064 if$
4065 eprint *
4066 }
4067 'skip$
4068 if$
4069 }
4070
4071 FUNCTION {format.note}
4072 { note empty$ not control.note and
4073 { note }
4074 { "" }
4075 if$
4076 }
4077
4078 % \end{macrocode}
4079 %
4080 % The function empty.misc.check complains if all six fields are empty, and
4081 % if there's been no sorting or alphabetic-label complaint.
4082 % \begin{macrocode}
4083 FUNCTION {empty.misc.check}
4084 { author empty$ title empty$
4085 year empty$
4086 and and
4087 key empty$ not and
4088 { "all relevant fields are empty in " cite$ * warning$ }
4089 'skip$
4090 if$
4091 }
4092
4093 FUNCTION {link.open}
4094 { control.link.journal
4095 { url empty$
4096 { doi empty$
4097 { "" }
4098 { "\href{https://doi.org/" doi * "}{" * }
4099 if$
4100 }
4101 { "\href{" url * "}{" * }
4102 if$
4103 duplicate$ empty$
4104 { pop$ }
4105 { "" set.punct
4106 output
4107 before.all 'output.state :=
4108 }
4109 if$
4110 }
4111 'skip$
4112 if$
4113 }
4114
4115 FUNCTION {link.close}
4116 { control.link.journal
4117 { url empty$ doi empty$ and
4118 'skip$
4119 { "" set.punct
4120 "}" output
4121 before.all 'output.state :=
4122 }
4123 if$
4124 }
4125 'skip$
4126 if$
4127 }
4128
4129 % \end{macrocode}
4130 %
4131 % \subsection{Functions for all entry types}
4132 %
4133 % Now we define the type functions for all entry types that may appear
4134 % in the .BIB file---e.g., functions like `article' and `book'. These
4135 % are the routines that actually generate the .BBL-file output for
4136 % the entry. These must all precede the READ command. In addition, the
4137 % style designer should have a function `default.type' for unknown types.
4138 % Note: The fields (within each list) are listed in order of appearance,
4139 % except as described for an `inbook' or a `proceedings'.
4140 %
4141 % The article function is for an article in a journal. An article may
4142 % CROSSREF another article.
4143 %
4144 % Required fields: author, title, journal, year
4145 %
4146 % Optional fields: volume, number, pages, month, note
4147 %
4148 % The other entry functions are all quite similar, so no "comment version"
4149 % will be given for them.
4150 % \begin{macrocode}
4151 FUNCTION {article.journal}
4152 { "J" set.entry.type.id
4153 volume empty$ number empty$ and entry.url empty$ not and
4154 date field.or.null text.length$ #9 > and
4155 entry.type.id "J" = and
4156 { #1 'require.url := }
4157 'skip$
4158 if$
4159 output.bibitem
4160 format.authors output
4161 %<*authoryear>
4162 format.date.before.title output
4163 %</authoryear>
4164 control.article.title
4165 { new.block
4166 format.title "title" output.check
4167 }
4168 'skip$
4169 if$
4170 new.block
4171 format.translators output
4172 new.block
4173 link.open
4174 format.journal "journal" output.check
4175 entry.type.id "N" =
4176 { format.full.date "date" output.check
4177 "" set.punct
4178 format.newspaper.pages output
4179 }
4180 {
4181 % \end{macrocode}
4182 %
4183 % 卷次和期号均为空时视为在线出版,使用完整日期。
4184 % \begin{macrocode}
4185 %<*2025>
4186 volume empty$ number empty$ and date field.or.null text.length$ #9 > and
4187 { format.full.date "date" output.check }
4188 { format.date "year" output.check }
4189 if$
4190 %</2025>
4191 %<*!2025>
4192 format.date output
4193 %</!2025>
4194 format.journal.volume output
4195 "" set.punct
4196 format.journal.number output
4197 bbl.pages.colon set.punct
4198 format.journal.pages output
4199 }
4200 if$
4201 link.close
4202 %<*!2025>
4203 "" set.punct
4204 format.urldate output
4205 %</!2025>
4206 format.url output
4207 format.doi output
4208 new.block
4209 format.note output
4210 fin.entry
4211 }
4212
4213 FUNCTION {archive}
4214 { "A" set.entry.type.id
4215 output.bibitem
4216 format.authors output
4217 %<*authoryear>
4218 format.date.before.title output
4219 %</authoryear>
4220 new.block
4221 format.btitle "title" output.check
4222 % new.block
4223 % format.translators output
4224 new.block
4225 format.address.publisher output
4226 %<*2025>
4227 format.full.date "year" output.check
4228 bbl.pages.colon set.punct
4229 format.pages output
4230 %</2025>
4231 %<*!2025>
4232 format.date output
4233 bbl.pages.colon set.punct
4234 format.pages output
4235 "" set.punct
4236 format.creation.modification.date output
4237 "" set.punct
4238 format.urldate output
4239 %</!2025>
4240 format.url output
4241 format.doi output
4242 new.block
4243 format.note output
4244 fin.entry
4245 }
4246
4247 % \end{macrocode}
4248 %
4249 %
4250 % The book function is for a whole book. A book may CROSSREF another book.
4251 %
4252 % Required fields: author or editor, title, publisher, year
4253 %
4254 % Optional fields: volume or number, series, address, edition, month,
4255 % note
4256 % \begin{macrocode}
4257 FUNCTION {book}
4258 { "M" set.entry.type.id
4259 output.bibitem
4260 format.authors.editors output
4261 %<*authoryear>
4262 format.date.before.title output
4263 %</authoryear>
4264 new.block
4265 format.btitle "title" output.check
4266 new.block
4267 format.translators output
4268 new.sentence
4269 format.edition output
4270 new.block
4271 format.address.publisher output
4272 format.date output
4273 bbl.pages.colon set.punct
4274 format.pages output
4275 %<*!2025>
4276 "" set.punct
4277 format.urldate output
4278 %</!2025>
4279 format.url output
4280 format.doi output
4281 new.block
4282 format.note output
4283 fin.entry
4284 }
4285
4286 FUNCTION {letter} { archive }
4287
4288 FUNCTION {dataset}
4289 { "DS" set.entry.type.id
4290 output.bibitem
4291 format.authors output
4292 %<*authoryear>
4293 format.date.before.title output
4294 %</authoryear>
4295 new.block
4296 format.btitle "title" output.check
4297 new.block
4298 format.version output
4299 new.block
4300 publisher "publisher" output.check
4301 "" set.punct
4302 format.creation.modification.date output
4303 "" set.punct
4304 %<*2025>
4305 format.urldate "urldate" output.check
4306 %</2025>
4307 %<*!2025>
4308 format.urldate output
4309 %</!2025>
4310 format.url output
4311 format.doi output
4312 new.block
4313 format.note output
4314 fin.entry
4315 }
4316
4317 FUNCTION {database}
4318 { "DB" set.entry.type.id
4319 dataset
4320 }
4321
4322 % \end{macrocode}
4323 %
4324 % An inbook is a piece of a book: either a chapter and/or a page range.
4325 % It may CROSSREF a book. If there's no volume field, the type field
4326 % will come before number and series.
4327 %
4328 % Required: author or editor, title, chapter and/or pages, publisher,year
4329 %
4330 % Optional: volume or number, series, type, address, edition, month, note
4331 %
4332 % 原生 BibTeX 的数据模型中 \texttt{@inbook} 不含 \texttt{booktitle} ,
4333 % 按照“专著”处理。而 biblatex 的 \texttt{@inbook} 跟 \texttt{incollection} 一样。
4334 % 按照“专著的析出文献”处理。
4335 % \begin{macrocode}
4336 FUNCTION {inbook}
4337 { "M" set.entry.type.id
4338 booktitle empty$
4339 'book
4340 { output.bibitem
4341 format.authors output
4342 %<*authoryear>
4343 format.date.before.title output
4344 %</authoryear>
4345 control.article.title
4346 { new.block
4347 format.title "title" output.check
4348 }
4349 'skip$
4350 if$
4351 new.block
4352 format.translators output
4353 new.slash
4354 booktitle empty$
4355 { "" }
4356 { control.in
4357 { bbl.in add.colon }
4358 { "" }
4359 if$
4360 bookauthor empty$
4361 { editor empty$
4362 'skip$
4363 { format.editors * output new.block "" }
4364 if$
4365 }
4366 { bookauthor format.names * output new.block "" }
4367 if$
4368 format.series.volume.booktitle *
4369 }
4370 if$
4371 "booktitle" output.check
4372 new.block
4373 format.edition output
4374 new.block
4375 format.address.publisher output
4376 format.date output
4377 bbl.pages.colon set.punct
4378 format.pages output
4379 %<*!2025>
4380 "" set.punct
4381 format.urldate output
4382 %</!2025>
4383 format.url output
4384 format.doi output
4385 new.block
4386 format.note output
4387 fin.entry
4388 }
4389 if$
4390 }
4391
4392 % \end{macrocode}
4393 %
4394 % \subsubsection{图书中的析出文献}
4395 %
4396 % An incollection is like inbook, but where there is a separate title
4397 % for the referenced thing (and perhaps an editor for the whole).
4398 % An incollection may CROSSREF a book.
4399 %
4400 % Required: author, title, booktitle, publisher, year
4401 %
4402 % Optional: editor, volume or number, series, type, chapter, pages,
4403 % address, edition, month, note
4404 % \begin{macrocode}
4405 FUNCTION {incollection}
4406 { "M" set.entry.type.id
4407 output.bibitem
4408 format.authors output
4409 %<*authoryear>
4410 format.date.before.title output
4411 %</authoryear>
4412 control.article.title
4413 { new.block
4414 format.title "title" output.check
4415 }
4416 'skip$
4417 if$
4418 new.block
4419 format.translators output
4420 new.slash
4421 format.in.ed.booktitle "booktitle" output.check
4422 new.block
4423 format.edition output
4424 new.block
4425 format.address.publisher output
4426 format.date output
4427 bbl.pages.colon set.punct
4428 format.pages output
4429 %<*!2025>
4430 "" set.punct
4431 format.urldate output
4432 %</!2025>
4433 format.url output
4434 format.doi output
4435 new.block
4436 format.note output
4437 fin.entry
4438 }
4439
4440 % \end{macrocode}
4441 %
4442 % An inproceedings is an article in a conference proceedings, and it may
4443 % CROSSREF a proceedings. If there's no address field, the month (\& year)
4444 % will appear just before note.
4445 %
4446 % Required: author, title, booktitle, year
4447 %
4448 % Optional: editor, volume or number, series, pages, address, month,
4449 % organization, publisher, note
4450 %
4451 % 以图书中的析出文献的形式出版的会议论文,按照 @incollection 处理,使用“//”符号。
4452 % 未正式出版的会议论文使用下的格式,不使用“//”符号。
4453 % \begin{macrocode}
4454 FUNCTION {inproceedings}
4455 { "C" set.entry.type.id
4456 output.bibitem
4457 format.authors output
4458 %<*authoryear>
4459 format.date.before.title output
4460 %</authoryear>
4461 control.article.title
4462 { new.block
4463 format.title "title" output.check
4464 }
4465 'skip$
4466 if$
4467 new.slash
4468 booktitle empty$
4469 { format.eventtitle "eventtitle" output.check }
4470 { format.in.ed.booktitle "booktitle" output.check
4471 new.block
4472 format.edition output
4473 new.block
4474 format.address.publisher output
4475 }
4476 if$
4477 format.date output
4478 bbl.pages.colon set.punct
4479 format.pages output
4480 %<*!2025>
4481 "" set.punct
4482 format.urldate output
4483 %</!2025>
4484 format.url output
4485 format.doi output
4486 new.block
4487 format.note output
4488 fin.entry
4489 }
4490
4491 % \end{macrocode}
4492 %
4493 % The conference function is included for Scribe compatibility.
4494 % \begin{macrocode}
4495 FUNCTION {conference} { inproceedings }
4496
4497 % \end{macrocode}
4498 %
4499 % \subsubsection{专利文献}
4500 %
4501 % number 域也可以用来表示专利号。
4502 % \begin{macrocode}
4503 FUNCTION {patent}
4504 { "P" set.entry.type.id
4505 output.bibitem
4506 holder empty$
4507 { format.authors "holder and author" output.check }
4508 { holder format.names output.nonnull }
4509 if$
4510 %<*authoryear>
4511 format.date.before.title output
4512 %</authoryear>
4513 control.article.title
4514 { new.block
4515 format.title "title" output.check
4516 }
4517 'skip$
4518 if$
4519 new.block
4520 format.full.date "year" output.check
4521 %<*2025>
4522 bbl.pages.colon set.punct
4523 format.pages output
4524 %</2025>
4525 %<*!2025>
4526 "" set.punct
4527 format.urldate output
4528 %</!2025>
4529 format.url output
4530 format.doi output
4531 new.block
4532 format.note output
4533 fin.entry
4534 }
4535
4536 % \end{macrocode}
4537 %
4538 % \subsubsection{连续出版物}
4539 %
4540 % \begin{macrocode}
4541 FUNCTION {format.periodical.volume}
4542 { volume number either.or
4543 duplicate$ empty$
4544 { pop$ "" }
4545 { format.punctuations
4546 normalize.year.dash
4547 }
4548 if$
4549 }
4550
4551 FUNCTION {periodical}
4552 { "J" set.entry.type.id
4553 output.bibitem
4554 format.editors output
4555 %<*authoryear>
4556 format.date.before.title output
4557 %</authoryear>
4558 new.block
4559 format.title "title" output.check
4560 new.block
4561 format.periodical.volume output
4562 new.block
4563 format.address.publisher output
4564 format.date output
4565 %<*2005|2015>
4566 "" set.punct
4567 format.urldate output
4568 %</2005|2015>
4569 format.url output
4570 format.doi output
4571 new.block
4572 format.note output
4573 fin.entry
4574 }
4575
4576 % \end{macrocode}
4577 %
4578 % A proceedings is a conference proceedings.
4579 % If there is an organization but no editor field, the organization will
4580 % appear as the first optional field (we try to make the first block nonempty);
4581 % if there's no address field, the month (\& year) will appear just before note.
4582 %
4583 % Required: title, year
4584 %
4585 % Optional: editor, volume or number, series, address, month,
4586 % organization, publisher, note
4587 % \begin{macrocode}
4588 FUNCTION {proceedings}
4589 { "C" set.entry.type.id
4590 output.bibitem
4591 format.editors output
4592 %<*authoryear>
4593 format.date.before.title output
4594 %</authoryear>
4595 new.block
4596 format.btitle "title" output.check
4597 new.block
4598 format.translators output
4599 new.sentence
4600 format.edition output
4601 new.block
4602 format.address.publisher output
4603 format.date output
4604 bbl.pages.colon set.punct
4605 format.pages output
4606 %<*!2025>
4607 "" set.punct
4608 format.urldate output
4609 %</!2025>
4610 format.url output
4611 format.doi output
4612 new.block
4613 format.note output
4614 fin.entry
4615 }
4616
4617 % \end{macrocode}
4618 %
4619 % \subsubsection{预印本}
4620 %
4621 % \begin{macrocode}
4622 FUNCTION {preprint}
4623 { #1 'require.url :=
4624 %<*2025>
4625 "PP" set.entry.type.id
4626 %</2025>
4627 %<*2015>
4628 "A" set.entry.type.id
4629 %</2015>
4630 %<*!(2015|2025)>
4631 "Z" set.entry.type.id
4632 %</!(2015|2025)>
4633 output.bibitem
4634 format.authors output
4635 %<*authoryear>
4636 format.date.before.title output
4637 %</authoryear>
4638 control.article.title
4639 { new.block
4640 format.title "title" output.check
4641 }
4642 'skip$
4643 if$
4644 new.block
4645 format.version output
4646 new.block
4647 format.eprint output
4648 "" set.punct
4649 format.creation.modification.date output
4650 "" set.punct
4651 format.urldate "urldate" output.check
4652 format.url "url" output.check
4653 format.doi output
4654 new.block
4655 format.note output
4656 fin.entry
4657 }
4658
4659 % \end{macrocode}
4660 %
4661 % A phdthesis is like a mastersthesis.
4662 %
4663 % Required: author, title, school, year
4664 %
4665 % Optional: type, address, month, note
4666 % \begin{macrocode}
4667 FUNCTION {thesis}
4668 { "D" set.entry.type.id
4669 output.bibitem
4670 format.authors output
4671 %<*authoryear>
4672 format.date.before.title output
4673 %</authoryear>
4674 new.block
4675 format.btitle "title" output.check
4676 new.block
4677 format.address.publisher output
4678 format.date output
4679 bbl.pages.colon set.punct
4680 format.pages output
4681 %<*!2025>
4682 "" set.punct
4683 format.urldate output
4684 %</!2025>
4685 format.url output
4686 format.doi output
4687 new.block
4688 format.note output
4689 fin.entry
4690 }
4691
4692 FUNCTION {phdthesis} { thesis }
4693
4694 % \end{macrocode}
4695 %
4696 % A mastersthesis is a Master's thesis.
4697 %
4698 % Required: author, title, school, year
4699 %
4700 % Optional: type, address, month, note
4701 % \begin{macrocode}
4702 FUNCTION {mastersthesis} { thesis }
4703
4704 % \end{macrocode}
4705 %
4706 % A techreport is a technical report.
4707 %
4708 % Required: author, title, institution, year
4709 %
4710 % Optional: type, number, address, month, note
4711 % \begin{macrocode}
4712 FUNCTION {techreport}
4713 { "R" set.entry.type.id
4714 output.bibitem
4715 format.authors output
4716 %<*authoryear>
4717 format.date.before.title output
4718 %</authoryear>
4719 new.block
4720 format.btitle "title" output.check
4721 % new.block
4722 % format.translators output
4723 new.block
4724 %<*2025>
4725 institution empty$ publisher empty$ and
4726 { format.full.date "year" output.check
4727 bbl.pages.colon set.punct
4728 format.pages output
4729 }
4730 { format.address.publisher output
4731 format.date output
4732 bbl.pages.colon set.punct
4733 format.pages output
4734 }
4735 if$
4736 %</2025>
4737 %<*!2025>
4738 institution empty$
4739 pages empty$ and
4740 control.url and
4741 entry.url empty$ not and
4742 'skip$
4743 { format.address.publisher output
4744 format.date output
4745 bbl.pages.colon set.punct
4746 format.pages output
4747 }
4748 if$
4749 "" set.punct
4750 format.creation.modification.date output
4751 "" set.punct
4752 format.urldate output
4753 %</!2025>
4754 format.url output
4755 format.doi output
4756 new.block
4757 format.note output
4758 fin.entry
4759 }
4760
4761 FUNCTION {report} { techreport }
4762
4763 % \end{macrocode}
4764 %
4765 % A manual is technical documentation.
4766 %
4767 % Required: title
4768 %
4769 % Optional: author, organization, address, edition, month, year, note
4770 % \begin{macrocode}
4771 FUNCTION {manual} { techreport }
4772
4773 % \end{macrocode}
4774 %
4775 % \subsubsection{电子资源}
4776 % \begin{macrocode}
4777 FUNCTION {webpage}
4778 { #1 'require.url :=
4779 output.bibitem
4780 format.authors output
4781 %<*authoryear>
4782 format.date.before.title output
4783 %</authoryear>
4784 new.block
4785 "EB" set.entry.type.id
4786 format.btitle "title" output.check
4787 new.block
4788 publisher empty$
4789 'skip$
4790 { format.address.publisher output
4791 format.date output
4792 bbl.pages.colon set.punct
4793 format.pages output
4794 "" set.punct
4795 }
4796 if$
4797 format.creation.modification.date output
4798 "" set.punct
4799 format.urldate "urldate" output.check
4800 format.url "url" output.check
4801 format.doi output
4802 new.block
4803 format.note output
4804 fin.entry
4805 }
4806
4807 % \end{macrocode}
4808 %
4809 % \subsubsection{其他文献类型}
4810 %
4811 % A misc is something that doesn't fit elsewhere.
4812 %
4813 % Required: at least one of the `optional' fields
4814 %
4815 % Optional: author, title, howpublished, month, year, note
4816 %
4817 % Misc 用来自动判断类型。
4818 % \begin{macrocode}
4819 FUNCTION {misc}
4820 { eprint empty$ not archiveprefix empty$ not or eprinttype empty$ not or
4821 'preprint
4822 { entry.url empty$
4823 {
4824 %<*!2005>
4825 "Z" set.entry.type.id
4826 %</!2005>
4827 %<*2005>
4828 "M" set.entry.type.id
4829 %</2005>
4830 book
4831 }
4832 'webpage
4833 if$
4834 }
4835 if$
4836 empty.misc.check
4837 }
4838
4839 FUNCTION {article}
4840 { entrysubtype field.or.null "l" change.case$ "newspaper" =
4841 { "N" set.entry.type.id
4842 article.journal
4843 }
4844 { journal journaltitle either.or shortjournal either.or
4845 duplicate$ empty$
4846 { pop$
4847 archiveprefix eprinttype either.or eprint either.or empty$
4848 'article.journal
4849 'preprint
4850 if$
4851 }
4852 { check.arxiv.preprint
4853 'preprint
4854 'article.journal
4855 if$
4856 }
4857 if$
4858 }
4859 if$
4860 }
4861
4862 % \end{macrocode}
4863 %
4864 % A booklet is a bound thing without a publisher or sponsoring institution.
4865 %
4866 % Required: title
4867 %
4868 % Optional: author, howpublished, address, month, year, note
4869 % \begin{macrocode}
4870 FUNCTION {booklet} { book }
4871
4872 FUNCTION {collection}
4873 { "G" set.entry.type.id
4874 book
4875 }
4876
4877 FUNCTION {image} { misc }
4878
4879 FUNCTION {legislation} { archive }
4880
4881
4882 FUNCTION {map}
4883 { "CM" set.entry.type.id
4884 booktitle empty$ not
4885 { incollection }
4886 { output.bibitem
4887 format.authors output
4888 %<*authoryear>
4889 format.date.before.title output
4890 %</authoryear>
4891 new.block
4892 format.btitle "title" output.check
4893 new.block
4894 format.edition output
4895 new.block
4896 format.address.publisher output
4897 format.date output
4898 bbl.pages.colon set.punct
4899 format.pages output
4900 %<*!(2005|2015)>
4901 new.block
4902 format.dimensions output
4903 %</!(2005|2015)>
4904 %<*2005|2015>
4905 "" set.punct
4906 format.creation.modification.date output
4907 "" set.punct
4908 format.urldate output
4909 %</2005|2015>
4910 format.url output
4911 format.doi output
4912 new.block
4913 format.note output
4914 fin.entry
4915 }
4916 if$
4917 }
4918
4919 FUNCTION {newspaper}
4920 { "N" set.entry.type.id
4921 article.journal
4922 }
4923
4924 FUNCTION {online}
4925 { eprint empty$
4926 archiveprefix empty$ and
4927 eprinttype empty$ and
4928 { webpage }
4929 { preprint }
4930 if$
4931 }
4932
4933 FUNCTION {software}
4934 { "CP" set.entry.type.id
4935 webpage
4936 }
4937
4938 FUNCTION {standard}
4939 { "S" set.entry.type.id
4940 %<*!(2005|2015)>
4941 output.bibitem
4942 %<*authoryear>
4943 format.authors.editors output
4944 format.date.before.title output
4945 new.block
4946 %</authoryear>
4947 number field.or.null output
4948 is.lang.cjk
4949 { "\quad " set.punct }
4950 { " " set.punct }
4951 if$
4952 format.btitle "title" output.check
4953 new.block
4954 format.url output
4955 new.block
4956 format.doi output
4957 new.block
4958 format.note output
4959 fin.entry
4960 %</!(2005|2015)>
4961 %<*2005|2015>
4962 booktitle empty$
4963 'book
4964 'incollection
4965 if$
4966 %</2005|2015>
4967 }
4968
4969 % \end{macrocode}
4970 %
4971 % An unpublished is something that hasn't been published.
4972 %
4973 % Required: author, title, note
4974 %
4975 % Optional: month, year
4976 % \begin{macrocode}
4977 FUNCTION {unpublished} { misc }
4978
4979 FUNCTION {video} { misc }
4980
4981 % \end{macrocode}
4982 %
4983 % We use entry type `misc' for an unknown type; BibTeX gives a warning.
4984 % \begin{macrocode}
4985 FUNCTION {default.type} { misc }
4986
4987 % \end{macrocode}
4988 %
4989 % The following is taken from ttb.pdf.
4990 % \begin{macrocode}
4991 FUNCTION {mult}
4992 { 'a := %% we store the first value
4993 'b := %% we store the second value
4994
4995 b #0 < %% We remember the sign of b, and
4996 {#-1 #0 b - 'b :=} %% then consider its absolute value.
4997 {#1} %%
4998 if$ %%
4999
5000 #0 %% Put 0 on the stack.
5001 {b #0 >} %% While b is strictly positive,
5002 { %% we add a to the value on the stack
5003 a + %% and decrement b.
5004 b #1 - 'b := %%
5005 } %%
5006 while$ %%
5007
5008 swap$ %% Last, we take the opposite
5009 'skip$ %% if b was negative.
5010 {#0 swap$ -} %%
5011 if$ %%
5012 }
5013
5014 FUNCTION {chr.to.value} %% The ASCII code of a character
5015 { chr.to.int$ #48 - %% ASCII value of "0" -> 48
5016 duplicate$ duplicate$ %% "1" -> 49
5017 #0 < swap$ #9 > or %% ...
5018 { %% "9" -> 57
5019 #48 + int.to.chr$
5020 " is not a number..." *
5021 warning$ %% Return 0 if it is not a number
5022 pop$ #0 %%
5023 }
5024 {}
5025 if$
5026 }
5027
5028 FUNCTION {str.to.int.aux} %% The auxiliary function
5029 { { duplicate$ empty$ not } %% While the string is not empty
5030 { %% consider its first char
5031 swap$ #10 mult 'a := %% and ``add'' it at the end of
5032 duplicate$ #1 #1 substring$ %% the result.
5033 chr.to.value a +
5034 swap$
5035 #2 global.max$ substring$
5036 }
5037 while$
5038 pop$
5039 }
5040
5041 FUNCTION {str.to.int}
5042 { %% Handling negative values
5043 duplicate$ #1 #1 substring$ "-" =
5044 {#1 swap$ #2 global.max$ substring$}
5045 {#0 swap$}
5046 if$
5047 %% Initialization, and then
5048 #0 swap$ str.to.int.aux %% call to the aux. function
5049 swap$
5050 {#0 swap$ -} %% And handle the sign.
5051 {}
5052 if$
5053 }
5054
5055 FUNCTION {boolean.to.int}
5056 { "l" change.case$ duplicate$
5057 "true" =
5058 { pop$ #1 }
5059 { duplicate$ "false" =
5060 { pop$ #0 }
5061 { "unknown boolean " quote$ * swap$ * quote$ *
5062 " in " * cite$ * warning$
5063 #0
5064 }
5065 if$
5066 }
5067 if$
5068 }
5069
5070 FUNCTION {GBT7714BSTCTL}
5071 { CTL_bib_punct empty$
5072 'skip$
5073 { CTL_bib_punct 'control.bib.punct := }
5074 if$
5075 CTL_convert_punct empty$
5076 'skip$
5077 { CTL_convert_punct boolean.to.int 'control.convert.punct := }
5078 if$
5079 CTL_max_bib_names empty$
5080 'skip$
5081 { CTL_max_bib_names str.to.int 'control.max.bib.names := }
5082 if$
5083 CTL_min_bib_names empty$
5084 'skip$
5085 { CTL_min_bib_names str.to.int 'control.min.bib.names := }
5086 if$
5087 CTL_max_cite_names empty$
5088 'skip$
5089 { CTL_max_cite_names str.to.int 'control.max.cite.names := }
5090 if$
5091 CTL_min_cite_names empty$
5092 'skip$
5093 { CTL_min_cite_names str.to.int 'control.min.cite.names := }
5094 if$
5095 CTL_uppercase_family empty$
5096 'skip$
5097 { CTL_uppercase_family boolean.to.int 'control.uppercase.family := }
5098 if$
5099 CTL_initialize_with_hyphen empty$
5100 'skip$
5101 { CTL_initialize_with_hyphen boolean.to.int 'control.initialize.with.hyphen := }
5102 if$
5103 CTL_check_pinyin empty$
5104 'skip$
5105 { CTL_check_pinyin boolean.to.int 'control.check.pinyin := }
5106 if$
5107 CTL_initialize_pinyin empty$
5108 'skip$
5109 { CTL_initialize_pinyin boolean.to.int 'control.initialize.pinyin := }
5110 if$
5111 CTL_bib_final_and empty$
5112 'skip$
5113 { CTL_bib_final_and boolean.to.int 'control.bib.final.and := }
5114 if$
5115 CTL_cite_final_and empty$
5116 'skip$
5117 { CTL_cite_final_and boolean.to.int 'control.cite.final.and := }
5118 if$
5119 CTL_cite_lang empty$
5120 'skip$
5121 { CTL_cite_lang 'control.cite.lang := }
5122 if$
5123 CTL_space_before_et_al empty$
5124 'skip$
5125 { CTL_space_before_et_al boolean.to.int 'control.space.before.et.al := }
5126 if$
5127 CTL_year_before_title empty$
5128 'skip$
5129 { CTL_year_before_title boolean.to.int 'control.year.before.title := }
5130 if$
5131 CTL_name_year_delim empty$
5132 'skip$
5133 { CTL_name_year_delim 'control.name.year.delim := }
5134 if$
5135 CTL_sentence_case empty$
5136 'skip$
5137 { CTL_sentence_case boolean.to.int 'control.sentence.case.title :=
5138 CTL_sentence_case boolean.to.int 'control.sentence.case.booktitle :=
5139 %<*2005|2015>
5140 CTL_sentence_case boolean.to.int 'control.sentence.case.journal :=
5141 %</2005|2015>
5142 }
5143 if$
5144 CTL_sentence_case_title empty$
5145 'skip$
5146 { CTL_sentence_case_title boolean.to.int 'control.sentence.case.title := }
5147 if$
5148 CTL_sentence_case_booktitle empty$
5149 'skip$
5150 { CTL_sentence_case_booktitle boolean.to.int 'control.sentence.case.booktitle := }
5151 if$
5152 CTL_sentence_case_journal empty$
5153 'skip$
5154 { CTL_sentence_case_journal boolean.to.int 'control.sentence.case.journal := }
5155 if$
5156 CTL_capitalize_subtitle empty$
5157 'skip$
5158 { CTL_capitalize_subtitle boolean.to.int 'control.capitalize.subtitle := }
5159 if$
5160 CTL_link_title empty$
5161 'skip$
5162 { CTL_link_title boolean.to.int 'control.link.title := }
5163 if$
5164 CTL_article_title empty$
5165 'skip$
5166 { CTL_article_title boolean.to.int 'control.article.title := }
5167 if$
5168 CTL_patent_country empty$
5169 'skip$
5170 { CTL_patent_country boolean.to.int 'control.patent.country := }
5171 if$
5172 CTL_entry_type_id empty$
5173 'skip$
5174 { CTL_entry_type_id boolean.to.int 'control.entry.type.id := }
5175 if$
5176 CTL_space_before_type_id empty$
5177 'skip$
5178 { CTL_space_before_type_id boolean.to.int 'control.space.before.type.id := }
5179 if$
5180 CTL_entry_medium_id empty$
5181 'skip$
5182 { CTL_entry_medium_id boolean.to.int 'control.entry.medium.id := }
5183 if$
5184 CTL_slash empty$
5185 'skip$
5186 { CTL_slash boolean.to.int 'control.slash := }
5187 if$
5188 CTL_in empty$
5189 'skip$
5190 { CTL_in boolean.to.int 'control.in := }
5191 if$
5192 CTL_emph_booktitle empty$
5193 'skip$
5194 { CTL_emph_booktitle boolean.to.int 'control.emph.booktitle := }
5195 if$
5196 CTL_emph_journal empty$
5197 'skip$
5198 { CTL_emph_journal boolean.to.int 'control.emph.journal := }
5199 if$
5200 CTL_short_journal empty$
5201 'skip$
5202 { CTL_short_journal boolean.to.int 'control.short.journal := }
5203 if$
5204 CTL_journal_dots empty$
5205 'skip$
5206 { CTL_journal_dots boolean.to.int 'control.journal.dots := }
5207 if$
5208 CTL_link_journal empty$
5209 'skip$
5210 { CTL_link_journal boolean.to.int 'control.link.journal := }
5211 if$
5212 CTL_bold_volume empty$
5213 'skip$
5214 { CTL_bold_volume boolean.to.int 'control.bold.volume := }
5215 if$
5216 CTL_unknown_publisher empty$
5217 'skip$
5218 { CTL_unknown_publisher boolean.to.int 'control.unknown.publisher := }
5219 if$
5220 CTL_space_before_pages empty$
5221 'skip$
5222 { CTL_space_before_pages boolean.to.int 'control.space.before.pages := }
5223 if$
5224 CTL_page_ranges empty$
5225 'skip$
5226 { CTL_page_ranges boolean.to.int 'control.page.ranges := }
5227 if$
5228 CTL_page_range_delim empty$
5229 'skip$
5230 { CTL_page_range_delim 'control.page.range.delim := }
5231 if$
5232 CTL_urldate empty$
5233 'skip$
5234 { CTL_urldate boolean.to.int 'control.urldate := }
5235 if$
5236 CTL_url empty$
5237 'skip$
5238 { CTL_url boolean.to.int 'control.url := }
5239 if$
5240 CTL_doi empty$
5241 'skip$
5242 { CTL_doi boolean.to.int 'control.doi := }
5243 if$
5244 CTL_eprint empty$
5245 'skip$
5246 { CTL_eprint boolean.to.int 'control.eprint := }
5247 if$
5248 CTL_note empty$
5249 'skip$
5250 { CTL_note boolean.to.int 'control.note := }
5251 if$
5252 CTL_end_dot empty$
5253 'skip$
5254 { CTL_end_dot boolean.to.int 'control.end.dot := }
5255 if$
5256 CTL_warn_empty_field empty$
5257 'skip$
5258 { CTL_warn_empty_field boolean.to.int 'control.warn.empty.field := }
5259 if$
5260 }
5261
5262 FUNCTION {control.pass}
5263 { type$ "gbt7714bstctl" =
5264 'GBT7714BSTCTL
5265 'skip$
5266 if$
5267 }
5268
5269 FUNCTION {control.check}
5270 { % TODO
5271 }
5272
5273 % \end{macrocode}
5274 %
5275 %
5276 % \subsection{Common macros}
5277 %
5278 % Here are macros for common things that may vary from style to style.
5279 % Users are encouraged to use these macros.
5280 %
5281 % Months are either written out in full or abbreviated
5282 % \begin{macrocode}
5283 MACRO {jan} {"January"}
5284
5285 MACRO {feb} {"February"}
5286
5287 MACRO {mar} {"March"}
5288
5289 MACRO {apr} {"April"}
5290
5291 MACRO {may} {"May"}
5292
5293 MACRO {jun} {"June"}
5294
5295 MACRO {jul} {"July"}
5296
5297 MACRO {aug} {"August"}
5298
5299 MACRO {sep} {"September"}
5300
5301 MACRO {oct} {"October"}
5302
5303 MACRO {nov} {"November"}
5304
5305 MACRO {dec} {"December"}
5306
5307 % \end{macrocode}
5308 %
5309 % Journals are either written out in full or abbreviated;
5310 % the abbreviations are like those found in ACM publications.
5311 %
5312 % To get a completely different set of abbreviations, it may be best to make
5313 % a separate .bib file with nothing but those abbreviations; users could then
5314 % include that file name as the first argument to the \cs{bibliography} command
5315 % \begin{macrocode}
5316 MACRO {acmcs} {"ACM Computing Surveys"}
5317
5318 MACRO {acta} {"Acta Informatica"}
5319
5320 MACRO {cacm} {"Communications of the ACM"}
5321
5322 MACRO {ibmjrd} {"IBM Journal of Research and Development"}
5323
5324 MACRO {ibmsj} {"IBM Systems Journal"}
5325
5326 MACRO {ieeese} {"IEEE Transactions on Software Engineering"}
5327
5328 MACRO {ieeetc} {"IEEE Transactions on Computers"}
5329
5330 MACRO {ieeetcad}
5331 {"IEEE Transactions on Computer-Aided Design of Integrated Circuits"}
5332
5333 MACRO {ipl} {"Information Processing Letters"}
5334
5335 MACRO {jacm} {"Journal of the ACM"}
5336
5337 MACRO {jcss} {"Journal of Computer and System Sciences"}
5338
5339 MACRO {scp} {"Science of Computer Programming"}
5340
5341 MACRO {sicomp} {"SIAM Journal on Computing"}
5342
5343 MACRO {tocs} {"ACM Transactions on Computer Systems"}
5344
5345 MACRO {tods} {"ACM Transactions on Database Systems"}
5346
5347 MACRO {tog} {"ACM Transactions on Graphics"}
5348
5349 MACRO {toms} {"ACM Transactions on Mathematical Software"}
5350
5351 MACRO {toois} {"ACM Transactions on Office Information Systems"}
5352
5353 MACRO {toplas} {"ACM Transactions on Programming Languages and Systems"}
5354
5355 MACRO {tcs} {"Theoretical Computer Science"}
5356
5357 % \end{macrocode}
5358 %
5359 %
5360 % \subsection{Format labels}
5361 %
5362 % The sortify function converts to lower case after |purify$|ing; it's
5363 % used in sorting and in computing alphabetic labels after sorting
5364 %
5365 % The chop.word(w,len,s) function returns either s or, if the first len
5366 % letters of s equals w (this comparison is done in the third line of the
5367 % function's definition), it returns that part of s after w.
5368 % \begin{macrocode}
5369 FUNCTION {sortify}
5370 { purify$
5371 "l" change.case$
5372 }
5373
5374 % \end{macrocode}
5375 %
5376 % We need the chop.word stuff for the dubious unsorted-list-with-labels case.
5377 % \begin{macrocode}
5378 FUNCTION {chop.word}
5379 { 's :=
5380 'len :=
5381 s #1 len substring$ =
5382 { s len #1 + global.max$ substring$ }
5383 's
5384 if$
5385 }
5386
5387 % \end{macrocode}
5388 %
5389 % The |format.lab.names| function makes a short label by using the initials of
5390 % the von and Last parts of the names (but if there are more than four names,
5391 % (i.e., people) it truncates after three and adds a superscripted "+";
5392 % it also adds such a "+" if the last of multiple authors is "others").
5393 % If there is only one name, and its von and Last parts combined have just
5394 % a single name-token ("Knuth" has a single token, "Brinch Hansen" has two),
5395 % we take the first three letters of the last name. The boolean
5396 % et.al.char.used tells whether we've used a superscripted "+", so that we
5397 % know whether to include a LaTeX macro for it.
5398 %
5399 % \begin{pseudocode}
5400 % format.lab.names(s) ==
5401 % BEGIN
5402 % numnames := num.names$(s)
5403 % if numnames > 1 then
5404 % if numnames > 4 then
5405 % namesleft := 3
5406 % else
5407 % namesleft := numnames
5408 % nameptr := 1
5409 % nameresult := ""
5410 % while namesleft > 0
5411 % do
5412 % if (name_ptr = numnames) and
5413 % format.name$(s, nameptr, "{ff }{vv }{ll}{ jj}") = "others"
5414 % then nameresult := nameresult * "{\etalchar{+}}"
5415 % et.al.char.used := true
5416 % else nameresult := nameresult *
5417 % format.name$(s, nameptr, "{v{}}{l{}}")
5418 % nameptr := nameptr + 1
5419 % namesleft := namesleft - 1
5420 % od
5421 % if numnames > 4 then
5422 % nameresult := nameresult * "{\etalchar{+}}"
5423 % et.al.char.used := true
5424 % else
5425 % t := format.name$(s, 1, "{v{}}{l{}}")
5426 % if text.length$(t) < 2 then % there's just one name-token
5427 % nameresult := text.prefix$(format.name$(s,1,"{ll}"),3)
5428 % else
5429 % nameresult := t
5430 % fi
5431 % fi
5432 % return nameresult
5433 % END
5434 % \end{pseudocode}
5435 %
5436 % Exactly what fields we look at in constructing the primary part of the label
5437 % depends on the entry type; this selectivity (as opposed to, say, always
5438 % looking at author, then editor, then key) helps ensure that "ignored" fields,
5439 % as described in the LaTeX book, really are ignored. Note that MISC is part
5440 % of the deepest `else' clause in the nested part of calc.label; thus, any
5441 % unrecognized entry type in the database is handled correctly.
5442 %
5443 % There is one auxiliary function for each of the four different sequences of
5444 % fields we use. The first of these functions looks at the author field, and
5445 % then, if necessary, the key field. The other three functions, which might
5446 % look at two fields and the key field, are similar, except that the key field
5447 % takes precedence over the organization field (for labels---not for sorting).
5448 %
5449 % The calc.label function calculates the preliminary label of an entry, which
5450 % is formed by taking three letters of information from the author or editor or
5451 % key or organization field (depending on the entry type and on what's empty,
5452 % but ignoring a leading "The " in the organization), and appending the last
5453 % two characters (digits) of the year. It is an error if the appropriate fields
5454 % among author, editor, organization, and key are missing, and we use
5455 % the first three letters of the |cite$| in desperation when this happens.
5456 % The resulting label has the year part, but not the name part, |purify$|ed
5457 % (|purify$|ing the year allows some sorting shenanigans by the user).
5458 %
5459 % This function also calculates the version of the label to be used in sorting.
5460 %
5461 % The final label may need a trailing 'a', 'b', etc., to distinguish it from
5462 % otherwise identical labels, but we can't calculated those "extra.label"s
5463 % until after sorting.
5464 %
5465 % \begin{pseudocode}
5466 % calc.label ==
5467 % BEGIN
5468 % if type$ = "book" or "inbook" then
5469 % author.editor.key.label
5470 % else if type$ = "proceedings" then
5471 % editor.key.organization.label
5472 % else if type$ = "manual" then
5473 % author.key.organization.label
5474 % else
5475 % author.key.label
5476 % fi fi fi
5477 % label := label * substring$(purify$(field.or.null(year)), -1, 2)
5478 % % assuming we will also sort, we calculate a sort.label
5479 % sort.label := sortify(label), but use the last four, not two, digits
5480 % END
5481 % \end{pseudocode}
5482 % \begin{macrocode}
5483 FUNCTION {format.lab.names}
5484 { 's :=
5485 #1 'nameptr :=
5486 s num.names$ 'numnames :=
5487 numnames 'namesleft :=
5488 { namesleft #0 > }
5489 { format.lab.name 't :=
5490 nameptr #1 >
5491 { numnames control.max.cite.names >
5492 nameptr control.min.cite.names > and
5493 { "others" 't :=
5494 #1 'namesleft :=
5495 }
5496 'skip$
5497 if$
5498 namesleft #1 >
5499 { add.comma t * }
5500 { t "others" =
5501 { nameptr #2 >
5502 { add.comma }
5503 { space.precedes.et.al * }
5504 if$
5505 cite.et.al *
5506 }
5507 { control.cite.final.and
5508 { is.lang.cjk not nameptr #2 > and
5509 { add.comma }
5510 { inter.word.space * }
5511 if$
5512 cite.and * inter.word.space *
5513 }
5514 { add.comma }
5515 if$
5516 t *
5517 }
5518 if$
5519 }
5520 if$
5521 }
5522 't
5523 if$
5524 nameptr #1 + 'nameptr :=
5525 namesleft #1 - 'namesleft :=
5526 }
5527 while$
5528 format.punctuations
5529 }
5530
5531 FUNCTION {author.key.label}
5532 { author empty$
5533 { bbl.anonymous }
5534 { author format.lab.names }
5535 if$
5536 }
5537
5538 FUNCTION {author.editor.key.label}
5539 { author empty$
5540 { editor empty$
5541 { bbl.anonymous }
5542 { editor format.lab.names }
5543 if$
5544 }
5545 { author format.lab.names }
5546 if$
5547 }
5548
5549 FUNCTION {author.key.organization.label}
5550 { author empty$
5551 { organization empty$
5552 { bbl.anonymous }
5553 { "The " #4 organization chop.word #3 text.prefix$ }
5554 if$
5555 }
5556 { author format.lab.names }
5557 if$
5558 }
5559
5560 FUNCTION {editor.key.organization.label}
5561 { editor empty$
5562 { organization empty$
5563 { bbl.anonymous }
5564 { "The " #4 organization chop.word #3 text.prefix$ }
5565 if$
5566 }
5567 { editor format.lab.names }
5568 if$
5569 }
5570
5571 FUNCTION {holder.author.label}
5572 { holder empty$
5573 { author empty$
5574 { bbl.anonymous }
5575 { author format.lab.names }
5576 if$
5577 }
5578 { holder format.lab.names }
5579 if$
5580 }
5581
5582 FUNCTION {calc.short.authors}
5583 { type$ "book" =
5584 type$ "inbook" = booktitle empty$ not and
5585 or
5586 'author.editor.key.label
5587 { type$ "collection" =
5588 type$ "proceedings" =
5589 or
5590 type$ "periodical" =
5591 or
5592 { editor empty$ not
5593 'editor.key.organization.label
5594 'author.key.organization.label
5595 if$
5596 }
5597 { type$ "patent" =
5598 'holder.author.label
5599 'author.key.label
5600 if$
5601 }
5602 if$
5603 }
5604 if$
5605 'short.list :=
5606 }
5607
5608 % \end{macrocode}
5609 %
5610 % 如果 label 中有中括号“[”,分别用大括号保护起来,防止 \cs{bibitem} 处理出错。
5611 % 另外为了兼容 \pkg{bibunits},“name(year)fullname” 的每一项都要分别保护起来,
5612 % 参考 \href{https://github.com/tuna/thuthesis/issues/630}{tuna/thuthesis/\#630}。
5613 % \begin{macrocode}
5614 FUNCTION {calc.label}
5615 { calc.short.authors
5616 short.list
5617 duplicate$ "]" contains
5618 { "{" swap$ * "}" * }
5619 'skip$
5620 if$
5621 "("
5622 *
5623 format.lab.date
5624 duplicate$ "]" contains
5625 { "{" swap$ * "}" * }
5626 'skip$
5627 if$
5628 *
5629 'label :=
5630 }
5631
5632 % \end{macrocode}
5633 %
5634 %
5635 % \subsection{Sorting}
5636 %
5637 % When sorting, we compute the sortkey by executing "presort" on each entry.
5638 % The presort key contains a number of "sortify"ed strings, concatenated
5639 % with multiple blanks between them. This makes things like "brinch per"
5640 % come before "brinch hansen per".
5641 %
5642 % The fields used here are: the sort.label for alphabetic labels (as set by
5643 % |calc.label|), followed by the author names (or editor names or organization
5644 % (with a leading "The " removed) or key field, depending on entry type and on
5645 % what's empty), followed by year, followed by the first bit of the title
5646 % (chopping off a leading "The ", "A ", or "An ").
5647 % Names are formatted: Von Last First Junior.
5648 % The names within a part will be separated by a single blank
5649 % (such as "brinch hansen"), two will separate the name parts themselves
5650 % (except the von and last), three will separate the names,
5651 % four will separate the names from year (and from label, if alphabetic),
5652 % and four will separate year from title.
5653 %
5654 % The |sort.format.names| function takes an argument that should be in
5655 % BibTeX name format, and returns a string containing " "-separated
5656 % names in the format described above. The function is almost the same
5657 % as format.names.
5658 % \begin{macrocode}
5659 %<*authoryear>
5660 FUNCTION {sort.language.label}
5661 { entry.lang lang.zh =
5662 { lang.zh.order }
5663 { entry.lang lang.ja =
5664 { lang.ja.order }
5665 { entry.lang lang.en =
5666 { lang.en.order }
5667 { entry.lang lang.ru =
5668 { lang.ru.order }
5669 { lang.other.order }
5670 if$
5671 }
5672 if$
5673 }
5674 if$
5675 }
5676 if$
5677 #64 +
5678 int.to.chr$
5679 }
5680
5681 FUNCTION {sort.format.names}
5682 { 's :=
5683 #1 'nameptr :=
5684 ""
5685 s num.names$ 'numnames :=
5686 numnames 'namesleft :=
5687 { namesleft #0 > }
5688 { s nameptr "{vv{ } }{ll{ }}{ ff{ }}{ jj{ }}" format.name$ 't :=
5689 nameptr #1 >
5690 { " " *
5691 namesleft #1 = t "others" = and
5692 { "zzzzz" * }
5693 { numnames #2 > nameptr #2 = and
5694 { "zz" * year field.or.null * " " * }
5695 'skip$
5696 if$
5697 t sortify *
5698 }
5699 if$
5700 }
5701 { t sortify * }
5702 if$
5703 nameptr #1 + 'nameptr :=
5704 namesleft #1 - 'namesleft :=
5705 }
5706 while$
5707 }
5708
5709 % \end{macrocode}
5710 %
5711 % The sort.format.title function returns the argument,
5712 % but first any leading "A "'s, "An "'s, or "The "'s are removed.
5713 % The chop.word function uses s, so we need another string variable, t
5714 % \begin{macrocode}
5715 FUNCTION {sort.format.title}
5716 { 't :=
5717 "A " #2
5718 "An " #3
5719 "The " #4 t chop.word
5720 chop.word
5721 chop.word
5722 sortify
5723 #1 global.max$ substring$
5724 }
5725
5726 % \end{macrocode}
5727 %
5728 % The auxiliary functions here, for the presort function, are analogous to
5729 % the ones for calc.label; the same comments apply, except that the
5730 % organization field takes precedence here over the key field. For sorting
5731 % purposes, we still remove a leading "The " from the organization field.
5732 % \begin{macrocode}
5733 FUNCTION {anonymous.sort}
5734 { entry.lang lang.zh =
5735 { "yi4 ming2" }
5736 { "anon" }
5737 if$
5738 }
5739
5740 FUNCTION {warn.empty.key}
5741 { is.lang.cjk
5742 { "key" warn.empty.field }
5743 'skip$
5744 if$
5745 }
5746
5747 FUNCTION {author.sort}
5748 { key empty$
5749 { warn.empty.key
5750 author empty$
5751 { anonymous.sort }
5752 { author sort.format.names }
5753 if$
5754 }
5755 { key }
5756 if$
5757 }
5758
5759 FUNCTION {author.editor.sort}
5760 { key empty$
5761 { warn.empty.key
5762 author empty$
5763 { editor empty$
5764 { anonymous.sort }
5765 { editor sort.format.names }
5766 if$
5767 }
5768 { author sort.format.names }
5769 if$
5770 }
5771 { key }
5772 if$
5773 }
5774
5775 FUNCTION {author.organization.sort}
5776 { key empty$
5777 { warn.empty.key
5778 author empty$
5779 { organization empty$
5780 { anonymous.sort }
5781 { "The " #4 organization chop.word sortify }
5782 if$
5783 }
5784 { author sort.format.names }
5785 if$
5786 }
5787 { key }
5788 if$
5789 }
5790
5791 FUNCTION {editor.organization.sort}
5792 { key empty$
5793 { warn.empty.key
5794 editor empty$
5795 { organization empty$
5796 { anonymous.sort }
5797 { "The " #4 organization chop.word sortify }
5798 if$
5799 }
5800 { editor sort.format.names }
5801 if$
5802 }
5803 { key }
5804 if$
5805 }
5806
5807 %</authoryear>
5808 % \end{macrocode}
5809 %
5810 % 顺序编码制的排序要简单得多
5811 % \begin{macrocode}
5812 %<*numeric>
5813 INTEGERS { seq.num }
5814
5815 FUNCTION {init.seq}
5816 { #0 'seq.num :=}
5817
5818 FUNCTION {int.to.fix}
5819 { "000000000" swap$ int.to.str$ *
5820 #-1 #10 substring$
5821 }
5822
5823 %</numeric>
5824 % \end{macrocode}
5825 %
5826 % There is a limit, |entry.max$|, on the length of an entry string variable
5827 % (which is what its |sort.key$| is), so we take at most that many characters
5828 % of the constructed key, and hope there aren't many references that match
5829 % to that many characters!
5830 % \begin{macrocode}
5831 FUNCTION {presort}
5832 { type$ "gbt7714bstctl" =
5833 {
5834 %<*authoryear>
5835 "_"
5836 " "
5837 %</authoryear>
5838 %<*numeric>
5839 "_ "
5840 seq.num int.to.fix
5841 %</numeric>
5842 }
5843 { set.entry.lang
5844 set.entry.numbered
5845 "" 'entry.url :=
5846 #0 'require.url :=
5847 check.electronic
5848 calc.label
5849 label sortify
5850 " "
5851 *
5852 %<*authoryear>
5853 sort.language.label
5854 " "
5855 *
5856 type$ "book" =
5857 type$ "inbook" = booktitle empty$ not and
5858 or
5859 'author.editor.sort
5860 { type$ "collection" =
5861 type$ "proceedings" =
5862 or
5863 'editor.organization.sort
5864 'author.sort
5865 if$
5866 }
5867 if$
5868 *
5869 " "
5870 *
5871 year field.or.null sortify
5872 *
5873 " "
5874 *
5875 cite$
5876 *
5877 #1 entry.max$ substring$
5878 %</authoryear>
5879 %<*numeric>
5880 seq.num #1 + 'seq.num :=
5881 seq.num int.to.fix
5882 %</numeric>
5883 }
5884 if$
5885 'sort.label :=
5886 sort.label *
5887 #1 entry.max$ substring$
5888 'sort.key$ :=
5889 }
5890
5891 % \end{macrocode}
5892 %
5893 % Now comes the final computation for alphabetic labels, putting in the 'a's
5894 % and 'b's and so forth if required. This involves two passes: a forward
5895 % pass to put in the 'b's, 'c's and so on, and a backwards pass
5896 % to put in the 'a's (we don't want to put in 'a's unless we know there
5897 % are 'b's).
5898 % We have to keep track of the longest (in |width$| terms) label, for use
5899 % by the "thebibliography" environment.
5900 %
5901 % \begin{pseudocode}
5902 % VAR: longest.label, last.sort.label, next.extra: string
5903 % longest.label.width, last.extra.num: integer
5904 %
5905 % initialize.longest.label ==
5906 % BEGIN
5907 % longest.label := ""
5908 % last.sort.label := int.to.chr$(0)
5909 % next.extra := ""
5910 % longest.label.width := 0
5911 % last.extra.num := 0
5912 % END
5913 %
5914 % forward.pass ==
5915 % BEGIN
5916 % if last.sort.label = sort.label then
5917 % last.extra.num := last.extra.num + 1
5918 % extra.label := int.to.chr$(last.extra.num)
5919 % else
5920 % last.extra.num := chr.to.int$("a")
5921 % extra.label := ""
5922 % last.sort.label := sort.label
5923 % fi
5924 % END
5925 %
5926 % reverse.pass ==
5927 % BEGIN
5928 % if next.extra = "b" then
5929 % extra.label := "a"
5930 % fi
5931 % label := label * extra.label
5932 % if width$(label) > longest.label.width then
5933 % longest.label := label
5934 % longest.label.width := width$(label)
5935 % fi
5936 % next.extra := extra.label
5937 % END
5938 % \end{pseudocode}
5939 % \begin{macrocode}
5940 STRINGS { longest.label last.label next.extra last.extra.label }
5941
5942 INTEGERS { longest.label.width number.label }
5943
5944 FUNCTION {initialize.longest.label}
5945 { "" 'longest.label :=
5946 #0 int.to.chr$ 'last.label :=
5947 "" 'next.extra :=
5948 #0 'longest.label.width :=
5949 #0 'number.label :=
5950 "" 'last.extra.label :=
5951 }
5952
5953 FUNCTION {forward.pass}
5954 { type$ "gbt7714bstctl" =
5955 'skip$
5956 {
5957 %<*authoryear>
5958 last.label label =
5959 { "" 'extra.label :=
5960 last.extra.label text.length$ 'charptr :=
5961 { last.extra.label charptr #1 substring$ "z" =
5962 charptr #0 > and
5963 }
5964 { "a" extra.label * 'extra.label :=
5965 charptr #1 - 'charptr :=
5966 }
5967 while$
5968 charptr #0 >
5969 { last.extra.label charptr #1 substring$ chr.to.int$ #1 + int.to.chr$
5970 extra.label * 'extra.label :=
5971 last.extra.label #1 charptr #1 - substring$
5972 extra.label * 'extra.label :=
5973 }
5974 { "a" extra.label * 'extra.label := }
5975 if$
5976 extra.label 'last.extra.label :=
5977 }
5978 { "a" 'last.extra.label :=
5979 "" 'extra.label :=
5980 label 'last.label :=
5981 }
5982 if$
5983 %</authoryear>
5984 number.label #1 + 'number.label :=
5985 }
5986 if$
5987 }
5988
5989 FUNCTION {reverse.pass}
5990 { type$ "gbt7714bstctl" =
5991 'skip$
5992 {
5993 %<*authoryear>
5994 next.extra "b" =
5995 { "a" 'extra.label := }
5996 'skip$
5997 if$
5998 extra.label 'next.extra :=
5999 extra.label
6000 duplicate$ empty$
6001 'skip$
6002 { "{\natexlab{" swap$ * "}}" * }
6003 if$
6004 'extra.label :=
6005 %</authoryear>
6006 label extra.label * 'label :=
6007 }
6008 if$
6009 }
6010
6011 FUNCTION {bib.sort.order}
6012 { sort.label 'sort.key$ := }
6013
6014 % \end{macrocode}
6015 %
6016 %
6017 % \subsection{Write bbl file}
6018 %
6019 % Now we're ready to start writing the .BBL file.
6020 % We begin, if necessary, with a \LaTeX{} macro for unnamed names in an
6021 % alphabetic label; next comes stuff from the `preamble' command in the
6022 % database files. Then we give an incantation containing the command
6023 % |\begin{thebibliography}{...}|
6024 % where the `...' is the longest label.
6025 %
6026 % We also call init.state.consts, for use by the output routines.
6027 % \begin{macrocode}
6028 FUNCTION {begin.bib}
6029 { preamble$ empty$
6030 'skip$
6031 { preamble$ write$ newline$ }
6032 if$
6033 "\begin{thebibliography}{" number.label int.to.str$ * "}" *
6034 write$ newline$
6035 control.cite.lang "macro" =
6036 { "\providecommand{\biband}{和}"
6037 write$ newline$
6038 "\providecommand{\bibetal}{等}"
6039 write$ newline$
6040 }
6041 'skip$
6042 if$
6043 "\providecommand{\natexlab}[1]{#1}"
6044 write$ newline$
6045 "\providecommand{\url}[1]{#1}"
6046 write$ newline$
6047 "\expandafter\ifx\csname urlstyle\endcsname\relax\else"
6048 write$ newline$
6049 " \urlstyle{same}\fi"
6050 write$ newline$
6051 control.doi control.eprint or
6052 { "\expandafter\ifx\csname href\endcsname\relax"
6053 write$ newline$
6054 control.doi
6055 { " \def\doi{\begingroup \urlstyle{same}\Url}"
6056 write$ newline$
6057 control.cstr
6058 { " \def\cstr{\begingroup \urlstyle{same}\Url}"
6059 write$ newline$
6060 }
6061 'skip$
6062 if$
6063 }
6064 'skip$
6065 if$
6066 control.eprint
6067 { " \def\eprint#1#2{#2}"
6068 write$ newline$
6069 }
6070 'skip$
6071 if$
6072 "\else"
6073 write$ newline$
6074 control.doi
6075 { " \def\doi#1{\href{https://doi.org/#1}{\nolinkurl{#1}}}"
6076 write$ newline$
6077 control.cstr
6078 { " \def\cstr#1{\href{https://cstr.cn/#1}{\nolinkurl{#1}}}"
6079 write$ newline$
6080 }
6081 'skip$
6082 if$
6083 }
6084 'skip$
6085 if$
6086 control.eprint
6087 { " \let\eprint\href"
6088 write$ newline$
6089 }
6090 'skip$
6091 if$
6092 "\fi"
6093 write$ newline$
6094 }
6095 'skip$
6096 if$
6097 }
6098
6099 % \end{macrocode}
6100 %
6101 % Finally, we finish up by writing the `|\end{thebibliography}|' command.
6102 % \begin{macrocode}
6103 FUNCTION {end.bib}
6104 { newline$
6105 "\end{thebibliography}" write$ newline$
6106 }
6107
6108 % \end{macrocode}
6109 %
6110 %
6111 % \subsection{Main execution}
6112 %
6113 % Now we read in the .BIB entries.
6114 % \begin{macrocode}
6115 READ
6116
6117 EXECUTE {init.state.consts}
6118
6119 EXECUTE {load.config}
6120
6121 ITERATE {control.pass}
6122
6123 EXECUTE {control.check}
6124
6125 %<*numeric>
6126 EXECUTE {init.seq}
6127
6128 %</numeric>
6129 ITERATE {presort}
6130
6131 % \end{macrocode}
6132 %
6133 % And now we can sort
6134 % \begin{macrocode}
6135 SORT
6136
6137 EXECUTE {initialize.longest.label}
6138
6139 ITERATE {forward.pass}
6140
6141 REVERSE {reverse.pass}
6142
6143 ITERATE {bib.sort.order}
6144
6145 SORT
6146
6147 EXECUTE {begin.bib}
6148
6149 % \end{macrocode}
6150 %
6151 % Now we produce the output for all the entries
6152 % \begin{macrocode}
6153 ITERATE {call.type$}
6154
6155 EXECUTE {end.bib}
6156 % \end{macrocode}