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

Updates AMS to V6.1 #444

Merged
merged 28 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
beec027
Cherry-pick @eliocamp
eliocamp Nov 9, 2020
5f12f3a
Uses xelatex in the AMS skeleton
eliocamp Nov 16, 2020
7f65495
Update for v6.1
ConorIA Oct 17, 2021
e9cd1a1
Default to twocol=FALSE
ConorIA Oct 17, 2021
5e580d8
Cleanup changes to
ConorIA Oct 17, 2021
9df3228
Redocument article.Rd
ConorIA Oct 17, 2021
c36f847
Fix last-entry cases for author and affiliation loops
ConorIA Oct 17, 2021
664ce6e
Merge branch 'main' into ams61
cderv Nov 27, 2024
29e34d2
check for old argument unsupported and warn
cderv Nov 29, 2024
3cc1fd7
Set pandoc requirment and add warning about new tempalte
cderv Nov 29, 2024
3352213
Check various metadata
cderv Nov 29, 2024
944c15a
rewrite the new for loop for auhtor
cderv Nov 29, 2024
0bd2da5
rewrite affiliation as YAML
cderv Nov 29, 2024
93c3121
Move article function to its own file
cderv Nov 29, 2024
4521383
set bibliography in the right place
cderv Nov 29, 2024
3aa21ec
Add missing part in template for Pandoc
cderv Nov 29, 2024
f013c2a
mention doc on abstract
cderv Nov 29, 2024
5409113
Use markdown in the template for most part
cderv Nov 29, 2024
ef268a7
Update bibliography file
cderv Nov 29, 2024
3b10ab5
Add a lua filter to help write expected AMS syntax
cderv Nov 29, 2024
4cd9f70
fix filter
cderv Nov 29, 2024
5ff8ffd
fix affiliation
cderv Nov 29, 2024
801be50
re-document
cderv Nov 29, 2024
3021031
Adapt test and fix citation package to natbib
cderv Nov 29, 2024
d16e04a
Fix merge problem
cderv Nov 29, 2024
f4550da
Re document
cderv Nov 29, 2024
e75fe96
Trigger warning immediately
cderv Nov 29, 2024
4ffd088
Bump version
cderv Dec 6, 2024
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: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
reference
inst/doc
.vscode

/.luarc.json
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.27.6
Version: 0.27.7
Authors@R: c(
person("JJ", "Allaire", , "[email protected]", role = "aut"),
person("Yihui", "Xie", , "[email protected]", role = "aut",
Expand Down
9 changes: 9 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@

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

- Update `ams_article()` to latest version 6.1 with some breaking changes:
- Pandoc v2.10 is required with the template now
- Removed metadata no more used :
- `journal`, `layout`, `exauthors`, `author1`, `author2`, `currentaddress`, `affiliation`)
- 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")`.
- Only `natbib` is supported now in `citation_package`
- Some knitr options are made default in the format: `fig.path = ""`, `out.extra = ""`, `echo = FALSE`. They can be overriden in the document.
- 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")`.

# rticles 0.27

- `joss_article()` now correctly works as `base_format` for `bookdown::pdf_book()` (thanks, @mlysy, #564).
Expand Down
61 changes: 61 additions & 0 deletions R/ams_article.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#' American Meteorological Society journals format.
#'
#' Format for creating submissions to American Meteorological Society journals.
#'
#' @inheritParams rmarkdown::pdf_document
#' @param citation_package only natbib is supported with this template.
#' @param ... Additional arguments to [rmarkdown::pdf_document()]. **Note**: `extra_dependencies` are not
#' allowed as Copernicus does not support additional packages included via \code{\\usepackage{}}.
#'
#' @return An R Markdown output format.
#' @details This was adapted from
#' <https://www.ametsoc.org/index.cfm/ams/publications/author-information/latex-author-info/>.
#'
#' The template require some default knitr option to be change:
#'
#' * `echo = FALSE` as no R code should be shown
#' * `fig.path = ""` as all directory paths need to be removed from figure names
#' * `out.extra = ""` to force figure labels with knitr
#'
#' @examples
#' \dontrun{
#' library("rmarkdown")
#' draft("MyArticle.Rmd", template = "ams", package = "rticles")
#' render("MyArticle/MyArticle.Rmd")
#' }
#' @export
ams_article <- function(..., keep_tex = TRUE, citation_package = "natbib", md_extensions = c("-autolink_bare_uris", "-auto_identifiers"), pandoc_args = NULL) {

rmarkdown::pandoc_available('2.10', TRUE)

if (citation_package != "natbib") {
stop("AMS template supports only `natbib` for citation processing.")
}

pandoc_args <- c(
pandoc_args,
"--lua-filter", find_resource("ams", "ams.lua")
)

base <- pdf_document_format(
"ams", keep_tex = keep_tex, md_extensions = md_extensions, citation_package = 'natbib',
pandoc_args = pandoc_args, ...
)
pre_knit <- base$pre_knit
base$pre_knit <- function(input, metadata, ...) {
if (is.function(pre_knit)) pre_knit(input, metadata, ...)
old_meta <- c("journal", "layout", "exauthors", "author1", "author2", "currentaddress", "affiliation")
# check old arg
metadata_used <- old_meta %in% names(metadata)
if (any(metadata_used)) {
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)
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)
}
}
base$knitr$opts_chunk <- merge_list(base$knitr$opts_chunk, list(
fig.path = "", # AMS required
out.extra = "", # To force figure labels
echo = FALSE # Don't show R code
))
return(base)
}
13 changes: 0 additions & 13 deletions R/article.R
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,6 @@ amq_article <- function(..., latex_engine = "xelatex", keep_tex = TRUE,
)
}

#' @section `ams_article`: Format for creating an American Meteorological
#' Society (AMS) Journal articles. Adapted from
#' <https://www.ametsoc.org/ams/index.cfm/publications/authors/journal-and-bams-authors/author-resources/latex-author-info/>.
#' @export
#' @rdname article
ams_article <- function(..., keep_tex = TRUE,
md_extensions = c("-autolink_bare_uris")) {
pdf_document_format(
"ams",
keep_tex = keep_tex, md_extensions = md_extensions, ...
)
}

#' @section `asa_article`: This format was adapted from The American
#' Statistician (TAS) format, but it should be fairly consistent across
#' American Statistical Association (ASA) journals.
Expand Down
70 changes: 70 additions & 0 deletions inst/rmarkdown/templates/ams/resources/ams.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
local function getLetter(counter)
if counter < 1 or counter > 26 then
return nil -- Return nil for invalid input
end
local letter = string.char(counter + 64) -- 64 is used because ASCII value of 'A' is 65
return letter
end

local function process_div(div)
if div.classes:includes("acknowledgments") then
if #div.content and #div.content[1].content then
div.content[1].content:insert(1, pandoc.RawInline("latex", "\\acknowledgments\n"))
elseif #div.content then
div.content:insert(1, pandoc.RawInline("latex", "\\acknowledgments\n"))
end
return div.content
end
if div.classes:includes("datastatement") then
if #div.content and #div.content[1].content then
div.content[1].content:insert(1, pandoc.RawInline("latex", "\\datastatement\n"))
elseif #div.content then
div.content:insert(1, pandoc.RawInline("latex", "\\datastatement\n"))
end
return div.content
end
if div.classes:includes("appendix") then
nb_appendix = 0
div.content:walk({
Header = function(h)
if h.level == 1 then
nb_appendix = nb_appendix + 1
end
end
})
if nb_appendix > 0 then
local counter = 0
return div.content:walk({
traverse = 'topdown',
Header = function(h)
if h.level == 1 then
counter = counter + 1
local appendix
if nb_appendix == 1 then
appendix = pandoc.RawInline("latex", "\\appendix\n")
else
appendix = pandoc.RawInline("latex", string.format("\\appendix[%s]\n", getLetter(counter)))
end
h.content:insert(1, pandoc.RawInline("latex", "\\appendixtitle{"))
h.content:insert(pandoc.RawInline("latex", "}"))
h.content:insert(1, appendix)
return { h.content }
elseif h.level == 2 then
local star = ""
if h.classes:includes("unnumbered") then
star = "*"
end
h.content:insert(1, pandoc.RawInline("latex", string.format("\\subsection%s{", star)))
h.content:insert(pandoc.RawInline("latex", "}"))
return { h.content}
end
end
})
end
end
return div.content
end

return {
Div = process_div,
}
Loading
Loading