Skip to content

Commit e8c7d14

Browse files
mps9506Michael Schrammcderv
committed
Mdpi update (#515)
Co-authored-by: Michael Schramm <michael.schramm@agnet.tamu.edu> Co-authored-by: Christophe Dervieux <christophe.dervieux@gmail.com>
1 parent 100ee40 commit e8c7d14

27 files changed

+39445
-1585
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Type: Package
22
Package: rticles
33
Title: Article Formats for R Markdown
4-
Version: 0.24.9
4+
Version: 0.24.10
55
Authors@R: c(
66
person("JJ", "Allaire", , "jj@posit.co", role = "aut"),
77
person("Yihui", "Xie", , "xie@yihui.name", role = "aut",

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export(rss_article)
4343
export(sage_article)
4444
export(sim_article)
4545
export(springer_article)
46+
export(string_to_table)
4647
export(tf_article)
4748
export(trb_article)
4849
export(wellcomeor_article)

NEWS.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,17 @@
66

77
## NEW FEATURES
88

9-
- `ieee_article()` now supports several affiliations per `authors` when using the `wide: true` mode (thanks, @phamdn, #500)
9+
- `ieee_article()` now supports several affiliations per `authors` when using the `wide: true` mode (thanks, @phamdn, #500).
10+
- Add a helper function `string_to_table()` for documentating configuration from a list copy pasted from a `.tex` template.
1011

1112
## MINOR CHANGES
1213

14+
- Update to the `mdpi_article()` format (thanks, @mps9506, #515)
15+
- New yaml configuration fields.
16+
- Now working with `xelatex`.
17+
- New template skeleton to start with.
18+
- Compatibility with new resources expectations to be in `Definitions/mdpi` folder.
19+
1320
- Improve `elsevier_article()` affilliations for authors by supporting same fields as in official template. This also fix address with comma not showing (thanks, @gjpstrain, @mps9506, #509).
1421

1522
- Update `RJournal.sty` to latest version to support number sections (thanks, @zeileis, #517).

R/article.R

Lines changed: 90 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ informs_article <- function(..., keep_tex = TRUE, citation_package = "natbib") {
272272
if (citation_package != "natbib") {
273273
stop("INFORMS template only supports `natbib` for citation processing.")
274274
}
275+
275276
if (!rmarkdown::pandoc_available("2.10")) {
276277
stop("informs_article requires a minimum of pandoc 2.10.")
277278
}
@@ -364,13 +365,99 @@ jedm_article <- function(..., keep_tex = TRUE, citation_package = "natbib") {
364365
#' @section `mdpi_article`: Format for creating submissions to
365366
#' Multidisciplinary Digital Publishing Institute (MDPI) journals. Adapted
366367
#' from <https://www.mdpi.com/authors/latex>.
368+
#'
369+
#' Possible arguments for the YAML header are:
370+
#' * `title` title of the manuscript
371+
#' * `author` list of authors, containing `name`, `affil`, and `orcid` (optional)
372+
#' * `affiliation` list containing `num`, `address`, and `email` for defining `author` affiliations
373+
#' * `authorcitation` string with last name and first intial of authors as expected to be shown in a reference
374+
#' * `firstnote` can include `firstnote` through `eightnote` that correspond to footnote marks in `affil`
375+
#' * `correspondence` contact information of the corresponding author
376+
#' * `journal` short name (case sensitive) of the journal, see template for options
377+
#' * `type` usually "article" but see template for options
378+
#' * `status` usually "submit"
379+
#' * `simplesummary` optional, may depend on specific journal
380+
#' * `abstract` abstract, limited to 200 words
381+
#' * `keywords` 3 to 10 keywords seperated with a semicolon
382+
#' * `acknowledgement` acknowledgement backmatter (optional)
383+
#' * `authorcontributions` report authorship contributions (optional)
384+
#' * `funding` research funding statement
385+
#' * `institutionalreview` IRB statements (optional)
386+
#' * `informedconsent` Informed consent statements for human research (optional)
387+
#' * `dataavailability` Links to datasets or archives (optional)
388+
#' * `conflictsofinterest` Conflict of interest statement (see journal instructions)
389+
#' * `sampleavailability` Sample availability statement (optional)
390+
#' * `supplementary` Supplementary data statement, see template for example (optional)
391+
#' * `abbreviations` list of abbreviations containing `short` and `long`
392+
#' * `bibliography` BibTeX `.bib` file
393+
#' * `appendix` name of appendix tex file
394+
#' * `endnote` boolean, if `TRUE` will print list of endnotes if included in text (optional)
395+
#' * `header-includes`: custom additions to the header, before the `\begin{document}` statement
396+
#' * `include-after`: for including additional LaTeX code before the `\end{document}` statement
367397
#' @export
368398
#' @rdname article
369-
mdpi_article <- function(..., keep_tex = TRUE) {
370-
pdf_document_format(
399+
mdpi_article <- function(..., keep_tex = TRUE, latex_engine = "pdflatex", pandoc_args = NULL, citation_package = "natbib") {
400+
401+
# check all arguments for format's default
402+
if (citation_package != "natbib") {
403+
stop("MDPI template only supports 'natbib' for citation processing.")
404+
}
405+
406+
## check if latex engine is pdflatex or xelatex
407+
if(!latex_engine %in% c("pdflatex", "xelatex")) {
408+
stop("`latex_engine` must be one of 'pdflatex' or 'xelatex' when using the MDPI template.")
409+
}
410+
411+
## check location of mdpi.cls file (new versions are in subfolder)
412+
## to ensure compatibility with old versions
413+
cls_loc <- if(file.exists("mdpi.cls")) "mdpi" else "Definitions/mdpi"
414+
pandoc_args <- c(pandoc_args, rmarkdown::pandoc_variable_arg("cls", cls_loc))
415+
416+
## if latex engine is pdflatex, mdpi class argument must be pdftex
417+
if(latex_engine == "pdflatex") {
418+
pandoc_args <- c(pandoc_args, rmarkdown::pandoc_variable_arg("pdftex", "pdftex"))
419+
}
420+
421+
base <- pdf_document_format(
371422
"mdpi",
372-
keep_tex = keep_tex, citation_package = "natbib", ...
423+
keep_tex = keep_tex,
424+
citation_package = "natbib",
425+
latex_engine = latex_engine,
426+
pandoc_args = pandoc_args,
427+
...
373428
)
429+
430+
base_pre_processor <- base$pre_processor
431+
432+
## pre_processor checks if author metadata > 1 and uses moreauthors mdpi class
433+
## argument
434+
mdpi_pre_processor <- function(metadata,
435+
input_file,
436+
runtime,
437+
knit_meta,
438+
files_dir,
439+
output_dir) {
440+
args <- c(
441+
# run the base prepocessor of the format
442+
if (is.function(base_pre_processor)) {
443+
base_pre_processor(
444+
metadata, input_file, runtime, knit_meta, files_dir, output_dir
445+
)
446+
},
447+
# Set a variable based on metadata field
448+
if (!is.null(metadata$author)) {
449+
if (length(metadata$author) > 1) {
450+
rmarkdown::pandoc_variable_arg("multipleauthors", "moreauthors")
451+
} else {
452+
rmarkdown::pandoc_variable_arg("multipleauthors", "oneauthor")
453+
}
454+
}
455+
)
456+
args
457+
}
458+
459+
base$pre_processor <- mdpi_pre_processor
460+
base
374461
}
375462

376463
#' @section `mnras_article`: Format for creating an Monthly Notices of

R/utils.R

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,43 @@ vec_to_pandoc_variable_args <- function(v_args) {
160160
)
161161
unlist(pandoc_arg_list)
162162
}
163+
164+
## takes a character string with names separated by comma (e.g. journal's names)
165+
## and turns them into a table
166+
167+
#' Split character string into table
168+
#'
169+
#' It takes a character string with names separated by comma (e.g. journal's names)
170+
#' and turns them into a table
171+
#'
172+
#' If the number of elements can't be split equally in the `n` column, blank
173+
#' cells will be created and all placed in the last column.
174+
#'
175+
#' @param x string to split and convert to table
176+
#' @param n number of bucket to create. It will be the number of column in the
177+
#' resulting data.frame
178+
#' @param split_regex defaults to `, ?`. Pass to `split` in [base::strsplit()].
179+
#'
180+
#' @return a dataframe of `n` columns
181+
#' @export
182+
#'
183+
#' @examples
184+
#' string_to_table(paste(letters, collapse = ", "), 3)
185+
string_to_table <- function(x, n, split_regex = ", ?") {
186+
vec <- unlist(strsplit(x, split_regex))
187+
vec_list <- split(vec, cut(seq_along(vec), n, labels = FALSE))
188+
max_n <- max(unlist(lapply(vec_list, length)))
189+
# fill with NA
190+
for (i in 1:n) {
191+
# resize bucket
192+
length(vec_list[[i]]) <- max_n
193+
# and move empty spot at the end
194+
if (i != n && any(ii <- is.na(vec_list[[i]]))) {
195+
vec_list[[i]][ii] <- vec_list[[i + 1]][seq_along(which(ii))]
196+
vec_list[[i + 1]] <- vec_list[[i + 1]][-seq_along(which(ii))]
197+
}
198+
}
199+
df <- data.frame(vec_list)
200+
df[is.na(df)] <- ""
201+
df
202+
}

README.Rmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ Currently included templates and their contributors are the following:
115115
| [JOSS: Journal of Open Source Software](https://joss.theoj.org/) [JOSE: Journal of Open Source Education](https://jose.theoj.org/) | [\@noamross](https://github.com/noamross) | [#229](https://github.com/rstudio/rticles/pull/229) | `joss_article()` |
116116
| [JSS: Journal of Statistical Software](https://www.jstatsoft.org/index) | | | `jss_article()` |
117117
| [LIPIcs](https://www.dagstuhl.de/en/publications/lipics) | [\@nuest](https://github.com/nuest) | [#288](https://github.com/rstudio/rticles/pull/288) | `lipics_article()` |
118-
| [MDPI](https://www.mdpi.com) | [\@dleutnant](https://github.com/dleutnant) | [#147](https://github.com/rstudio/rticles/pull/147) | `mdpi_article()` |
118+
| [MDPI](https://www.mdpi.com) | [\@dleutnant](https://github.com/dleutnant), [\@mps9506](https://github.com/mps9506) | [#147](https://github.com/rstudio/rticles/pull/147), [#515](https://github.com/rstudio/rticles/pull/515) | `mdpi_article()` |
119119
| [MNRAS: Monthly Notices of the Royal Astronomical Society](https://academic.oup.com/mnras) | [\@oleskiewicz](https://github.com/oleskiewicz) | [#175](https://github.com/rstudio/rticles/pull/175) | `mnras_article()` |
120120
| [OUP: Oxford University Press](https://academic.oup.com/pages/authoring/journals/preparing_your_manuscript) | [\@dmkaplan](https://github.com/dmkaplan) | [#284](https://github.com/rstudio/rticles/pull/284) | `oup_articles()` |
121121
| [PeerJ: Journal of Life and Environmental Sciences](https://peerj.com) | [\@zkamvar](https://github.com/zkamvar) | [#127](https://github.com/rstudio/rticles/pull/127) | `peerj_article()` |

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ Currently included templates and their contributors are the following:
102102
| [JOSS: Journal of Open Source Software](https://joss.theoj.org/) [JOSE: Journal of Open Source Education](https://jose.theoj.org/) | [@noamross](https://github.com/noamross) | [\#229](https://github.com/rstudio/rticles/pull/229) | `joss_article()` |
103103
| [JSS: Journal of Statistical Software](https://www.jstatsoft.org/index) | | | `jss_article()` |
104104
| [LIPIcs](https://www.dagstuhl.de/en/publications/lipics) | [@nuest](https://github.com/nuest) | [\#288](https://github.com/rstudio/rticles/pull/288) | `lipics_article()` |
105-
| [MDPI](https://www.mdpi.com) | [@dleutnant](https://github.com/dleutnant) | [\#147](https://github.com/rstudio/rticles/pull/147) | `mdpi_article()` |
105+
| [MDPI](https://www.mdpi.com) | [@dleutnant](https://github.com/dleutnant), [@mps9506](https://github.com/mps9506) | [\#147](https://github.com/rstudio/rticles/pull/147), [\#515](https://github.com/rstudio/rticles/pull/515) | `mdpi_article()` |
106106
| [MNRAS: Monthly Notices of the Royal Astronomical Society](https://academic.oup.com/mnras) | [@oleskiewicz](https://github.com/oleskiewicz) | [\#175](https://github.com/rstudio/rticles/pull/175) | `mnras_article()` |
107107
| [OUP: Oxford University Press](https://academic.oup.com/pages/authoring/journals/preparing_your_manuscript) | [@dmkaplan](https://github.com/dmkaplan) | [\#284](https://github.com/rstudio/rticles/pull/284) | `oup_articles()` |
108108
| [PeerJ: Journal of Life and Environmental Sciences](https://peerj.com) | [@zkamvar](https://github.com/zkamvar) | [\#127](https://github.com/rstudio/rticles/pull/127) | `peerj_article()` |

_pkgdown.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,9 @@ reference:
7272
- title: Journal templates
7373
contents:
7474
- ends_with("article")
75+
- title: Utility function
76+
desc: Functions useful in templates
77+
contents:
78+
- string_to_table
7579

7680

0 commit comments

Comments
 (0)