Debian Codegraph @

texmf-dist/doc/latex/biblatex/examples/95-customlists.tex

raw
1 \documentclass[a4paper]{article}
2 \usepackage{fontspec}
3 % Using a custom data model to declare the "coauthor" field
4 \usepackage[style=authoryear,datamodel=95-customlists,backend=biber]{biblatex}
5 \addbibresource{95-customlists.bib}
6
7 % 1. First, check if the author list contain me, here, "Arthur Smith" (and
8 % isn't *just* me as then we can ignore this entry as there are no coauthors)
9 % 2. Copy the author field to a temporary field "coauthortext". We don't need
10 % datamodel declarations for this as this will be deleted after use and
11 % will never get anywhere near code that queries the data model.
12 % 3. Remove me (Arthur Smith) from this temporary copy of the author list
13 % 4. Turn the resulting field into a comma-separated list
14 % 5. Loop over this comma-separated list, creating new entries of type
15 % "coauthor" each with a "coauthor" name list field containing the data
16 % from the loop variable
17 % 6. Remove the temporary author field copy "coauthortext"
18 %
19 % The special $MAPLOOP variable holds each value of the csv field named by
20 % the "foreach" option on the \map macro.
21 % The special $MAPUNIQ variable is a random string generated automatically
22 % at the beginning of each \map section. This is useful when you need a unique
23 % string as we do here because citation keys should be unique.
24 % $MAPLOOPVAL can be used to refer to the last created $MAPUNIQ
25 \DeclareSourcemap{
26 \maps[datatype=bibtex]{
27 \map[overwrite]{
28 \step[fieldsource=author,
29 match=\regexp{Arthur\s+Smith}, final]
30 \step[fieldsource=author,
31 notmatch=\regexp{^Arthur\s+Smith$}, final]
32 \step[fieldsource=author, fieldset=coauthortext, origfieldval]
33 \step[fieldsource=coauthortext,
34 match=\regexp{Arthur\s+Smith\s+and\s+},
35 replace={}]
36 \step[fieldsource=coauthortext,
37 match=\regexp{\s+and\s+Arthur\s+Smith},
38 replace={}]
39 \step[fieldsource=coauthortext,
40 match=\regexp{\s+and\s+},
41 replace={,}]
42 }
43 \map[overwrite, foreach=coauthortext]{
44 \step[fieldsource=coauthortext, match=\regexp{.}, final]
45 \step[entrynew=\regexp{$MAPUNIQ}, entrynewtype=coauthor]
46 \step[entrytarget=\regexp{$MAPUNIQVAL}, fieldset=coauthor, fieldvalue=\regexp{$MAPLOOP}]
47 \step[entrytarget=\regexp{$MAPUNIQVAL}, fieldset=options, fieldvalue=skipbib]
48 }
49 \map[overwrite]{
50 \step[fieldsource=coauthortext, null]
51 }
52 }
53 }
54
55 % Sort the biblist by coauthor name
56 \DeclareSortingTemplate{coauthor}{
57 \sort{
58 \field{coauthor}
59 }
60 }
61
62 % Driver to print the biblist items
63 \DeclareBibliographyDriver{coauthor}{%
64 \printnames{coauthor}}
65
66 % bibcheck to strip duplicates
67 \defbibcheck{coauthor}{%
68 \ifcsdef{\strname{coauthor}}
69 {\skipentry}
70 {\savenamecs{coauthor}{\strname{coauthor}}}}
71
72 % Simple bibenvironment to print the biblist
73 \defbibenvironment{coauthor}
74 {\list{}
75 {\setlength{\leftmargin}{\bibhang}%
76 \setlength{\itemindent}{-\leftmargin}%
77 \setlength{\itemsep}{\bibitemsep}%
78 \setlength{\parsep}{\bibparsep}}}
79 {\endlist}
80 {\item}
81
82 \begin{document}
83 \nocite{*}
84 \printbibliography
85 % This will automatically use the "coauthor" sorting scheme/biblist/driver etc.
86 \printbiblist[title=CoAuthors]{coauthor}
87 \end{document}
88
89
90
91
92
93