Skip to content

Commit

Permalink
Mdpi update (#515)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Schramm <[email protected]>
Co-authored-by: Christophe Dervieux <[email protected]>
  • Loading branch information
3 people authored Apr 25, 2023
1 parent d7c4a52 commit e6241e3
Show file tree
Hide file tree
Showing 27 changed files with 39,445 additions and 1,585 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: rticles
Title: Article Formats for R Markdown
Version: 0.24.9
Version: 0.24.10
Authors@R: c(
person("JJ", "Allaire", , "[email protected]", role = "aut"),
person("Yihui", "Xie", , "[email protected]", role = "aut",
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export(rss_article)
export(sage_article)
export(sim_article)
export(springer_article)
export(string_to_table)
export(tf_article)
export(trb_article)
export(wellcomeor_article)
Expand Down
9 changes: 8 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,17 @@

## NEW FEATURES

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

## MINOR CHANGES

- Update to the `mdpi_article()` format (thanks, @mps9506, #515)
- New yaml configuration fields.
- Now working with `xelatex`.
- New template skeleton to start with.
- Compatibility with new resources expectations to be in `Definitions/mdpi` folder.

- 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).

- Update `RJournal.sty` to latest version to support number sections (thanks, @zeileis, #517).
Expand Down
93 changes: 90 additions & 3 deletions R/article.R
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ informs_article <- function(..., keep_tex = TRUE, citation_package = "natbib") {
if (citation_package != "natbib") {
stop("INFORMS template only supports `natbib` for citation processing.")
}

if (!rmarkdown::pandoc_available("2.10")) {
stop("informs_article requires a minimum of pandoc 2.10.")
}
Expand Down Expand Up @@ -364,13 +365,99 @@ jedm_article <- function(..., keep_tex = TRUE, citation_package = "natbib") {
#' @section `mdpi_article`: Format for creating submissions to
#' Multidisciplinary Digital Publishing Institute (MDPI) journals. Adapted
#' from <https://www.mdpi.com/authors/latex>.
#'
#' Possible arguments for the YAML header are:
#' * `title` title of the manuscript
#' * `author` list of authors, containing `name`, `affil`, and `orcid` (optional)
#' * `affiliation` list containing `num`, `address`, and `email` for defining `author` affiliations
#' * `authorcitation` string with last name and first intial of authors as expected to be shown in a reference
#' * `firstnote` can include `firstnote` through `eightnote` that correspond to footnote marks in `affil`
#' * `correspondence` contact information of the corresponding author
#' * `journal` short name (case sensitive) of the journal, see template for options
#' * `type` usually "article" but see template for options
#' * `status` usually "submit"
#' * `simplesummary` optional, may depend on specific journal
#' * `abstract` abstract, limited to 200 words
#' * `keywords` 3 to 10 keywords seperated with a semicolon
#' * `acknowledgement` acknowledgement backmatter (optional)
#' * `authorcontributions` report authorship contributions (optional)
#' * `funding` research funding statement
#' * `institutionalreview` IRB statements (optional)
#' * `informedconsent` Informed consent statements for human research (optional)
#' * `dataavailability` Links to datasets or archives (optional)
#' * `conflictsofinterest` Conflict of interest statement (see journal instructions)
#' * `sampleavailability` Sample availability statement (optional)
#' * `supplementary` Supplementary data statement, see template for example (optional)
#' * `abbreviations` list of abbreviations containing `short` and `long`
#' * `bibliography` BibTeX `.bib` file
#' * `appendix` name of appendix tex file
#' * `endnote` boolean, if `TRUE` will print list of endnotes if included in text (optional)
#' * `header-includes`: custom additions to the header, before the `\begin{document}` statement
#' * `include-after`: for including additional LaTeX code before the `\end{document}` statement
#' @export
#' @rdname article
mdpi_article <- function(..., keep_tex = TRUE) {
pdf_document_format(
mdpi_article <- function(..., keep_tex = TRUE, latex_engine = "pdflatex", pandoc_args = NULL, citation_package = "natbib") {

# check all arguments for format's default
if (citation_package != "natbib") {
stop("MDPI template only supports 'natbib' for citation processing.")
}

## check if latex engine is pdflatex or xelatex
if(!latex_engine %in% c("pdflatex", "xelatex")) {
stop("`latex_engine` must be one of 'pdflatex' or 'xelatex' when using the MDPI template.")
}

## check location of mdpi.cls file (new versions are in subfolder)
## to ensure compatibility with old versions
cls_loc <- if(file.exists("mdpi.cls")) "mdpi" else "Definitions/mdpi"
pandoc_args <- c(pandoc_args, rmarkdown::pandoc_variable_arg("cls", cls_loc))

## if latex engine is pdflatex, mdpi class argument must be pdftex
if(latex_engine == "pdflatex") {
pandoc_args <- c(pandoc_args, rmarkdown::pandoc_variable_arg("pdftex", "pdftex"))
}

base <- pdf_document_format(
"mdpi",
keep_tex = keep_tex, citation_package = "natbib", ...
keep_tex = keep_tex,
citation_package = "natbib",
latex_engine = latex_engine,
pandoc_args = pandoc_args,
...
)

base_pre_processor <- base$pre_processor

## pre_processor checks if author metadata > 1 and uses moreauthors mdpi class
## argument
mdpi_pre_processor <- function(metadata,
input_file,
runtime,
knit_meta,
files_dir,
output_dir) {
args <- c(
# run the base prepocessor of the format
if (is.function(base_pre_processor)) {
base_pre_processor(
metadata, input_file, runtime, knit_meta, files_dir, output_dir
)
},
# Set a variable based on metadata field
if (!is.null(metadata$author)) {
if (length(metadata$author) > 1) {
rmarkdown::pandoc_variable_arg("multipleauthors", "moreauthors")
} else {
rmarkdown::pandoc_variable_arg("multipleauthors", "oneauthor")
}
}
)
args
}

base$pre_processor <- mdpi_pre_processor
base
}

#' @section `mnras_article`: Format for creating an Monthly Notices of
Expand Down
40 changes: 40 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,43 @@ vec_to_pandoc_variable_args <- function(v_args) {
)
unlist(pandoc_arg_list)
}

## takes a character string with names separated by comma (e.g. journal's names)
## and turns them into a table

#' Split character string into table
#'
#' It takes a character string with names separated by comma (e.g. journal's names)
#' and turns them into a table
#'
#' If the number of elements can't be split equally in the `n` column, blank
#' cells will be created and all placed in the last column.
#'
#' @param x string to split and convert to table
#' @param n number of bucket to create. It will be the number of column in the
#' resulting data.frame
#' @param split_regex defaults to `, ?`. Pass to `split` in [base::strsplit()].
#'
#' @return a dataframe of `n` columns
#' @export
#'
#' @examples
#' string_to_table(paste(letters, collapse = ", "), 3)
string_to_table <- function(x, n, split_regex = ", ?") {
vec <- unlist(strsplit(x, split_regex))
vec_list <- split(vec, cut(seq_along(vec), n, labels = FALSE))
max_n <- max(unlist(lapply(vec_list, length)))
# fill with NA
for (i in 1:n) {
# resize bucket
length(vec_list[[i]]) <- max_n
# and move empty spot at the end
if (i != n && any(ii <- is.na(vec_list[[i]]))) {
vec_list[[i]][ii] <- vec_list[[i + 1]][seq_along(which(ii))]
vec_list[[i + 1]] <- vec_list[[i + 1]][-seq_along(which(ii))]
}
}
df <- data.frame(vec_list)
df[is.na(df)] <- ""
df
}
2 changes: 1 addition & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ Currently included templates and their contributors are the following:
| [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()` |
| [JSS: Journal of Statistical Software](https://www.jstatsoft.org/index) | | | `jss_article()` |
| [LIPIcs](https://www.dagstuhl.de/en/publications/lipics) | [\@nuest](https://github.com/nuest) | [#288](https://github.com/rstudio/rticles/pull/288) | `lipics_article()` |
| [MDPI](https://www.mdpi.com) | [\@dleutnant](https://github.com/dleutnant) | [#147](https://github.com/rstudio/rticles/pull/147) | `mdpi_article()` |
| [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()` |
| [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()` |
| [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()` |
| [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()` |
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Currently included templates and their contributors are the following:
| [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()` |
| [JSS: Journal of Statistical Software](https://www.jstatsoft.org/index) | | | `jss_article()` |
| [LIPIcs](https://www.dagstuhl.de/en/publications/lipics) | [@nuest](https://github.com/nuest) | [\#288](https://github.com/rstudio/rticles/pull/288) | `lipics_article()` |
| [MDPI](https://www.mdpi.com) | [@dleutnant](https://github.com/dleutnant) | [\#147](https://github.com/rstudio/rticles/pull/147) | `mdpi_article()` |
| [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()` |
| [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()` |
| [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()` |
| [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()` |
Expand Down
4 changes: 4 additions & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,9 @@ reference:
- title: Journal templates
contents:
- ends_with("article")
- title: Utility function
desc: Functions useful in templates
contents:
- string_to_table


Loading

0 comments on commit e6241e3

Please sign in to comment.