pbs-assess / csasdown

:book: An R package for creating CSAS reports in PDF or Word format with R Markdown and bookdown
Other
46 stars 16 forks source link

Update .sty files for latest Pandoc citeproc approach #236

Closed seananderson closed 5 months ago

seananderson commented 11 months ago

The latest Pandoc has changed how references are handled by the default 'citeproc' method. Argh!

You can verify this is an issue by trying to build the unit tests. I tried with the tech report.

See https://tex.stackexchange.com/questions/695228/undefined-control-sequence-using-citeproc-to-convert-md-to-pdf-with-a-template And an example of extra code now needed in the preamble here: https://github.com/jgm/pandoc/issues/9031#issuecomment-1694744040

However, it's more complicated than this for us and I'm out of time to try fixing this right now. So, I'm documenting where I left off. Working on the tech report, here is what I've found:

\NewDocumentCommand\citeproctext{}{}
\NewDocumentCommand\citeproc{mm}{%
  \begingroup\def\citeproctext{#2}\cite{#1}\endgroup}
\makeatletter
% avoid brackets around text for \cite:
 \def\@biblabel#1{}
 \def\@cite#1#2{{#1\if@tempswa , #2\fi}}
\makeatother
\newlength{\cslhangindent}
\setlength{\cslhangindent}{1.5em}
\newlength{\csllabelwidth}
\setlength{\csllabelwidth}{3em}
\newlength{\cslentryspacing}
\setlength{\cslentryspacing}{0em}
\usepackage{enumitem}
\newlist{biblist}{itemize}{1}
\setlist[biblist]{label={},leftmargin=\cslhangindent,itemindent=-1\cslhangindent,itemsep=\cslentryspacing}
\usepackage{calc}
\newcommand{\CSLBlock}[1]{#1\hfill\break}
\newcommand{\CSLLeftMargin}[1]{\parbox[t]{\csllabelwidth}{#1}}
\newcommand{\CSLRightInline}[1]{\parbox[t]{\linewidth - \csllabelwidth}{#1}\break}
\newcommand{\CSLIndent}[1]{\hspace{\cslhangindent}#1}

Then in reference list, need to stop injecting CSLReferences at beginning and end of bibliography. I forget if we're doing that or pandoc was. Replace with biblist?

e.g. \begin{CSLReferences} becomes \begin{biblist}

@jdunic first flagged this

seananderson commented 11 months ago

Hit the Blame button on this file: https://github.com/jgm/pandoc-templates/blame/master/default.latex and start at line 338 % definitions for citeproc citations. That's what needs to change (keeping in mind we need formatting to match CSAS requirements).

seananderson commented 11 months ago

This is all done (except resdoc-b). Note, however, that for some document types I had to change the default rendering back to bookdown::render_book() for the French version to build. You can see which ones in the 2 commits linked above in this issue with their TODO. I couldn't quickly figure out what was going wrong with the csasdown::render() versions.

cgrandin commented 11 months ago

On the server we have Pandoc version:

pandoc 2.9.2.1
Compiled with pandoc-types 1.20, texmath 0.12.0.2, skylighting 0.8.5

With this, the English techreport fails for me as it is now using either csasdown::render() or bookdown::render_book(). I can fix it (maybe the indents etc are wrong though) by changing the code starting here https://github.com/pbs-assess/csasdown/blob/92f7f6429fd0844f1f952a2e2b26b03f738e2dd9/inst/csas-style/tech-report.sty#L436 to this:

\usepackage{enumitem}
\newenvironment{CSLReferences}%
  {}%
  {\par}
% \newlist{CSLReferences}{itemize}{1}
% \setlist[CSLReferences]{label={},
%   leftmargin=\cslhangindent,
%   itemindent=-1\cslhangindent,
%   parsep=\parskip,
%   itemsep=\cslentryspacing}
\usepackage{calc}

Appears it cannot be a list the way it is now...

seananderson commented 11 months ago

This should now be working with pandoc < 3.1.7 and with pandoc >= 3.1.8. Pandoc 3.1.7 requires its own template, so csasdown checks for it and stops. I check the pandoc version on the fly and uncomment/comment sections of the .sty file as needed. https://github.com/pbs-assess/csasdown/commit/417f88c274099184c16470a5ec04a7759fec6598