summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/biblatex-contrib/biblatex-unified/unified.cbx
blob: 95fe0d99e07bd78b7ccff01c38677f1ac120cd2d (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
%% ---------------------------------------------------------------
%% biblatex-unified --- A biblatex implementation of the Unified Style
%%   Sheet for Linguistics Journals. This is the house style of the
%%   journal "Semantics & Pragmatics" (A journal of the Linguistic
%%   Society of America).
%% Maintained by Kai von Fintel (fintel@mit.edu)
%% Released under the LaTeX Project Public License v1.3c or later
%% See http://www.latex-project.org/lppl.txt
%% ---------------------------------------------------------------
%%

\ProvidesFile{unified.cbx}[2020/05/25 v1.00 biblatex citation style]

\RequireCitationStyle{authoryear-comp}

\ExecuteBibliographyOptions{%
  labeldateparts,%
  uniquename=minfull,%
  uniquelist=minyear,%
  autocite=inline,%
  sortcites=false}

% disabled sortcites option, since it was sorting by name, instead of
% year, and we often want to keep citations in the order chosen by the
% author

% Setting the delimiters the way we want them:

\renewcommand*{\nameyeardelim}{\addspace}
\renewcommand*{\postnotedelim}{\addcolon\space}
\renewcommand*{\multicitedelim}{\addcomma\space}

% Apart from setting some options, the main change from
% authoryear-comp is that we extend what parts of a citation label are
% hyperlinked (to match what natbib did in the old days). The solution
% used to be a very ugly homegrown rewrite of the entirety of
% `authoryear-comp.cbx`, which meant that we were left behind when
% that style was updated. The new solution, still a hack, is to apply
% patches to the base style. These patches were first proposed in
% https://tex.stackexchange.com/a/27615/70432.

% It would be nice if biblatex simply offered more expansive
% hyperlinks as an option and then we wouldn't have to patch things.
% But this seems not to be in the cards:
% https://github.com/plk/biblatex/issues/428

\usepackage{xpatch}

% Patches for biblatex > v3.8 2017-11-04, when labeldate+extradate
% were introduced

% Combine label and labelyear links
\xpatchbibmacro{cite}
  {\usebibmacro{cite:label}%
   \setunit{\printdelim{nonameyeardelim}}%
   \usebibmacro{cite:labeldate+extradate}}
  {\printtext[bibhyperref]{%
     \DeclareFieldAlias{bibhyperref}{default}%
     \usebibmacro{cite:label}%
     \setunit{\printdelim{nonameyeardelim}}%
     \usebibmacro{cite:labeldate+extradate}}}{}{}

% Include labelname in labelyear link
\xpatchbibmacro{cite}
  {\printnames{labelname}%
   \setunit{\printdelim{nameyeardelim}}%
   \usebibmacro{cite:labeldate+extradate}}
  {\printtext[bibhyperref]{%
     \DeclareFieldAlias{bibhyperref}{default}%
     \printnames{labelname}%
     \setunit{\printdelim{nameyeardelim}}%
     \usebibmacro{cite:labeldate+extradate}}}{}{}

% Patches for biblatex 3.7

% Combine label and labelyear links
\xpatchbibmacro{cite}
 {\usebibmacro{cite:label}%
   \setunit{\printdelim{nonameyeardelim}}%
   \usebibmacro{cite:labelyear+extrayear}}
 {\printtext[bibhyperref]{%
     \DeclareFieldAlias{bibhyperref}{default}%
     \usebibmacro{cite:label}%
     \setunit{\addspace}%
     \usebibmacro{cite:labelyear+extrayear}}}{}{}

% Include labelname in labelyear link
\xpatchbibmacro{cite}
 {\printnames{labelname}%
   \setunit{\printdelim{nameyeardelim}}%
   \usebibmacro{cite:labelyear+extrayear}}
 {\printtext[bibhyperref]{%
     \DeclareFieldAlias{bibhyperref}{default}%
     \printnames{labelname}%
     \setunit{\nameyeardelim}%
     \usebibmacro{cite:labelyear+extrayear}}}{}{} 

% Patches for biblatex before 3.7

% Combine label and labelyear links
\xpatchbibmacro{cite}
  {\usebibmacro{cite:label}%
   \setunit{\addspace}%
   \usebibmacro{cite:labelyear+extrayear}}
  {\printtext[bibhyperref]{%
     \DeclareFieldAlias{bibhyperref}{default}%
     \usebibmacro{cite:label}%
     \setunit{\addspace}%
     \usebibmacro{cite:labelyear+extrayear}}}{}{}

% Include labelname in labelyear link
\xpatchbibmacro{cite}
  {\printnames{labelname}%
   \setunit{\nameyeardelim}%
   \usebibmacro{cite:labelyear+extrayear}}
  {\printtext[bibhyperref]{%
     \DeclareFieldAlias{bibhyperref}{default}%
     \printnames{labelname}%
     \setunit{\nameyeardelim}%
     \usebibmacro{cite:labelyear+extrayear}}}{}{} 

% Access hyperref's citation link start/end commands
\protected\def\blx@imc@biblinkstart{%
  \@ifnextchar[%]
    {\blx@biblinkstart}
    {\blx@biblinkstart[\abx@field@entrykey]}}
\def\blx@biblinkstart[#1]{%
  \blx@sfsave\hyper@natlinkstart{\the\c@refsection @#1}\blx@sfrest}
\protected\def\blx@imc@biblinkend{%
  \blx@sfsave\hyper@natlinkend\blx@sfrest}
\blx@regimcs{\biblinkstart \biblinkend}

\newbool{cbx:link}

% Include parentheses around labelyear in \textcite only in
% single citations without pre- and postnotes
\def\iflinkparens{%
  \ifboolexpr{ test {\ifnumequal{\value{multicitetotal}}{0}} and
               test {\ifnumequal{\value{citetotal}}{1}} and
               test {\iffieldundef{prenote}} and
               test {\iffieldundef{postnote}} }}

\xpatchbibmacro{textcite}
  {\printnames{labelname}}
  {\iflinkparens
     {\DeclareFieldAlias{bibhyperref}{default}%
      \global\booltrue{cbx:link}\biblinkstart%
      \printnames{labelname}}
     {\printtext[bibhyperref]{\printnames{labelname}}}}{}{}

\xpatchbibmacro{textcite}
  {\usebibmacro{cite:label}}
  {\iflinkparens
     {\DeclareFieldAlias{bibhyperref}{default}%
      \global\booltrue{cbx:link}\biblinkstart%
      \usebibmacro{cite:label}}
     {\usebibmacro{cite:label}}}{}{}

\xpretobibmacro{textcite:postnote}
  {\ifbool{cbx:link}% patch 2.7+
     {\ifbool{cbx:parens}
        {\bibcloseparen\global\boolfalse{cbx:parens}}
        {}%
         \biblinkend\global\boolfalse{cbx:link}}
        {}}
  {}
  {\xpatchbibmacro{textcite}% patch earlier releases
     {\setunit{%
        \ifbool{cbx:parens}
          {\bibcloseparen\global\boolfalse{cbx:parens}}
          {}%
        \multicitedelim}}
     {\ifbool{cbx:link}
        {\ifbool{cbx:parens}
           {\bibcloseparen\global\boolfalse{cbx:parens}}
           {}%
         \biblinkend\global\boolfalse{cbx:link}}
        {}%
      \setunit{%
        \ifbool{cbx:parens}
          {\bibcloseparen\global\boolfalse{cbx:parens}}
          {}%
        \multicitedelim}}
    {}{}}

% Making the old code in \posscite work with new biblatex
\@ifpackagelater{biblatex}{2016/12/06}%
{\letbibmacro{cite:labelyear+extrayear}{cite:labeldate+extradate}}
{}

% What follows is ugly and meh. These cite commands have been part of
% S&P's author convenience macros since the beginning. We shouldn't
% advertise them anymore, but here they are. We should add warnings
% that people shouldn't use them, because they are deprecated and will
% go away at some point.

\newcommand{\pgcitep}[2]{(\cite{#1}:~#2)}
\newcommand{\pgcitealt}[2]{\cite{#1}:~#2}
\newcommand{\pgcitet}[2]{\citeauthor{#1} (\citeyear{#1}:~#2)}
\newcommand{\pgposscitet}[2]{\citeauthor{#1}'s (\citeyear{#1}:~#2)}
\newcommand{\seccitealt}[2]{\cite{#1}:~$\S$#2}
\newcommand{\seccitep}[2]{(\cite{#1}:~$\S$#2)}
\newcommand{\seccitet}[2]{\citeauthor{#1} (\citeyear{#1}:~$\S$#2)}
\newcommand{\secposscitet}[2]{\citeauthor{#1}'s (\citeyear{#1}:~$\S$#2)}

\newbibmacro*{posscite}{% Based on textcite
  \iffieldequals{namehash}{\cbx@lasthash}
    {\iffieldundef{shorthand}
       {\usebibmacro{labelyearrepeat}}
       {\setunit{\compcitedelim}%
        \usebibmacro{cite:shorthand}%
        \global\undef\cbx@lastyear}}
    {\ifnameundef{labelname}
       {\printtext[bibhyperref]{% Include labelname in hyperlink
          \DeclareFieldAlias{bibhyperref}{default}% Prevent nested hyperlinks
          \iffieldundef{shorthand}
            {\usebibmacro{cite:label}%
             \setunit{%
               \global\booltrue{cbx:parens}%
               \addspace\bibopenparen}%
             \ifnumequal{\value{citecount}}{1}
               {\usebibmacro{prenote}}
               {}%
             \usebibmacro{cite:labelyear+extrayear}}
            {\usebibmacro{cite:shorthand}}%
          \ifthenelse{\iffieldundef{postnote}\AND
                      \(\value{multicitetotal}=0\AND\value{citetotal}=1\)}
            {\bibcloseparen% Include closing parenthesis in hyperlink
             \global\boolfalse{cbx:parens}}
            {}}}
       {\printtext[bibhyperref]{% Include labelname in hyperlink
          \DeclareFieldAlias{bibhyperref}{default}% Prevent nested hyperlinks
          \printnames{labelname}'s%
          \setunit{%
            \global\booltrue{cbx:parens}%
            \addspace\bibopenparen}%
          \ifnumequal{\value{citecount}}{1}
            {\usebibmacro{prenote}}
            {}%
          \iffieldundef{shorthand}
            {\iffieldundef{labelyear}
               {\usebibmacro{cite:label}}
               {\usebibmacro{cite:labelyear+extrayear}}%
             \savefield{labelyear}{\cbx@lastyear}}
            {\usebibmacro{cite:shorthand}%
             \global\undef\cbx@lastyear}%
          \ifthenelse{\iffieldundef{postnote}\AND
                      \(\value{multicitetotal}=0\AND\value{citetotal}=1\)}
            {\bibcloseparen% Include closing parenthesis in hyperlink
             \global\boolfalse{cbx:parens}}
            {}}%
          \savefield{namehash}{\cbx@lasthash}}}%
  \setunit{%
    \ifbool{cbx:parens}
      {\bibcloseparen\global\boolfalse{cbx:parens}}
      {}%
    \multicitedelim}}
\DeclareCiteCommand{\posscitet}
  {\usebibmacro{cite:init}}
  {\usebibmacro{citeindex}%
   \usebibmacro{posscite}}
  {}
  {\usebibmacro{textcite:postnote}}

\DeclareCiteCommand{\posscitealt}
  {\boolfalse{citetracker}%
   \boolfalse{pagetracker}}
  {\printtext[bibhyperref]{\printnames{labelname}'s \iffieldundef{year}{\printfield{labelyear}}{\printfield{year}}\printfield{extradate}}}
  {}
  {}

\DeclareCiteCommand{\possciteauthor}
  {\boolfalse{citetracker}%
   \boolfalse{pagetracker}}
  {\printtext[bibhyperref]{\printnames{labelname}'s}}
  {}
  {}

  
\endinput