-
Notifications
You must be signed in to change notification settings - Fork 6
/
credits.sty
367 lines (341 loc) · 11.3 KB
/
credits.sty
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
% credits.sty
%
% This package permits creating simple contributor statements, as
% proposed by CRediT, the contributor roles taxonomy. The initial
% version of this taxonomy was inspired by Dan O'Shea (@djoshea).
%
% Copyright 2024 Bastian Rieck, Jannis Born
%
% Redistribution and use in source and binary forms, with or without
% modification, are permitted provided that the following conditions are
% met:
%
% 1. Redistributions of source code must retain the above copyright
% notice, this list of conditions and the following disclaimer.
%
% 2. Redistributions in binary form must reproduce the above copyright
% notice, this list of conditions and the following disclaimer in the
% documentation and/or other materials provided with the
% distribution.
%
% 3. Neither the name of the copyright holder nor the names of its
% contributors may be used to endorse or promote products derived
% from this software without specific prior written permission.
%
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
% “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
% LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
% A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
% HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
% SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
% LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
% DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
% THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
% (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
% OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{credits}[2023/02/21 LaTeX package for contributor statements following CRediT, the contributor roles taxonomy]
\RequirePackage{ifthen}
\RequirePackage{kvoptions}
\RequirePackage{pgfkeys}
\RequirePackage{tikz}
\RequirePackage{xstring}
\RequirePackage{etoolbox}
\SetupKeyvalOptions{%
family = CREDITS,
prefix = CREDITS@
}
\DeclareBoolOption{horizontal}
\DeclareBoolOption{skipempty}
\DeclareStringOption[black]{role}
\DeclareStringOption[white]{grid}
\DeclareStringOption[;]{separator}
\ProcessKeyvalOptions*
\usetikzlibrary{calc}
\usetikzlibrary{intersections}
\def\concepts{%
Conceptualization,
Data curation,
Formal analysis,
Funding acquisition,
Investigation,
Methodology,
Project administration,
Resources,
Software,
Supervision,
Validation,
Visualization,
Writing -- original draft,
Writing -- review \& editing%
}
\let\credits\relax
\newcounter{row}
\newcommand{\credit}[2]{%
% Split the contributions and check if each is valid
\foreach \entry in {#2} {%
\global\def\conceptfound{0}
\foreach \concept in \concepts {%
\ifthenelse{\equal{\entry}{\concept}}{%
\global\def\conceptfound{1}%
\breakforeach
}{}%
}%
\ifnum\conceptfound=0\relax%
% \entry did not match any concept
\IfDecimal{\entry}{%
\pgfmathparse{\entry}%
% Now check if it's between 0 and 1 (inclusive)
\ifdim\pgfmathresult pt<0pt%
\PackageWarning{credits}{Unknown contribution "\entry" by #1. It doesn't match any predefined concept and is not between 0 and 1.}%
\else%
\ifdim\pgfmathresult pt>1pt%
\PackageWarning{credits}{Unknown contribution "\entry" by #1. It doesn't match any predefined concept and is not between 0 and 1.}%
\fi%
\fi%
}{%
% \entry is not a decimal number
\PackageWarning{credits}{Unknown contribution "\entry" by #1. It doesn't match any predefined concept.}%
}%
\fi%
}%
% Store the credit information
\ifx\credits\relax%
\def\credits{#1/{#2}}%
\else%
\xdef\credits{\credits,#1/{#2}}%
\fi%
}
\tikzset{
/credits/tile/.style = {
align=center,
minimum size=5mm,
anchor=north west,
},
}
\ifCREDITS@horizontal%
\tikzset{
/credits/author/.style = {%
anchor = north east,
xshift = 1.5em,
},%
/credits/concept/.style = {%
anchor = north west,
rotate = 90,
xshift = -1.5em,
},
}
\else%
\tikzset{
/credits/author/.style = {%
anchor = north west,
rotate = 45,
xshift = -0.50em,
yshift = -0.25em,
},%
/credits/concept/.style = {%
anchor = north east,
xshift = 1.5em,
},
}
\fi
% Define the credit contributions
\newcommand{\insertcredits}{%
\begin{tikzpicture}[scale = 0.5]
\tikzset{%
author/.style = /credits/author,
concept/.style = /credits/concept,
tile/.style = /credits/tile,
}
% First draw the author names
\foreach \name/\column [count=\authorIndex] in \credits {%
\ifCREDITS@horizontal%
\node[author] at (0, -\authorIndex) {\name};
\else%
\node[author] at (\authorIndex, 0) {\name};
\fi%
}
% Next, process each concept
\setcounter{row}{0}
\foreach \concept [count=\conceptIndex] in \concepts {%
\setcounter{CREDITS@concepts}{0}%
% Check if any author contributed to this concept
\foreach \name/\column in \credits {%
\foreach \entry in \column {%
% Compare entry to concept
\ifx\entry\concept%
\addtocounter{CREDITS@concepts}{1}%
\fi%
}%
}%
% Add concept if there are contributors or if skipempty is false
\pgfmathparse{\value{CREDITS@concepts}>0 || \ifCREDITS@skipempty 0\else 1\fi}%
\ifnum\pgfmathresult=1\relax%
\addtocounter{row}{1}%
\ifCREDITS@horizontal%
\node[concept] at (\value{row}, 0) {\concept};
\else%
\node[concept] at (0, -\value{row}) {\concept};
\fi%
% Now for each author, check if they contributed to this concept
\foreach \name/\column [count=\authorIndex] in \credits {%
\foreach \entry in \column {%
% Default color
\def\cellfill{white}%
\ifthenelse{\equal{\entry}{\concept}}{%
\def\cellfill{\CREDITS@role}%
\breakforeach
}{}%
\ifCREDITS@horizontal%
\node[fill = \cellfill, draw = \CREDITS@grid, tile] at (\value{row}, -\authorIndex) {};
\else%
\node[fill = \cellfill, draw = \CREDITS@grid, tile] at (\authorIndex, -\value{row}) {};
\fi%
}%
}%
\fi%
}%
\end{tikzpicture}
}
% Continue support for passing information via floats
\newcommand{\insertcreditsgranular}{%
\begin{tikzpicture}[scale = 0.5]
\tikzset{%
author/.style = /credits/author,
concept/.style = /credits/concept,
tile/.style = /credits/tile,
}
% First draw the author names
\foreach \name/\column [count=\n] in \credits {%
% Put an author label here. If you want to *rotate* names in
% a different way because you are using abbreviations, it is
% sufficient to update the `author` style.
\ifCREDITS@horizontal%
\node[author] at (0, -\n) {\name};
\else
\node[author] at (\n, 0) {\name};
\fi
}
% Next, count the number of contributors per concept
\setcounter{row}{0}
\foreach \concept [count = \i] in \concepts {%
\setcounter{CREDITS@concepts}{0}%
\foreach \name/\column in \credits {%
\foreach \entry [count=\m] in \column {%
\ifthenelse{\i = \m}{%
\pgfmathparse{\entry > 0 ? 1 : 0}%
\ifthenelse{\pgfmathresult > 0}{%
\addtocounter{CREDITS@concepts}{1}%
}{}%
}%
{}%
}%
}%
% Add concept if >0 contributors or if we don't skip empty concepts
\pgfmathparse{\value{CREDITS@concepts}>0 || \ifCREDITS@skipempty 0\else 1\fi}
\ifnum\pgfmathresult=1\relax
\addtocounter{row}{1}
\ifCREDITS@horizontal%
\node[concept] at (\value{row}, 0) {\concept};
\else%
\node[concept] at (0, -\value{row}) {\concept};
\fi%
\fi
\foreach \name/\column [count=\n] in \credits {%
\foreach \entry [count = \m] in \column {%
\pgfmathparse{\entry*100}
\colorlet{fill}{\CREDITS@role!\pgfmathresult}
\colorlet{grid}{\CREDITS@grid}
\pgfmathparse{\value{CREDITS@concepts}>0 || \ifCREDITS@skipempty 0\else 1\fi && \m==\i ? 1 : 0}
\ifnum\pgfmathresult=1\relax
\ifCREDITS@horizontal
\node[fill = fill, draw = grid, tile] (tile) at (\value{row}, -\n) {};
\else%
\node[fill = fill, draw = grid, tile] (tile) at (\n, -\value{row}) {};
\fi
\fi
}
}%
}%
\end{tikzpicture}
}
% Required to ensure that we can count active concepts later on when
% generating text statements.
\newcounter{CREDITS@concepts}
% Initialize a counter for the number of already-added authors
\newcounter{CREDITSADDED@concepts}
\newcommand{\resetcredits}{%
\global\let\credits\relax%
% Reset any other global variables if necessary
}
\newcommand{\insertcreditsstatement}{%
\foreach \concept [count = \i] in \concepts {%
\setcounter{CREDITS@concepts}{0}%
\setcounter{CREDITSADDED@concepts}{0}%
\foreach \name/\column in \credits {%
\foreach \entry in \column {%
\ifthenelse{\equal{\entry}{\concept}}{%
\addtocounter{CREDITS@concepts}{1}%
}{}%
}%
}%
\pgfmathparse{\value{CREDITS@concepts}>0 || \ifCREDITS@skipempty 0\else 1\fi}%
\ifnum\pgfmathresult=1\relax
{\bfseries\concept: }%
\foreach \name/\column in \credits {%
\foreach \entry in \column {%
\ifthenelse{\equal{\entry}{\concept}}{%
\ifnum\value{CREDITSADDED@concepts}>0 {, } \fi%
\name%
\addtocounter{CREDITSADDED@concepts}{1}%
}{}%
}%
}%
\ifnum\i<14\relax
\CREDITS@separator{}
\fi
\fi
}%
}
\newcommand{\insertcreditsgranularstatement}{%
\foreach \concept [count = \i] in \concepts {%
\setcounter{CREDITS@concepts}{0}%
\setcounter{CREDITSADDED@concepts}{0}%
\foreach \name/\column [count=\n] in \credits {%
\foreach \entry [count=\m] in \column {%
\ifthenelse{\i = \m}{%
\pgfmathparse{\entry > 0 ? 1 : 0}%
\ifthenelse{\pgfmathresult > 0}{%
\addtocounter{CREDITS@concepts}{1}%
}{}%
}%
{}%
}%
}%
\pgfmathparse{\value{CREDITS@concepts}>0 || \ifCREDITS@skipempty 0\else 1\fi}
\ifnum\pgfmathresult=1\relax
{\bfseries\concept: }%
\foreach \name/\column [count=\n] in \credits {%
\foreach \entry [count=\m] in \column {%
\ifthenelse{\i = \m}{%
% Check if the author contributed to the concept
% If yes, add a comma before the author acronym if >=1 author was already added
\pgfmathparse{int(\entry > 0) && \value{CREDITSADDED@concepts} > 0 && \value{CREDITS@concepts} > 1 ? ", " : ""}%
\pgfmathresult
% Add the author acronym if they contributed to the concept
\pgfmathparse{\entry > 0 ? "\name" : ""}%
\pgfmathresult
\ifdim\entry pt > 0pt
\addtocounter{CREDITSADDED@concepts}{1}%
\fi
}%
{}%
}%
}%
\ifthenelse{\i < 14}{%
\CREDITS@separator{}
}%
{}%
\fi
}%
}