-
Notifications
You must be signed in to change notification settings - Fork 37
/
backref.dtx
959 lines (959 loc) · 28 KB
/
backref.dtx
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
% \iffalse
%% File: backref.dtx
%% Copyright (C) 1995-2000 David Carlisle, Sebastian Rahtz, Heiko Oberdiek
%% 2001-2012 Heiko Oberdiek
%% 2016-2019 Oberdiek Package Suport Group
%% 2019-2024 The LaTeX Project
%% https://github.com/latex3/hyperref/issues
%%
%% This file is part of the `Hyperref Bundle'.
%% -------------------------------------------
%%
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%% http://www.latex-project.org/lppl.txt
%% and version 1.3 or later is part of all distributions of LaTeX
%% version 2005/12/01 or later.
%%
%% This work has the LPPL maintenance status `maintained'.
%%
%% The Current Maintainer of this work is The LaTeX Project.
%%
%% The list of all files belonging to the `Hyperref Bundle' is
%% given in the file `manifest.txt'.
%
%<*dtx>
\ProvidesFile{backref.dtx}
%</dtx>
%<package>\NeedsTeXFormat{LaTeX2e}
%<package>\ProvidesPackage{backref}
%<driver>\ProvidesFile{backref.drv}
% \fi
% \ProvidesFile{backref.dtx}
[2023-11-26 v1.44 Bibliographical back referencing]%
%
%
% \iffalse
%<*driver>
\PassOptionsToPackage{numbered}{hypdoc}
\documentclass{ltxdoc}
\usepackage[numbered]{hypdoc}
\usepackage{bmhydoc}
\usepackage{backref}
\EnableCrossrefs
\CodelineIndex
\begin{document}
\GetFileInfo{backref.sty}%
\title{%
Back referencing from bibliographical citations%
\thanks{%
This file has version number \fileversion, %
last revised \filedate.%
}%
}%
\author{David Carlisle and Sebastian Rahtz (deceased)\thanks{\url{https://github.com/latex3/hyperref/issues}}}%
\date{\filedate}%
\maketitle
\makeatletter
\@ifundefined{HyperrefOverview}{}{%
\HyperrefOverview*%
}%
\tableofcontents
\DocInput{backref.dtx}%
\PrintIndex
\end{document}
%</driver>
% \fi
%
% \MakeShortVerb{|}
%
% \section{Introduction}
%
% \section{Usage}
%
% \subsection{Options}
%
% The supported options are given as package options.
% Few options (e.g. |verbose|, |enable|, |disable|)
% can be changed after the package is loaded by
% the macro \cs{backrefsetup}, e.g.:
% \begin{quote}
%\begin{verbatim}
%\usepackage[verbose]{backref}
%\backrefsetup{verbose=false}
%\end{verbatim}
% \end{quote}
% This macro is available since version 2012/07/24 v1.37.
%
% \subsubsection{Options for type of back references}
%
% In short the following options set the type of back
% references. Default is option |pageref|.
% \begin{quote}
% \begin{tabular}{@{}ll@{}}
% |ref| & section number\\
% |pageref| & page number\\
% |hyperref| & section number as hyper link\\
% |hyperpageref| & page number as hyper link
% \end{tabular}
% \end{quote}
% The options that start with |hyper| are intended for
% the use with package |hyperref|. In this case package
% |backref| will be loaded automatically if the |hyperref|
% options |backref| or |pagebackref| are given. Package
% |hyperref| then loads package |backref| with the appropriate
% option:
% \begin{quote}
% \begin{tabular}{@{}ll@{}}
% |hyperref| option & |backref| option set by |hyperref|\\
% \hline
% |backref| & |hyperref|\\
% |backref=section| & |hyperref|\\
% |backref=slide| & |hyperref|\\
% |backref=page| & |hyperpageref|\\
% |pagebackref| & |hyperpageref|
% \end{tabular}
% \end{quote}
%
% \subsubsection{Language options}
%
% Currently supported options are |english| (|american|, |australian|,
% |british|, |canadian|, |newzealand|, |UKenglish|, |USenglish|),
% |german| (|ngerman|, |austrian|, |naustrian|),
% |french| (|acadian|, |canadien|, |frenchb|, |francais|),
% |spanish|, and |brazil| (|brazilian|).
% Default is |english|.
%
% \subsubsection{Other options}
%
% \begin{description}
% \item[|verbose|:]
% A message is written into the |.aux| file for each
% reference that is found for back citing.
% \item[|enable|, |disable|:]
% If a citation should not be back cited, then
% the recording can be turned off by option |disable|
% and enabled again afterwards, e.g.:
% \begin{quote}
%\begin{verbatim}
%\backrefsetup{disable}\cite{...}\backrefsetup{enable}
%\end{verbatim}
% or
%\begin{verbatim}
%\backrefsetup{disable}\listoffigures \backrefsetup{enable}
%\end{verbatim}
% \end{quote}
% Both options are added in version 2012/07/24 v1.37.
% \end{description}
%
% \subsection{Detecting the end of a bibliography entry}
%
% Package |backref| has to be able to detect the end of an entry
% in the bibliography, therefore each \cmd{\bibitem} entry must
% be ended by an empty line (or a |\par| token).
% \nopagebreak
%
% Example:
%\begin{quote}
%\begin{verbatim}
%\begin{thebibliography}{9}
%\bibitem[bib:abc] First entry.
%
%\bibitem[bib:foo] Second entry.
%
%\end{thebibliography}
%\end{verbatim}
%\end{quote}
% Then package |backref| can automatically add hooks
% for the back references list at the end of the entries.
%
% \DescribeMacro{\backrefparscanfalse}
% \DescribeMacro{\backrefparscantrue}
% Sometimes it is not appropriate if the entry is read as
% argument. For example, catcode changes for verbatim stuff
% do not have the desired effect. Therefore the scan for
% the \cs{par} token can be disabled by \cs{backrefparscanfalse}
% before \cs{bibitem} and enabled by \cs{backrefparscantrue}
% afterwards.
%
% \DescribeMacro{\backrefprint}
% If the scan for the end of the entry is disabled, then package
% |backref| does not know where to put the back references
% list. The list is printed by the macro \cs{backrefprint}, thus
% just call it at the right place. Example:
%\begin{quote}
%\begin{verbatim}
%\backrefparscanfalse % disable scan for entry ending
%\bibitem[...]{...}
% ... \verb|...| ... % potentially dangerous stuff
% ... \url{...} ...
% \backrefprint % print back reference list here
%\backrefparscantrue % enable scan again
%\end{verbatim}
%\end{quote}
%
% \subsection{Formatting of the back references list}
%
% The back references list is separated from the entry
% by \cmd{\newblock},
% if the used bibliography package supports this. The package options
% control the kind of back references (page numbers, sections numbers),
% whereas the hooks control the formatting.
%
% There are two hooks \cmd{\backref} and a new hook \cmd{\backrefalt},
% available since version 1.21 of package |backref|. The former one
% is enabled by default.
%
% \subsubsection{Formatting hook \cs{backref}}
%
% Macro \cmd{\backref} has a a comma separated
% list of backref references as first and only argument.
% With hyperref options only this list will be printed. Without
% hyperref there is an introductionary text, controlled by
% macros \cmd{\backrefpagesname} or \cmd{\backrefsectionsname}.
%
% \subsubsection{Formatting hook \cs{backrefalt}}
%
% \cmd{\backrefalt} is a new interface since version 1.21 of package
% |backref|. It takes four arguments:
% \begin{enumerate}
% \item Number of citations without dupes.
% \item Back references list without dupes.
% \item Number of all citations (with dupes).
% \item Back reference list with all entries (with dupes).
% \end{enumerate}
% The latter options consider equal entries as one entry.
% Now \cmd{\backrefalt} can easily be defined with text that
% depends on the number of citations, for example:
%\begin{quote}
%\begin{verbatim}
%\usepackage[backref]{backref}
%\renewcommand*{\backref}[1]{}% for backref < 1.33 necessary
%\renewcommand*{\backrefalt}[4]{%
% \ifcase #1 %
% No citations.%
% \or
% One citation in section #2.%
% \else
% #1 citations in sections #2.%
% \fi
%}
%\end{verbatim}
%\end{quote}
% The separation between the list entries are controlled by
% the following macros:
% \begin{itemize}
% \item \cmd{\backrefsep}: inserted between entries except for the
% next cases, default is ``\verb*|, |''.
% \item \cmd{\backreftwosep}: inserted between entries in
% a list of two entries, default is ``\verb*| and~|''.
% \item \cmd{\backreflastsep}: inserted between the last two
% entries of a list with more than two entries, default is
% ``\verb*|, and~|''.
% \end{itemize}
% Examples:
% \begin{quote}
% \meta{entry1}\\
% \meta{entry1} \cmd{\backreftwosep} \meta{entry2}\\
% \meta{entry1} \cmd{\backrefsep} \meta{entry2}
% \cmd{\backreflastsep} \meta{entry3}
% \end{quote}
% Since version 1.33 it is not necessary to redefine
% \backref, it is automatically disabled if \backrefalt
% is redefined.
%
% \subsubsection{Refinement \cs{backrefentrycount}}
%
% Since version 1.33 the entries of the distinct list of
% interface \cs{backrefalt} are wrapped in
% \cs{backrefentrycount}. The macro is called with two
% arguments. The first is the backref entry and the second
% one the citation count of this entry. As default the
% macro passes the first argument through and ignores the
% count argument. But it can be redefined, e.g.
%\begin{quote}
%\begin{verbatim}
%\renewcommand*{\backrefalt}[4]{...}% see above
%\renewcommand*{\backrefentrycount}[2]{%
% #1%
% \ifnum#2>1 %
% ~(#2)%
% \fi
%}
%\end{verbatim}
%\end{quote}
% In case of duplicates, the distinct entry is
% appended by the number of citations in parentheses.
%
% \StopEventually{}
%
% \section{The macros}
% Internal command names of this package start with |\BR@|,
% commands, that store the original meaning of commands, which
% will be redefined, are prefixed with |\BRorg@|.
%
% \subsection{Package identification}
% \begin{macrocode}
%<*package>
% \end{macrocode}
%
% \subsection{Options}
%
% \begin{macrocode}
\RequirePackage{kvoptions}[2011/06/30]
\RequirePackage{kvsetkeys}[2009/07/30]
\SetupKeyvalOptions{%
family=backref,%
prefix=BR@,%
}
% \end{macrocode}
% \begin{macro}{\backrefsetup}
% \begin{macrocode}
\newcommand*{\backrefsetup}{\kvsetkeys{backref}}
% \end{macrocode}
% \end{macro}
%
% \subsubsection{Option verbose}
% If package hyperref is loaded, then its setting is used as
% default for the verbose switch.
% \begin{macrocode}
\DeclareBoolOption[%
\@ifundefined{ifHy@verbose}{%
false%
}{%
\ifx\ifHy@verbose\iftrue true\else false\fi
}%
]{verbose}
% \end{macrocode}
%
% \subsubsection{Options for way of working}
%
% What is printed depends on how the 3 available items of
% information are used (page number, section number, label).
% \begin{macrocode}
\long\def\page@backref#1#2#3{#1}
\long\def\section@backref#1#2#3{#2}
\long\def\hyper@section@backref#1#2#3{\hyperlink{#3}{#2}}
\long\def\hyper@page@backref#1#2#3{\hyperlink{page.#1}{#1}}
% \end{macrocode}
% Now the options follows, that can be used without
% package hyperref.
% \begin{macrocode}
\DeclareVoidOption{pageref}{%
\def\backref{\backrefpagesname\ }%
\let\backrefxxx\page@backref
}
\DeclareVoidOption{ref}{%
\def\backref{\backrefsectionsname\ }%
\let\backrefxxx\section@backref
}
% \end{macrocode}
% Set up back-referencing to be hyper links, by page or section.
% \begin{macrocode}
\DeclareVoidOption{hyperref}{%
\def\backref{}\let\backrefxxx\hyper@section@backref
}
\DeclareVoidOption{hyperpageref}{%
\def\backref{}\let\backrefxxx\hyper@page@backref
}
% \end{macrocode}
% Recording the back references in the auxiliary file can
% be enabled and disabled by the following options.
% \begin{macrocode}
\DeclareBoolOption[true]{enable}
\DeclareComplementaryOption{disable}{enable}
% \end{macrocode}
%
% \subsubsection{Language options}
%
% \begin{macrocode}
\def\backrefenglish{%
\def\backrefpagesname{pages}%
\def\backrefsectionsname{sections}%
\def\backrefsep{, }%
\def\backreftwosep{ and~}%
\def\backreflastsep{, and~}%
}
\def\backrefgerman{%
\def\backrefpagesname{Seiten}%
\def\backrefsectionsname{Abschnitte}%
\def\backrefsep{, }%
\def\backreftwosep{ und~}%
\def\backreflastsep{ und~}%
}
\def\backreffrench{%
\def\backrefpagesname{pages}%
\def\backrefsectionsname{sections}%
\def\backrefsep{, }%
\def\backreftwosep{ et~}%
\def\backreflastsep{ et~}%
}
\def\backrefspanish{%
\def\backrefpagesname{p\'aginas}%
\def\backrefsectionsname{secciones}%
\def\backrefsep{, }%
\def\backreftwosep{ y~}%
\def\backreflastsep{ y~}%
}
\def\backrefbrazil{%
\def\backrefpagesname{p\'aginas}%
\def\backrefsectionsname{se\c c\~oes}%
\def\backrefsep{, }%
\def\backreftwosep{ e~}%
\def\backreflastsep{ e~}%
}
\def\backrefafrikaans{%
\def\backrefpagesname{bladsye}%
\def\backrefsectionsname{afdelings}%
\def\backrefsep{, }%
\def\backreftwosep{ en~}%
\def\backreflastsep{ en~}%
}
\def\backrefitalian{%
\def\backrefpagesname{pagine}%
\def\backrefsectionsname{sezioni}%
\def\backrefsep{, }%
\def\backreftwosep{ e~}%
\def\backreflastsep{ e~}%
}%
% \end{macrocode}
% Instead of package babel's definition of \cmd{\addto} the
% implementation of package varioref is used. Additionally
% argument |#1| is checked for \cmd{\relax}.
% \begin{macrocode}
\def\BR@addto#1#2{%
#2%
\@temptokena{#2}%
\ifx#1\relax
\let#1\@empty
\fi
\ifx#1\@undefined
\edef#1{\the\@temptokena}%
\else
\toks@\expandafter{#1}%
\edef#1{\the\toks@\the\@temptokena}%
\fi
\@temptokena{}\toks@\@temptokena
}
% \end{macrocode}
% \begin{macrocode}
\def\BR@DeclareLang#1#2{%
\begingroup
\edef\x##1##2{%
\noexpand\ifx##2\relax
\errmessage{No definitions for language `#2' found!}%
\noexpand\fi
\endgroup
\noexpand\DeclareVoidOption{#1}{%
\noexpand\BR@addto{\noexpand##1}{\noexpand##2}%
}%
}%
\expandafter\x\csname extras#1\expandafter\endcsname
\csname backref#2\expandafter\endcsname
}
\BR@DeclareLang{english}{english}
\BR@DeclareLang{american}{english}
\BR@DeclareLang{australian}{english}
\BR@DeclareLang{british}{english}
\BR@DeclareLang{canadian}{english}
\BR@DeclareLang{newzealand}{english}
\BR@DeclareLang{UKenglish}{english}
\BR@DeclareLang{USenglish}{english}
\BR@DeclareLang{german}{german}
\BR@DeclareLang{ngerman}{german}
\BR@DeclareLang{austrian}{german}
\BR@DeclareLang{naustrian}{german}
\BR@DeclareLang{french}{french}
\BR@DeclareLang{acadian}{french}
\BR@DeclareLang{canadien}{french}
\BR@DeclareLang{frenchb}{french}
\BR@DeclareLang{francais}{french}
\BR@DeclareLang{spanish}{spanish}
\BR@DeclareLang{brazil}{brazil}
\BR@DeclareLang{brazilian}{brazil}
\BR@DeclareLang{afrikaans}{afrikaans}
\BR@DeclareLang{italian}{italian}
% \end{macrocode}
% Default is the english version:
% \begin{macrocode}
\backrefenglish
% \end{macrocode}
%
% \subsubsection{Process options}
%
% \begin{macrocode}
\backrefsetup{pageref}
\ProcessKeyvalOptions*
% \end{macrocode}
%
% \begin{macro}{\BR@DisableOption}
% \begin{macrocode}
\def\BR@DisableOption#1{%
\DisableKeyvalOption[%
action=warning,%
package=backref,%
]{backref}{#1}%
}
% \end{macrocode}
% \end{macro}
% \begin{macrocode}
\BR@DisableOption{ref}
\BR@DisableOption{pageref}
\BR@DisableOption{hyperref}
\BR@DisableOption{hyperpageref}
% \end{macrocode}
%
% \subsection{The bibliography}
%
% \begin{macro}{\ifbackrefparscan}
% \begin{macrocode}
\newif\ifbackrefparscan
\backrefparscantrue
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ifBR@BackrefAlt}
% \begin{macrocode}
\newif\ifBR@BackrefAlt
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\BR@bibitem}
% \begin{macrocode}
\def\BR@bibitem{%
\ifbackrefparscan
\expandafter\@ifnextchar\expandafter[\expandafter
\BR@@lbibitem\expandafter\BR@@bibitem
\else
\expandafter\@ifnextchar\expandafter[\expandafter
\BR@@@lbibitem\expandafter\BR@@@bibitem
\fi
}
% \end{macrocode}
% \end{macro}
% \begin{macrocode}
\def\BR@@lbibitem[#1]#2#3\par{%
\let\backrefprint\BR@backrefprint
\BRorg@bibitem[{#1}]{#2}#3%
\BR@backref{#2}%
}%
\def\BR@@bibitem#1#2\par{%
\let\backrefprint\BR@backrefprint
\BRorg@bibitem{#1}#2%
\BR@backref{#1}%
}
\def\BR@@@lbibitem[#1]#2{%
\def\backrefprint{\BR@backref{#2}}%
\BRorg@bibitem[{#1}]{#2}%
}
\def\BR@@@bibitem#1{%
\def\backrefprint{\BR@backref{#1}}%
\BRorg@bibitem{#1}%
}
\def\BR@backrefprint{%
\PackageError{backref}{%
\string\backrefprint\space is only available after \string\bibitem
\MessageBreak
with setting \string\backrefparscanfalse
}\@ehc
}
\let\backrefprint\BR@backrefprint
\def\BR@backref#1{%
\newblock
\begingroup
\csname @safe@activestrue\endcsname
\expandafter\providecommand\csname brc@#1\endcsname{0}%
\expandafter\providecommand\csname brcd@#1\endcsname{0}%
\csname @safe@activesfalse\expandafter\endcsname
\ifBR@BackrefAlt
\ifx\backrefentrycount\BR@BackrefEntryCountUnused
\else
\BR@PopulateEntryCount{#1}%
\fi
\expandafter\backrefalt\csname brc@#1\expandafter\endcsname
\csname brl@#1\expandafter\endcsname
\csname brcd@#1\expandafter\endcsname
\csname brld@#1\endcsname
\else
\expandafter\backref\csname br@#1\expandafter\endcsname
\fi
\endgroup
\par
}
\@ifundefined{newblock}{\def\newblock{\par}}{}
\let\BR@Unused\@empty
\def\BR@BackrefAltUnused#1#2#3#4{\BR@Unused}
\@ifundefined{backrefalt}{%
\let\backrefalt\BR@BackrefAltUnused
}{}
\def\BR@BackrefEntryCountUnused#1#2{\BR@Unused#1}
\@ifundefined{backrefentrycount}{%
\let\backrefentrycount\BR@BackrefEntryCountUnused
}{}
% \end{macrocode}
%
% \subsection{Reading .brf file}
%
% \begin{macro}{\backcite}
% The file |\jobname.brf| collects the back cite informations
% as calls of \cmd{\backcite} with the informations
% in the arguments.
%
% The first argument of macro \cmd{\backcite} is the citation
% label, the second parameter contains the page number
% (\cmd{\thepage}), the current label of the citation
% (\cmd{\@currentlabel}), and the current anchor name
% (\cmd{\@currentHref}). Example for a citation at the
% first page in second section:
%\begin{verbatim}
%\backcite {bib:abc}{{1}{2}{section.2}}
%\end{verbatim}
%
% While the file |\jobname.brf| is read, the informations are
% collected and stored in macros whose names are build by the
% citation label \meta{label}:
% \begin{quote}
% \begin{tabular}{@{}ll@{}}
% |\br@|\meta{label} & list, entries separated by comma without dupes\\
% |\brc@|\meta{label} & number of citations without dupes\\
% |\brl@|\meta{label} & backref list without dupes\\
% |\brcd@|\meta{label} & number of all citations (with dupes)\\
% |\brld@|\meta{label} & backref list with all entries (with dupes)
% \end{tabular}
% \end{quote}
% What are ``dupes''? An instance: you have three references to
% an entry in the bibliography on the first page:
%\begin{verbatim}
%\backcite {bib:abc}{{1}{1}{section.1}}
%\backcite {bib:abc}{{1}{1}{section.1}}
%\backcite {bib:abc}{{1}{2}{section.2}}
%\end{verbatim}
% Then the whole backref list with option |pageref| would print, e.g.:
% \begin{quote}
% Entry for |bib:abc|. Cited on pages 1, 1, 1.
% \end{quote}
% Without dupes the entries with the same page number would be removed,
% e.g.:
% \begin{quote}
% Entry for |bib:abc|. Cited on page 1.
% \end{quote}
% Also the third entry is removed, because it has the same page number.
% For the comparison only these pieces of information are considered
% that will be used later by \cmd{\backrefxxx}. With option
% |pageref| macro \cmd{\backrefxxx} becomes \cmd{\page@backref} that
% throws away the second and third argument and only uses the first
% argument with the page number. To be more precise, the first
% expansion of \cmd{\backrefxxx} is used in comparison. If some
% arguments are used here, but later omitted, then this will not
% be detected.
%
% \begin{macro}{\backrefxxxdupe}
% With option |hyperref| you will get two entries
% in the following example because the second entry differs in the
% link information, so the result will be the same section number,
% but as different links.
%\begin{verbatim}
%\backref {bib:abc}{{1}{1}{section.1}}
%\backref {bib:abc}{{1}{1}{equation.1}}
%\end{verbatim}
% Macro \cmd{\backrefxxxdupe} will be used
% in the comparison test if it is defined. Thus you can provide a
% definition in this case as follows:
%\begin{verbatim}
%\newcommand*{\backrefxxxdupe}[3]{#2}
%\end{verbatim}
% Then only the section number is interpreted, but not the anchor name.
% \end{macro}
%
% To avoid same entries, it is checked before, whether the entry
% already exists. Only the information needed by \cmd{\backrefxxx}
% is compared.
% \begin{macrocode}
\def\backcite#1#2{%
\@for\x:=#1\do{%
\begingroup
\csname @safe@activestrue\endcsname
\edef\x{\endgroup
\def\noexpand\x{\expandafter\@firstofone\x\@empty}%
}%
\x
% \end{macrocode}
% Now macro \cmd{\x} contains the citation label name.
% \begin{macrocode}
\expandafter\ifx\csname br@\x\endcsname\relax
% \end{macrocode}
% Initialization, fill in the first entry.
% \begin{macrocode}
\expandafter\protected@xdef\csname br@\x\endcsname{%
\protect\backrefxxx#2%
}%
\ifBR@BackrefAlt
\global\expandafter\let\csname brl@\x\expandafter\endcsname
\csname br@\x\endcsname
\global\expandafter\let\csname brld@\x\expandafter\endcsname
\csname br@\x\endcsname
\expandafter\gdef\csname brc@\x\endcsname{1}%
\expandafter\gdef\csname brcd@\x\endcsname{1}%
\fi
\else
% \end{macrocode}
% Fill in further entry. But check for dupe first.
% \begin{macrocode}
\begingroup
\@ifundefined{backrefxxxdupe}{}{\let\backrefxxx\backrefxxxdupe}%
\expandafter\def\expandafter\reserved@a\expandafter{%
\backrefxxx#2%
}%
\let\BRorg@backrefxxx\backrefxxx
\global\let\BR@found=N%
\long\def\backrefxxx##1##2##3{%
\expandafter\def\expandafter\reserved@b\expandafter{%
\BRorg@backrefxxx{##1}{##2}{##3}%
}%
\ifx\reserved@a\reserved@b
\global\let\BR@found=Y%
\fi
}%
\setbox\@tempboxa\hbox{\csname br@\x\endcsname}%
\endgroup
\let\backrefsep\relax
\def\backreftwosep{\backrefsep}%
\def\backreflastsep{\backrefsep}%
\if N\BR@found
\expandafter\protected@xdef\csname br@\x\endcsname{%
\csname br@\x\endcsname, %
\protect\backrefxxx#2%
}%
\ifBR@BackrefAlt
\expandafter\protected@xdef\csname brl@\x\endcsname{%
\csname brl@\x\endcsname
\ifnum\@nameuse{brc@\x}=1 %
\noexpand\backreftwosep
\else
\noexpand\backreflastsep
\fi
\protect\backrefxxx#2%
}%
\count@=\@nameuse{brc@\x}\relax
\advance\count@ by 1 %
\expandafter\xdef\csname brc@\x\endcsname{\the\count@}%
\fi
\fi
\ifBR@BackrefAlt
\expandafter\protected@xdef\csname brld@\x\endcsname{%
\csname brld@\x\endcsname
\ifnum\@nameuse{brcd@\x}=1 %
\noexpand\backreftwosep
\else
\noexpand\backreflastsep
\fi
\protect\backrefxxx#2%
}%
\count@=\@nameuse{brcd@\x}\relax
\advance\count@ by 1 %
\expandafter\xdef\csname brcd@\x\endcsname{\the\count@}%
\fi
\fi
}%
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\BR@PopulateEntryCount}
% \begin{macrocode}
\def\BR@PopulateEntryCount#1{%
\begingroup
\toks@{}%
\def\backrefsep{%
\toks@\expandafter{\the\toks@\backrefsep}%
}%
\def\backreftwosep{%
\toks@\expandafter{\the\toks@\backreftwosep}%
}%
\def\backreflastsep{%
\toks@\expandafter{\the\toks@\backreflastsep}%
}%
\def\protect{}%
\let\BR@backrefxxx\backrefxxx
\let\backrefxxx\BR@PopulateBackrefxxx
\def\BR@name{#1}%
\csname brl@#1\endcsname
\expandafter\xdef\csname brl@#1\endcsname{\the\toks@}%
\endgroup
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\BR@PopulateBackrefxxx}
% \begin{macrocode}
\def\BR@PopulateBackrefxxx#1#2#3{%
\expandafter\def\expandafter\BR@tempa\expandafter{%
\BR@backrefxxx{#1}{#2}{#3}%
}%
\begingroup
\count@=\z@
\def\backrefsep{}%
\def\backreftwosep{}%
\def\backreflastsep{}%
\let\backrefxxx\BR@@PopulateBackrefxxx
\csname brld@\BR@name\endcsname
\toks\tw@={\backrefxxx{#1}{#2}{#3}}%
\edef\x{\endgroup
\toks@{%
\the\toks@
\noexpand\backrefentrycount{%
\the\toks\tw@
}{\the\count@}%
}%
}%
\x
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\BR@@PopulateBackrefxxx}
% \begin{macrocode}
\def\BR@@PopulateBackrefxxx#1#2#3{%
\expandafter\def\expandafter\BR@tempb\expandafter{%
\BR@backrefxxx{#1}{#2}{#3}%
}%
\ifx\BR@tempa\BR@tempb
\advance\count@\@ne
\fi
}
% \end{macrocode}
% \end{macro}
%
% \subsection{Initialization}
%
% \begin{macrocode}
\def\@currentHref{}
\AtBeginDocument{%
\let\BRorg@bibitem\bibitem
\let\bibitem\BR@bibitem
\let\BRorg@thebibliography\thebibliography
\def\thebibliography{%
\BR@starttoc
\BRorg@thebibliography
}%
\@ifundefined{NAT@parse}{%
\global\let\BRorg@citex\@citex
\global\let\@citex\BR@citex
}{%
\@ifpackageloaded{hyperref}{}{%
\def\hyper@natlinkstart#1{\Hy@backout{#1}}%
}%
\PackageInfo{backref}{** backref set up for natbib **}%
}%
}
% \end{macrocode}
% \begin{macro}{\BR@starttoc}
% \begin{macrocode}
\def\BR@starttoc{%
\ifx\backrefalt\BR@BackrefAltUnused
\global\BR@BackrefAltfalse
\else
\global\BR@BackrefAlttrue
\fi
\begingroup
\makeatletter
\@input{\jobname.brf}%
\if@filesw
\@ifundefined{tf@brf}{%
\expandafter\newwrite\csname tf@brf\endcsname
}{}%
\@ifundefined{tf@brf@open}{%
\BR@RerunFileCheck
\immediate\openout\csname tf@brf\endcsname\jobname.brf\relax
\gdef\tf@brf@open{}%
}{}%
\fi
\@nobreakfalse
\endgroup
}
% \end{macrocode}
% \end{macro}
%
% \subsection{Collecting back cite informations}
%
% \begin{macro}{\BR@citex}
% \begin{macrocode}
\def\BR@citex[#1]#2{%
\BRorg@citex[{#1}]{#2}%
\Hy@backout{#2}%
}
% \end{macrocode}
% \end{macro}
%
% Grr. for chicago.sty
% \begin{macrocode}
\@ifpackageloaded{chicago}{%
\let\BRorg@citedatax\@citedatax
\def\@citedatax[#1]#2{%
\BRorg@citedatax[{#1}]{#2}%
\Hy@backout{#2}%
}%
}{}
% \end{macrocode}
% \begin{macro}{\Hy@backout}
% \begin{macrocode}
\def\Hy@backout#1{%
\@bsphack
\ifBR@enable
\ifBR@verbose
\PackageInfo{backref}{Back cite \string`#1\string'}%
\fi
\ifx\@empty\@currentlabel
\protected@write\@auxout{}{%
\string\@writefile{brf}{%
\string\backcite{#1}{{\thepage}{(document)}{Doc-Start}}%
}%
}%
\else
\protected@write\@auxout{}{%
\string\@writefile{brf}{%
\string\backcite{#1}{{\thepage}{\@currentlabel}{\@currentHref}}%
}%
}%
\fi
\else
\ifBR@verbose
\PackageInfo{backref}{Disabled back cite \string`#1\string'}%
\fi
\fi
\@esphack
}
% \end{macrocode}
% \end{macro}
%
% \subsection{Rerun warning}
%
% \begin{macro}{\BR@RerunFileCheck}
% The following code computes a MD5 sum and the file size of the
% |.brf| file at the begin and the end of the document and compares
% them. A rerun warning is given, if they do not match.
% This method requires pdf\TeX\ or Lua\TeX. The method fails,
% if the MD5 sum and the file size are the same for
% a changed |.brf| file (it's probably very seldom).
% \begin{macrocode}
\RequirePackage{rerunfilecheck}[2009/12/10]
\def\BR@RerunFileCheck{%
\RerunFileCheck{\jobname.brf}{%
\@ifundefined{tf@brf@open}{%
}{%
\immediate\closeout\tf@brf
}%
}{%
Rerun to get bibliographical references right%
}%
}
% \end{macrocode}
% \end{macro}
%
% \begin{macrocode}
%</package>
% \end{macrocode}
%
% \Finale
%
\endinput