Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mdpi update #515

Merged
merged 44 commits into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
4af424f
remove old mdpi files
Feb 4, 2023
b942fd1
add new mdpi files and preserve structure
Feb 4, 2023
b149971
update template to mdpi version 2022-12
Feb 4, 2023
521fb6e
new yaml options for mdpi template.tex
Feb 4, 2023
6544fa5
update figures and table examples
Feb 4, 2023
b867bff
update math environment examples
Feb 4, 2023
d234a8f
edits
Feb 4, 2023
1068c6d
edits
Feb 4, 2023
293a210
update to 2023-03-25 template files
Apr 17, 2023
4284601
remove old comment
Apr 17, 2023
301b1cf
check location of mdpi.cls directly from mdpi_article()
Apr 17, 2023
278166d
use comment chunk
Apr 17, 2023
45a2aa5
go back to class specific options in the yaml
Apr 17, 2023
0e2247b
define pdftex class option using latex_engine variable in template fu…
Apr 17, 2023
e360b59
fix template date
Apr 17, 2023
b541e4c
add markdown math
Apr 18, 2023
0345732
remove bibliography comment
Apr 18, 2023
64a90e7
clarify comment
Apr 18, 2023
2bf8a93
handle moreauthor arg in format function
Apr 18, 2023
3da379b
journal names as table
Apr 18, 2023
03671db
remove journals class option comment
Apr 18, 2023
e2a611a
typo: moreauthors
Apr 18, 2023
d2bf6cc
remove \externalbibliography
Apr 18, 2023
731f7d4
document mdpi_article
Apr 19, 2023
564405e
remove pipe
Apr 19, 2023
87b4783
update documentation in template
Apr 19, 2023
5f22c98
add journal specific variables
Apr 19, 2023
5267301
clean up journal specific template comments
Apr 19, 2023
42441ef
document yaml options
Apr 20, 2023
b1a4a9e
Expose argument but check them early for format's allowed values
cderv Apr 20, 2023
b480528
`pandoc_args` needs to be exposed as we modify it
cderv Apr 20, 2023
eebdb68
Rewrite pre_processor handling to not miss the pdf_document one
cderv Apr 20, 2023
9054859
Use :: for namespace instead
cderv Apr 20, 2023
f7eb8ea
Add a function to split text into table
cderv Apr 21, 2023
568589f
Use available field in format function
cderv Apr 21, 2023
8ef1b2a
Correct reference
cderv Apr 21, 2023
ea1c876
Bump VERSION
cderv Apr 21, 2023
0d96cb7
Add NEWS
cderv Apr 21, 2023
551bb08
Add new contributor to README
cderv Apr 21, 2023
e346471
Merge branch 'main' into mdpi-update
cderv Apr 21, 2023
49c988e
Function was renamed :facepalm:
cderv Apr 21, 2023
ebdc0d7
visual editor is messing with README
cderv Apr 21, 2023
b8b90a6
Fix examples
cderv Apr 21, 2023
8dd3fcd
Add new helper to NEWS
cderv Apr 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
mps9506 marked this conversation as resolved.
Show resolved Hide resolved
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