-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathpubmatter.typ
More file actions
535 lines (500 loc) · 16.5 KB
/
Copy pathpubmatter.typ
File metadata and controls
535 lines (500 loc) · 16.5 KB
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
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
#import "@preview/scienceicons:0.1.0": orcid-icon, email-icon, open-access-icon, github-icon, cc-icon, cc-zero-icon, cc-by-icon, cc-nc-icon, cc-nd-icon, cc-sa-icon, ror-icon
#import "./validate-frontmatter.typ": load, show-citation
#let THEME = state("THEME", (color: blue.darken(20%), font: ""))
#let with-theme(func) = context {
let theme = THEME.at(here())
func(theme)
}
/// Create a ORCID link with an ORCID logo
///
/// ```example
/// #pubmatter.orcid-link(orcid: "0000-0002-7859-8394")
/// ```
///
/// - orcid (str): Use an ORCID identifier with no URL, e.g. `0000-0000-0000-0000`
/// -> content
#let orcid-link(
orcid: none,
) = {
let orcid-green = rgb("#AECD54")
if (orcid == none) { return orcid-icon(color: orcid-green) }
if (orcid.starts-with("https://")) { return link(orcid, orcid-icon(color: orcid-green)) }
return link("https://orcid.org/" + orcid, orcid-icon(color: orcid-green))
}
/// Create a DOI link
///
/// ```example
/// #pubmatter.doi-link(doi: "10.1190/tle35080703.1")
/// ```
///
/// - doi (str): Only include the DOI identifier, not the URL
/// -> content
#let doi-link(doi: none) = {
if (doi == none) { return none }
// Proper practices are to show the whole DOI link in text
if (doi.starts-with("https://")) { return link(doi, doi) };
return link("https://doi.org/" + doi, "https://doi.org/" + doi)
}
/// Create a ROR link
///
/// ```example
/// #pubmatter.ror-link(ror: "02mz0e468")
/// ```
///
/// - ror (str): Only include the ROR identifier, not the URL
/// -> content
#let ror-link(ror: none) = {
let ror-black = rgb("#2c2c2c")
if (ror == none) { return none }
if (ror.starts-with("https://")) { return link(ror, ror-icon(color: ror-black)) };
return link("https://ror.org/" + ror, ror-icon(color: ror-black))
}
/// Create a mailto link with an email icon
///
/// ```example
/// #pubmatter.email-link(email: "rowan@curvenote.com")
/// ```
///
/// - email (str): Email as a string
/// -> content
#let email-link(email: none) = {
if (email == none) { return none }
return link("mailto:" + email, email-icon(color: gray))
}
/// Create a link to Wikipedia with an OpenAccess icon.
///
/// ```example
/// #pubmatter.open-access-link()
/// ```
///
/// -> content
#let open-access-link() = {
let orange = rgb("#E78935")
return link("https://en.wikipedia.org/wiki/Open_access", open-access-icon(color: orange))
}
/// Create a link to a GitHub profile with the GitHub icon.
///
/// ```example
/// #pubmatter.github-link(github: "rowanc1")
/// ```
///
/// - github (str): GitHub username (no `@`)
/// -> content
#let github-link(github: none) = {
if (github.starts-with("https://")) { return link(github, github-icon()) }
return link("https://github.com/" + github, github-icon())
}
/// Create a spaced content array separated with a `spacer`.
///
/// The default spacer is ` | `, and undefined elements are removed.
///
/// ```example
/// #pubmatter.show-spaced-content(("Hello", "There"))
/// ```
///
/// - spacer (content): How to join the content
/// - content (array): The various things to going together
/// -> content
#let show-spaced-content(spacer: text(fill: gray)[#h(8pt) | #h(8pt)], content) = {
content.filter(h => h != none and h != "").join(spacer)
}
/// Show license badge
///
/// Works for creative common license and other license.
///
/// ```example
/// #pubmatter.show-license-badge(pubmatter.load((license: "CC0")))
/// ```
///
/// ```example
/// #pubmatter.show-license-badge(pubmatter.load((license: "CC-BY-4.0")))
/// ```
///
/// ```example
/// #pubmatter.show-license-badge(pubmatter.load((license: "CC-BY-NC-4.0")))
/// ```
///
/// ```example
/// #pubmatter.show-license-badge(pubmatter.load((license: "CC-BY-NC-ND-4.0")))
/// ```
///
/// - fm (fm): The frontmatter object
/// -> content
#let show-license-badge(color: black, fm) = {
let license = if ("license" in fm) { fm.license }
if (license == none) { return none }
if (license.id == "CC0-1.0") {
return link(license.url, [#cc-icon(color: color)#cc-zero-icon(color: color)])
}
if (license.id == "CC-BY-4.0") {
return link(license.url, [#cc-icon(color: color)#cc-by-icon(color: color)])
}
if (license.id == "CC-BY-NC-4.0") {
return link(license.url, [#cc-icon(color: color)#cc-by-icon(color: color)#cc-nc-icon(color: color)])
}
if (license.id == "CC-BY-NC-SA-4.0") {
return link(license.url, [#cc-icon(color: color)#cc-by-icon(color: color)#cc-nc-icon(color: color)])
}
if (license.id == "CC-BY-ND-4.0") {
return link(license.url, [#cc-icon(color: color)#cc-by-icon(color: color)#cc-nd-icon(color: color)])
}
if (license.id == "CC-BY-NC-ND-4.0") {
return link(license.url, [#cc-icon(color: color)#cc-by-icon(color: color)#cc-nc-icon(color: color)#cc-nd-icon(color: color)])
}
}
/// Show copyright
///
/// Function chose a short citation with the copyright year followed by the license text.
/// If the license is a Creative Commons License, additional explainer text is shown.
///
/// ```example
/// #pubmatter.show-copyright(fm)
/// ```
///
/// - fm (fm): The frontmatter object
/// -> content
#let show-copyright(fm) = {
let year = if (fm.date != none) { fm.date.display("[year]") }
let citation = show-citation(show-year: false, fm)
let license = if ("license" in fm) { fm.license }
if (license == none) {
return [Copyright © #{ year }
#citation#{if (fm.at("open-access", default: none) == true){[. This article is open-access.]}}]
}
return [Copyright © #{ year }
#citation.
This #{if (fm.at("open-access", default: none) == true){[is an open-access article]} else {[article is]}} distributed under the terms of the
#link(license.url, license.name) license#{
if (license.id == "CC-BY-4.0") {
[, which enables reusers to distribute, remix, adapt, and build upon the material in any medium or format, so long as attribution is given to the creator]
} else if (license.id == "CC-BY-NC-4.0") {
[, which enables reusers to distribute, remix, adapt, and build upon the material in any medium or format for _noncommercial purposes only_, and only so long as attribution is given to the creator]
} else if (license.id == "CC-BY-NC-SA-4.0") {
[, which enables reusers to distribute, remix, adapt, and build upon the material in any medium or format for noncommercial purposes only, and only so long as attribution is given to the creator. If you remix, adapt, or build upon the material, you must license the modified material under identical terms]
} else if (license.id == "CC-BY-ND-4.0") {
[, which enables reusers to copy and distribute the material in any medium or format in _unadapted form only_, and only so long as attribution is given to the creator]
} else if (license.id == "CC-BY-NC-ND-4.0") {
[, which enables reusers to copy and distribute the material in any medium or format in _unadapted form only_, for _noncommercial purposes only_, and only so long as attribution is given to the creator]
}
}.]
}
/// Get corresponding author
///
/// Returns the first author marked as corresponding author, or the first author with an email.
///
/// ```example
/// #let author = pubmatter.get-corresponding-author(authors)
/// ```
///
/// - authors (fm, array): The frontmatter object or authors directly
/// -> dictionary
#let get-corresponding-author(authors) = {
// Allow to pass frontmatter as well
let authors = if (type(authors) == dictionary and "authors" in authors) {authors.authors} else { authors }
if authors.len() == 0 { return none }
// First, look for an author with corresponding: true
for author in authors {
if ("corresponding" in author and author.corresponding == true) {
return author
}
}
// If none found, look for first author with email that doesn't have corresponding: false
for author in authors {
if ("email" in author and ("corresponding" not in author or author.corresponding != false)) {
return author
}
}
return none
}
/// Show authors
///
/// ```example
/// #pubmatter.show-authors(authors)
/// ```
///
/// - size (length): Size of the author text
/// - weight (weight): Weight of the author text
/// - show-affiliations (boolean): Show affiliations text
/// - show-orcid (boolean): Show orcid logo
/// - show-email (boolean): Show email logo
/// - show-github (boolean): Show github logo
/// - show-equal-contributor (boolean): Show equal contributor asterisk
/// - authors (fm, array): The frontmatter object or authors directly
/// -> content
#let show-authors(
size: 10pt,
weight: "semibold",
show-affiliations: true,
show-orcid: true,
show-email: true,
show-github: true,
show-equal-contributor: true,
authors,
) = {
// Allow to pass frontmatter as well
let authors = if (type(authors) == dictionary and "authors" in authors) {authors.authors} else { authors }
if authors.len() == 0 { return none }
return box(inset: (top: 10pt, bottom: 5pt), width: 100%, {
with-theme((theme) => {
set text(size, font: theme.font)
authors.map(author => {
text(size, font: theme.font, weight: weight, author.name)
if (show-affiliations and "affiliations" in author) {
text(size: 2.5pt, [~]) // Ensure this is not a linebreak
if (type(author.affiliations) == str) {
super(author.affiliations)
} else if (type(author.affiliations) == array) {
super(author.affiliations.map((affiliation) => str(affiliation.index)).join(","))
}
if (show-equal-contributor and "equal-contributor" in author and author.equal-contributor) {
super("†")
}
}
if (show-orcid and "orcid" in author) {
orcid-link(orcid: author.orcid)
}
if (show-github and "github" in author) {
github-link(github: author.github)
}
if (show-email and "email" in author) {
email-link(email: author.email)
}
}).join(", ", last: ", and ")
})
})
}
/// Show affiliations
///
/// ```example
/// #pubmatter.show-affiliations(affiliations)
/// ```
///
/// - size (length): Size of the affiliations text
/// - fill (color): Color of of the affiliations text
/// - show-ror (boolean): Show ror logo
/// - show-equal-contributor (boolean): Show equal contributor note
/// - separator (str): Separator between affiliations
/// - affiliations (fm, array): The frontmatter object or affiliations directly
/// -> content
#let show-affiliations(
size: 8pt,
fill: gray.darken(50%),
show-ror: true,
show-equal-contributor: true,
separator: ", ",
affiliations
) = {
// Allow to pass frontmatter as well
let fm = affiliations
let affiliations = if (type(affiliations) == dictionary and "affiliations" in affiliations) {affiliations.affiliations} else { affiliations }
if affiliations.len() == 0 { return none }
// Check if any author has equal-contributor
let has-equal-contributor = false
if (show-equal-contributor and type(fm) == dictionary and "authors" in fm) {
has-equal-contributor = fm.authors.any(author => "equal-contributor" in author and author.equal-contributor)
}
return box(inset: (bottom: 9pt), width: 100%, {
with-theme((theme) => {
set text(size, font: theme.font, fill: fill)
affiliations.map(affiliation => {
super(str(affiliation.index))
text(size: 2.5pt, [~]) // Ensure this is not a linebreak
if ("name" in affiliation) {
affiliation.name
} else if ("institution" in affiliation) {
affiliation.institution
}
if ("ror" in affiliation) {
text(size: 8pt, [~]) // Ensure this is not a linebreak
ror-link(ror: affiliation.ror)
}
}).join(separator)
if (has-equal-contributor) {
"; "
super("†")
text(size: 2.5pt, [~]) // Ensure this is not a linebreak
[Contributed Equally]
}
})
})
}
/// Show author block, including author, icon links (e.g. ORCID, email, etc.) and affiliations
///
/// ```example
/// #pubmatter.show-author-block(fm)
/// ```
///
/// - fm (fm): The frontmatter object
/// -> content
#let show-author-block(fm) = {
show-authors(fm)
show-affiliations(fm)
}
/// Show title and subtitle
///
/// ```example
/// #pubmatter.show-title(fm)
/// ```
///
/// - fm (fm): The frontmatter object
/// -> content
#let show-title(fm) = {
with-theme(theme => {
set text(font: theme.font)
let title = if (type(fm) == dictionary and "title" in fm) {fm.title} else if (type(fm) == str or type(fm) == content) { fm } else { none }
let subtitle = if (type(fm) == dictionary and "subtitle" in fm) {fm.subtitle} else { none }
if (title != none) {
box(inset: (bottom: 2pt), width: 100%, text(17pt, weight: "bold", fill: theme.color, title))
}
if (subtitle != none) {
parbreak()
box(width: 100%, text(12pt, fill: gray.darken(30%), subtitle))
}
})
}
/// Show title block - title, authors and affiliations
///
/// ```example
/// #pubmatter.show-title-block(fm)
/// ```
///
/// - fm (fm): The frontmatter object
/// -> content
#let show-title-block(fm) = {
with-theme(theme => {
show-title(fm)
show-author-block(fm)
})
}
/// Show page footer
///
/// Default is the venue, date and page numbers
///
/// ```example
/// #pubmatter.show-page-footer(fm)
/// ```
///
/// - fm (fm): The frontmatter object
/// -> content
#let show-page-footer(fm) = {
return block(
width: 100%,
stroke: (top: 1pt + gray),
inset: (top: 8pt, right: 2pt),
with-theme((theme) => [
#set text(font: theme.font)
#grid(columns: (75%, 25%),
align(left, text(size: 9pt, fill: gray.darken(50%),
show-spaced-content((
if("venue" in fm) {emph(fm.venue)},
if("date" in fm and fm.date != none) {fm.date.display("[month repr:long] [day], [year]")}
))
)),
align(right)[
#text(
size: 9pt, fill: gray.darken(50%)
)[
#counter(page).display() of #{context {counter(page).final().first()}}
]
]
)
])
)
}
/// Show page header
///
/// Default an open-access badge and the DOI and then the running-title and citation
///
/// ```example
/// #pubmatter.show-page-header(fm)
/// ```
///
/// - fm (fm): The frontmatter object
/// -> content
#let show-page-header(fm) = context {
let loc = here()
if(loc.page() == 1) {
let headers = (
if ("open-access" in fm) {[#smallcaps[Open Access] #open-access-link()]},
if ("doi" in fm) { link("https://doi.org/" + fm.doi, "https://doi.org/" + fm.doi)}
)
// TODO: There is a bug in the first page state update
// https://github.com/typst/typst/issues/2987
return with-theme((theme) => {
align(left, text(size: 8pt, font: theme.font, fill: gray, show-spaced-content(headers)))
})
} else {
return with-theme((theme) => {align(right + top, box(inset: (top: 1cm), text(size: 8pt, font: theme.font, fill: gray.darken(50%),
show-spaced-content((
if ("short-title" in fm) { fm.short-title } else if ("title" in fm) { fm.title },
if ("citation" in fm) { fm.citation },
)))
))
})
}
}
/// Show all abstracts (e.g. abstract, plain language summary)
///
/// ```example
/// #pubmatter.show-abstracts(fm)
/// ```
///
/// - fm (fm): The frontmatter object
/// -> content
#let show-abstracts(fm) = {
let abstracts
if (type(fm) == content) {
abstracts = ((title: "Abstract", content: fm),)
} else if (type(fm) == dictionary and "abstracts" in fm) {
abstracts = fm.abstracts
} else {
return
}
with-theme((theme) => {
abstracts.map(abs => {
set text(font: theme.font)
text(fill: theme.color, weight: "semibold", size: 9pt, abs.title)
parbreak()
set par(justify: true)
text(size: 9pt, abs.content)
}).join(parbreak())
})
}
/// Show keywords
///
/// ```example
/// #pubmatter.show-keywords(fm)
/// ```
///
/// - fm (fm): The frontmatter object
/// -> content
#let show-keywords(fm) = {
let keywords
if (type(fm) == dictionary and "keywords" in fm) {
keywords = fm.keywords
} else {
return
}
if (keywords.len() > 0) {
with-theme((theme) => {
text(size: 9pt, font: theme.font, {
text(fill: theme.color, weight: "semibold", "Keywords")
h(8pt)
keywords.join(", ")
})
})
}
}
/// Show abstract-block including all abstracts and keywords
///
/// ```example
/// #pubmatter.show-abstract-block(fm)
/// ```
///
/// - fm (fm): The frontmatter object
/// -> content
#let show-abstract-block(fm) = {
box(inset: (top: 16pt, bottom: 16pt), stroke: (top: 0.5pt + gray.lighten(30%), bottom: 0.5pt + gray.lighten(30%)), show-abstracts(fm))
show-keywords(fm)
v(10pt)
}