summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/biblatex-apa/apa.cbx
blob: 4312c0b854fbd9ba2f01ef6112be2b345c76f0cf (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
%% apa.cbx v2.7
%% Copyright 2011 Philip Kime
%%
%% 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 Philip Kime.
%%
%% This work consists of the files:
%%
%% apa.cbx (biblatex citation style)
%% apa.bbx (biblatex references style)
%% *.lbx (localisation files for APA-specific strings)
%% biblatex-apa.pdf (Style documentation)
%% biblatex-apa.tex (Style documentation source)
%% biblatex-apa-test.pdf (Style examples)
%% biblatex-apa-test.tex (Style examples source)
%% biblatex-apa-test-citations.bib (Style examples - citations)
%% biblatex-apa-test-references.bib (Style examples - references)

\ProvidesFile{apa.cbx}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% (APA 6.16) year postfix is not emphasised or italic

\DeclareFieldFormat{extrayear}{\mknumalph{#1}}

%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% (APA 6.11) requires comma separator between authors and years

\renewcommand*{\nameyeardelim}{\addcomma\space}

%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% (APA 6.12) ampersand separator in parenthetical cites

\DeclareCiteCommand{\parencite}[\mkbibparens]
  {\renewcommand{\finalnamedelim}{\ifnum\value{liststop}>2 \finalandcomma\fi\addspace\&\space}%
   \usebibmacro{cite:init}%
   \usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \usebibmacro{cite}}
  {}
  {\usebibmacro{postnote}}

\DeclareCiteCommand*{\parencite}[\mkbibparens]
  {\renewcommand{\finalnamedelim}{\ifnum\value{liststop}>2 \finalandcomma\fi\addspace\&\space}%
   \usebibmacro{cite:init}%
   \usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \usebibmacro{citeyear}}
  {}
  {\usebibmacro{postnote}}

%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% (APA 6.12) 3-5 authors have "et al." after first cite

% #1 = last name
% #2 = last name (initials)
% #3 = first name
% #4 = first name (initials)
% #5 = name prefix, a.k.a. 'von part'
% #6 = name prefix (initials)
% #7 = name affix, a.k.a. 'junior part'
% #8 = name affix (initials)

\newbibmacro*{labelname:doname}[8]{%
  \ifcase\value{uniquename}%
     \usebibmacro{name:last}{#1}{#3}{#5}{#7}%
   \or
     \usebibmacro{name:first-last}{#1}{#4}{#5}{#8}%
   \or
     \usebibmacro{name:first-last}{#1}{#3}{#5}{#7}%
   \fi
   \usebibmacro{name:andothers}}

% Can't do this with the built-in printnames as APA requires truncation
% and disambiguation only after first cite

\DeclareNameFormat{labelname}{%
  \ifthenelse{\value{listcount}=1\OR\value{listtotal}=2}
    {\usebibmacro{labelname:doname}{#1}{#2}{#3}{#4}{#5}{#6}{#7}{#8}}
    {\ifthenelse{\ifciteseen\OR\value{listtotal}>5}
     {\ifnumcomp{\value{listcount}}{<}{\value{uniquelist} + 1}% normal name
      {\usebibmacro{labelname:doname}{#1}{#2}{#3}{#4}{#5}{#6}{#7}{#8}}%
       {}%
      \ifnumcomp{\value{listcount}}{=}{\value{uniquelist} + 1}% first past ul is et al
       {\andothersdelim\bibstring{andothers}}%
       {}%
      \ifnumcomp{\value{listcount}}{>}{\value{uniquelist} + 1}% nothing thereafter
       {\relax}%
       {}}%
     {\usebibmacro{labelname:doname}{#1}{#2}{#3}{#4}{#5}{#6}{#7}{#8}}}}

%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% (APA 6.13) Groups as names
%            SHORTAUTHOR brackets in parencites

\DeclareNameFormat{sabrackets}{\ifciteseen
                                 {\usebibmacro{labelname:doname}{#1}{#2}{#3}{#4}{#5}{#6}{#7}{#8}}
                                 {\mkbibbrackets{\usebibmacro{labelname:doname}{#1}{#2}{#3}{#4}{#5}{#6}{#7}{#8}}}}

\DeclareFieldFormat{shorthand}{\ifciteseen
                                {#1}
                                {\mkbibbrackets{#1}}}

%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% (APA 6.13) Deal with SHORTAUTHOR fields
% (APA 6.16) Multiple same author cites in a compact citation call do not
%            need to be repeated but the full years must be repeated with
%            their extrayear postfixes
%            "in press" extrayear needs a short dash to join to label
% (APA 6.28) If no date, use "(n.d.)"
% (APA 6.18) Cite ORIGYEAR/YEAR if ORIGYEAR present

\newbibmacro*{cite}{%
  \iffieldequals{namehash}{\cbx@lasthash}
% Multiple cites in one command
   {\setunit{\compcitedelim}%
    \usebibmacro{cite:plabelyear+extrayear}}%
% Single cite
   {\ifthenelse{\ifnameundef{labelname}\OR\equal{\thefield{entrytype}}{patent}}
% No author/editor
     {\usebibmacro{cite:noname}%
       \setunit{\nameyeardelim}%
      \iffieldundef{labelyear}
        {\usebibmacro{cite:noyear}}
        {\usebibmacro{cite:plabelyear+extrayear}%
         \savefield{namehash}{\cbx@lasthash}}}
% Normal cite
     {\ifnameundef{shortauthor}
        {\printnames{labelname}}
        {\ifciteseen
          {\printnames{shortauthor}}
          {\printnames{author}\addspace\printnames[sabrackets]{shortauthor}}}%
      \setunit{\nameyeardelim}%
      \iffieldundef{labelyear}
        {\usebibmacro{cite:noyear}}
        {\usebibmacro{cite:plabelyear+extrayear}%
         \savefield{namehash}{\cbx@lasthash}}}}%
   \setunit{\multicitedelim}}

\newbibmacro*{textcite}{%
  \iffieldequals{namehash}{\cbx@lasthash}
% Compact cite - more than one thing for same author
    {\setunit{\compcitedelim}%
     \usebibmacro{cite:plabelyear+extrayear}}
% Single cite
    {\ifthenelse{\ifnameundef{labelname}\OR\equal{\thefield{entrytype}}{patent}}
  % No author/editor or patent
       {\iffieldundef{shorthand}%
    % Cite using title
         {\usebibmacro{cite:noname}%
          \setunit{\ifbool{cbx:np}%
                   {\nameyeardelim}%
                   {\global\booltrue{cbx:parens}\addspace\bibopenparen}}%
          \usebibmacro{cite:plabelyear+extrayear}}
    % Cite using shorthand
         {\usebibmacro{cite:shorthand}}}
  % Normal cite with author/editor
  % Normal full cite
       {\ifnameundef{shortauthor}%
    % Normal full cite
         {\printnames{labelname}}
    % Cite using short author
         {\ifciteseen
           {\printnames{shortauthor}}
           {\printnames{author}}}%
  % Year
        \setunit{\ifbool{cbx:np}
                  {\nameyeardelim}
                  {\global\booltrue{cbx:parens}\addspace\bibopenparen}}%
  % Put the shortauthor inside the year brackets if necessary
        \ifnameundef{shortauthor}
         {}
         {\ifciteseen
           {}
           {\printnames{shortauthor}\setunit{\nameyeardelim}}}%
        \iffieldundef{labelyear}%
          {\usebibmacro{cite:noyear}}
  % Actual year printing
          {\usebibmacro{cite:plabelyear+extrayear}}%
        \savefield{namehash}{\cbx@lasthash}}}%
  \setunit{%
    \ifbool{cbx:parens}
      {\bibcloseparen\global\boolfalse{cbx:parens}}
      {}%
    % multicitedelim semi-colon doesn't make much sense for textcites
    \compcitedelim}}

\newcommand{\apashortdash}{-}

\newbibmacro*{cite:plabelyear+extrayear}{%
  \iffieldundef{labelyear}
    {}
    {\printtext[bibhyperref]{%
     \printfield[noformat]{origyear}\setunit*{\addslash}%
     \printfield{labelyear}%
     \iffieldequalstr{labelyear}{in press}
       {\iffieldundef{extrayear}
         {\setunit{\relax}}
         {\setunit{\apashortdash}}%
       \printfield{extrayear}}
       {\printfield{extrayear}}}}}%

\newbibmacro*{cite:shorthand}{%
  \ifciteseen
    {\printfield{shorthand}}
    {\printnames{labelname}%
     \setunit{\nameyeardelim}%
     \printfield{title}\space\printfield{shorthand}}}

%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% (APA 6.15) Fall back to title for citations without authors

\DeclareFieldFormat{citetitle}{\mkbibquote{#1}}
\DeclareFieldFormat[book]{citetitle}{\mkbibemph{#1}}
\DeclareFieldFormat[inbook]{citetitle}{\mkbibemph{#1}}
\DeclareFieldFormat[report]{citetitle}{\mkbibemph{#1}}
\DeclareFieldFormat[periodical]{citetitle}{\mkbibemph{#1}}
\DeclareFieldFormat[patent]{citetitle}{#1}

\newbibmacro*{cite:noname}{%
    \printfield[citetitle]{labeltitle}}

%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% (APA 6.22) Fall back to "n.d." for citations without dates
%            Strings defined in apa.bbx

\newbibmacro*{cite:noyear}{%
  \ifnameundef{shortauthor}
    {}
    {\ifciteseen
      {}
      {\printnames{shortauthor}\setunit{\nameyeardelim}}}%
  \printtext[bibhyperref]{\biblcstring{nodate}}}

%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% (APA 6.21) No parens round year for cites when the cite is in
%            parentheses. Use new command \nptextcite for such cites.


\DeclareMultiCiteCommand{\nptextcites}{\nptextcite}{\multicitedelim}
\DeclareCiteCommand{\nptextcite}
  {\renewcommand{\finalnamedelim}{\ifnum\value{liststop}>2 \finalandcomma\fi\addspace\&\space}%
   \usebibmacro{cite:init}%
   \usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \global\booltrue{cbx:np}%
   \usebibmacro{textcite}%
   \global\boolfalse{cbx:np}}%
  {}
  {\iffieldundef{postnote}
     {}
     {\nameyeardelim
      \printfield{postnote}}}

%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% No shorthand
% 
\newbibmacro*{citeyear}{%
  \iffieldundef{labelyear}
    {\usebibmacro{cite:noyear}%
     \usebibmacro{cite:init}}
    {\iffieldequals{namehash}{\cbx@lasthash}
       {\setunit{\compcitedelim}%
        \usebibmacro{pcite:labelyear+extrayear}}
       {\usebibmacro{pcite:labelyear+extrayear}%
        \savefield{namehash}{\cbx@lasthash}}}
  \setunit{\multicitedelim}}

%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Fullcite should use "&"
\DeclareCiteCommand{\fullcite}
  {\renewcommand{\finalnamedelim}{\ifnum\value{liststop}>2 \finalandcomma\fi\addspace\&\space}%
  \usebibmacro{prenote}}
  {\usedriver
    {\DeclareNameAlias{sortname}{default}}
    {\thefield{entrytype}}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\fullcitebib}
  {\renewcommand{\finalnamedelim}{\ifnum\value{liststop}>2 \finalandcomma\fi\addspace\&\space}%
  \begin{thebibliography}\thebibitem}
  {\usedriver
    {\DeclareNameAlias{sortname}{default}}
    {\thefield{entrytype}}\finentry}
  {\thebibitem}
  {\end{thebibliography}}

%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newbool{cbx:parens} % boolean to say we're inside parens
\newbool{cbx:np} % boolean to say we're using a non-parentheses text cite

\newbibmacro*{textcite:postnote}{%
  \usebibmacro{postnote}%
  \ifthenelse{\value{multicitecount}=\value{multicitetotal}}
    {\setunit{}%
     \printtext{%
       \ifbool{cbx:parens}
	 {\bibcloseparen\global\boolfalse{cbx:parens}}
	 {}}}
    {\setunit{%
       \ifbool{cbx:parens}
	 {\bibcloseparen\global\boolfalse{cbx:parens}}
	 {}%
       \multicitedelim}}}


\newbibmacro*{cite:init}{%
  \global\boolfalse{cbx:parens}%
  \global\undef\cbx@lasthash}

\newbibmacro*{cite:labelyear}{%
  \printfield{labelyear}}

\newbibmacro*{cite:extrayear}{%
  \printfield{extrayear}}

\newbibmacro*{cite:labelyear+extrayear}{%
  \iffieldundef{labelyear}
    {}
    {\printfield{labelyear}%
       \printfield{extrayear}}}

\DeclareCiteCommand{\citeyear}
  {\boolfalse{citetracker}%
   \boolfalse{pagetracker}%
   \usebibmacro{prenote}}
  {\usebibmacro{cite:plabelyear+extrayear}}
  {\multinamedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\cite}
  {\usebibmacro{cite:init}%
   \usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \usebibmacro{cite}}
  {}
  {\usebibmacro{postnote}}

\DeclareCiteCommand*{\cite}
  {\usebibmacro{cite:init}%
   \usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \usebibmacro{citeyear}}
  {}
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\footcite}[\mkbibfootnote]
  {\bibsentence
   \usebibmacro{cite:init}%
   \usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \usebibmacro{cite}}
  {}
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\textcite}
  {\usebibmacro{cite:init}%
   \usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \usebibmacro{textcite}}
  {}
  {\usebibmacro{textcite:postnote}}

\endinput