summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/biblatex-ext/biblatex-ext-tabular.sty
blob: 993a5f94284a8a9c3918524cecd3a3afff18e821 (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
\ProvidesPackage{biblatex-ext-tabular}
  [2019/01/11 v0.6b tabular bibliographies for biblatex (MW)]

% Code based on Audrey's (https://tex.stackexchange.com/users/4483/audrey)
% answer https://tex.stackexchange.com/a/71454/35864 on TeX.SX
% relicensed under CC0, see
% https://tex.meta.stackexchange.com/a/1755/35864
% ultimately based on LPPL code from biblatex.sty
% Additional modifications by me in
% https://tex.stackexchange.com/a/440356/35864

\protected\def\extblxtab@error#1#2{%
  \PackageError{biblatex-ext-tabular}{#1}{#2.}}

\protected\def\extblxtab@warning@noline{%
  \PackageWarningNoLine{biblatex-ext-tabular}}

\let\extblxtab@warning\extblxtab@warning@noline
\AtEndOfPackage{%
  \protected\def\extblxtab@warning{%
    \PackageWarning{biblatex-ext-tabular}}}

% user-level command for printing tabular bibliography

\newrobustcmd*{\printbibtabular}{%
  \begingroup % closed in \extblxtab@bibtabular
  \delimcontext{bib}%
  \edef\on@line{\on@line}%
  \@ifnextchar[%]
    {\extblxtab@printbibtabular}
    {\extblxtab@printbibtabular[]}}

\def\extblxtab@printbibtabular[#1]{%
  \toggletrue{blx@tempa}%
  \toggletrue{blx@tempb}%
  \def\blx@theheading{bibliography}%
  \def\blx@theenv{bibtabular}%
  \let\blx@theprenote\@empty
  \let\blx@thepostnote\@empty
  \let\blx@thetitle\@empty
  % defaults
  \let\blx@tempa\@empty% before there is a .bbl, this must not be undef
  \edef\blx@tempe{\the\c@refsection}% default refsection is current
  \blx@safe@actives
  \togglefalse{blx@resetnumsexplicit}%
  \setkeys{blx@bib1}{#1}% First pass options keys - section and resetnumbers
  % Is there a user-specified option for resetnumbers
  % If so, this overrides the default
  % "labelprefix implies resetnumbers" behaviour
  \iftoggle{blx@resetnumsexplicit}
    {}
    {\ifdefempty\blx@refcontext@labelprefix
      {}
      {\setkeys{blx@bib2}{resetnumbers}}}%
  \blx@rest@actives
  \ifcsvoid{blx@dlist@entry@\blx@tempe @\blx@refcontext@context}
    {}
    {\letcs\blx@tempa{blx@dlist@entry@\blx@tempe @\blx@refcontext@context}}%
  \blx@safe@actives
  % Must reset omitnumbers as it's a global macro and if we don't, any
  % \printbibliography following one with this set will inherit any
  % previous "true" value
  \togglefalse{blx@omitnumbers}%
  \setkeys{blx@bib2}{#1}% ... now we have correct \blx@tempa,
  % set rest of options
  \blx@rest@actives
  % Add datalist to list of seen datalists to prevent duplicates
  \xifinlist{\blx@refcontext@context @\blx@tempe @entry}\blx@dlistnames
    {}
    {\listxadd\blx@dlistnames{\blx@refcontext@context @\blx@tempe @entry}%
     \csxappto{blx@dlists}{%
       \blx@xml@dlist{\blx@refcontext@context}{entry}{\blx@tempe}{%
         \blx@xml@dlist@refcontext
           {\blx@refcontext@sortingtemplatename}
           {\blx@refcontext@sortingnamekeytemplatename}
           {\blx@refcontext@labelprefix}
           {\blx@refcontext@uniquenametemplatename}
           {\blx@refcontext@labelalphanametemplatename}}{}}}%
  \ifdefvoid\blx@tempa
    {\blx@warn@bibempty\endgroup}
    {\extblxtab@bibtabular\blx@tempa}}

% underlying macros
\def\extblxtab@bibtabular#1{%
  \blx@langstrings
  \blx@bibheading\blx@theheading\blx@thetitle
  \blx@bibnote\blx@theprenote
  \begingroup
  \blx@bibinit
  \let\@noitemerr\@empty
  \let\blx@noitem\blx@warn@bibempty
  \ifnum\bibinitsep=\z@
    \let\blx@initsep\relax
  \fi
  \ifnum\bibnamesep=\z@
    \let\blx@namesep\relax
  \fi
  \csuse{blx@hook@bibinit}%
  \csuse{blx@hook@bibinit@next}%
  % copy filtered list of entries to internal list macro
  \let\blx@tempb\@empty
  \def\blx@do##1{%
    \blx@ifdata{##1}{%
      \begingroup
      \blx@getdata{##1}%
      \blx@bibcheck
      \iftoggle{blx@skipentry}{}{%
        \global\let\blx@noitem\@empty
        \listgadd\blx@tempb{##1}}%
      \endgroup}{}}%
  \let\blx@done\relax
  \blx@listloop{#1}%
  \begingroup
  % sane names for wrapper macros
  \def\plain     {\extblxtab@tab@item@plain     {\extblxtab@tabrow@entrykey}}%
  \def\plainlang {\extblxtab@tab@item@plainlang {\extblxtab@tabrow@entrykey}}%
  \def\anchor    {\extblxtab@tab@item@anchor    {\extblxtab@tabrow@entrykey}}%
  \def\anchorlang{\extblxtab@tab@item@anchorlang{\extblxtab@tabrow@entrykey}}%
  \def\driver    {\extblxtab@tab@item@driver    {\extblxtab@tabrow@entrykey}}%
  % tabular output for each item in list
  % note that each cell is in its own group, hence we need \gdef to break
  % out of the first cell as soon as the row format has a & in it since
  % the assignment will be counted as being in the first cell
  \def\do##1{%
    \gdef\extblxtab@tabrow@entrykey{##1}%
    \csuse{extblxtab@tabrow@format@\blx@theenv}}%
  \csuse{extblxtab@env@\blx@theenv}%
  \dolistloop{\blx@tempb}%
  \csuse{extblxtab@endenv@\blx@theenv}%
  \endgroup
  \blx@bibnote\blx@thepostnote
  \endgroup
  \endgroup % this closes the group opened by \printbibtabular
}

\def\extblxtab@tab@item@aux@lang#1{%
  \blx@initunit
  \blx@beglangbib
  \bibsentence
  #1%
  \blx@postpunct
  \blx@endlangbib
}

\def\extblxtab@tab@item@plain#1#2{%
  \begingroup
  \blx@getdata{#1}%
  \blx@setoptions@type\abx@field@entrytype
  \blx@setoptions@entry
  \blx@thelabelnumber
  \csuse{blx@hook@bibitem}%
  \blx@execute
  #2%
  \endgroup
}

\def\extblxtab@tab@item@plainlang#1#2{%
  \extblxtab@tab@item@plain{#1}{%
    \extblxtab@tab@item@aux@lang{#2}}}

\def\extblxtab@tab@item@anchor#1#2{%
  \extblxtab@tab@item@plain{#1}{%
    \addtocounter{instcount}\@ne
    \blx@anchor
    \blx@pagetracker
    #2}}

\def\extblxtab@tab@item@anchorlang#1#2{%
  \extblxtab@tab@item@anchor{#1}{%
    \extblxtab@tab@item@aux@lang{#2}}}

\def\extblxtab@tab@item@driver#1#2{%
  \begingroup
  \blx@getdata{#1}%
  \blx@setdefaultrefcontext{#1}%
  \blx@setoptions@type\abx@field@entrytype
  \blx@setoptions@entry
  \blx@thelabelnumber
  \csuse{blx@hook@bibitem}%
  \blx@execute
  #2%
  \blx@initunit
  \blx@beglangbib
  \bibsentence
  \blx@driver\abx@field@entrytype
  \blx@postpunct
  \blx@endlangbib
  \endgroup
}

% user-level command for defining tabular bibliography format
\newrobustcmd*{\defbibtabular}[4]{%
  \long\csdef{extblxtab@env@#1}{#2}%
  \long\csdef{extblxtab@endenv@#1}{#3}%
  \long\csdef{extblxtab@tabrow@format@#1}{#4}}

% error message in case user does not initialise bibtabular
\defbibtabular{bibtabular}
  {\extblxtab@error{%
     tabular bibliography environment\MessageBreak
     'bibtabular' undefined}
     {Please supply a suitable definition with \string\defbibtabular.%
      \MessageBreak
      See the documentation for more details}}
  {\textbf{Error!
           The tabular bibliography environment `bibtabular' is undefined.
           No tabular bibliography was produced.
           Please supply a suitable definition with
           \mbox{\string\defbibtabular}.
           See the manual for more information.}}
  {}

\newrobustcmd*{\defbibtabulartwocolumn}[5]{%
  \long\csdef{extblxtab@env@#1}{#2}%
  \long\csdef{extblxtab@endenv@#1}{#3}%
  \long\csdef{extblxtab@tabrow@format@#1}{%
    \anchorlang{#4} & \driver{#5}\\
  }%
}

% Two useful bibmacros for tabular bibliographies

% print the labelname/sortname with editor or translator string if appropriate
\newbibmacro*{tabular:sortname}{%
  \ifnameundef{labelname}
    {\usebibmacro{labeltitle}}
    {\printnames[sortname]{labelname}%
     \iffieldequalstr{labelnamesource}{editor}
       {\setunit{\printdelim{editortypedelim}}%
        \usebibmacro{editor+othersstrg}}
       {\iffieldequalstr{labelnamesource}{translator}
          {\setunit{\printdelim{translatortypedelim}}%
           \usebibmacro{translator+othersstrg}}
          {}}}}

% bibitem hook to suppress redundant sortname list
% useful for \driver since it usually lives in its own group
\newbibmacro*{tabular:omitsortname}{%
  \ifnameundef{labelname}
    {}
    {\clearname{\thefield{labelnamesource}}}}

\endinput
%
% This file is part of the biblatex-ext bundle.
% biblatex-ext is released under the LaTeX Project Public License v1.3c
% or later.
%
% A complete list of files included in that package can be found in README.md
% or - failing that - in ext-standard.bbx.
%
% Official releases of this package are on CTAN
%   https://www.ctan.org/pkg/biblatex-ext
% development takes place on GitHub
%   https://github.com/moewew/biblatex-ext
%