summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/biblatex/latex/blx-bibtex.def
blob: 956b4708c543f17f7c9e21b3ec949588574bb430 (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
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
\ProvidesFile{blx-bibtex.def}
[\abx@cptid]

\blx@warning@noline{%
  Using fall-back BibTeX(8) backend:\MessageBreak
  functionality may be reduced/unavailable%
}

% Initialisation of backend-related switches, variables, etc.
\newtoggle{blx@runbtx}

% No interface provided for this but can be set 'in emergency' by user
\def\blx@maxline{79}

% Rename write stream so use is clear
\let\blx@write\blx@bcfout

% Data file initialisation
\edef\blx@auxfile{\jobname}
\let\blx@aux\@mainaux
\newcommand*{\blxauxsuffix}{-blx}

\begingroup
\def\blx@tempa#1"#2{%
  #1\ifx#2\@empty\else
    \expandafter\blx@tempa
  \fi#2}
\edef\blx@ctrlfile{%
  \noexpand\blx@tempa
  \expandafter\blx@tempa\jobname"\@empty
  \space\noexpand\@empty}
\def\blx@tempa#1 #2{%
  #1\ifx#2\@empty\else
    \string_\expandafter\blx@tempa
  \fi#2}
\xdef\blx@ctrlfile{\blx@ctrlfile}
\endgroup

\def\blx@auxinit#1{%
  \blx@auxwrite\blx@aux
    {\def\do##1{,\blx@stripbib{##1}}}
    {\ifx\blx@aux\@mainaux
     \else
       \blx@msg@aux
     \fi
     \string\bibstyle{biblatex}\blx@nl
     \string\bibdata{%
       \blx@ctrlfile\blxauxsuffix
       \ifx#1\@empty
       \else
         \dolistloop#1%
       \fi}\blx@nl
     \string\citation{biblatex-control}}}

\def\blx@sig@bib{@Comment{$ biblatex control file $}}
\edef\blx@ver@bib{%
  @Comment{$ biblatex bcf format version \blx@bcfversion\space $}}

\let\blx@sig@aux\blx@sig@bbl
\let\blx@ver@aux\blx@ver@bbl

\edef\blx@msg@text{%
  \@percentchar\space Do not modify this file!\blx@nl
  \@percentchar\blx@nl
  \@percentchar\space This is an auxiliary file
  used by the 'biblatex' package.\blx@nl
  \@percentchar\space This file may safely be deleted.
  It will be recreated as\blx@nl
  \@percentchar\space required.\blx@nl}

\edef\blx@msg@aux{%
  \blx@sig@aux\blx@nl
  \blx@ver@aux\blx@nl
  \blx@msg@text
  \@percentchar\blx@nl\string\relax\blx@nl}
\edef\blx@msg@bib{%
  \blx@sig@bib\blx@nl
  \blx@ver@bib\blx@nl
  \blx@msg@text\blx@nl}

% User feedback

\renewrobustcmd*{\RequireBiber}[1][2]{%
  \ifnumgreater{#1}\blx@reqbiber
    {\numgdef\blx@reqbiber{#1}}
    {}%
    \blx@checkbackend{style}}
\@onlypreamble\RequireBiber
\let\blx@reqbiber\z@

\def\blx@checkbackend#1{%
  \ifnum\blx@reqbiber>2 %
     \blx@error
       {Biber backend is required by #1}
       {The selected style or one of the .bib files
        requires Biber.\MessageBreak It will
        not work at all with BibTeX.}%
   \fi}

\def\blx@check@logreq{%
  \begingroup
  \ltxrequest{biblatex}{{\iftoggle{blx@runltx}{1}{0}}}{%
    \provides[type=dynamic]{
      \def\do##1{\file{##1.aux}}
      \dolistloop\blx@list@inactive
      \file{\blx@ctrlfile\blxauxsuffix.bib}
    }
    \requires[type=dynamic]{
      \def\do##1{\file{##1.bbl}}
      \dolistloop\blx@list@inactive
    }
    \ifdef\blx@list@req@edit
      {\requires[type=editable]{
         \forlistloop\file\blx@list@req@edit
       }}
      {}
    \ifdef\blx@list@req@stat
      {\requires[type=static]{
         \forlistloop\file\blx@list@req@stat
       }}
      {}
  }%
  \def\do##1{%
    \ifinlist{##1}{\blx@list@active}
      {\blx@logreq@bibtex{1}{##1}}
      {\blx@logreq@bibtex{0}{##1}}}%
  \dolistloop\blx@list@inactive
  \endgroup}

\def\blx@logreq@bibtex#1#2{%
  \logrequest[package=biblatex,priority=5,active=#1]{%
    \generic{bibtex}
    \cmdline{%
      \iftoggle{blx@bibtex8}
        {\binary{bibtex8}
         \option{--wolfgang}
         \option{--min\string_crossrefs \blx@mincrossrefs}}
        {\binary{bibtex}
         \option{-min-crossrefs \blx@mincrossrefs}}%
      \infile{#2}
     }
     \input{
       \file{#2.aux}
     }
     \output{
       \file{#2.bbl}
     }
      \provides[type=dynamic]{
        \file{#2.bbl}
      }
      \requires[type=dynamic]{
        \file{#2.aux}
        \file{\blx@ctrlfile\blxauxsuffix.bib}
      }
      \requires[type=editable]{
        \ifcsdef{blx@list@bibfiles@#2}
          {\def\do{\file}
           \dolistcsloop{blx@list@bibfiles@#2}}
          {}
      }
      \requires[type=static]{
        \file{biblatex.bst}}
  }%
}

\def\blx@logreq@active#1{%
  \xifinlist{\blx@auxfile}{\blx@list@active}
    {}
    {\listxadd\blx@list@active{\blx@auxfile}}%
  \ifblank{#1}
    {}
    {\@latex@warning{#1}}%
  \blx@rerun@latex
  \blx@rerun@bibtex}

\def\blx@logreq@inactive{%
  \xifinlist{\blx@auxfile}{\blx@list@inactive}
    {}
    {\listxadd\blx@list@inactive{\blx@auxfile}}}

\def\blx@rerun@bibtex{%
  \global\toggletrue{blx@runbtx}%
  \global\let\blx@rerun@bibtex\relax}

% Only the toggle name changes here
\patchcmd{\blx@check@rerun}{blx@runbiber}{blx@runbtx}{}{}

\def\blx@warn@auxlist{%
  \begingroup
  \edef\blx@tempa{Please (re)run BibTeX on the file(s):}%
  \def\do##1{\appto\blx@tempa{\MessageBreak##1}}%
  \dolistloop\blx@list@active
  \blx@warning@noline{%
    \blx@tempa\MessageBreak
    and rerun LaTeX afterwards}%
  \endgroup}

\protected\def\blx@bibreq#1{%
  \blx@auxwrite\blx@aux{}{\string\citation{#1}}}

% bibtex doesn't parse ISO8601 dates so these overrides do nothing
\appto\blx@blxinit{%
  \def\iflabeldateera#1{\@secondoftwo}%
  \def\iflabelenddateera#1{\@secondoftwo}%
  \let\iflabeldatecirca\@secondoftwo
  \let\iflabelenddatecirca\@secondoftwo
  \let\iflabeldateuncertain\@secondoftwo
  \let\iflabelenddateuncertain\@secondoftwo}


% Alter message text
\patchcmd{\blx@bbl@warn}{Biber}{BibTeX}{}{}

%% Data input

\patchcmd{\blx@bblinput}{\blx@bblfile}{\blx@bblfile\blx@bblsecs}{}{}


\def\blx@bblfile{%
  \blx@secinit
  \begingroup
  \blx@bblstart
  \ifnum\c@refsection>\z@
    \edef\blx@auxfile{\jobname\the\c@refsection\blxauxsuffix}%
  \else
    \edef\blx@auxfile{\jobname}%
  \fi
  \blx@ifsigned{\blx@auxfile}{bbl}
    {\InputIfFileExists{\blx@auxfile.bbl}
       {\blx@info@noline{... file '\blx@auxfile.bbl' found}%
        \global\toggletrue{blx@bbldone}%
        \blx@generate@bbl@mdfivesum@found{\blx@auxfile.bbl}}
       {\blx@info@noline{... file '\blx@auxfile.bbl' not found}%
        \typeout{No file \blx@auxfile.bbl.}%
        \global\togglefalse{blx@bbldone}%
        \blx@generate@bbl@mdfivesum@notfound}}
    {}%
  \blx@bblend
  \endgroup
  % Check if Biber rerun was not carried out.
  % If so, ask for it again.
  \blx@check@bbl@rerun@mdfivesum
  \csnumgdef{blx@labelnumber@\the\c@refsection}{0}}

\def\blx@bblsecs{%
  \advance\c@refsection\@ne
  \ifnum\c@refsection>\blx@maxsection
  \else
    \blx@bblfile
    \expandafter\blx@bblsecs
  \fi}

\def\blx@refsection@ii{%
  \xdef\blx@auxfile{\jobname\the\c@refsection\blxauxsuffix}%
  \blx@regbibfiles\blx@auxfile\blx@bibfiles
  \blx@logreq@inactive
  \blx@ifsigned{\blx@auxfile}{aux}
    {\immediate\openout\blx@write\blx@auxfile.aux\relax
     \global\let\blx@aux\blx@write
     \blx@auxinit\blx@bibfiles}
    {}}

\def\blx@endrefsection{%
  \blx@endrefsegment
  \ifx\blx@aux\blx@write
    \immediate\closeout\blx@write
    \global\let\blx@aux\@mainaux
    \xdef\blx@auxfile{\jobname}%
  \fi
  \global\c@refsection\z@}

% xref support

% {<entrykey>}
\protected\def\blx@bbl@xref#1{%
  \ifcsdef{blx@refp@\the\c@refsection @\detokenize{#1}}
    {}
    {\listcsxadd{blx@refs@\the\c@refsection}{\detokenize{#1}}}%
  \listcsxadd{blx@refp@\the\c@refsection @\detokenize{#1}}{\abx@field@entrykey}%
  \csxdef{blx@refc@\the\c@refsection @\abx@field@entrykey}{\detokenize{#1}}}

\def\blx@addxref#1{%
  \blx@ifdata{#1}
    {\begingroup
     \def\do##1{%
       \csgappto{blx@data@\the\c@refsection @##1}{%
         \def\abx@field@xref{#1}}}%
     \dolistcsloop{blx@refp@\the\c@refsection @#1}%
     \endgroup}
    {}%
  \global\csundef{blx@refp@\the\c@refsection @#1}}

\def\blx@citation@xref#1{%
  \begingroup
  \edef\blx@tempa{blx@refp@\the\c@refsection @%
          \csname blx@refc@\the\c@refsection @#1\endcsname}%
  \ifcsdef\blx@tempa
    {\ifinlistcs{#1}\blx@tempa
       {}
       {\listcsxadd\blx@tempa{#1}}%
     \blx@tempcnta\z@
     \def\do##1{\advance\blx@tempcnta\@ne}%
     \dolistcsloop\blx@tempa}
    {\listcsxadd\blx@tempa{#1}%
     \blx@tempcnta\@ne}%
  \expandafter\endgroup\ifnum\blx@tempcnta<\blx@minxrefs\relax
  \else
    \expandafter\expandafter\expandafter\blx@citation@entry
    \expandafter\expandafter\expandafter{%
      \csname blx@refc@\the\c@refsection @#1\endcsname}\blx@msg@cundef
  \fi}

\def\blx@bblend{%
  \ifcsdef{blx@refs@\the\c@refsection}%
    {\begingroup
     \let\do\blx@addxref
     \dolistcsloop{blx@refs@\the\c@refsection}%
     \endgroup
     \global\csundef{blx@refs@\the\c@refsection}}
    {}%
  \iftoggle{blx@addset}
    {\blx@addset
     \global\togglefalse{blx@addset}}
    {}}


% set support

% We'll generate 'fake sets' for sorting.
% A fake set will be the copy of a normal set but with a crossref
% to the first set member, that way it inherits sorting info.

\def\blx@grabfirstcsvitem#1,#2\blx@grabfirstcsvitem@end{#1}

\def\blx@btx@fakesetentry#1#2#3#4{%
  \blx@nl
  @set{#1,\blx@nl
  \space\space fakeset  = {#2},\blx@nl
  \space\space entryset = {#3},\blx@nl
  \space\space crossref = {#4},\blx@nl
  }%
}

\def\blx@fakeset@prefix{blx@fakeset-}

\protected\def\blx@writefakeset@oo#1#2{%
  \begingroup
  \edef\blx@tempa{\endgroup
    \noexpand\blx@writefakeset
      {\expandonce{#1}}
      {\expandonce{#2}}}%
  \blx@tempa
}

\protected\def\blx@writefakeset#1#2{%
  \blx@auxwrite\blx@bcfout{}{%
    \blx@btx@fakesetentry
      {\blx@fakeset@prefix#1}
      {#1}
      {#2}
      {\blx@grabfirstcsvitem#2,\blx@grabfirstcsvitem@end}}}

\protected\def\blx@bbl@fakeset#1{%
  \csxdef{blx@isfakeset@\the\c@refsection @\abx@field@entrykey}{%
    \detokenize{#1}}%
  \global\cslet{blx@getfakeset@\the\c@refsection @#1}\abx@field@entrykey
}

% we can't rely on \inset in the .bbl (which should be in the child
% entry), so we produce setc manually from the @set parent
% but the bibliography may not be in a nice order to grab setc
% properly, so we need to save setc data in the .aux file
\appto\blx@secinit{%
  \cslet{blx@setclist@\the\c@refsection}\@empty
  \cslet{blx@fakesetplist@\the\c@refsection}\@empty}

\apptocmd{\blx@bbl@set@i}
  {\ifcsundef{blx@isfakeset@\the\c@refsection @\abx@field@entrykey}
     {\csxdef{blx@setc@\the\c@refsection @#1}{\abx@field@entrykey}%
      \listcsxadd{blx@setclist@\the\c@refsection}{\detokenize{#1}}}
     {}}
  {}
  {\blx@error
     {Failed to patch '\string\blx@bbl@set@i'}
     {Patching '\string\blx@bbl@set@i' failed for some reason.
      \MessageBreak
      Please report this bug}}

% {<section>}{<set child>}{<set parent>}
\protected\def\blx@aux@set@setc#1#2#3{%
  \csxdef{blx@setc@#1@#2}{#3}}

\protected\def\blx@aux@write@setc#1#2#3{%
  \blx@auxwrite\blx@aux{}{\string\blx@aux@set@setc{#1}{#2}{#3}}}

\def\blx@write@setc#1{%
  \ifcsundef{blx@setc@\the\c@refsection @#1}
    {}
    {\blx@aux@write@setc{\the\c@refsection}{#1}
       {\csuse{blx@setc@\the\c@refsection @#1}}}}

\appto\blx@bblend{%
  \forlistcsloop{\blx@write@setc}{blx@setclist@\the\c@refsection}}

% blx@setonly doesn't exist here, since it is defined in \inset,
% rely on the existence of setc instead.
% We also make sure to skip the actual @set entries and display
% the fake ones.
\patchcmd{\blx@bbl@endentry}
  {\nottoggle{blx@setonly}}
  {\ifentrytype{set}
    {\ifcsundef{blx@isfakeset@\the\c@refsection @\abx@field@entrykey}
       {\blx@writefakeset@oo{\abx@field@entrykey}{\abx@field@entryset}%
        \settoggle{blx@skipbib}{true}%
        \settoggle{blx@skipbiblist}{true}%
        \settoggle{blx@skiplab}{true}}
       {\listcsxadd{blx@fakesetplist@\the\c@refsection}{%
          \abx@field@entrykey}}}
    {}%
   \ifcsundef{blx@setc@\the\c@refsection @\abx@field@entrykey}}
  {}
  {\blx@error
     {Failed to patch '\string\blx@bbl@endentry'}
     {Patching '\string\blx@bbl@endentry' failed for some reason.
      \MessageBreak
      Please report this bug}}

% cite the fake set for our current set
% the \expandafter party essentially does
% \blx@citation@entry{\blx@fakeset@prefix#1}{\blx@msg@cundef}
% (just correctly \detokenize'd and all)
\def\blx@citation@set#1#2{%
  \blx@citation@entry{#1}{#2}%
  \ifcsundef{blx@isfakeset@\the\c@refsection @#1}
    {\begingroup
     \expandafter\def\expandafter\blx@tempa\expandafter{%
       \expandafter\detokenize\expandafter{\blx@fakeset@prefix#1}}%
     \expandafter\expandafter\expandafter\blx@citation@entry
     \expandafter\expandafter\expandafter{\blx@tempa}{\blx@msg@cundef}%
     \endgroup}
    {}%
  \begingroup
  \def\do##1{\blx@citation@entry{##1}\blx@msg@cundef}%
  \expandafter\expandafter\expandafter\docsvlist
  \expandafter\expandafter\expandafter{%
    \csname blx@setp@\the\c@refsection @#1\endcsname}%
  \endgroup}

\def\blx@citation@inset#1#2{%
  \blx@citation@entry{#1}{#2}%
  \expandafter\expandafter\expandafter\blx@citation@inset@i
  \expandafter\expandafter\expandafter{%
    \csname blx@setc@\the\c@refsection @#1\endcsname}\blx@msg@cundef}

\def\blx@citation@inset@i#1{%
  \ifcsdef{blx@setp@\the\c@refsection @#1}
    {\blx@citation@set{#1}}
    {\blx@citation@entry{#1}}}

\def\blx@appentrydatato#1#2{%
  \ifdef#2
    {\appto#1{%
       \def\noexpand#2{\expandonce#2}}}
    {}}

% if we have a fakeset, load the real @set to get the right entrykey
% if we have a real @set, load the fakeset for all entry data
% but make sure that the entrykey fits
% in any case copy over some label data from its first child
\def\blx@getdata#1{%
  \csuse{blx@data@\the\c@refsection @\blx@refcontext@context @#1}%
  \ifcsundef{blx@isfakeset@\the\c@refsection @#1}
    {}
    {\csuse{blx@data@\the\c@refsection @\blx@refcontext@context
             @\csuse{blx@isfakeset@\the\c@refsection @#1}}}%
  \ifcsundef{blx@getfakeset@\the\c@refsection @#1}
    {}
    {\let\blx@real@abx@field@entrykey\abx@field@entrykey
     \csuse{blx@data@\the\c@refsection @\blx@refcontext@context
            @\csuse{blx@getfakeset@\the\c@refsection @#1}}%
     \let\abx@field@entrykey\blx@real@abx@field@entrykey}%
  \ifcsundef{blx@setp@\the\c@refsection @\abx@field@entrykey}
    {}
    {\begingroup
     \expandafter\expandafter\expandafter\expandafter
     \expandafter\expandafter\expandafter\def
     \expandafter\expandafter\expandafter\expandafter
     \expandafter\expandafter\expandafter\blx@tempa
     \expandafter\expandafter\expandafter\expandafter
     \expandafter\expandafter\expandafter{%
       \expandafter\expandafter\expandafter\blx@grabfirstcsvitem
         \csname blx@setp@\the\c@refsection
           @\abx@field@entrykey\endcsname,\blx@grabfirstcsvitem@end}%
     \let\blx@tempb\@empty
     \blx@ifdata{\blx@tempa}
       {\blx@getdata{\blx@tempa}%
        \blx@appentrydatato\blx@tempb\abx@field@labelyear
        \blx@appentrydatato\blx@tempb\abx@field@labelendyear
        \blx@appentrydatato\blx@tempb\abx@field@labelmonth
        \blx@appentrydatato\blx@tempb\abx@field@labelendmonth
        \blx@appentrydatato\blx@tempb\abx@field@labelday
        \blx@appentrydatato\blx@tempb\abx@field@labelendday
        \blx@appentrydatato\blx@tempb\abx@field@labelprefix
        \blx@appentrydatato\blx@tempb\abx@field@labelalpha
        \blx@appentrydatato\blx@tempb\abx@field@extraalpha
        \blx@appentrydatato\blx@tempb\abx@field@extradate}
       {}%
     \edef\blx@tempb{\endgroup\blx@tempb}%
     \blx@tempb}%
  \blx@adjustyears
  \blx@getlabeldata
  \blx@aliasfields
  \blx@setcitecounter}


\def\blx@bblend@redosetlabelwidth@i#1{%
  \begingroup
  \blx@ifdata{#1}
    {\blx@getdata{#1}%
     \nottoggle{blx@skiplab}
       {\iftoggle{blx@labelnumber}
          {\ifdefempty\abx@field@localnumber
             {}
             {\ifundef\abx@field@shorthand
                {\blx@bbl@labelnumberwidth@numeric{}}
                {\blx@bbl@labelnumberwidth@shorthand{}}}}
          {}%
        \iftoggle{blx@labelalpha}
          {\blx@bbl@labelalpha}
          {}%
        \iftoggle{blx@labeltitle}
          {\blx@bbl@labeltitle}
          {}%
        \iftoggle{blx@labeltitleyear}
          {\blx@bbl@labeltitleyear}
          {}%
        \iftoggle{blx@labeldateparts}
          {\blx@bbl@labeldate}
          {}%
        \blx@bbl@labelname}
       {}}
    {}%
  \endgroup
}

\def\blx@bblend@redosetlabelwidth{%
  \forlistcsloop{\blx@bblend@redosetlabelwidth@i}
    {blx@fakesetplist@\the\c@refsection}}

\appto\blx@bblend{\blx@bblend@redosetlabelwidth}

% categories need the correct entry key for fake sets
\def\blx@addtocategory#1#2{%
  % If we are adding a set member to a category, make sure we also add the
  % set parent if it is cited. If it is cited, we should be using the set
  % parent in the category, not the set child member. blx@setc@... will
  % only exist if the set parent is also cited as it is only defined when a
  % member contains \inset which only happens when the set parent is cited.
  \ifcsdef{blx@setc@\the\c@refsection @#2}
    {\blx@auxwrite\@mainaux{}{\string\abx@aux@category{#1}{\csuse{blx@setc@\the\c@refsection @#2}}}%
     \abx@aux@category{#1}{\csuse{blx@setc@\the\c@refsection @#2}}}
    {}%
  \ifcsundef{blx@getfakeset@\the\c@refsection @#2}
    {}
    {\blx@auxwrite\@mainaux{}{\string\abx@aux@category{#1}{\csuse{blx@getfakeset@\the\c@refsection @#2}}}%
     \abx@aux@category{#1}{\csuse{blx@getfakeset@\the\c@refsection @#2}}}%
  \blx@auxwrite\@mainaux{}{\string\abx@aux@category{#1}{#2}}%
  \abx@aux@category{#1}{#2}}

% dynamic entry sets

\def\blx@btx@citeset#1#2{%
  \blx@nl
  @set{#1,\blx@nl
  \space\space entryset = {#2},\blx@nl
  }%
}

\protected\def\blx@setreq#1#2{%
  \blx@auxwrite\blx@bcfout{}{\blx@btx@citeset{#1}{#2}}%
  \blx@nocite@do{#1}}

% xref and @set
\def\blx@citation@i#1#2{%
  \ifbool{citerequest}
    {\ifcsdef{blx@setp@\the\c@refsection @#1}
       {\blx@citation@set{#1}{#2}}
       {\ifcsdef{blx@setc@\the\c@refsection @#1}
         {\blx@citation@inset{#1}{#2}}
         {\blx@citation@entry{#1}{#2}}}%
     \ifcsdef{blx@refc@\the\c@refsection @#1}%
       {\blx@citation@xref{#1}}
       {}}
    {}}

% refcontexts are out, but we can try to save labelprefix

% Luckily all refcontext names use \blx@refcontext@labelprefix, so if we
% don't modify that macro, we don't actually change the refcontext.
% Remember that \blx@refcontext@labelprefix contains a hash of the labelprefix
% and that \blx@refcontext@labelprefix@real contains the value.
% Effectively we always stay in \blx@sorting/global/global//global/global,
% and additionally carry around the labelprefix value
% in \blx@refcontext@labelprefix@real and pass it to the aux file.
% There are differences to the result obtained with Biber,
% but it should be good enough for very simple applications.
\blx@kv@defkey{blx@refcontext}{labelprefix}{%
  \xdef\blx@refcontext@labelprefix@real{#1}%
  \iftoggle{blx@defernumbers}
    {}%
    {\iftoggle{blx@labelnumber}
       {\blx@warning{%
          Option 'labelprefix' requires global\MessageBreak
          'defernumbers=true'}}
       {}}%
  \ifundef{\blx@bibtexwarn@labelprefix@used}
    {\blx@warning@noline{%
       The option 'labelprefix' is limited\MessageBreak
       when used with BibTeX.\MessageBreak
       Consider using Biber instead}%
     \global\let\blx@bibtexwarn@labelprefix@used\@empty}
    {}}

\def\blx@warn@bibtexrefcontext#1{%
  \blx@warning{%
    The refcontext option\MessageBreak
    '#1'\MessageBreak
    is not supported by the BibTeX backend.\MessageBreak
    Consider switching to Biber instead.\MessageBreak
    The option will be ignored}}

\def\blx@bibtexrefcontext@disable#1{%
  \blx@kv@defkey{blx@refcontext}{#1}{%
    \blx@warn@bibtexrefcontext{#1}}}

\forcsvlist{\blx@bibtexrefcontext@disable}{%
  nametemplates,sorting,sortingnamekeytemplatename,uniquenametemplatename,
  labelalphanametemplatename}

\def\blx@assignrefcontext@disable#1{%
  \blx@warning{%
    BibTeX does not support refcontext assignments with\MessageBreak
    '\string\assignrefcontext#1'.\MessageBreak
    Consider using Biber instead.\MessageBreak
    Ignoring the refconext assignment}}

\def\blx@assignrefcontextkeyws[#1][#2]#3{%
  \blx@assignrefcontext@disable{keyws}}
\def\blx@assignrefcontextcats[#1][#2]#3{%
  \blx@assignrefcontext@disable{cats}}
\def\blx@assignrefcontextentries[#1][#2]#3{%
  \blx@assignrefcontext@disable{entries}}

\apptocmd{\blx@setdefaultrefcontext}
  {\csxdef{blx@assignedlabelprefix@\the\c@refsection @#1}{%
     \blx@refcontext@labelprefix@real}}
  {}
  {\blx@error
     {Failed to patch '\string\blx@setdefaultrefcontext'}
     {Patching '\string\blx@setdefaultrefcontext' failed for some reason.
      \MessageBreak
      Please report this bug}}

\def\abx@aux@defaultlabelprefix#1#2#3{%
  \csgdef{blx@assignedlabelprefix@#1@#2}{#3}}

\apptocmd{\blx@bbl@entry}
  {\ifcsundef{blx@assignedlabelprefix@\the\c@refsection @\thefield{entrykey}}
     {}
     {\blx@bbl@addfield{labelprefix}{%
        \csuse{blx@assignedlabelprefix@\the\c@refsection
          @\thefield{entrykey}}}}}
  {}
  {\blx@error
     {Failed to patch '\string\blx@bbl@entry'}
     {Patching '\string\blx@bbl@entry' failed for some reason.
      \MessageBreak
      Please report this bug}}

\AtEndDocument{%
  % always add default labelprefix declarations to .aux
  \iftoggle{blx@bbldone}
    {\def\do#1{%
       \begingroup
       \def\do##1{%
         \blx@auxwrite\@mainaux{}{\string\abx@aux@defaultlabelprefix{#1}{##1}{%
           \csuse{blx@assignedlabelprefix@#1@##1}}}}%
       \dolistcsloop{blx@defaultrefcontexts@#1}%
       \endgroup}
     \dolistloop\blx@allrefsections}
    {}}


% Translate sorting schemes to BibTeX form
\def\blx@sorting@none{0}
\def\blx@sorting@nty{1}
\def\blx@sorting@nyt{2}
\def\blx@sorting@nyvt{3}
\def\blx@sorting@anyt{12}
\def\blx@sorting@anyvt{13}
\def\blx@sorting@ynt{21}
\def\blx@sorting@ydnt{22}
\def\blx@sorting@debug{99}

% Control file

\edef\blx@ctrl{%
  \blx@msg@bib
  @Control\string{biblatex-control,\blx@nl
  \space\space options = \string{%
    \blx@bcfversion:%
    \noexpand\iftoggle{blx@debug}{1}{0}:%
    \noexpand\iftoggle{blx@bibtex8}{1}{0}:%
    \noexpand\iftoggle{blx@sortcase}{1}{0}:%
    \noexpand\iftoggle{blx@useprefix}{1}{0}:%
    \noexpand\iftoggle{blx@useauthor}{1}{0}:%
    \noexpand\iftoggle{blx@useeditor}{1}{0}:%
    \noexpand\iftoggle{blx@usetranslator}{1}{0}:%
    \noexpand\iftoggle{blx@labelalpha}{1}{0}:%
    \noexpand\iftoggle{blx@labeldateparts}{1}{0}:%
    \noexpand\iftoggle{blx@singletitle}{1}{0}:%
    \noexpand\csuse{blx@sorting@\noexpand\blx@sorting}:%
    \noexpand\blx@maxcitenames:%
    \noexpand\blx@mincitenames:%
    \noexpand\blx@maxsortnames:%
    \noexpand\blx@minsortnames:%
    \noexpand\iftoggle{blx@nohashothers}{1}{0}:%
    \noexpand\iftoggle{blx@nosortothers}{1}{0}:%
    \noexpand\blx@maxalphanames:%
    \noexpand\blx@minalphanames:%
    \noexpand\blx@maxline:%
    \noexpand\detokenize\noexpand\expandafter{\noexpand\labelalphaothers}:%
    \noexpand\detokenize\noexpand\expandafter{\noexpand\blx@sortalphaothers}:%
    \noexpand\detokenize\noexpand\expandafter{\noexpand\blx@sorting}%
  \string},\blx@nl
  \string}%
}

\def\blx@ctrlwrite{%
  \begingroup
  \blx@safe@actives
  \let\protect\string
  \edef\blx@sortalphaothers{\sortalphaothers}%
  \immediate\openout\blx@write\blx@ctrlfile\blxauxsuffix.bib\relax
  \blx@auxwrite\blx@write{}{\blx@ctrl}%
  \endgroup
  \AfterEndDocument{\immediate\closeout\blx@write}}


% {<string>}
% This mustn't be robust as it's likely to be used mainly in tests and so
% needs to be expandable
\renewcommand*\rangelen[1]{%
  \ifblank{#1}
    {0}%
    {\expandafter\blx@rangelen@range\romannumeral-`\q%
      #1\bibrangedash\bibrangedash&%
    }}

\def\blx@rangelen@range#1\bibrangedash#2\bibrangedash#3&{%
  \ifblank{#3}
    {\blx@rangelen@hyphen#1--&}
    {\blx@rangelen@check{#1}{#2}}%
}
\def\blx@rangelen@hyphen#1-#2-#3&{%
  \ifblank{#3}
    {1}% No range at all: assume one page
    {\blx@rangelen@check{#1}{#2}}%
}
\def\blx@rangelen@check#1#2{%
  \expandafter\blx@rangelen@check@aux
    \number\numexpr
      \blx@rangelen@check@int{#2}
      -
      \blx@rangelen@check@int{#1}
      + 1
    \relax
    &\stop
}
\def\blx@rangelen@check@aux#1&#2\stop{%
  \ifblank{#2}
    {#1}
    {-1}%
}
\def\blx@rangelen@check@int#1{%
  \ifblank{#1}
    {0&}
    {%
      \if\number\numexpr0#1-0#1\relax0
        #1
      \else
        0&
      \fi
    }%
}


% Disable some interfaces

\renewrobustcmd*{\DeclareSortingScheme}[3][]{}
\renewrobustcmd*{\DeclareExtradate}[1]{}

\def\blx@checkencoding{}

\AtBeginDocument{%
  \blx@checkencoding
  \if@filesw
    \blx@auxinit\blx@bibfiles
  \fi}

\endinput