Skip to content

Commit

Permalink
Adapt template to a change of Pandoc regarding strikeout
Browse files Browse the repository at this point in the history
Backward compatibility requires to pass the version to the template

Changes is ulem to soul (jgm/pandoc@144bf90) and adaptation for LuaLaTeX (jgm/pandoc@5af2d70)
  • Loading branch information
cderv committed May 2, 2023
1 parent 5e81f6a commit 91bc2bd
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 18 deletions.
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.24.10
Version: 0.24.11
Authors@R: c(
person("JJ", "Allaire", , "jj@posit.co", role = "aut"),
person("Yihui", "Xie", , "xie@yihui.name", role = "aut",
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
- Better support for `natbib` to tweak option and biblio-style using Pandoc's variables
- Update to template following the guidelines
- Better support for links in template to be closer to guidelines

- Adapt some template supporting strikethrough to new Pandoc 3.0+ usage of **soul** instead of **ulem**.

## BUG FIXES

Expand Down
48 changes: 32 additions & 16 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,6 @@ template_pandoc <- function(metadata, template, output,
invisible(output)
}

# Helper function to create a custom format derived from pdf_document that
# includes a custom LaTeX template
pdf_document_format <- function(format,
template = find_resource(format, "template.tex"),
...) {
fmt <- rmarkdown::pdf_document(..., template = template)
fmt$inherits <- "pdf_document"
fmt
}

# recursion into a list to get an element using a vector of names
get_list_element <- function(x, names) {
n <- length(names)
Expand Down Expand Up @@ -150,13 +140,23 @@ render_draft <- function(journal, output_options = NULL, quiet = FALSE) {

# Use to create variables command for Pandoc from a named vector
vec_to_pandoc_variable_args <- function(v_args) {
truthy <- Filter(isTRUE, v_args)
v_args <- setdiff(v_args, truthy)
# Convert to pandoc arguments
pandoc_arg_list <- mapply(
rmarkdown::pandoc_variable_arg,
names(v_args),
v_args,
SIMPLIFY = FALSE,
USE.NAMES = FALSE
pandoc_arg_list <- c(
mapply(
rmarkdown::pandoc_variable_arg,
names(v_args),
v_args,
SIMPLIFY = FALSE,
USE.NAMES = FALSE
),
mapply(
rmarkdown::pandoc_variable_arg,
names(truthy),
SIMPLIFY = FALSE,
USE.NAMES = FALSE
)
)
unlist(pandoc_arg_list)
}
Expand Down Expand Up @@ -200,3 +200,19 @@ string_to_table <- function(x, n, split_regex = ", ?") {
df[is.na(df)] <- ""
df
}

# Helper function to create a custom format derived from pdf_document that
# includes a custom LaTeX template
pdf_document_format <- function(format,
template = find_resource(format, "template.tex"),
...) {
fmt <- rmarkdown::pdf_document(..., template = template)
fmt$inherits <- "pdf_document"

## Set some variables to adapt template based on Pandoc version
args <- vec_to_pandoc_variable_args(list(
pandoc3 = rmarkdown::pandoc_available("3")
))
fmt$pandoc$args <- c(fmt$pandoc$args, args)
fmt
}
11 changes: 11 additions & 0 deletions inst/rmarkdown/templates/acs/resources/template.tex
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,19 @@
\renewcommand{\href}[2]{#2\footnote{\url{#1}}}
$endif$
$if(strikeout)$
% For pandoc feature
$if(pandoc3)$
$-- Compatible only with Pandoc 3.0+
\ifLuaTeX
\usepackage{luacolor}
\usepackage[soul]{lua-ul}
\else
\usepackage{soul}
\fi
$else$
\usepackage[normalem]{ulem}
$endif$
$endif$
$if(highlighting-macros)$
% Pandoc syntax highlighting
Expand Down
11 changes: 11 additions & 0 deletions inst/rmarkdown/templates/elsevier/resources/template.tex
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,19 @@
\renewcommand{\href}[2]{#2\footnote{\url{#1}}}
$endif$
$if(strikeout)$
% For pandoc feature
$if(pandoc3)$
$-- Compatible only with Pandoc 3.0+
\ifLuaTeX
\usepackage{luacolor}
\usepackage[soul]{lua-ul}
\else
\usepackage{soul}
\fi
$else$
\usepackage[normalem]{ulem}
$endif$
$endif$

$if(numbersections)$
\setcounter{secnumdepth}{5}
Expand Down
11 changes: 11 additions & 0 deletions inst/rmarkdown/templates/joss/resources/template.tex
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,19 @@
\renewcommand{\href}[2]{#2\footnote{\url{#1}}}
$endif$
$if(strikeout)$
% For pandoc feature
$if(pandoc3)$
$-- Compatible only with Pandoc 3.0+
\ifLuaTeX
\usepackage{luacolor}
\usepackage[soul]{lua-ul}
\else
\usepackage{soul}
\fi
$else$
\usepackage[normalem]{ulem}
$endif$
$endif$
$if(indent)$
$else$
\IfFileExists{parskip.sty}{%
Expand Down
11 changes: 10 additions & 1 deletion inst/rmarkdown/templates/oup_v1/resources/template.tex
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,18 @@
$endif$
$if(strikeout)$
% For pandoc feature
$-- also used for underline
$if(pandoc3)$
$-- Compatible only with Pandoc 3.0+
\ifLuaTeX
\usepackage{luacolor}
\usepackage[soul]{lua-ul}
\else
\usepackage{soul}
\fi
$else$
\usepackage[normalem]{ulem}
$endif$
$endif$
% Counters for addresses and footnotes
\newcounter{correspcnt} % For author footnotes
Expand Down

0 comments on commit 91bc2bd

Please sign in to comment.