summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/biblatex-contrib/biblatex-gb7714-2015/gb7714-2015mx.cbx
blob: 7eacc808ddff5c29a386b95668e36165203211b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
%%
%% ---------------------------------------------------------------
%% biblatex-gb7714-2015 --- A biblatex implementation of the
%% GBT7714-2015 citation style,numerical sequence
%% Maintained by huzhenzhen
%% E-mail: hzzmail@163.com
%% Released under the LaTeX Project Public License v1.3c or later
%% ---------------------------------------------------------------
%%
\ProvidesFile{gb7714-2015.cbx}[a biblatex citation style for GB/T 7714-2015]

%
%   加载标准样式
%
\RequireCitationStyle{numeric-comp} %numeric


%
%   选项设置
%
\ExecuteBibliographyOptions{
  %autocite  = superscript ,
  %autopunct = true       ,
  %sorting   = none        ,
  maxcitenames=1,
  mincitenames=1,
  uniquename=init,%因为使用了名字缩写选项,所以需要设置uniquename=init而不是full避免冲突
  uniquelist=minyear,
  labeldateparts,
  sortcites,
}

%修改\mkbibsuperscript宏在最后加上一个空白使得xeCJK不会自动在引用标签后面加上中英文之间的空白
%hzz,v1.0w,2021-0401
\renewrobustcmd{\mkbibsuperscript}[1]{%
  \unspace\allowhyphens\textsuperscript{%
    \begingroup
    \protected\long\def\mkbibsuperscript##1{%
      \blx@warning{Nested superscript}%
      \mkbibbrackets{##1}}%
    #1\endgroup}\kern\z@}

%
%   定义一个上标方括号wrapper
%
\newcommand*\mkbibsuperbracket[1]{%
  \mkbibsuperscript{\mkbibbrackets{#1}}%
}

%   修改postnote的输出格式
\DeclareFieldFormat{postnote}{#1}

%
%   重定义cite命令
%
%   方法:\DeclareCiteCommand{\cite}[\mkbibparens]{precode}{loopcode}{sepcode}{postcode}
%    v1.0p版后将cite的处理方式修改为类似pagescite,而不再使用biblatex的标准方式
\DeclareCiteCommand{\cite}[\mkbibsuperscript]%利用mkbibsuperbracket添加方括号
  {[\usebibmacro{cite:init}%
   \usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \usebibmacro{cite:comp}}
  {}
  {\usebibmacro{cite:dump}]%
   \printfield{postnote}}
%   v1.0p 以前用的方式
%\DeclareCiteCommand{\cite}[\mkbibsuperbracket]%利用mkbibsuperbracket添加方括号
%  {\usebibmacro{cite:init}%
%   \usebibmacro{prenote}}
%  {\usebibmacro{citeindex}%
%   \usebibmacro{cite:comp}}
%  {}
%  {\usebibmacro{cite:dump}%
%   \usebibmacro{postnote}}

%
%   定义upcite命令
%   20180604,v1.0l,hzz
%   20190409,v1.0r,hzz
%   方法:对supercite增加[]
\newrobustcmd*{\upcite}{%
    \cite}

%
%   重定义parencite命令,以满足标签带页码的国标要求
%
\DeclareCiteCommand{\parencite}%[\mkbibbrackets]
  {[\usebibmacro{cite:init}%]
   \usebibmacro{prenote}}%
  {\usebibmacro{citeindex}%
   \usebibmacro{cite:comp}}
  {}
  {%[
  \usebibmacro{cite:dump}]%
   \mkbibsuperscript{\printfield{postnote}}}

%
%   新定义pagescite命令,以满足标签带页码的国标要求
%
%   原理方法:
%   1.新增页码输出宏
\newbibmacro*{postpages}{%
  \iffieldundef{postnote}
    {\printfield[postnote]{pages}}
    {\printfield{postnote}}}
%   2.新增\pagescite引用命令
\DeclareCiteCommand{\pagescite}[\mkbibsuperscript]%\mkbibbrackets,仍然用上标
  {[\usebibmacro{cite:init}%]直接添加方括号
   \usebibmacro{prenote}%
   }
  {\usebibmacro{citeindex}%
   \usebibmacro{cite:comp}}
  {}
  {\usebibmacro{cite:dump}]%
   \usebibmacro{postpages}}

%
%   定义yearpagescite,为与ay样式兼容,等同于\pagescite
%
\DeclareCiteCommand{\yearpagescite}[\mkbibsuperscript]%\mkbibbrackets,仍然用上标
  {[\usebibmacro{cite:init}%]直接添加方括号
   \usebibmacro{prenote}%
   }
  {\usebibmacro{citeindex}%
   \usebibmacro{cite:comp}}
  {}
  {\usebibmacro{cite:dump}]%
   \usebibmacro{postpages}}

%
%   定义\yearcite命令,为与ay样式兼容,且提供不输出页码的标签格式,
%
%   原理方法:等同于\pagescite,但不要页码
\DeclareCiteCommand{\yearcite}[\mkbibsuperscript]%\mkbibbrackets,仍然用上标
  {[\usebibmacro{cite:init}%]直接添加方括号
   \usebibmacro{prenote}%
   }
  {\usebibmacro{citeindex}%
   \usebibmacro{cite:comp}}
  {}
  {\usebibmacro{cite:dump}]}

%
%   定义\authornumcite命令,输出作者信息,然后在后面带上顺序编码
%   20180427,v1.0k,增加,hzz
%   gb7714样式新定义的命令都把cite放到最后,比如前面的pagescite,yearcite,这里的\authornumcite
%   区别于biblatex定义的命令都把cite放到前面,比如citeauthor等。
%见numeric.CBX
\newbibmacro*{cite}{%
  \printtext[bibhyperref]{%
    \printfield{labelprefix}%
    \printfield{labelnumber}%
    \ifbool{bbx:subentry}
      {\printfield{entrysetcount}}
      {}}}
%见numeric.CBX,\DeclareCiteCommand{\cite},
\DeclareCiteCommand{\authornumcite}%[\mkbibsuperscript]
  {\usebibmacro{prenote}}
  {\iffieldequalstr{userf}{cn}{\renewcommand*{\andothersdelim}{\addthinspace}}%\addthinspace
  {\renewcommand*{\andothersdelim}{\addspace}}%
  \printnames{labelname}\mkbibsuperscript{\mkbibbrackets{\usebibmacro{citeindex}%
   \usebibmacro{cite}}}}
  {\multicitedelim}
  {\mkbibsuperscript{\printfield{postnote}}}


%
%   增加如下多个命令
%   20190409,v1.0r,hzz
%   方法:利用newcommand或newrobustcmd命令进行定义
%   注意\citet和\citep命令之所以不用newrobustcmd,是为避免加载natbib模块后产生冲突
\DeclareCiteCommand{\citet}%
  {\usebibmacro{prenote}}
  {\iffieldequalstr{userf}{cn}{\renewcommand*{\andothersdelim}{\addthinspace}}%\addthinspace
  {\renewcommand*{\andothersdelim}{\addspace}}%
  \printnames{labelname}\mkbibsuperscript{\mkbibbrackets{\usebibmacro{citeindex}%
   \usebibmacro{cite}}}}
  {\multicitedelim}
  {\mkbibsuperscript{\printfield{postnote}}}


\DeclareCiteCommand{\citep}[\mkbibsuperscript]%利用mkbibsuperbracket添加方括号
  {[\usebibmacro{cite:init}%
   \usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \usebibmacro{cite:comp}}
  {}
  {\usebibmacro{cite:dump}]%
   \printfield{postnote}}

\newrobustcmd*{\citetns}%
    {\textcite}

\newrobustcmd*{\citepns}%
    {\parencite}

\newrobustcmd*{\inlinecite}%
    {\parencite}


%textcite标注命令中的标点设置
%\DeclareDelimFormat[textcite]{andothersdelim}{\addspace}%

%textcite标注命令中的标点设置,注意只针对textcite命令。
\DeclareDelimFormat[textcite]{nameyeardelim}{}%\addcomma\space
\DeclareDelimFormat[textcite]{andothersdelim}{\iffieldequalstr{userf}{chinese}{\addthinspace}{\addspace}}%
\AtEveryCitekey{%
\iffieldequalstr{userf}{chinese}{\renewcommand*{\andothersdelim}{\addthinspace}}%\addthinspace
  {\renewcommand*{\andothersdelim}{\addspace}}%
}

%
%
%
\apptocmd{\refsection}{

%\edef\gb@refsecnum{\number\c@refsection}
\edef\gb@refsecnum{\number\c@refsection}%
\ifcsundef{gb@aystyle@section\gb@refsecnum}%
{}%
{

\renewcommand*{\iffinalcitedelim}{%
  \ifnumequal{\value{textcitecount}}{\value{textcitetotal}-1}}

\newbibmacro*{cite:init}{%
  \ifnumless{\value{multicitecount}}{2}
    {\global\boolfalse{cbx:parens}%
     \global\undef\cbx@lasthash
     \global\undef\cbx@lastyear}
    {\iffieldundef{prenote}
       {}
       {\global\undef\cbx@lasthash
        \global\undef\cbx@lastyear}}}

\newbibmacro*{cite:reinit}{%
  \global\undef\cbx@lasthash
  \global\undef\cbx@lastyear}

\newbibmacro*{cite}{%
  \iffieldundef{shorthand}
    {\ifthenelse{\ifnameundef{labelname}\OR\iffieldundef{labelyear}}
       {\usebibmacro{cite:label}%
        \setunit{\printdelim{nonameyeardelim}}%
        \usebibmacro{cite:labeldate+extradate}%
        \usebibmacro{cite:reinit}}
       {\iffieldequals{namehash}{\cbx@lasthash}
          {\ifthenelse{\iffieldequals{labelyear}{\cbx@lastyear}\AND
                       \(\value{multicitecount}=0\OR\iffieldundef{postnote}\)}
             {\setunit{\addcomma}%
              \usebibmacro{cite:extradate}}
             {\setunit{\compcitedelim}%
              \usebibmacro{cite:labeldate+extradate}%
              \savefield{labelyear}{\cbx@lastyear}}}
          {\printnames{labelname}%
           \setunit{\printdelim{nameyeardelim}}%
           \usebibmacro{cite:labeldate+extradate}%
           \savefield{namehash}{\cbx@lasthash}%
           \savefield{labelyear}{\cbx@lastyear}}}}
    {\usebibmacro{cite:shorthand}%
     \usebibmacro{cite:reinit}}%
  \setunit{\multicitedelim}}

\newbibmacro*{citeyear}{%
  \iffieldundef{shorthand}
    {\iffieldundef{labelyear}
       {\usebibmacro{cite:label}%
        \usebibmacro{cite:reinit}}
       {\iffieldequals{namehash}{\cbx@lasthash}
          {\ifthenelse{\iffieldequals{labelyear}{\cbx@lastyear}\AND
                       \(\value{multicitecount}=0\OR\iffieldundef{postnote}\)}
             {\setunit{\addcomma}%
              \usebibmacro{cite:extradate}}
             {\setunit{\compcitedelim}%
              \usebibmacro{cite:labeldate+extradate}%
              \savefield{labelyear}{\cbx@lastyear}}}
          {\usebibmacro{cite:labeldate+extradate}%
           \savefield{namehash}{\cbx@lasthash}%
           \savefield{labelyear}{\cbx@lastyear}}}}
    {\usebibmacro{cite:shorthand}%
     \usebibmacro{cite:reinit}}%
  \setunit{\multicitedelim}}

\newbibmacro*{textcite}{%
  \iffieldequals{namehash}{\cbx@lasthash}
    {\iffieldundef{shorthand}
       {\ifthenelse{\iffieldequals{labelyear}{\cbx@lastyear}\AND
                    \(\value{multicitecount}=0\OR\iffieldundef{postnote}\)}
          {\setunit{\addcomma}%
           \usebibmacro{cite:extradate}}
          {\setunit{\compcitedelim}%
           \usebibmacro{cite:labeldate+extradate}%
           \savefield{labelyear}{\cbx@lastyear}}}
       {\setunit{\compcitedelim}%
        \usebibmacro{cite:shorthand}%
        \global\undef\cbx@lastyear}}
    {\ifnameundef{labelname}
       {\iffieldundef{shorthand}
          {\usebibmacro{cite:label}%
           \setunit{%
             \global\booltrue{cbx:parens}%
             \printdelim{nonameyeardelim}\bibopenparen}%
           \ifnumequal{\value{citecount}}{1}
             {\usebibmacro{prenote}}
             {}%
           \usebibmacro{cite:labeldate+extradate}}
          {\usebibmacro{cite:shorthand}}}
       {\printnames{labelname}%
        \setunit{%
          \global\booltrue{cbx:parens}%
          \printdelim{nameyeardelim}\bibopenparen}%
        \ifnumequal{\value{citecount}}{1}
          {\usebibmacro{prenote}}
          {}%
        \iffieldundef{shorthand}
          {\iffieldundef{labelyear}
             {\usebibmacro{cite:label}}
             {\usebibmacro{cite:labeldate+extradate}}%
           \savefield{labelyear}{\cbx@lastyear}}
          {\usebibmacro{cite:shorthand}%
           \global\undef\cbx@lastyear}}%
     \stepcounter{textcitecount}%
     \savefield{namehash}{\cbx@lasthash}}%
  \setunit{%
    \ifbool{cbx:parens}
      {\bibcloseparen\global\boolfalse{cbx:parens}}
      {}%
    \textcitedelim}}

\newbibmacro*{cite:shorthand}{%
  \printtext[bibhyperref]{\printfield{shorthand}}}

%
%   重定义cite:label,针对biblatex3.8以上版本set条目集的标注(引用)标签
%
%   原理方法:当条目是set时,v3.8以上版本,都没有有用的信息(区别于3.7以下版本set复制第一个成员的信息),
%   于是利用entrykey来给出标签,那么就要set的条目关键字是需要的字符串,注意字符串中间不能有空格
\renewbibmacro*{cite:label}{%
  \iffieldundef{label}%
    {\iffieldundef{labeltitle}{\printtext[bibhyperref]{\printfield{entrykey}}}%entrykey
    {\printtext[bibhyperref]{\printfield[citetitle]{labeltitle}}}}%
    {\printtext[bibhyperref]{\printfield{label}}}}

\newbibmacro*{cite:labeldate+extradate}{%
  \iffieldundef{labelyear}
    {}
    {\printtext[bibhyperref]{\printlabeldateextra}}}

\newbibmacro*{cite:extradate}{%
  \iffieldundef{extradate}
    {}
    {\printtext[bibhyperref]{\printfield{extradate}}}}



%
%   重定义cite:label,针对biblatex3.8以上版本set条目集的标注(引用)标签
%
%   原理方法:当条目是set时,v3.8以上版本,都没有有用的信息(区别于3.7以下版本set复制第一个成员的信息),
%   于是利用entrykey来给出标签,那么就要set的条目关键字是需要的字符串,注意字符串中间不能有空格
\renewbibmacro*{cite:label}{%
  \iffieldundef{label}%
    {\iffieldundef{labeltitle}{\printtext[bibhyperref]{\printfield{entrykey}}}%entrykey
    {\printtext[bibhyperref]{\printfield[citetitle]{labeltitle}}}}%
    {\printtext[bibhyperref]{\printfield{label}}}}

%
%   重定义cite命令
%
%   方法:\DeclareCiteCommand{\cite}[\mkbibparens]{precode}{loopcode}{sepcode}{postcode}
%    v1.0p版后将cite的处理方式修改为类似pagescite,而不再使用biblatex的标准方式
\DeclareCiteCommand{\cite}
  {\usebibmacro{cite:init}%
  \renewbibmacro*{postnote}{%
  \iffieldundef{postnote}%
    {}%
    {\thefield{postnote}}}%
    (\usebibmacro{prenote}}%)
  {\usebibmacro{citeindex}%
   \usebibmacro{cite}}
  {}
  {%(
  )\mkbibsuperscript{\usebibmacro{postnote}}%\usebibmacro{postnote}
  }

\DeclareCiteCommand{\parencite}[\mkbibparens]
  {\usebibmacro{cite:init}%
   \usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \usebibmacro{cite}}
  {}
  {\usebibmacro{postnote}}

%
%   定义\authornumcite命令,输出作者信息,然后在后面带上顺序编码
%   20180427,v1.0k,增加,hzz
%   20190409,v1.0r,hzz
%   为与顺序编码制兼容,增加了命令,定义与citet相同
\newbibmacro*{citet}{%
  \iffieldundef{shorthand}
    {\ifthenelse{\ifnameundef{labelname}\OR\iffieldundef{labelyear}}
       {\usebibmacro{cite:label}%
        \setunit{\printdelim{nonameyeardelim}}%
        \usebibmacro{cite:labeldate+extradate}%
        \usebibmacro{cite:reinit}}
       {\iffieldequals{namehash}{\cbx@lasthash}
          {\ifthenelse{\iffieldequals{labelyear}{\cbx@lastyear}\AND
                       \(\value{multicitecount}=0\OR\iffieldundef{postnote}\)}
             {\setunit{\addcomma}%
              \usebibmacro{cite:extradate}}
             {\setunit{\compcitedelim}%
              \usebibmacro{cite:labeldate+extradate}%
              \savefield{labelyear}{\cbx@lastyear}}}
          {\printnames{labelname}%
           %\setunit{\printdelim{nameyeardelim}}%
           (\usebibmacro{cite:labeldate+extradate})%
           \savefield{namehash}{\cbx@lasthash}%
           \savefield{labelyear}{\cbx@lastyear}}}}
    {\usebibmacro{cite:shorthand}%
     \usebibmacro{cite:reinit}}%
  \setunit{\multicitedelim}}

\DeclareCiteCommand{\authornumcite}%
  {\usebibmacro{cite:init}%
  \renewbibmacro*{postnote}{%
  \iffieldundef{postnote}%
    {}%
    {\thefield{postnote}}}%
    \usebibmacro{prenote}}%
  {\usebibmacro{citeindex}%
   \usebibmacro{citet}}
  {}
  {\mkbibsuperscript{\usebibmacro{postnote}}%\usebibmacro{postnote}
  }

%
%   增加如下多个命令
%   20190409,v1.0r,hzz
%   方法:利用newcommand或newrobustcmd命令进行定义
%   注意\citet和\citep命令之所以不用newrobustcmd,是为避免加载natbib模块后产生冲突

%同\authornumcite
\DeclareCiteCommand{\citet}%
  {\usebibmacro{cite:init}%
  \renewbibmacro*{postnote}{%
  \iffieldundef{postnote}%
    {}%
    {\thefield{postnote}}}%
    \usebibmacro{prenote}}%
  {\usebibmacro{citeindex}%
   \usebibmacro{citet}}
  {}
  {\mkbibsuperscript{\usebibmacro{postnote}}%\usebibmacro{postnote}
  }

%同cite
\DeclareCiteCommand{\citep}
  {\usebibmacro{cite:init}%
  \renewbibmacro*{postnote}{%
  \iffieldundef{postnote}%
    {}%
    {\thefield{postnote}}}%
    (\usebibmacro{prenote}}%)
  {\usebibmacro{citeindex}%
   \usebibmacro{cite}}
  {}
  {%(
  )\mkbibsuperscript{\usebibmacro{postnote}}%\usebibmacro{postnote}
  }


}
}{}{}