-
Notifications
You must be signed in to change notification settings - Fork 0
/
mciteplus.sty
1349 lines (1164 loc) · 59.7 KB
/
mciteplus.sty
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
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
%% mciteplus.sty
%% enhanced mcite
%% Version 1.1, 2008/09/30
%%
%% Copyright (c) 2008 Michael Shell
%% Support site:
%% http://www.michaelshell.org/tex/mciteplus/
%%
%%*************************************************************************
%% Legal Notice:
%% This code is offered as-is without any warranty either expressed or
%% implied; without even the implied warranty of MERCHANTABILITY or
%% FITNESS FOR A PARTICULAR PURPOSE!
%% User assumes all risk.
%% In no event shall any contributor to this code be liable for any damages
%% or losses, including, but not limited to, incidental, consequential, or
%% any other damages, resulting from the use or misuse of any information
%% contained here.
%%
%% All comments are the opinions of their respective authors.
%%
%% This work is distributed under the LaTeX Project Public License (LPPL)
%% ( http://www.latex-project.org/ ) version 1.3, and may be freely used,
%% distributed and modified. A copy of the LPPL, version 1.3, is included
%% in the base LaTeX documentation of all distributions of LaTeX released
%% 2003/12/01 or later.
%% Retain all contribution notices and credits.
%% ** Modified files should be clearly indicated as such, including **
%% ** renaming them and changing author support contact information. **
%%**********************************************************************
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{mciteplus}[2008/09/30 v1.1 enhanced mcite]
% package option conditionals
\newif\if@OPTIONmcitenohooks\@OPTIONmcitenohooksfalse
\newif\if@OPTIONmcitechapterbibrootbib\@OPTIONmcitechapterbibrootbibfalse
\newif\if@OPTIONmcitedebug\@OPTIONmcitedebugfalse
\DeclareOption{debug}{\global\@OPTIONmcitedebugtrue}
\DeclareOption{nohooks}{\global\@OPTIONmcitenohookstrue}
% use ds@ for chapterbibrootbib to keep option local
\def\ds@chapterbibrootbib{\global\@OPTIONmcitechapterbibrootbibtrue}
\ProcessOptions
% first entry in citation or bibliography flag
\newif\if@mcitefirstentry
% first head entry in citation or bibliography flag
\newif\if@mcitefirstheadentry
% entry using star (is a tail) flag
\newif\if@mcitestarentry
% head declared more than once flag
\newif\if@mciteheadredeclared
% sublist block is open flag
\newif\if@mcitesublistopen
% bst indicates that end punctuation would normally be used
\newif\ifmciteBstWouldAddEndPunct
% flag to indicate that the label widths have changed
% and that LaTeX has to be rerun
\newif\if@mciteLaTeXrerun\@mciteLaTeXrerunfalse
% flag to indicate the use of the first optional argument of a macro
\newif\ifmciteMacroOptArgI\mciteMacroOptArgIfalse
% flag to indicate the use of the first optional argument of a macro (local, non user, use)
\newif\if@mciteLocalMacroOptArgI\@mciteLocalMacroOptArgIfalse
% flag to indicate the use of the second optional argument of a macro
\newif\ifmciteMacroOptArgII\mciteMacroOptArgIIfalse
% flag to indicate the use of the star form of a macro
\newif\ifmciteMacroStarForm\mciteMacroStarFormfalse
% flag to indicate the use of the star form of the \cite forwarding macro
\newif\ifmciteCiteStarFwdArg\mciteCiteStarFwdArgfalse
% flag to indicate the use of the sec ID argument for the \cite forwarding macro
\newif\if@mciteCiteSecIDArg\@mciteCiteSecIDArgfalse
% flag to indicate the use of the first optional argument of a bibitem
\newif\ifmciteBibitemOptArgI\mciteBibitemOptArgIfalse
% flag to indicate the use of the first optional argument of the current head bibitem
\newif\ifmciteCurheadBibitemOptArgI\mciteCurheadBibitemOptArgIfalse
% temporary token list
\newtoks\@mcitetmptoksA
% macro to add (unexpanded) to token list
\def\@mciteAppendToTmpToksA#1{\@mcitetmptoksA=\expandafter{\the\@mcitetmptoksA#1}}
% temporary dimen registers
\newdimen\@mcitetmpdima
\newdimen\@mcitetmpdimb
% temporary count registers
\newcount\@mcitetmpcnta
\newcount\@mcitetmpcntb
% count of entries
\newcounter{mcitebibitemcount}
\setcounter{mcitebibitemcount}{0}
% count of sub items
\newcounter{mcitesubitemcount}
% the default entry punctuation and separator
\providecommand{\mcitedefaultmidpunct}{;\space}
\providecommand{\mcitedefaultendpunct}{.}
\providecommand{\mcitedefaultseppunct}{\relax}
% the default sublist label, begin and end macros
\providecommand{\mcitedefaultsublistlabel}{\alph{mcitesubitemcount})\space}
\providecommand{\mcitedefaultsublistbegin}{\relax}
\providecommand{\mcitedefaultsublistend}{\relax}
% the default max width forms
\providecommand{\mcitedefaultmaxwidthbibitemform}{\arabic{mcitebibitemcount}}
\providecommand{\mcitedefaultmaxwidthbibitemforminit}{\mciteorgbibsamplelabel}
\providecommand{\mcitedefaultmaxwidthsubitemform}{\alph{mcitesubitemcount})}
\providecommand{\mcitedefaultmaxwidthsubitemforminit}{a)}
% sample label which is forwarded to \thebibliography
\def\mcitebibsamplelabel{\rule{\mcitemaxwidthbibitem sp}{0.2pt}}
% Aux and track handles
%
% aux used by \mcite
\def\mciteauxout{\@auxout}
% aux used within \mcitethebibliography
\def\mcitebibauxout{\@mainaux}
% current auxout in use
\def\@mcitecurauxout{\mciteauxout}
% This is the unique ID string used to track multiple bibliographies.
\def\mcitetrackID{main}
% for \mcitethebibliography
\def\mcitebibtrackID{main}
% current Track ID in use
\def\@mcitecurtrackID{\mcitetrackID}
% macros for letter code and string tests
\def\@mciteMacrod{d}
\def\@mciteMacron{n}
\def\@mciteMacros{s}
\def\@mciteMacrob{b}
\def\@mciteMacrof{f}
\def\@mciteMacroh{h}
\def\@mciteMacrobibitem{bibitem}
\def\@mciteMacrosubitem{subitem}
% sets the punctuation bst hooks
\long\def\mciteSetBstMidEndSepPunct#1#2#3{\long\def\mcitebstmidpunct{#1}\relax
\long\def\mcitebstendpunct{#2}\long\def\mcitebstseppunct{#3}}
% sets the actual punctuation used
\long\def\mciteSetMidEndSepPunct#1#2#3{\long\def\mcitemidpunct{#1}\relax
\long\def\mciteendpunct{#2}\long\def\mciteseppunct{#3}}
% sets the sublabel bst hooks
\long\def\mciteSetBstSublistLabelBeginEnd#1#2#3{\long\def\mcitebstsublistlabel{#1}\relax
\long\def\mcitebstsublistbegin{#2}\long\def\mcitebstsublistend{#3}}
% sets the actual sublabel used
\long\def\mciteSetSublistLabelBeginEnd#1#2#3{\long\def\mcitesublistlabel{#1}\relax
\long\def\mcitesublistbegin{#2}\long\def\mcitesublistend{#3}}
% sublist mode flags, b and first forms should be set to false unless \@mcitesublistmode is also true
\newif\if@mcitesublistmode\@mcitesublistmodefalse
\newif\if@mcitesublistmodeb\@mcitesublistmodebfalse
\newif\if@mcitesublistmodef\@mcitesublistmodeffalse
\newif\if@mcitesublistmodeh\@mcitesublistmodehfalse
% reset entry counter flag
\newif\ifmciteResetBibitemCount\mciteResetBibitemCounttrue
% error on unknown entries
\newif\ifmciteErrorOnUnknown\mciteErrorOnUnknowntrue
% BST can request a sublist mode using \mciteSetBstSublistMode, but user requests can override it:
% d = default, use current settings
% n = no sublist
% s = sublist
% b = sublistb
% f = sublistfirst
% h = sublistfirst, including single heads
% note that the changes here are local and will not be remembered outside of the \mcitethebibliography environment
\def\mciteSetBstSublistMode#1{\edef\@mcitetemp{#1}\relax
% only make changes if the user mode allows
\ifx\@mcitesublistmode\@mciteMacrod\relax
\ifx\@mcitetemp\@mciteMacrod
\def\@mcitebstsublistmode{d}\else
\ifx\@mcitetemp\@mciteMacron
\def\@mcitebstsublistmode{n}\@mcitesublistmodefalse\@mcitesublistmodebfalse\@mcitesublistmodeffalse\@mcitesublistmodehfalse\else
\ifx\@mcitetemp\@mciteMacros
\def\@mcitebstsublistmode{s}\@mcitesublistmodetrue\@mcitesublistmodebfalse\@mcitesublistmodeffalse\@mcitesublistmodehfalse\else
\ifx\@mcitetemp\@mciteMacrob
\def\@mcitebstsublistmode{b}\@mcitesublistmodetrue\@mcitesublistmodebtrue\@mcitesublistmodeffalse\@mcitesublistmodehfalse\else
\ifx\@mcitetemp\@mciteMacrof
\def\@mcitebstsublistmode{f}\@mcitesublistmodetrue\@mcitesublistmodebfalse\@mcitesublistmodeftrue\@mcitesublistmodehfalse\else
\ifx\@mcitetemp\@mciteMacroh
\def\@mcitebstsublistmode{h}\@mcitesublistmodetrue\@mcitesublistmodebfalse\@mcitesublistmodeftrue\@mcitesublistmodehtrue\else
\PackageError{mciteplus}{Unknown mode `#1' in argument to \protect\mciteSetBstSublistMode}%
{Only `d', `n', `s', `b', `f' and `h' are valid.}\relax
\fi
\fi
\fi
\fi
\fi
\fi
\fi}
% User can specify a sublist mode:
% d = default, use current settings, allow BST to choose
% n = no sublist
% s = sublist
% b = sublistb
% f = sublistfirst
% h = sublistfirst, including single heads
\def\mciteSetSublistMode#1{\edef\@mcitetemp{#1}\relax
\ifx\@mcitetemp\@mciteMacrod
\def\@mcitesublistmode{d}\else
\ifx\@mcitetemp\@mciteMacron
\def\@mcitesublistmode{n}\@mcitesublistmodefalse\@mcitesublistmodebfalse\@mcitesublistmodeffalse\@mcitesublistmodehfalse\else
\ifx\@mcitetemp\@mciteMacros
\def\@mcitesublistmode{s}\@mcitesublistmodetrue\@mcitesublistmodebfalse\@mcitesublistmodeffalse\@mcitesublistmodehfalse\else
\ifx\@mcitetemp\@mciteMacrob
\def\@mcitesublistmode{b}\@mcitesublistmodetrue\@mcitesublistmodebtrue\@mcitesublistmodeffalse\@mcitesublistmodehfalse\else
\ifx\@mcitetemp\@mciteMacrof
\def\@mcitesublistmode{f}\@mcitesublistmodetrue\@mcitesublistmodebfalse\@mcitesublistmodeftrue\@mcitesublistmodehfalse\else
\ifx\@mcitetemp\@mciteMacroh
\def\@mcitesublistmode{h}\@mcitesublistmodetrue\@mcitesublistmodebfalse\@mcitesublistmodeftrue\@mcitesublistmodehtrue\else
\PackageError{mciteplus}{Unknown mode `#1' in argument to \protect\mciteSetSublistMode}%
{Only `d', `n', `s', `b', `f' and `h' are valid.}\relax
\fi
\fi
\fi
\fi
\fi
\fi}
% checks to see if valid type in \@mciteformtypeArg (bibitem or subitem), errors if not
% #1 is name of calling macro
\def\@mcitecheckformtypeerror#1{\relax
\ifx\@mciteformtypeArg\@mciteMacrobibitem\relax
\else
\ifx\@mciteformtypeArg\@mciteMacrosubitem\relax
\else
\PackageError{mciteplus}{Unknown form type `\@mciteformtypeArg' in argument to \protect#1}%
{Only `bibitem' and `subitem' are valid.}\relax
\fi
\fi}
% sets the bst max width forms
% usage: \mciteSetBstMaxWidthForm[init]{type}{form}
% where type is bibitem or subitem
% if [init] not given, uses \mcitedefaultmaxwidth[TYPE]forminit
\def\mciteSetBstMaxWidthForm{\@ifnextchar[{\@mciteLocalMacroOptArgItrue\@mciteSetBstMaxWidthForm}{\@mciteLocalMacroOptArgIfalse\@mciteSetBstMaxWidthForm[\relax]}}
\def\@mciteSetBstMaxWidthForm[#1]#2#3{\edef\@mciteformtypeArg{#2}\relax
\@mcitecheckformtypeerror{\mciteSetBstMaxWidthForm}\relax
\expandafter\def\csname mcitebstmaxwidth\@mciteformtypeArg form\endcsname{#3}\relax
\if@mciteLocalMacroOptArgI
\expandafter\def\csname mcitebstmaxwidth\@mciteformtypeArg forminit\endcsname{#1}\relax
\else
\expandafter\expandafter\expandafter\def\expandafter\expandafter\csname mcitebstmaxwidth\@mciteformtypeArg forminit\endcsname\expandafter{\csname mcitedefaultmaxwidth\@mciteformtypeArg forminit\endcsname}\relax
\fi}
% sets the max width forms
% usage: \mciteSetMaxWidthForm[init]{type}{form}
% where type is bibitem or subitem
% if [init] not given, uses \mcitebstmaxwidth[TYPE]forminit
\def\mciteSetMaxWidthForm{\@ifnextchar[{\@mciteLocalMacroOptArgItrue\@mciteSetMaxWidthForm}{\@mciteLocalMacroOptArgIfalse\@mciteSetMaxWidthForm[\relax]}}
\def\@mciteSetMaxWidthForm[#1]#2#3{\edef\@mciteformtypeArg{#2}\relax
\@mcitecheckformtypeerror{\mciteSetMaxWidthForm}\relax
\expandafter\def\csname mcitemaxwidth\@mciteformtypeArg form\endcsname{#3}\relax
\if@mciteLocalMacroOptArgI
\expandafter\def\csname mcitemaxwidth\@mciteformtypeArg forminit\endcsname{#1}\relax
\else
\expandafter\expandafter\expandafter\def\expandafter\expandafter\csname mcitemaxwidth\@mciteformtypeArg forminit\endcsname\expandafter{\csname mcitebstmaxwidth\@mciteformtypeArg forminit\endcsname}\relax
\fi}
% initialize punctuation, sublist and maxwidth hooks
%
% punctuation controls
% default is to hook into the bst
\mciteSetMidEndSepPunct{\mcitebstmidpunct}{\mcitebstendpunct}{\mcitebstseppunct}
% the default bst setting is to use the package defaults
\mciteSetBstMidEndSepPunct{\mcitedefaultmidpunct}{\mcitedefaultendpunct}{\mcitedefaultseppunct}
%
% sublist controls
% default sublist mode is to use the defaults
\mciteSetBstSublistMode{d}
\mciteSetSublistMode{d}
% the default sublabel bst setting is to use the package defaults
\mciteSetBstSublistLabelBeginEnd{\mcitedefaultsublistlabel}{\mcitedefaultsublistbegin}{\mcitedefaultsublistend}
% default sublabel setting is to hook into the bst settings
\mciteSetSublistLabelBeginEnd{\mcitebstsublistlabel}{\mcitebstsublistbegin}{\mcitebstsublistend}
%
% max width form controls
% the default max width form bst settings is to use the package defaults
\mciteSetBstMaxWidthForm[\mcitedefaultmaxwidthbibitemforminit]{bibitem}{\mcitedefaultmaxwidthbibitemform}
\mciteSetBstMaxWidthForm[\mcitedefaultmaxwidthsubitemforminit]{subitem}{\mcitedefaultmaxwidthsubitemform}
% the default max width form settings is to hook into the bst settings
\mciteSetMaxWidthForm[\mcitebstmaxwidthbibitemforminit]{bibitem}{\mcitebstmaxwidthbibitemform}
\mciteSetMaxWidthForm[\mcitebstmaxwidthsubitemforminit]{subitem}{\mcitebstmaxwidthsubitemform}
% Defines a macro to track the status of entries. An example showing the
% format is \@mciteEntryStatus@1@Smith98
% where the 1 is the tracking ID, and Smith98 is the cite key.
% Possible values for this status macro are:
% 0 = not yet determined
% 1 = tail (tail entry following a head entry)
% 2 = head (head entry followed by one or more tails)
% 3 = single (head entry not followed by any tails)
% usage: \@mciteSetEntryStatus{track ID}{cite key}{status}
\def\@mciteSetEntryStatus#1#2#3{\expandafter\xdef\csname @mciteEntryStatus@#1@#2\endcsname{#3}\relax
%\typeout{SetEntryStatus: Track:`#1' Key:`#2' Status:`#3'}\relax
}
% used to obtain status of a given cite key
% usage: \@mciteGetEntryStatus*{track ID}{cite key}{status out}
% star form: no error checking
\def\@mciteGetEntryStatus{\@ifstar{\@mciteGetEntryStatusStar}{\@mciteGetEntryStatusNoStar}}
\def\@mciteGetEntryStatusStar#1#2#3{\expandafter\let\expandafter#3\csname @mciteEntryStatus@#1@#2\endcsname}
\def\@mciteGetEntryStatusNoStar#1#2#3{\expandafter\let\expandafter#3\csname @mciteEntryStatus@#1@#2\endcsname\relax
\ifx#3\relax
\ifmciteErrorOnUnknown
\PackageError{mciteplus}{Entry Status for cite key `#2' under tracking ID `#1' is undefined, treating it as a head entry}{I don't have a
record of the head/tail status of this citation. Possible reasons include the use
of a cite command that is not mciteplus aware, the use of `\string\nocite{*}', or a problem with the
tracking ID and/or aux file handles. `\string\mciteErrorOnUnknownfalse' can be used to disable this error message.}\relax
\fi
\expandafter\def#3{3}\relax
\fi}
% set head key for given tail
% usage: \@mciteSetHeadofTail{track ID}{tail cite key}{head cite key}
\def\@mciteSetHeadofTail#1#2#3{\expandafter\xdef\csname @mciteHeadofTail@#1@#2\endcsname{#3}}
% get head key for given tail
% usage: \@mciteGetHeadofTail{track ID}{tail cite key}{head key out}
% star form: no error checking
\def\@mciteGetHeadofTail{\@ifstar{\@mciteGetHeadofTailStar}{\@mciteGetHeadofTailNoStar}}
\def\@mciteGetHeadofTailStar#1#2#3{\expandafter\let\expandafter#3\csname @mciteHeadofTail@#1@#2\endcsname}
\def\@mciteGetHeadofTailNoStar#1#2#3{\expandafter\let\expandafter#3\csname @mciteHeadofTail@#1@#2\endcsname\relax
\ifx#3\relax
\PackageError{mciteplus}{Head for tail cite key `#2' under tracking ID `#1' is undefined}{I don't have a
record of the head key of this citation.}\relax
\fi}
% for debug status messages
% converts given status number to word description
\def\@mciteStatusNumToWord#1{\expandafter\ifcase#1\relax
Unknown\or Tail\or Head with tails\or Head without tails\else Invalid (#1)\fi}
% form that makes no distinction between status 2 or 3. Used with \cite debug as
% head status is not finalized till after the entry group
\def\@mciteStatusNumToWordH#1{\expandafter\ifcase#1\relax
Unknown\or Tail\or Head\or Head\else Invalid (#1)\fi}
% usage:\mciteSetMaxWidth{track ID}{type}{width}
% Defines a macro to track the max width of a given label type.
% An example showing the format is \@mciteMaxWidthStore@main@bibitem
% which is set globally
% we don't use @ in the macro name as this cmd appears in the aux
\def\mciteSetMaxWidth#1#2#3{\edef\@mciteformtypeArg{#2}\relax
\@mcitecheckformtypeerror{\mciteSetMaxWidth}\relax
\expandafter\xdef\csname @mciteMaxWidthStore@#1@\@mciteformtypeArg\endcsname{#3}}
%
% usage:\mciteGetMaxWidth{track ID}{type}{out macro}
% reads the stored max width of the given label type into the out macro
% which is set globally
\def\mciteGetMaxWidth#1#2#3{\edef\@mciteformtypeArg{#2}\relax
\@mcitecheckformtypeerror{\mciteGetMaxWidth}\relax
\expandafter\global\expandafter\let\expandafter#3\csname @mciteMaxWidthStore@#1@\@mciteformtypeArg\endcsname}
% usage:\mciteSetMaxCount{track ID}{type}{count}
% Defines a macro to track the max count of a given label type.
% An example showing the format is \@mciteMaxCountStore@main@bibitem
% which is set globally
% we don't use @ in the macro name as this cmd appears in the aux
\def\mciteSetMaxCount#1#2#3{\edef\@mciteformtypeArg{#2}\relax
\@mcitecheckformtypeerror{\mciteSetMaxCount}\relax
\expandafter\xdef\csname @mciteMaxCountStore@#1@\@mciteformtypeArg\endcsname{#3}}
%
% usage:\mciteGetMaxCount{track ID}{type}{out macro}
% reads the stored max count of the given label type into the out macro
% which is set globally
\def\mciteGetMaxCount#1#2#3{\edef\@mciteformtypeArg{#2}\relax
\@mcitecheckformtypeerror{\mciteGetMaxCount}\relax
\expandafter\global\expandafter\let\expandafter#3\csname @mciteMaxCountStore@#1@\@mciteformtypeArg\endcsname}
% sets \mcitemaxcountbibitem and \mcitemaxcountsubitem via \mciteGetMaxCount globally
% sets them to zero if \mciteGetMaxCount returns \relax
% clears \@mcitecorrectmaxcountbibitem and \@mcitecorrectmaxcountsubitem
% uses \@mcitecurtrackID
\def\@mciteMaxCountInitialize{\mciteGetMaxCount{\@mcitecurtrackID}{bibitem}{\mcitemaxcountbibitem}\relax
\ifx\mcitemaxcountbibitem\relax\gdef\mcitemaxcountbibitem{0}\fi
\mciteGetMaxCount{\@mcitecurtrackID}{subitem}{\mcitemaxcountsubitem}\relax
\ifx\mcitemaxcountsubitem\relax\gdef\mcitemaxcountsubitem{0}\fi
\global\let\mcitemaxcountbibitem\mcitemaxcountbibitem
\global\let\mcitemaxcountsubitem\mcitemaxcountsubitem
\xdef\@mcitecorrectmaxcountbibitem{0}\relax
\xdef\@mcitecorrectmaxcountsubitem{0}\relax}
%
% usage: \@mciteMaxCountUpdate
% updates \@mcitecorrectmaxcountsubitem
% no need for \@mcitecorrectmaxcountbibitem as this is carried by the counter itself
\def\@mciteMaxCountUpdate{\relax
\ifnum\@mcitecorrectmaxcountsubitem<\arabic{mcitesubitemcount}\relax
\xdef\@mcitecorrectmaxcountsubitem{\arabic{mcitesubitemcount}}\relax
\fi}
%
% usage: \@mciteMaxCountAuxWrite uses \@mcitecurauxout and \@mcitecurtrackID
% writes \mciteSetMaxCount{track ID}{type}{count} to \@mcitecurauxout
% and warns if correct values do not match \mcitemaxcountbibitem, \mcitemaxcountsubitem
\def\@mciteMaxCountAuxWrite{\relax
\if@filesw
\immediate\write\@mcitecurauxout{\string\mciteSetMaxCount{\@mcitecurtrackID}{bibitem}{\arabic{mcitebibitemcount}}}\relax
\immediate\write\@mcitecurauxout{\string\mciteSetMaxCount{\@mcitecurtrackID}{subitem}{\@mcitecorrectmaxcountsubitem}}\relax
\fi
\ifnum\mcitemaxcountbibitem=\arabic{mcitebibitemcount}\relax
\ifnum\mcitemaxcountsubitem=\@mcitecorrectmaxcountsubitem\relax\else
\@latex@warning@no@line{Mciteplus max count has changed}\global\@mciteLaTeXreruntrue
\fi
\else
\@latex@warning@no@line{Mciteplus max count has changed}\global\@mciteLaTeXreruntrue
\fi}
% usage: \@mciteMaxWidthInitialize{type}
% sets \mcitemaxwidth[TYPE] via \GetMaxWidth globally
% if \GetMaxWidth returns \relax, sets them to the width (without sp units at end) of \mcitebstmaxwidth[TYPE]forminit
% as evaluated when bibitem and subitem counters are both = 1
% clears \@mcitecorrectmaxwidth[TYPE] globally to 0
% uses \@mcitecurtrackID
\def\@mciteMaxWidthInitialize#1{\edef\@mcitemaxwidthinitializetypeArg{#1}\relax
\expandafter\mciteGetMaxWidth\expandafter{\expandafter\@mcitecurtrackID\expandafter}\expandafter{\expandafter\@mcitemaxwidthinitializetypeArg\expandafter}\expandafter{\csname mcitemaxwidth#1\endcsname}\relax
\expandafter\ifx\csname mcitemaxwidth#1\endcsname\relax
\begingroup
% set counters to 1 locally
\csname c@mcitebibitemcount\endcsname 1\relax
\csname c@mcitesubitemcount\endcsname 1\relax
\settowidth{\@mcitetmpdima}{\csname mcitemaxwidth#1forminit\endcsname}\relax
\@mcitetmpcnta=\@mcitetmpdima\relax
\expandafter\xdef\csname mcitemaxwidth#1\endcsname{\the\@mcitetmpcnta}\relax
\endgroup
\fi
\expandafter\xdef\csname @mcitecorrectmaxwidth#1\endcsname{0}}
%
% usage: \@mciteMaxWidthUpdate{type}
% globally updates \@mcitecorrectmaxwidth[TYPE] based on \mcitemaxwidth[TYPE]form
\def\@mciteMaxWidthUpdate#1{\relax
\settowidth{\@mcitetmpdima}{\csname mcitemaxwidth#1form\endcsname}\relax
\@mcitetmpcnta=\@mcitetmpdima\relax
\@mcitetmpcntb=\csname @mcitecorrectmaxwidth#1\endcsname\relax
\ifnum\@mcitetmpcnta>\@mcitetmpcntb\relax
\expandafter\xdef\csname @mcitecorrectmaxwidth#1\endcsname{\the\@mcitetmpcnta}\relax
\fi}
%
%
% usage: \@mciteMaxWidthAuxWrite uses \@mcitecurauxout and \@mcitecurtrackID
% writes \mciteSetMaxWidth{track ID}{type}{correct width in sp}
% for both bibitem and subitem to \@mcitecurauxout
% and warns if correct values do not match \mcitemaxwidthbibitem, \mcitemaxwidthsubitem
\def\@mciteMaxWidthAuxWrite{\relax
\if@filesw
\immediate\write\@mcitecurauxout{\string\mciteSetMaxWidth{\@mcitecurtrackID}{bibitem}{\@mcitecorrectmaxwidthbibitem}}\relax
\immediate\write\@mcitecurauxout{\string\mciteSetMaxWidth{\@mcitecurtrackID}{subitem}{\@mcitecorrectmaxwidthsubitem}}\relax
\fi
\ifnum\mcitemaxwidthbibitem=\@mcitecorrectmaxwidthbibitem\relax
\ifnum\mcitemaxwidthsubitem=\@mcitecorrectmaxwidthsubitem\relax\else
\@latex@warning@no@line{Mciteplus max width has changed}\global\@mciteLaTeXreruntrue
\fi
\else
\@latex@warning@no@line{Mciteplus max width has changed}\global\@mciteLaTeXreruntrue
\fi}
% empty \mciteheadlist in case someone trys to access it before a \cite
\def\mciteheadlist{}
% default wrappers for \cite and \nocite, package hooks (e.g., multibbl) can change these later
\def\@mciteCiteWrapper{\mciteCiteA{\mciteauxout}{\mcitetrackID}{\relax}{\relax}{\mciteOrgcite}}
\def\@mciteNociteWrapper{\mciteCiteA{\mciteauxout}{\mcitetrackID}{\relax}{\relax}{\mciteOrgnocite}}
% \mcite was undocumented in mcite.sty. We don't need it and it will not work with
% some multibibliography packages. So, we'll not use them.
% mcite version of \cite
%\def\mcite{\mciteCiteA{\mciteauxout}{\mcitetrackID}{\relax}{\relax}{\mciteOrgcite}}
% mcite version of \nocite
%\def\mnocite{\mciteCiteA{\mciteauxout}{\mcitetrackID}{\relax}{\relax}{\mciteOrgnocite}}
% mciteplus \cite wrappers
% usage: \mciteCiteA*{aux out}{track ID}{prehandler}{posthandler}{fwd macro}*[opt1][opt2]{cite list}
% \mciteCiteB*{aux out}{track ID}{prehandler}{posthandler}{fwd macro}*[opt1][opt2]{sec ID}{cite list}
% B form is for \cite that use two arguments, such as that of multibbl.sty
% processes cite list and fowards arguments and list of heads to specified \cite macro
% star form means no default \mciteDoList processing
\DeclareRobustCommand{\mciteCiteA}{\@mciteCiteSecIDArgfalse\@mciteCiteAB}
\DeclareRobustCommand{\mciteCiteB}{\@mciteCiteSecIDArgtrue\@mciteCiteAB}
\def\@mciteCiteAB{\@ifstar{\mciteMacroStarFormtrue\@@mciteCiteAB}{\mciteMacroStarFormfalse\@@mciteCiteAB}}
\def\@@mciteCiteAB#1#2#3#4#5{\def\mciteCiteAuxArg{#1}\def\mciteCiteTrackArg{#2}\def\mciteCitePrehandlerArg{#3}\relax
\def\mciteCitePosthandlerArg{#4}\relax\def\mciteCiteFwdArg{#5}\relax
\@ifstar{\mciteCiteStarFwdArgtrue\@@@mciteCiteAB}{\mciteCiteStarFwdArgfalse\@@@mciteCiteAB}}
\def\@@@mciteCiteAB{\@ifnextchar[{\mciteMacroOptArgItrue\@@@@mciteCiteAB}%
{\mciteMacroOptArgIfalse\@@@@mciteCiteAB[\relax]}}
\def\@@@@mciteCiteAB[#1]{\def\mciteCiteOptArgI{#1}\relax
\@ifnextchar[{\mciteMacroOptArgIItrue\@@@@@mciteCiteAB}%
{\mciteMacroOptArgIIfalse\@@@@@mciteCiteAB[\relax]}}
\def\@@@@@mciteCiteAB[#1]{\def\mciteCiteOptArgII{#1}\relax
\if@mciteCiteSecIDArg
\def\@mciteNextMacroChain{\@@@@@mciteCiteB}\relax
\else
\let\mciteCiteSecIDArg\relax
\def\@mciteNextMacroChain{\@@@@@@mciteCiteAB}\relax
\fi
\@mciteNextMacroChain}
\def\@@@@@mciteCiteB#1{\def\mciteCiteSecIDArg{#1}\@@@@@@mciteCiteAB}
\def\@@@@@@mciteCiteAB#1{\def\mciteCiteListArg{#1}\relax
\edef\mciteFwdCiteListArg{}\relax
% execute the user's pre-handler code
\mciteCitePrehandlerArg\relax
\ifmciteMacroStarForm
% star form means no mcite default processing
% the user will have to do all of this in their handler
\else
% otherwise, process the cite list and set the forward cite list to the list of heads
\mciteDoList{\mciteCiteAuxArg}{\mciteCiteTrackArg}{\mciteCiteListArg}\relax
\edef\mciteFwdCiteListArg{\mciteheadlist}\relax
% optional additional calls to do lists for duplicate/global bibliographies
\mciteExtraDoLists\relax
\fi
\relax
% execute the user's post-handler code
\mciteCitePosthandlerArg\relax
% build the forwarding macro and arguments list
\@mcitetmptoksA=\expandafter{\mciteCiteFwdArg}\relax
\ifmciteCiteStarFwdArg
\@mciteAppendToTmpToksA{*}\relax
\fi
\ifmciteMacroOptArgI
\@mciteAppendToTmpToksA{[}\relax
\expandafter\@mciteAppendToTmpToksA\expandafter{\mciteCiteOptArgI}\relax
\@mciteAppendToTmpToksA{]}\relax
\fi
\ifmciteMacroOptArgII
\@mciteAppendToTmpToksA{[}\relax
\expandafter\@mciteAppendToTmpToksA\expandafter{\mciteCiteOptArgII}\relax
\@mciteAppendToTmpToksA{]}\relax
\fi
\if@mciteCiteSecIDArg
\expandafter\@mciteAppendToTmpToksA\expandafter{\expandafter{\mciteCiteSecIDArg}}\relax
\fi
\expandafter\@mciteAppendToTmpToksA\expandafter{\expandafter{\mciteFwdCiteListArg}}\relax
\edef\@mciteCiteFwd{\the\@mcitetmptoksA}\relax
% forward to the "real" \cite
\@mciteCiteFwd}
% mciteplus engine
% processes cite list, records status of keys and writes tail (and head)
% citations to aux file
% list of heads is output to \mciteheadlist for forwarding to \cite
% usage: \mciteDoList{aux out}{track ID}{cite list}
% use noauxwrite for aux out to disable writes to aux
\def\mciteDoList#1#2#3{\edef\@mcitecurauxout{#1}\edef\@mcitecurtrackID{#2}\edef\@mcitetemp{#3}\relax
\expandafter\@mciteDoList\expandafter{\@mcitetemp}}
% flag to determine if mciteDoList should write to aux file
\newif\if@mciteDoListwriteaux \@mciteDoListwriteauxtrue
\def\@mciteMacronoauxwrite{noauxwrite}
\def\@mciteDoList#1{\let\@mcitecurhead\relax % reset current head
\@mciteDoListwriteauxtrue
% disable aux writes if aux parameter is "noauxwrite"
\ifx\@mcitecurauxout\@mciteMacronoauxwrite\@mciteDoListwriteauxfalse\fi
\@mcitefirstentrytrue\@mcitefirstheadentrytrue
\def\mciteheadlist{}\def\@mcitecurstatus{\relax}\relax
\@for\@mcitecurkey:=#1\do{\expandafter\@mciteCheckKey\@mcitecurkey\end\relax
% ignore empty keys
\ifx\@mcitecurkey\@empty
% warn about \nocite{*}
\if@mcitestarentry
\typeout{** WARNING: mciteplus: Wildcard `*' citation entry declared. BibTeX will add untracked entries to the bibliography.}\relax
% add * to the head list
\if@mcitefirstentry
\@mcitefirstentryfalse
\edef\mciteheadlist{*}\relax
\else
\edef\mciteheadlist{\mciteheadlist,*}\relax
\fi
\fi
\else % key is not empty
% get entry status
\@mciteGetEntryStatus*{\@mcitecurtrackID}{\@mcitecurkey}{\@mcitecurstatus}\relax
% if entry status is undefined, set status number code to undetermined and update \@mcitecurstatus
\ifx\@mcitecurstatus\relax
\@mciteSetEntryStatus{\@mcitecurtrackID}{\@mcitecurkey}{0}\relax
\@mciteGetEntryStatus{\@mcitecurtrackID}{\@mcitecurkey}{\@mcitecurstatus}\relax
\fi
\if@mcitestarentry % if declared to be a tail
\if@mcitefirstheadentry % tail cannot be declared until after a head
\PackageError{mciteplus}{Tail `\@mcitecurkey' is declared without a valid head}{You have to
declare a head citation before entering tail citations in cite list.}\relax
\fi
\ifnum\@mcitecurstatus>1\relax % cannot have been previously declared as a head
\PackageError{mciteplus}{Tail citation `\@mcitecurkey' has previously been declared as a head}{Declare
each citation entry as a head or a tail, but not both.}\relax
\fi
\if@mciteheadredeclared % the current head has been redeclared, OK with some restrictions
\ifnum\@mcitecurstatus=0\relax % cannot add new tails to previous group definitions
\PackageError{mciteplus}{New tail citation `\@mcitecurkey' cannot be added to the already existing
definition of group of head `\@mcitecurhead'}{You cannot define a group,
then reissue the head and add new tail citations.}\relax
\fi
\ifnum\@mcitecurstatus=1\relax % OK to respecify tails as long as they already belong to this group,
% this allows for overall (global) bibliographies
\@mciteGetHeadofTail{\@mcitecurtrackID}{\@mcitecurkey}{\@mciteheadofcurkey}\relax
\ifx\@mciteheadofcurkey\@mcitecurhead
% Note: We don't/can't catch the case of repeated tail declarations under a redeclared head.
% Not a mandatory error anyway.
\else
% tail cannot have been declared in definition of another group
\PackageError{mciteplus}{Tail citation `\@mcitecurkey' is not allowed in group of head
`\@mcitecurhead' as this tail has already been declared in group
of head `\@mciteheadofcurkey'}{You cannot have a tail citation
that appears in more than one citation group.}\relax
\fi
\fi
\else % head not redeclared
\ifnum\@mcitecurstatus=1\relax % the current head has not been declared before, so neither should any of its tails
\@mciteGetHeadofTail{\@mcitecurtrackID}{\@mcitecurkey}{\@mciteheadofcurkey}\relax
\ifx\@mciteheadofcurkey\@mcitecurhead
% tail cannot be declared twice in initial definition, this is an optional error
\PackageError{mciteplus}{Tail citation `\@mcitecurkey' has been declared more than once in
definition of group for head `\@mcitecurhead'}{Each tail
citation can only be specified once in the definition
of a group.}\relax
\else
% tail cannot have been declared in definition of another group
\PackageError{mciteplus}{Tail citation `\@mcitecurkey' is not allowed in group of head
`\@mcitecurhead' as this tail has already been declared in group
of head `\@mciteheadofcurkey'}{You cannot have a tail citation
that appears in more than one citation group.}\relax
\fi
\fi
\fi% end if head redeclared
% if not declared before, process as a valid tail
\ifnum\@mcitecurstatus=0\relax
% record type as tail
\@mciteSetEntryStatus{\@mcitecurtrackID}{\@mcitecurkey}{1}\relax
\@mciteGetEntryStatus{\@mcitecurtrackID}{\@mcitecurkey}{\@mcitecurstatus}\relax
% write out tail citation to aux as it will not be forwarded to \cite
\if@mciteDoListwriteaux
\@mcitewritecurkeytoaux
\fi
% record head for this tail
\@mciteSetHeadofTail{\@mcitecurtrackID}{\@mcitecurkey}{\@mcitecurhead}\relax
% change current head from code 3 (single) to 2 (one or more tails)
\@mciteSetEntryStatus{\@mcitecurtrackID}{\@mcitecurhead}{2}\relax
\fi
\else % is declared to be a head
\edef\@mcitecurhead{\@mcitecurkey}\relax % this is our new current head
% add to the head list
\if@mcitefirstentry
\@mcitefirstentryfalse
\edef\mciteheadlist{\@mcitecurkey}\relax
\else
\edef\mciteheadlist{\mciteheadlist,\@mcitecurkey}\relax
\fi
\@mcitefirstheadentryfalse
\ifnum\@mcitecurstatus=1\relax % cannot have previously been used as a tail
\@mciteGetHeadofTail{\@mcitecurtrackID}{\@mcitecurkey}{\@mciteheadofcurkey}\relax
\PackageError{mciteplus}{Head citation `\@mcitecurkey' has previously been declared
as a tail of `\@mciteheadofcurkey'}{Declare each citation
entry as a head or a tail, but not both.}\relax
\fi
\@mciteheadredeclaredfalse % assume not redeclared
\ifnum\@mcitecurstatus>1\relax % has already been declared?
\@mciteheadredeclaredtrue % OK, but do not allow any new future tails for this head
\fi
% if not declared before, set as a head, single. Will later change to code 2 if tails are found.
\if@mciteheadredeclared\else
\@mciteSetEntryStatus{\@mcitecurtrackID}{\@mcitecurkey}{3}\relax
\@mciteGetEntryStatus{\@mcitecurtrackID}{\@mcitecurkey}{\@mcitecurstatus}\relax
% write out head citation to aux.
% This will result in the entry appearing twice in the aux file as the
% entry will be part of the \mciteheadlist which will be forwarded to \cite.
% However, we need to write this out now to preserve the order of the citations.
\if@mciteDoListwriteaux
\@mcitewritecurkeytoaux
\fi
% this is the new current head
\let\@mcitecurhead\@mcitecurkey
\fi % fi not headredeclared
\fi % fi tail or head
% debug report
\if@OPTIONmcitedebug
\ifnum\@mcitecurstatus=1\relax
\edef\@mcitedebugheadoftail{Head of this tail: `\@mcitecurhead'}\relax
\else
\edef\@mcitedebugheadoftail{}\relax
\fi
\typeout{** Mciteplus Debug: Citation Entry: `\@mcitecurkey' TrackID: `\@mcitecurtrackID'
Auxout: \ifx\@mcitecurauxout\@mciteMacronoauxwrite `none (\@mciteMacronoauxwrite)' \else `\the\@mcitecurauxout' \fi
Status: `\@mciteStatusNumToWordH{\@mcitecurstatus}' \@mcitedebugheadoftail}\relax
\fi
% end debug report
\fi % only nonempty
}% end do loop
}
% hook to allow for a redo. Useful for global bibliographies
\def\mciteExtraDoLists{\relax}
% determines if an entry starts with an *, removes the * from the start of the entry name
% and sets \@mcitestarentry and \@mcitecurkey accordingly
\def\@mciteCheckKey#1#2\end{\@mcitestarentryfalse
\ifx*#1\@mcitestarentrytrue\edef\@mcitecurkey{#2}\relax
\else
\edef\@mcitecurkey{#1#2}%
\fi}
% writes current key citation to aux. We put this in a macro because some packages
% may fiddle with \if@filesw (making it a macro rather than an if), tripping up
% TeX's parser if \if@filesw is ever within another conditional as is the case
% within \@mciteDoList
\def\@mcitewritecurkeytoaux{\if@filesw\immediate\write\@mcitecurauxout{\string\citation{\@mcitecurkey}}\fi}
% custom \ref command displays \mcitesubrefform when
% \ref'd
% prefix to reference labels to avoid namespace clash
\def\@mcitereflabelprefix{MciteSubReferenceLabel}
\def\@mciteSetSubRefLabel{\begingroup\def\@currentlabel{\mcitesubrefform}\label{\@mcitereflabelprefix:\@mcitecurtrackID:\mciteBibitemArgI}\endgroup}
% default to using the actual sublist form.
\providecommand{\mcitesubrefform}{\arabic{mcitebibitemcount}.\alph{mcitesubitemcount}}
% give user access to sublist \ref and \pageref
% usage: \mciteSubRef[track ID]{cite key}
\def\mciteSubRef{\@ifnextchar[{\@mciteSubRef}{\@mciteSubRef[\mcitetrackID]}}
\def\@mciteSubRef[#1]#2{\ref{\@mcitereflabelprefix:#1:#2}}
\def\mciteSubPageRef{\@ifnextchar[{\@mciteSubPageRef}{\@mciteSubPageRef[\mcitetrackID]}}
\def\@mciteSubPageRef[#1]#2{\pageref{\@mcitereflabelprefix:#1:#2}}
% for debug, head of tail lookup
\def\@mcitecurheadlookup{}
% mciteplus version of \bibitem
% support the optional arg of \bibitem[]{} as well
\def\mcitebibitem{\@ifnextchar[{\global\mciteBibitemOptArgItrue\@mcitebibitem}%
{\global\mciteBibitemOptArgIfalse\@mcitebibitem[\relax]}}
\def\@mcitebibitem[#1]#2{\relax
% build the forwarding macro: \mciteOrgbibitem{#2} or \mciteOrgbibitem[#1]{#2}
\gdef\mciteBibitemOptArgI{#1}\gdef\mciteBibitemArgI{#2}\relax
\@mcitetmptoksA={\mciteOrgbibitem}\relax
\ifmciteBibitemOptArgI
\@mciteAppendToTmpToksA{[}\relax
\expandafter\@mciteAppendToTmpToksA\expandafter{\mciteBibitemOptArgI}\relax
\@mciteAppendToTmpToksA{]}\relax
\fi
\expandafter\@mciteAppendToTmpToksA\expandafter{\expandafter{\mciteBibitemArgI}}\relax
% build the command. we need a global def here so that the changes will persist in spite
% of a later closed sublist
\xdef\@mciteBibitemFwdMacroArgs{\the\@mcitetmptoksA}\relax
% on the very first \bibitem initialize the maxwidths
% we do this here so that the bibstyle can have its say on the forminit
\if@mcitefirstentry
\@mciteMaxWidthInitialize{bibitem}\relax
\@mciteMaxWidthInitialize{subitem}\relax
\fi
% get status of entry and process accordingly
\@mciteGetEntryStatus{\@mcitecurtrackID}{#2}{\@mcitecurstatus}\relax
% status get may happen inside a list, so make the changes to \@mcitecurstatus global
\global\let\@mcitecurstatus\@mcitecurstatus
% debug report
\if@OPTIONmcitedebug
\ifnum\@mcitecurstatus=1\relax
\@mciteGetHeadofTail{\@mcitecurtrackID}{\mciteBibitemArgI}{\@mcitecurheadlookup}\relax
\edef\@mcitedebugheadoftail{Head of this tail: `\@mcitecurheadlookup' (from citation), `\@mcitecurhead' (in bibliography)}\relax
\else
\edef\@mcitedebugheadoftail{}\relax
\fi
\typeout{** Mciteplus Debug: \string\mcitebibitem\space Entry: `\mciteBibitemArgI' TrackID: `\@mcitecurtrackID'
Status: `\@mciteStatusNumToWord{\@mcitecurstatus}' \@mcitedebugheadoftail}\relax
\fi
% end debug report
\ifnum\@mcitecurstatus=1\relax % if a tail
% error if a tail starts the bibliography
\if@mcitefirstentry
\PackageError{mciteplus}{Bibliography begins with a tail entry `\mciteBibitemArgI'}{For sorting
bibstyles, you must set the `mcitetail' BibTeX database field
for each tail entry and use a bibstyle that understands that field.}\relax
\fi
\mcitemidpunct\relax
% open sublist if needed
\if@mcitesublistmode
\if@mcitesublistopen\else
\global\@mcitesublistopentrue
\relax\mcitesublistbegin\relax
\fi
\relax\mcitesublistlabel\relax\@mciteSetSubRefLabel\relax\@mciteMaxWidthUpdate{subitem}\relax
\fi
\@mciteMaxCountUpdate
\addtocounter{mcitesubitemcount}{1}\relax
\else% is head
\if@mcitefirstentry\else\mciteendpunct\relax\mciteEndOfBibGroupPresubcloseHook\relax\fi
% close sublist if open
% watch out with variables as this will close off local changes
% addtocounter and setcounter make global changes
\if@mcitesublistopen
\mcitesublistend\relax
\global\@mcitesublistopenfalse
\fi
\relax\mciteEndOfBibGroupPostsubcloseHook\relax
% record current head key and argument info
\xdef\@mcitecurhead{#2}\relax
\gdef\mciteCurheadBibitemArgI{#2}\relax
\gdef\mciteCurheadBibitemOptArgI{#1}\relax
\ifmciteBibitemOptArgI\global\mciteCurheadBibitemOptArgItrue\else\global\mciteCurheadBibitemOptArgIfalse\fi
% note: with \mcitebibitem mcitebibitemcount advances with heads
% and holds the current head count until the next \mcitebibitem
% However, at the end of the \mcitebibitem, mcitesubitemcount
% is one more than the number of subitems as the label is
% rendered before updating the counter.
\setcounter{mcitesubitemcount}{1}\relax
\addtocounter{mcitebibitemcount}{1}\relax
\@mciteMaxCountUpdate
\if@mcitefirstentry\else\relax\mciteseppunct\relax\fi
\@mciteBibitemFwdMacroArgs\relax\relax\relax
% check and update the bibitem label width
\@mciteMaxWidthUpdate{bibitem}\relax
\ifnum\@mcitecurstatus=2\relax % if head with tails
\if@mcitesublistmodef
% open sublist if needed
\if@mcitesublistopen\else
\global\@mcitesublistopentrue
\mcitesublistbegin\relax
\fi
\relax\mcitesublistlabel\relax\@mciteSetSubRefLabel\relax\@mciteMaxWidthUpdate{subitem}\relax
\addtocounter{mcitesubitemcount}{1}\relax
\fi
\fi
\ifnum\@mcitecurstatus=3\relax % if head without tails
\if@mcitesublistmodeh
% open sublist if needed
\if@mcitesublistopen\else
\global\@mcitesublistopentrue
\mcitesublistbegin\relax
\fi
\relax\mcitesublistlabel\relax\@mciteSetSubRefLabel\relax\@mciteMaxWidthUpdate{subitem}\relax
\addtocounter{mcitesubitemcount}{1}\relax
\fi
\fi
\if@mcitesublistmodeb
\addtocounter{mcitesubitemcount}{1}\relax
\fi
\fi% if tail or head
\global\@mcitefirstentryfalse\ignorespaces}
% End of \bibitem marker from bibstyle
\def\EndOfBibitem{\relax}
% hook inserted at the end of bibitem group, before the sublist is closed
\def\mciteEndOfBibGroupPresubcloseHook{\relax}
% hook inserted at the end of bibitem group, after the sublist is closed
\def\mciteEndOfBibGroupPostsubcloseHook{\relax}
% hook inserted at \mcitethebibliography
\def\mcitethebibliographyHook{\relax}
% hook to allow insertion of custom code at end of mcitethebibliography
\def\mciteBIBdecl{\relax}
% hook to allow insertion of custom code at end of endmcitethebibliography
\def\mciteBIBenddecl{\relax}
% hook to allow insertion of custom code at end of thebibliography
\def\mcitefwdBIBdecl{\relax}
% Bibdecl for package hooks
\def\@mcitepkgBIBdecl{\relax}
% single use internal BIB hook, is automatically reset to \relax at end of \mcitethebibliography
\let\@mciteoneshotBIBdecl\relax
% mciteplus version of \thebibliography
\def\mcitethebibliography#1{\@mcitefirstentrytrue
\@mcitesublistopenfalse
\let\@mcitecurauxout\mcitebibauxout
\let\@mcitecurtrackID\mcitebibtrackID
\ifmciteResetBibitemCount\setcounter{mcitebibitemcount}{0}\fi
\setcounter{mcitesubitemcount}{0}\relax
\xdef\mciteorgbibsamplelabel{#1}\relax
% set these to something so that init forms that reference them won't choke
\gdef\mciteBibitemOptArgI{\relax}\relax
\gdef\mciteBibitemArgI{\relax}\relax
\global\mciteBibitemOptArgIfalse
\gdef\mciteCurheadBibitemOptArgI{\relax}\relax
\gdef\mciteCurheadBibitemArgI{\relax}\relax
\global\mciteCurheadBibitemOptArgIfalse
% note: pkg and user hooks may update tracking ID
\relax\@mcitepkgBIBdecl\relax
\relax\@mciteoneshotBIBdecl\relax
\relax\mciteBIBdecl\relax
\@mciteMaxCountInitialize
% we initialize here to get a valid \mcitemaxwidthbibitem for \mcitebibsamplelabel
% but we will reinitialize again at the first \bibitem so that any BST changes can take affect
\@mciteMaxWidthInitialize{bibitem}\relax
% debug report
\if@OPTIONmcitedebug
\typeout{}\typeout{}\relax
\typeout{** Mciteplus Debug: \string\mcitethebibliography\space TrackID: `\@mcitecurtrackID' Auxout: `\the\@mcitecurauxout'}\relax
\fi
% end debug report
\thebibliography{\mcitebibsamplelabel}\relax
\mcitethebibliographyHook\relax
\relax\mcitefwdBIBdecl\relax
\let\mciteOrgbibitem\bibitem
\def\bibitem{\mcitebibitem}}
\def\endmcitethebibliography{\mciteendpunct\relax
\relax\mciteEndOfBibGroupPresubcloseHook\relax
% close sublist if open
\if@mcitesublistopen
\mcitesublistend\relax
\@mcitesublistopenfalse
\fi
\relax\mciteEndOfBibGroupPostsubcloseHook\relax
\relax\mciteBIBenddecl\relax
% globally clear oneshot decl
\global\let\@mciteoneshotBIBdecl\relax
% restore original \bibitem as some \endthebibliography tack notes at the end (e.g., REVTeX)
% we'll add them to the count with mcite's counters and continue to track the bibitem width
\setcounter{mcitesubitemcount}{1}\relax
\def\bibitem{\addtocounter{mcitebibitemcount}{1}\@mciteMaxWidthUpdate{bibitem}\relax\mciteOrgbibitem}
\endthebibliography\relax
% update max count for possible \endthebibliography tack notes
\@mciteMaxCountUpdate
% write correct max counter to aux and warn if changed
\@mciteMaxCountAuxWrite
% write correct max widths to aux and warn if changed
\@mciteMaxWidthAuxWrite
% debug report
\if@OPTIONmcitedebug
\typeout{}\relax
\typeout{** Mciteplus Debug: \string\endmcitethebibliography^^J
Current Max bibitem count: `\mcitemaxcountbibitem'^^J
Correct Max bibitem count: `\arabic{mcitebibitemcount}'^^J^^J
Current Max subitem count: `\mcitemaxcountsubitem'^^J
Correct Max subitem count: `\@mcitecorrectmaxcountsubitem'^^J^^J
Current Max bibitem width: `\mcitemaxwidthbibitem'(sp)^^J
Correct Max bibitem width: `\@mcitecorrectmaxwidthbibitem'(sp)^^J^^J
Current Max subitem width: `\mcitemaxwidthsubitem'(sp)^^J
Correct Max subitem width: `\@mcitecorrectmaxwidthsubitem'(sp)}^^J