summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/biblatex/doc/examples/93-nameparts.tex
blob: 44115b6acdc118fa418f07fc3d9fb11310a9b324 (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
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
\documentclass[a4paper]{article}
\usepackage{fontspec}
\usepackage{libertine}
\usepackage[fallback]{xeCJK}
\usepackage[british]{babel}
\usepackage{csquotes}
\begin{filecontents}[force]{\jobname.bib}
@book{tolstoy,
  author = {given=Лев, patronymic=Николаевич, family=Толстой, nametemplates=russian},
  title  = {Война и мир},
  date   = {1877},
  langid = {russian},
}
@book{bulgakov,
  author = {given=Михаил, patronymic=Афанасьевич, family=Булгаков, nametemplates=russian},
  title  = {Мастер и Маргарита},
  date   = {1966},
  langid = {russian},
}
@book{bulgakov:val,
  author = {given=Валентин, patronymic=Фёдорович, family=Булгаков, nametemplates=russian},
  title  = {Л. Н. Толстой в последний год его жизни},
  date   = {1911},
  langid = {russian},
}

@book{dosto:1,
  author = {given=Александр , patronymic=Андреевич, family=Достоевский, nametemplates=russian},
  title  = {О строении телец Грандри},
  date   = {1885},
  langid = {russian},
}
@book{dosto:2,
  author = {given=Андрей , patronymic=Андреевич, family=Достоевский, nametemplates=russian},
  title  = {П. П. Семенов-Тян-Шанский как исследователь, географ и статистик},
  date   = {1914},
  langid = {russian},
}

@book{demeke,
  author  = {given=Kebede, patronymic=Daniel, papponymic=Demeke, nametemplates=ethiopian},
  title   = {One},
  date    = {1983}
}
@book{dameke,
  author  = {given=Kebede, patronymic=Daniel, papponymic=Dameke, nametemplates=ethiopian},
  title   = {Two},
  date    = {1983}
}
@book{james,
  author  = {given=Kebede, patronymic=James, papponymic=Demeke, nametemplates=ethiopian},
  title   = {Three},
  date    = {1983}
}
@book{jonathan,
  author  = {given=Kebede, patronymic=Jonathan, papponymic=Kebede, nametemplates=ethiopian},
  title   = {Four},
  date    = {1986}
}
@book{william,
  author  = {given=Kebede, patronymic=William, papponymic=Kebede, nametemplates=ethiopian},
  title   = {Four},
  date    = {1987}
}

@book{zhangx1,
  title      = {Shuming},
  titleaddon = {書名},
  author     = {family=Zhang, cjk=章學成, given=Xuecheng, nametemplates=cjk},
  location   = {Beijing},
  publisher  = {Zhonghua Shuju},
  date       = {2017},
}
@book{zhangx2,
  title      = {Shuming er},
  titleaddon = {書名二},
  author     = {family=Zhang, cjk=張學成, given=Xuecheng, nametemplates=cjk},
  location   = {Shanghai},
  publisher  = {Shangwu Yinshuguan},
  date       = {2016},
}

@book{bronte:c,
  author     = {Charlotte Brontë},
  date       = {1847},
  title      = {Jane Eyre},
}
@book{bronte:e,
  author     = {Emily Brontë},
  date       = {1847},
  title      = {Wuthering Heights},
}

@book{austen:jane,
  author     = {Jane Austen},
  date       = {1813},
  title      = {Pride and Prejudice},
}
@collection{austen:john,
  editor     = {John Austen},
  editortype = {compiler},
  date       = {1924},
  title      = {Rogues in Porcelain: A Miscellany of 18th Poems},
}
\end{filecontents}
\usepackage[style=authoryear,datamodel=93-nameparts,backend=biber, autolang=hyphen]{biblatex}
\addbibresource{biblatex-examples.bib}
\addbibresource{\jobname.bib}


% Use transliteration to sort Cyrillic among Latin script
\DeclareSortTranslit{
  \translit[russian]{*}{russian}{bgn/pcgn-standard}
}

\makeatletter
%% CJK names
% the idea is to sort family -> given -> cjk (full name)
% and disambiguate in the same manner using only full
% forms of the name, no initials
% the order should always be family -> given -> cjk
% names are not reversed
\DeclareSortingNamekeyTemplate[cjk]{
  \keypart{
    \namepart{family}
  }
  \keypart{
    \namepart{given}
  }
  \keypart{
    \namepart{cjk}
  }
}

\DeclareUniquenameTemplate[cjk]{
  \namepart[base=true]{family}
  \namepart[disambiguation=full]{given}
  \namepart[disambiguation=full]{cjk}
}

\newbibmacro*{name:cjk}[3]{%
  \usebibmacro{name:delim}{#2#3#1}%
  \usebibmacro{name:hook}{#2#3#1}%
  \mkbibnamefamily{#1}%
  \ifdefvoid{#2}{}{\bibnamedelimd\mkbibnamegiven{#2}}%
  \ifdefvoid{#3}{}{\bibnamedelimd\mkbibnamecjk{#3}}}

%% Ethiopian names
% Ethiopian names are given -> patronymic -> papponymic
% the latter two are only needed for disambiguation
% names order is never reversed
\DeclareSortingNamekeyTemplate[ethiopian]{
  \keypart{
    \namepart{given}
  }
  \keypart{
    \namepart{patronymic}
  }
  \keypart{
    \namepart{papponymic}
  }
}

\DeclareUniquenameTemplate[ethiopian]{
  \namepart[base=true]{given}
  \namepart[disambiguation=full]{patronymic}
  \namepart[disambiguation=full]{papponymic}
}

\newbibmacro*{name:ethiopian}[3]{%
  \usebibmacro{name:delim}{#1#2#3}%
  \usebibmacro{name:hook}{#1#2#3}%
  \mkbibethgiven{#1}%
  \ifdefvoid{#2}{}{\bibnamedelimd\mkbibethpat{#2}\isdot}%
  \ifdefvoid{#3}{}{\bibnamedelimd\mkbibethpap{#3}\isdot}}

\let\mkbibethgiven\mkbibnamefamily
\let\mkbibethpat\mkbibnamegiven
\let\mkbibethpap\mkbibnamegiven

%% Russian names
% family -> given -> patronymic
% we never show the given name alone, it is always accompanied
% by the patronymic
% (patronymic could just be treated as another given name)
% reversed name order is 'family, given patronymic'
\DeclareSortingNamekeyTemplate[russian]{
  \keypart{
    \namepart{family}
  }
  \keypart{
    \namepart{given}
  }
  \keypart{
    \namepart{patronymic}
  }
}

\DeclareUniquenameTemplate[russian]{
  \namepart[base=true]{family}
  \namepart{given}
  \namepart{patronymic}
}

\newbibmacro*{name:russian}[3]{%
  \usebibmacro{name:delim}{#1#2#3}%
  \usebibmacro{name:hook}{#1#2#3}%
  \ifdefvoid{#2}
    {}
    {\mkbibnamegiven{#2}\isdot\bibnamedelimd
     \ifdefvoid{#3}
       {}
       {\mkbibnamepatronymic{#3}\isdot\bibnamedelimd}}%
  \mkbibnamefamily{#1}}

\newbibmacro*{name:russian-rev}[3]{%
  \usebibmacro{name:delim}{#1#2#3}%
  \usebibmacro{name:hook}{#1#2#3}%
  \mkbibnamefamily{#1}%
  \ifdefvoid{#2}
    {}
    {\revsdnamepunct\bibnamedelimd
     \mkbibnamegiven{#2}\isdot
     \ifdefvoid{#3}
       {}
       {\bibnamedelimd\mkbibnamepatronymic{#3}\isdot}}}

%% sortname
% helper to select the sorting template in \ifcase
\newcommand*{\abx@sortingnamekeytemplate}{0}
\newcommand*{\abx@getsortingnamekeytemplate}{%
  \ifsortingnamekeytemplatename{cjk}
     {\def\abx@sortingnamekeytemplate{1}}
     {\ifsortingnamekeytemplatename{ethiopian}
        {\def\abx@sortingnamekeytemplate{2}}
        {\ifsortingnamekeytemplatename{russian}
           {\def\abx@sortingnamekeytemplate{3}}
           {}}}}

% show fullest version of names,
% reverse Russian and western names for sorting
% all other names are always in the correct order for sorting
\DeclareNameFormat{sortname}{%
  \abx@getsortingnamekeytemplate
  \ifcase\abx@sortingnamekeytemplate\relax
    \usebibmacro{name:family-given}
      {\namepartfamily}
      {\namepartgiven}
      {\namepartprefix}
      {\namepartsuffix}%
  \or
    \usebibmacro{name:cjk}
      {\namepartfamily}
      {\namepartgiven}
      {\namepartcjk}%
  \or
    \usebibmacro{name:ethiopian}
      {\namepartgiven}
      {\namepartpatronymic}
      {\namepartpapponymic}%
  \or
    \usebibmacro{name:russian-rev}
      {\namepartfamily}
      {\namepartgiven}
      {\namepartpatronymic}%
  \fi
  \usebibmacro{name:andothers}}

%% labelname
% copy of the standard definition in biblatex.def
% uses the 'old way' of finding the disambiguating name part
\newbibmacro{labelname:western}{%
  \ifcase\value{uniquename}%
    \usebibmacro{name:family}
      {\namepartfamily}
      {\namepartgiven}
      {\namepartprefix}
      {\namepartsuffix}%
  \or
    \ifuseprefix
      {\usebibmacro{name:given-family}
        {\namepartfamily}
        {\namepartgiveni}
        {\namepartprefix}
        {\namepartsuffixi}}
      {\usebibmacro{name:given-family}
        {\namepartfamily}
        {\namepartgiveni}
        {\namepartprefixi}
        {\namepartsuffixi}}%
  \or
    \usebibmacro{name:given-family}
      {\namepartfamily}
      {\namepartgiven}
      {\namepartprefix}
      {\namepartsuffix}%
  \fi
  \usebibmacro{name:andothers}}

% Uses \iffieldequalstr{uniquepart} to find the disambiguating
% name part.
% If neither base (i.e. family) nor given name are enough,
% go with the full name.
% Uses \empty for suppressed name parts, so we don't have to define
% dedicated macros for the shorter name forms.
\newbibmacro{labelname:cjk}{%
  \iffieldequalstr{uniquepart}{base}%
    {\usebibmacro{name:cjk}
       {\namepartfamily}
       {\empty}
       {\empty}}
    {\iffieldequalstr{uniquepart}{given}%
       {\usebibmacro{name:cjk}
          {\namepartfamily}
          {\namepartgiven}
          {\empty}}
       {\usebibmacro{name:cjk}
          {\namepartfamily}
          {\namepartgiven}
          {\namepartcjk}}}}

% similar to the CJK format
\newbibmacro{labelname:ethiopian}{%
  \iffieldequalstr{uniquepart}{base}%
    {\usebibmacro{name:ethiopian}
       {\namepartgiven}
       {\empty}
       {\empty}}
    {\iffieldequalstr{uniquepart}{patronymic}%
       {\usebibmacro{name:ethiopian}
          {\namepartgiven}
          {\namepartpatronymic}
          {\empty}}
       {\usebibmacro{name:ethiopian}
          {\namepartgiven}
          {\namepartpatronymic}
          {\namepartpapponymic}}}}

% Uses \iffieldequalstr{uniquepart} to get the disambiguating
% name part.
% We only choose between 'Given Patronymic Family' and
% 'G. P. Family', the decision whether or not to use
% initials is for the given name to decide.
% If the given initial is enough to disambiguate the name,
% the given name and patronymic become initials.
% Even if the initial of the patronymic would make the name
% unique we go with the full name instead.
% There is no 'Given P. Family' format.
% \namepart<>un=1 says initials are enough
% 2 means the full name is required
% 0 means not used
\newbibmacro{labelname:russian}{%
  \iffieldequalstr{uniquepart}{base}%
    {\usebibmacro{name:russian}
       {\namepartfamily}
       {\empty}
       {\empty}}
    {\ifnum\namepartgivenun=1\relax
       \usebibmacro{name:russian}
          {\namepartfamily}
          {\namepartgiveni}
          {\namepartpatronymici}%
     \else
       \usebibmacro{name:russian}
          {\namepartfamily}
          {\namepartgiven}
          {\namepartpatronymic}%
     \fi}}

% helper to select the uniquename template in \ifcase
\newcommand*{\abx@uniquenametemplatename}{0}
\newcommand*{\abx@getuniquenametemplatename}{%
  \ifuniquenametemplatename{cjk}
     {\def\abx@uniquenametemplatename{1}}
     {\ifuniquenametemplatename{ethiopian}
        {\def\abx@uniquenametemplatename{2}}
        {\ifuniquenametemplatename{russian}
           {\def\abx@uniquenametemplatename{3}}
           {}}}}

\DeclareNameFormat{labelname}{%
  \abx@getuniquenametemplatename
  \ifcase\abx@uniquenametemplatename\relax
    \usebibmacro{labelname:western}%
  \or
    \usebibmacro{labelname:cjk}%
  \or
    \usebibmacro{labelname:ethiopian}%
  \or
    \usebibmacro{labelname:russian}%
  \fi
  \usebibmacro{name:andothers}}
\makeatother

\begin{document}
% Historically, name handling in latex bibliographies has been determined by
% the name parsing rules of bibtex. In a modern context, this name handling
% is rather archaic, restricted to Western names with the four parts
% "family", "given", "prefix", "suffix" (often referred to in bibtex
% documentation as "last", "first", "von" and "Jr" parts). When using biber,
% it is possible to define arbitrary name parts since the allowable name
% parts are defined in the data model (see accompanying file 93-nameparts.dbx).

% Here we demonstrate the possibility of adding a new name parts to the
% datamodel and then using it in formatting, sorting etc.
% Notice that we can use the new name part types in the datasource
% which is now allowable due to the enhanced datamodel constant definition.
% We have also defined a new name format and method of sorting names which
% are aware of the new name parts.
%
\textcite{tolstoy,bulgakov,bulgakov:val}

\textcite{dosto:1}

\textcite{dosto:2}

\textcite{demeke,dameke,james,jonathan,william}

\textcite{sigfridsson,worman,geer,knuth:ct:a,cicero,companion,vangennep}

\textcite{bronte:c,bronte:e,austen:jane,austen:john}

\textcite{zhangx1,zhangx2}

\printbibliography
\end{document}