Skip to content

Commit

Permalink
Conditionally use CSL list environments based on pandoc version
Browse files Browse the repository at this point in the history
Resolves #246
  • Loading branch information
mitchelloharawild committed Jun 12, 2024
1 parent cc04ab0 commit e70de68
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 0 deletions.
5 changes: 5 additions & 0 deletions R/cv_document.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
#' @export
cv_document <- function(..., pandoc_args = NULL, pandoc_vars = NULL,
base_format = rmarkdown::pdf_document) {
pandoc_vars <- c(
pandoc_vars,
csl_list = rmarkdown::pandoc_version() >= "3.1.8"
)

for (i in seq_along(pandoc_vars)){
pandoc_args <- c(pandoc_args, rmarkdown::pandoc_variable_arg(names(pandoc_vars)[[i]], pandoc_vars[[i]]))
}
Expand Down
14 changes: 14 additions & 0 deletions inst/rmarkdown/templates/awesomecv/resources/awesome-cv.tex
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
\newlength{\csllabelwidth}
\setlength{\csllabelwidth}{3em}
\newenvironment{CSLReferences}[2] % #1 hanging-indent, #2 entry-spacing
$if(csl_list)$
{\begin{list}{}{%
\setlength{\itemindent}{0pt}
\setlength{\leftmargin}{0pt}
Expand All @@ -165,6 +166,19 @@
% set entry spacing
\setlength{\itemsep}{#2\baselineskip}}}
{\end{list}}
$else$
{% don't indent paragraphs
\setlength{\parindent}{0pt}
% turn on hanging indent if param 1 is 1
\ifodd #1 \everypar{\setlength{\hangindent}{\cslhangindent}}\ignorespaces\fi
% set entry spacing
\ifnum #2 > 0
\setlength{\parskip}{#2\baselineskip}
\fi
}%
{}
$endif$

\usepackage{calc}
\newcommand{\CSLBlock}[1]{\hfill\break\parbox[t]{\linewidth}{\strut\ignorespaces#1\strut}}
\newcommand{\CSLLeftMargin}[1]{\parbox[t]{\csllabelwidth}{\strut#1\strut}}
Expand Down
14 changes: 14 additions & 0 deletions inst/rmarkdown/templates/hyndman/resources/hyndmantemplate.tex
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@
\newlength{\csllabelwidth}
\setlength{\csllabelwidth}{3em}
\newenvironment{CSLReferences}[2] % #1 hanging-indent, #2 entry-spacing
$if(csl_list)$
{\begin{list}{}{%
\setlength{\itemindent}{0pt}
\setlength{\leftmargin}{0pt}
Expand All @@ -299,6 +300,19 @@
% set entry spacing
\setlength{\itemsep}{#2\baselineskip}}}
{\end{list}}
$else$
{% don't indent paragraphs
\setlength{\parindent}{0pt}
% turn on hanging indent if param 1 is 1
\ifodd #1 \everypar{\setlength{\hangindent}{\cslhangindent}}\ignorespaces\fi
% set entry spacing
\ifnum #2 > 0
\setlength{\parskip}{#2\baselineskip}
\fi
}%
{}
$endif$

\usepackage{calc}
\newcommand{\CSLBlock}[1]{\hfill\break\parbox[t]{\linewidth}{\strut\ignorespaces#1\strut}}
\newcommand{\CSLLeftMargin}[1]{\parbox[t]{\csllabelwidth}{\strut#1\strut}}
Expand Down
14 changes: 14 additions & 0 deletions inst/rmarkdown/templates/latexcv/resources/classic/main.tex
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@
\newlength{\csllabelwidth}
\setlength{\csllabelwidth}{3em}
\newenvironment{CSLReferences}[2] % #1 hanging-indent, #2 entry-spacing
$if(csl_list)$
{\begin{list}{}{%
\setlength{\itemindent}{0pt}
\setlength{\leftmargin}{0pt}
Expand All @@ -322,6 +323,19 @@
% set entry spacing
\setlength{\itemsep}{#2\baselineskip}}}
{\end{list}}
$else$
{% don't indent paragraphs
\setlength{\parindent}{0pt}
% turn on hanging indent if param 1 is 1
\ifodd #1 \everypar{\setlength{\hangindent}{\cslhangindent}}\ignorespaces\fi
% set entry spacing
\ifnum #2 > 0
\setlength{\parskip}{#2\baselineskip}
\fi
}%
{}
$endif$

\usepackage{calc}
\newcommand{\CSLBlock}[1]{\hfill\break\parbox[t]{\linewidth}{\strut\ignorespaces#1\strut}}
\newcommand{\CSLLeftMargin}[1]{\parbox[t]{\csllabelwidth}{\strut#1\strut}}
Expand Down
14 changes: 14 additions & 0 deletions inst/rmarkdown/templates/moderncv/resources/moderncv.tex
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
\newlength{\csllabelwidth}
\setlength{\csllabelwidth}{3em}
\newenvironment{CSLReferences}[2] % #1 hanging-indent, #2 entry-spacing
$if(csl_list)$
{\begin{list}{}{%
\setlength{\itemindent}{0pt}
\setlength{\leftmargin}{0pt}
Expand All @@ -105,6 +106,19 @@
% set entry spacing
\setlength{\itemsep}{#2\baselineskip}}}
{\end{list}}
$else$
{% don't indent paragraphs
\setlength{\parindent}{0pt}
% turn on hanging indent if param 1 is 1
\ifodd #1 \everypar{\setlength{\hangindent}{\cslhangindent}}\ignorespaces\fi
% set entry spacing
\ifnum #2 > 0
\setlength{\parskip}{#2\baselineskip}
\fi
}%
{}
$endif$

\usepackage{calc}
\newcommand{\CSLBlock}[1]{\hfill\break\parbox[t]{\linewidth}{\strut\ignorespaces#1\strut}}
\newcommand{\CSLLeftMargin}[1]{\parbox[t]{\csllabelwidth}{\strut#1\strut}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
\newlength{\csllabelwidth}
\setlength{\csllabelwidth}{3em}
\newenvironment{CSLReferences}[2] % #1 hanging-indent, #2 entry-spacing
$if(csl_list)$
{\begin{list}{}{%
\setlength{\itemindent}{0pt}
\setlength{\leftmargin}{0pt}
Expand All @@ -118,6 +119,19 @@
% set entry spacing
\setlength{\itemsep}{#2\baselineskip}}}
{\end{list}}
$else$
{% don't indent paragraphs
\setlength{\parindent}{0pt}
% turn on hanging indent if param 1 is 1
\ifodd #1 \everypar{\setlength{\hangindent}{\cslhangindent}}\ignorespaces\fi
% set entry spacing
\ifnum #2 > 0
\setlength{\parskip}{#2\baselineskip}
\fi
}%
{}
$endif$

\usepackage{calc}
\newcommand{\CSLBlock}[1]{\hfill\break\parbox[t]{\linewidth}{\strut\ignorespaces#1\strut}}
\newcommand{\CSLLeftMargin}[1]{\parbox[t]{\csllabelwidth}{\strut#1\strut}}
Expand Down

0 comments on commit e70de68

Please sign in to comment.