Skip to content

Commit 0ac11b7

Browse files
committed
close #28: when author is an array of length > 1, write each author in a separate <h2> (for LaTeX output, join authors by \and)
1 parent 8c16e7b commit 0ac11b7

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: litedown
22
Type: Package
33
Title: A Lightweight Version of R Markdown
4-
Version: 0.2.7
4+
Version: 0.2.8
55
Authors@R: c(
66
person("Yihui", "Xie", role = c("aut", "cre"), email = "[email protected]", comment = c(ORCID = "0000-0003-0645-5666")),
77
person()

NEWS.md

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
- Added a new vignette engine `litedown::book` to make it possible to build multiple vignettes into a book. To use this engine, declare `\VignetteEngine{litedown::book}` only in the book index file (e.g., `index.Rmd`) but not in other book chapter files.
1212

13+
- Added support for an array of multiple authors in the YAML metadata (thanks, @AlbertLei, #28). If the `author` field in YAML is an array of length > 1, each author will be written to a separate `<h2>` in HTML output, or concatenated by `\and` in LaTeX output. Note that you can also write multiple authors in a single string (e.g., `author: "Jane X and John Y"`) instead of using an array (`author: ["Jane X", "John Y"]`), in which case the string will be treated as a single author (they will be put inside a single `<h2>` in HTML output).
14+
1315
# CHANGES IN litedown VERSION 0.2
1416

1517
- A data frame (or matrix/tibble) wrapped in `I()` is fully printed to a table now by default. Without `I()`, data objects are truncated to 10 rows by default when printing to tables.

R/mark.R

+10-6
Original file line numberDiff line numberDiff line change
@@ -309,18 +309,22 @@ mark = function(input, output = NULL, text = NULL, options = NULL, meta = list()
309309

310310
meta$body = ret
311311
# convert some meta variables in case they use Markdown syntax
312-
for (i in top_meta) if (length(meta[[i]])) {
313-
meta[[i]] = render(meta[[i]], clean = i != 'abstract')
312+
for (i in top_meta) if (meta_len <- length(meta[[i]])) {
313+
# if author is of length > 1, render them individually
314+
m_author = i == 'author' && meta_len > 1
315+
meta[[i]] = if (m_author) uapply(meta[[i]], render) else {
316+
render(meta[[i]], clean = i != 'abstract')
317+
}
314318
# also provide *_ version of top-level meta variables, containing tags/commands
315319
meta[[paste0(i, '_')]] = I(if (format == 'html') {
316320
tag = tag_meta[i]
317321
sprintf(
318-
'<div class="%s">%s</div>', i, if (tag == '') meta[[i]] else sprintf(
319-
'<%s>%s</%s>', tag, meta[[i]], tag
320-
)
322+
'<div class="%s">%s</div>', i, if (tag == '') meta[[i]] else {
323+
one_string(sprintf('<%s>%s</%s>', tag, meta[[i]], tag))
324+
}
321325
)
322326
} else if (format == 'latex') {
323-
sprintf(cmd_meta[i], meta[[i]])
327+
sprintf(cmd_meta[i], if (m_author) one_string(meta[[i]], ' \\and ') else meta[[i]])
324328
})
325329
}
326330
# use the template (if provided) to create a standalone document

0 commit comments

Comments
 (0)