Skip to content

Commit

Permalink
Add support to all bibliography styles required by Taylor & Francis j…
Browse files Browse the repository at this point in the history
…ournals (#581)

Co-authored-by: Christophe Dervieux <[email protected]>
  • Loading branch information
rlaboiss and cderv authored Dec 16, 2024
1 parent 0a95675 commit 42eef14
Show file tree
Hide file tree
Showing 16 changed files with 8,353 additions and 252 deletions.
6 changes: 4 additions & 2 deletions 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.9
Version: 0.27.10
Authors@R: c(
person("JJ", "Allaire", , "[email protected]", role = "aut"),
person("Yihui", "Xie", , "[email protected]", role = "aut",
Expand Down Expand Up @@ -79,7 +79,9 @@ Authors@R: c(
person("Dmytro", "Perepolkin", , "[email protected]", role = "ctb",
comment = c(ORCID = "0000-0001-8558-6183", github = "dmi3kno")),
person("Tom", "Palmer", , "[email protected]", role = "ctb",
comment = c(ORCID = "0000-0003-4655-4511", github = "remlapmot"))
comment = c(ORCID = "0000-0003-4655-4511", github = "remlapmot")),
person("Rafael", "Laboissière", , "[email protected]", role = "ctb",
comment = c(ORCID = "0000-0002-2180-9250", github = "rlaboiss"))
)
Description: A suite of custom R Markdown formats and templates for
authoring journal articles and conference submissions.
Expand Down
11 changes: 0 additions & 11 deletions R/article.R
Original file line number Diff line number Diff line change
Expand Up @@ -539,17 +539,6 @@ springer_article <- function(..., keep_tex = TRUE, citation_package = "natbib",
format
}

#' @section `tf_article`: Format for creating submissions to a Taylor & Francis journal. Adapted from
#' \samp{https://www.tandf.co.uk/journals/authors/InteractCADLaTeX.zip}.
#' @export
#' @rdname article
tf_article <- function(..., keep_tex = TRUE, citation_package = "natbib") {
pdf_document_format(
"tf",
keep_tex = keep_tex, citation_package = citation_package, ...
)
}

#' @section \code{trb_article}: Format for creating submissions to the Transportation
#' Research Board Annual Meeting. Adapted from
#' \samp{https://www.overleaf.com/latex/templates/transportation-research-board-trb-latex-template/jkfndnnkkksw},
Expand Down
121 changes: 121 additions & 0 deletions R/tf_article.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
#' Taylor & Francis journals format
#'
#' Format for creating submissions to many Taylor & Francis journals.
#' Adapted from:
#' * <https://www.tandf.co.uk/journals/authors/InteractAPALaTeX.zip>
#' * <https://www.tandf.co.uk/journals/authors/InteractCADLaTeX.zip>
#' * <https://www.tandf.co.uk/journals/authors/InteractNLMLaTeX.zip>
#' * <https://www.tandf.co.uk/journals/authors/InteractTFPLaTeX.zip>
#' * <https://www.tandf.co.uk/journals/authors/InteractTFQLaTeX.zip>
#' * <https://www.tandf.co.uk/journals/authors/InteractTFSLaTeX.zip>
#'
#' @inheritParams rmarkdown::pdf_document
#' @param reference_style should be set according to the specific Taylor & Francis
#' journal. Possibles values: "APA" (American Psychological Association
#' reference style), "CAD" (Chicago Author-Date reference style), "NLM"
#' (National Library of Medicine reference style), "TFP" (Reference
#' Style-P), "TFQ" (Reference Style-Q), and "TFS" (Reference Style-S).
#' @param ... Additional arguments to [rmarkdown::pdf_document()]
#'
#' @examples \dontrun{
#' rmarkdown::draft("MyArticle.Rmd", template = "tf", package = "rticles")
#' setwd("MyArticle")
#' rmarkdown::render("MyArticle.Rmd")
#' }
#' @importFrom rmarkdown pandoc_variable_arg
#' @export
tf_article <- function(..., keep_tex = TRUE, citation_package = "natbib",
reference_style = c("CAD", "APA", "NLM", "TFP", "TFQ", "TFS"),
pandoc_args = NULL) {
styles <- list(
APA = list(
bst = "apacite",
cmd = c(
"\\usepackage[natbibapa]{apacite}",
"\\setlength\\bibhang{12pt}",
"\\renewcommand\\bibliographytypesize{\\fontsize{10}{12}\\selectfont}"
)
),
CAD = list(
bst = "tfcad",
cmd = c(
"\\usepackage{natbib}",
"\\bibpunct[, ]{(}{)}{;}{a}{}{,}"
)
),
NLM = list(
bst = "tfnlm",
cmd = c(
"\\usepackage[numbers,sort&compress]{natbib}",
"\\makeatletter",
"\\def\\NAT@def@citea{\\def\\@citea{\\NAT@separator}}",
"\\makeatother",
"\\bibpunct[, ]{[}{]}{,}{n}{,}{,}",
"\\renewcommand\\bibfont{\\fontsize{10}{12}\\selectfont}"
)
),
TFP = list(
bst = "tfp",
cmd = c(
"\\usepackage[numbers,sort&compress,merge]{natbib}",
"\\bibpunct[, ]{(}{)}{,}{n}{,}{,}",
"\\renewcommand\\bibfont{\\fontsize{10}{12}\\selectfont}",
"\\renewcommand\\citenumfont[1]{\\textit{#1}}",
"\\renewcommand\\bibnumfmt[1]{(#1)}"
)
),
TFQ = list(
bst = "tfq",
cmd = c(
"\\usepackage[numbers,sort&compress]{natbib}",
"\\bibpunct[, ]{[}{]}{,}{n}{,}{,}",
"\\renewcommand\\bibfont{\\fontsize{10}{12}\\selectfont}"
)
),
TFS = list(
bst = "tfs",
cmd = c(
"\\usepackage[numbers,sort&compress]{natbib}",
"\\bibpunct[, ]{[}{]}{,}{n}{,}{,}",
"\\renewcommand\\bibfont{\\fontsize{10}{12}\\selectfont}"
)
)
)
reference_style <- match.arg(reference_style)
if (! reference_style %in% names(styles))
stop(
paste(
"Invalid reference_style in Taylor and Francis article. Allowed values are:",
paste(names(styles), collapse = ", ")
)
)
sty <- styles[[reference_style]]
pandoc_args <- c(
pandoc_args,
rmarkdown::pandoc_variable_arg("biblio-style", sty$bst),
rmarkdown::pandoc_variable_arg(
"biblio-commands",
paste(sty$cmd, collapse = "\n")
)
)

base <- pdf_document_format(
"tf",
keep_tex = keep_tex,
citation_package = citation_package,
pandoc_args = pandoc_args,
...
)
pre_knit <- base$pre_knit

# Alert the user about deprecation of the biblio_style field in the YAML header
base$pre_knit <- function(input, metadata, ...) {
if (is.function(pre_knit)) pre_knit(input, metadata, ...)
if (!is.null(metadata$biblio_style))
warning("`tf_article()` now ignores the 'biblio_style' field in YAML header. ",
" Use the 'reference_style' option of 'output:tf_article', instead.",
call. = FALSE)
}

base
}
17 changes: 11 additions & 6 deletions inst/rmarkdown/templates/tf/resources/template.tex
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
% interactcadsample.tex
% v1.04 - May 2023
% Template for Taylor & Francis journals
%
% Based on the original files distributed by T&F:
% * interactapasample.tex: v1.05 - August 2017
% * interactcadsample.tex: v1.04 - May 2023
% * interactnlmsample.tex: v1.05 - August 2017
% * interacttfpsample.tex: v1.01 - June 2016
% * interacttfqsample.tex: v1.05 - August 2017
% * interacttfssample.tex: v1.05 - August 2017

\documentclass[$for(classoption)$$classoption$$sep$,$endfor$]{interact}

\usepackage{epstopdf}% To incorporate .eps illustrations using PDFLaTeX, etc.
\usepackage{subfigure}% Support for small, `sub' figures and tables
%\usepackage[nolists,tablesfirst]{endfloat}% To `separate' figures and tables from text if required

\usepackage{natbib}% Citation support using natbib.sty
\bibpunct[, ]{(}{)}{;}{a}{}{,}% Citation support using natbib.sty
\renewcommand\bibfont{\fontsize{10}{12}\selectfont}% Bibliography support using natbib.sty
$biblio-commands$

\theoremstyle{plain}% Theorem-like structures provided by amsthm.sty
\newtheorem{theorem}{Theorem}[section]
Expand Down Expand Up @@ -202,7 +207,7 @@
$body$
$if(bibliography)$
\bibliographystyle{$if(biblio-style)$$biblio-style$$else$tfcad$endif$}
\bibliographystyle{$biblio-style$}
\bibliography{$bibliography$}
$endif$
Expand Down
Loading

0 comments on commit 42eef14

Please sign in to comment.