Skip to content

Commit

Permalink
Do bibliography commands logic in R instead of doing in TeX
Browse files Browse the repository at this point in the history
The convoluted logic using \ifboolexpr and \ifstrequal in the preamble of
template.tex is done now done in function tf_article(). A new pandoc
variable ("biblio-commands") is now used.
  • Loading branch information
rlaboiss committed Dec 3, 2024
1 parent 6715c81 commit dfca827
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 38 deletions.
52 changes: 45 additions & 7 deletions R/article.R
Original file line number Diff line number Diff line change
Expand Up @@ -558,22 +558,60 @@ springer_article <- function(..., keep_tex = TRUE, citation_package = "natbib",
#' @rdname article
tf_article <- function(..., keep_tex = TRUE, citation_package = "natbib",
biblio_style = "CAD", pandoc_args = NULL) {
styles <- list(APA = "apacite",
CAD = "tfcad",
NLM = "tfnlm",
TFP = "tfp",
TFQ = "tfq",
TFS = "tfs")
styles <- list(
APA = list(
bst = "apacite",
cmd = "\\usepackage[natbibapa]{apacite}
\\setlength\\bibhang{12pt}
\\renewcommand\\bibliographytypesize{\\fontsize{10}{12}\\selectfont}"
),
CAD = list(
bst = "tfcad",
cmd = "\\usepackage{natbib}
\\bibpunct[, ]{(}{)}{;}{a}{}{,}"
),
NLM = list(
bst = "tfnlm",
cmd = "\\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 = "\\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 = "\\usepackage[numbers,sort&compress]{natbib}
\\bibpunct[, ]{[}{]}{,}{n}{,}{,}
\\renewcommand\\bibfont{\\fontsize{10}{12}\\selectfont}"
),
TFS = list(
bst = "tfs",
cmd = "\\usepackage[numbers,sort&compress]{natbib}
\\bibpunct[, ]{[}{]}{,}{n}{,}{,}
\\renewcommand\\bibfont{\\fontsize{10}{12}\\selectfont}"
)
)
if (! biblio_style %in% names(styles))
stop(
paste(
"Invalid biblio_style in Taylor and Francis article. Allowed values are:",
paste(names(styles), collapse = ", ")
)
)
sty <- styles[[biblio_style]]
pandoc_args <- c(
pandoc_args,
rmarkdown::pandoc_variable_arg("bst-name", styles[[biblio_style]])
rmarkdown::pandoc_variable_arg("bst-name", sty$bst),
rmarkdown::pandoc_variable_arg("biblio-commands", sty$cmd)
)
pdf_document_format(
"tf",
Expand Down
32 changes: 1 addition & 31 deletions inst/rmarkdown/templates/tf/resources/template.tex
Original file line number Diff line number Diff line change
@@ -1,40 +1,10 @@
\documentclass[$for(classoption)$$classoption$$sep$,$endfor$]{interact}

\usepackage{etoolbox}
\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

\newcommand{\BiblioStyleErrorMessage}{%
\errmessage{%
Invalid biblio_style in Taylor and Francis template. Allowed values are APA, CAD, NLM, TFP, TFQ, and TFS}}

\ifstrequal{$bst-name$}{apacite}%
{\usepackage[natbibapa]{apacite}% Citation support using apacite.sty. Commands using natbib.sty MUST be deactivated first!
\setlength\bibhang{12pt}% To set the indentation in the list of references using apacite.sty. Commands using natbib.sty MUST be deactivated first!
\renewcommand\bibliographytypesize{\fontsize{10}{12}\selectfont}}% To set the list of references in 10 point font using apacite.sty. Commands using natbib.sty MUST be deactivated first!
{\ifboolexpr{%
test {\ifstrequal{$bst-name$}{tfcad}}%
or test {\ifstrequal{$bst-name$}{}}}% Default
{\usepackage{natbib}% Citation support using natbib.sty
\bibpunct[, ]{(}{)}{;}{a}{}{,}}% Citation support using natbib.sty
{\ifboolexpr{%
test {\ifstrequal{$bst-name$}{tfnlm}}%
or test {\ifstrequal{$bst-name$}{tfq}}%
or test {\ifstrequal{$bst-name$}{tfs}}}%
{\usepackage[numbers,sort&compress]{natbib}% Citation support using natbib.sty
\ifstrequal{$bst-name$}{tfnlm}%
{\makeatletter% @ becomes a letter
\def\NAT@def@citea{\def\@citea{\NAT@separator}}% Suppress spaces between citations using natbib.sty
\makeatother}
{}}% @ becomes a symbol again
{\ifstrequal{$bst-name$}{tfp}%
{\usepackage[numbers,sort&compress,merge]{natbib}% Citation support using natbib.sty
\renewcommand\citenumfont[1]{\textit{#1}}% Citation numbers in italic font using natbib.sty
\renewcommand\bibnumfmt[1]{(#1)}}% Parentheses enclose ref. numbers in list using natbib.sty
{\BiblioStyleErrorMessage}}%
\bibpunct[, ]{[}{]}{,}{n}{,}{,}}% 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

0 comments on commit dfca827

Please sign in to comment.