Skip to content

Commit fe7347d

Browse files
ConorIAeliocampcderv
authored
Updates AMS to V6.1 (#444)
* Cherry-pick @eliocamp * Uses xelatex in the AMS skeleton * Update for v6.1 * Default to twocol=FALSE * check for old argument unsupported and warn * Set pandoc requirement and add warning about new tempalte * Check various metadata * rewrite the new for loop for author * rewrite affiliation as YAML * Move article function to its own file and document * set bibliography in the right place * Add missing part in template for Pandoc * Use markdown in the template for most part * Update bibliography file * Add a lua filter to help write expected AMS syntax * fix affiliation * Adapt test and fix citation package to natbib * Trigger warning immediately * Bump version --------- Co-authored-by: Elio Campitelli <[email protected]> Co-authored-by: Christophe Dervieux <[email protected]>
1 parent 4497cf1 commit fe7347d

File tree

18 files changed

+3874
-941
lines changed

18 files changed

+3874
-941
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@
66
reference
77
inst/doc
88
.vscode
9+
10+
/.luarc.json

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.27.6
4+
Version: 0.27.7
55
Authors@R: c(
66
person("JJ", "Allaire", , "[email protected]", role = "aut"),
77
person("Yihui", "Xie", , "[email protected]", role = "aut",

NEWS.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@
88

99
- Update `mdpi_article()` to latest version of September 2024 (thanks, @nielsbock, #573, #580).
1010

11+
- Update `ams_article()` to latest version 6.1 with some breaking changes:
12+
- Pandoc v2.10 is required with the template now
13+
- Removed metadata no more used :
14+
- `journal`, `layout`, `exauthors`, `author1`, `author2`, `currentaddress`, `affiliation`)
15+
- Authors related variable are now `authors` and `affiliations` fields which accept multi authors. See the new skeleton by creating new template with `rmarkdown::draft("Untiltle.Rmd", "ams", "rticles")`.
16+
- Only `natbib` is supported now in `citation_package`
17+
- Some knitr options are made default in the format: `fig.path = ""`, `out.extra = ""`, `echo = FALSE`. They can be overriden in the document.
18+
- Specific markdown syntax are available in template for `acknowledgments`, `datastatement`, `appendix`. See the new skeleton by creating new template with `rmarkdown::draft("Untiltle.Rmd", "ams", "rticles")`.
19+
1120
# rticles 0.27
1221

1322
- `joss_article()` now correctly works as `base_format` for `bookdown::pdf_book()` (thanks, @mlysy, #564).

R/ams_article.R

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
}

R/article.R

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -86,19 +86,6 @@ amq_article <- function(..., latex_engine = "xelatex", keep_tex = TRUE,
8686
)
8787
}
8888

89-
#' @section `ams_article`: Format for creating an American Meteorological
90-
#' Society (AMS) Journal articles. Adapted from
91-
#' <https://www.ametsoc.org/ams/index.cfm/publications/authors/journal-and-bams-authors/author-resources/latex-author-info/>.
92-
#' @export
93-
#' @rdname article
94-
ams_article <- function(..., keep_tex = TRUE,
95-
md_extensions = c("-autolink_bare_uris")) {
96-
pdf_document_format(
97-
"ams",
98-
keep_tex = keep_tex, md_extensions = md_extensions, ...
99-
)
100-
}
101-
10289
#' @section `asa_article`: This format was adapted from The American
10390
#' Statistician (TAS) format, but it should be fairly consistent across
10491
#' American Statistical Association (ASA) journals.
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
local function getLetter(counter)
2+
if counter < 1 or counter > 26 then
3+
return nil -- Return nil for invalid input
4+
end
5+
local letter = string.char(counter + 64) -- 64 is used because ASCII value of 'A' is 65
6+
return letter
7+
end
8+
9+
local function process_div(div)
10+
if div.classes:includes("acknowledgments") then
11+
if #div.content and #div.content[1].content then
12+
div.content[1].content:insert(1, pandoc.RawInline("latex", "\\acknowledgments\n"))
13+
elseif #div.content then
14+
div.content:insert(1, pandoc.RawInline("latex", "\\acknowledgments\n"))
15+
end
16+
return div.content
17+
end
18+
if div.classes:includes("datastatement") then
19+
if #div.content and #div.content[1].content then
20+
div.content[1].content:insert(1, pandoc.RawInline("latex", "\\datastatement\n"))
21+
elseif #div.content then
22+
div.content:insert(1, pandoc.RawInline("latex", "\\datastatement\n"))
23+
end
24+
return div.content
25+
end
26+
if div.classes:includes("appendix") then
27+
nb_appendix = 0
28+
div.content:walk({
29+
Header = function(h)
30+
if h.level == 1 then
31+
nb_appendix = nb_appendix + 1
32+
end
33+
end
34+
})
35+
if nb_appendix > 0 then
36+
local counter = 0
37+
return div.content:walk({
38+
traverse = 'topdown',
39+
Header = function(h)
40+
if h.level == 1 then
41+
counter = counter + 1
42+
local appendix
43+
if nb_appendix == 1 then
44+
appendix = pandoc.RawInline("latex", "\\appendix\n")
45+
else
46+
appendix = pandoc.RawInline("latex", string.format("\\appendix[%s]\n", getLetter(counter)))
47+
end
48+
h.content:insert(1, pandoc.RawInline("latex", "\\appendixtitle{"))
49+
h.content:insert(pandoc.RawInline("latex", "}"))
50+
h.content:insert(1, appendix)
51+
return { h.content }
52+
elseif h.level == 2 then
53+
local star = ""
54+
if h.classes:includes("unnumbered") then
55+
star = "*"
56+
end
57+
h.content:insert(1, pandoc.RawInline("latex", string.format("\\subsection%s{", star)))
58+
h.content:insert(pandoc.RawInline("latex", "}"))
59+
return { h.content}
60+
end
61+
end
62+
})
63+
end
64+
end
65+
return div.content
66+
end
67+
68+
return {
69+
Div = process_div,
70+
}

0 commit comments

Comments
 (0)