|
| 1 | +#' American Meteorological Society journals format. |
| 2 | +#' |
| 3 | +#' Format for creating submissions to American Meteorological Society journals. |
| 4 | +#' |
| 5 | +#' @inheritParams rmarkdown::pdf_document |
| 6 | +#' @param citation_package only natbib is supported with this template. |
| 7 | +#' @param ... Additional arguments to [rmarkdown::pdf_document()]. **Note**: `extra_dependencies` are not |
| 8 | +#' allowed as Copernicus does not support additional packages included via \code{\\usepackage{}}. |
| 9 | +#' |
| 10 | +#' @return An R Markdown output format. |
| 11 | +#' @details This was adapted from |
| 12 | +#' <https://www.ametsoc.org/index.cfm/ams/publications/author-information/latex-author-info/>. |
| 13 | +#' |
| 14 | +#' The template require some default knitr option to be change: |
| 15 | +#' |
| 16 | +#' * `echo = FALSE` as no R code should be shown |
| 17 | +#' * `fig.path = ""` as all directory paths need to be removed from figure names |
| 18 | +#' * `out.extra = ""` to force figure labels with knitr |
| 19 | +#' |
| 20 | +#' @examples |
| 21 | +#' \dontrun{ |
| 22 | +#' library("rmarkdown") |
| 23 | +#' draft("MyArticle.Rmd", template = "ams", package = "rticles") |
| 24 | +#' render("MyArticle/MyArticle.Rmd") |
| 25 | +#' } |
| 26 | +#' @export |
| 27 | +ams_article <- function(..., keep_tex = TRUE, citation_package = "natbib", md_extensions = c("-autolink_bare_uris", "-auto_identifiers"), pandoc_args = NULL) { |
| 28 | + |
| 29 | + rmarkdown::pandoc_available('2.10', TRUE) |
| 30 | + |
| 31 | + if (citation_package != "natbib") { |
| 32 | + stop("AMS template supports only `natbib` for citation processing.") |
| 33 | + } |
| 34 | + |
| 35 | + pandoc_args <- c( |
| 36 | + pandoc_args, |
| 37 | + "--lua-filter", find_resource("ams", "ams.lua") |
| 38 | + ) |
| 39 | + |
| 40 | + base <- pdf_document_format( |
| 41 | + "ams", keep_tex = keep_tex, md_extensions = md_extensions, citation_package = 'natbib', |
| 42 | + pandoc_args = pandoc_args, ... |
| 43 | + ) |
| 44 | + pre_knit <- base$pre_knit |
| 45 | + base$pre_knit <- function(input, metadata, ...) { |
| 46 | + if (is.function(pre_knit)) pre_knit(input, metadata, ...) |
| 47 | + old_meta <- c("journal", "layout", "exauthors", "author1", "author2", "currentaddress", "affiliation") |
| 48 | + # check old arg |
| 49 | + metadata_used <- old_meta %in% names(metadata) |
| 50 | + if (any(metadata_used)) { |
| 51 | + warning("You are probably using an old version of the template - please update to new skeleton or keep using rticles 0.27.", immediate. = TRUE, call. = FALSE) |
| 52 | + warning("Some metadata are no more used in new AMS template: ", knitr::combine_words(old_meta[metadata_used]), ". They will be ignored.", immediate. = TRUE, call. = FALSE) |
| 53 | + } |
| 54 | + } |
| 55 | + base$knitr$opts_chunk <- merge_list(base$knitr$opts_chunk, list( |
| 56 | + fig.path = "", # AMS required |
| 57 | + out.extra = "", # To force figure labels |
| 58 | + echo = FALSE # Don't show R code |
| 59 | + )) |
| 60 | + return(base) |
| 61 | +} |
0 commit comments