crsh / papaja

papaja (Preparing APA Journal Articles) is an R package that provides document formats to produce complete APA manuscripts from RMarkdown-files (PDF and Word documents) and helper functions that facilitate reporting statistics, tables, and plots.
https://frederikaust.com/papaja_man/
Other
657 stars 133 forks source link

Bibliography in papaja::revision_letter_pdf gives LaTeX Error: Lonely \item--perhaps a missing list environment. #587

Closed cjvanlissa closed 2 months ago

cjvanlissa commented 5 months ago

I'm sorry, this won't be a reproducible example. If it's not a bug, feel free to ignore.

I'm unable to render a revision_letter_pdf with references, because the bibliography entries each give this error:

LaTeX Error: Lonely \item--perhaps a missing list environment.

The entries look like this:

\bibitem[\citeproctext]{ref-benjaminRedefineStatisticalSignificance2017}
Benjamin, D. J., Berger, J. O., Johannesson, M., Nosek, B. A., Wagenmakers, E.-J., Berk, R., \ldots{} Johnson, V. E. (2017). Redefine statistical significance. \emph{Nature Human Behaviour}, \emph{2}(1), 6--10. \url{https://doi.org/10.1038/s41562-017-0189-z}

Which seems to be the same as the entries from my papaja::apa6_pdf manuscript:

\bibitem[\citeproctext]{ref-benjaminRedefineStatisticalSignificance2017}
Benjamin, D. J., Berger, J. O., Johannesson, M., Nosek, B. A., Wagenmakers, E.-J., Berk, R., \ldots{} Johnson, V. E. (2017). Redefine statistical significance. \emph{Nature Human Behaviour}, \emph{2}(1), 6--10. \url{https://doi.org/10.1038/s41562-017-0189-z}

Maybe some package is missing from the revision_letter template?

cjvanlissa commented 5 months ago

Just changing output : papaja::revision_letter_pdf to output : papaja::apa6_pdf allows me to render successfully, so I do think something might be missing from the revision_letter_pdf template.

jvcasillas commented 5 months ago

Adding that I am also getting this error.

crsh commented 5 months ago

Thanks for reporting this. I'll take a look as soon as possible.

jvcasillas commented 2 months ago

Any update or workaround for this error?

jvcasillas commented 2 months ago

Following @cjvanlissa comment, I notice that if I try to render the Rmd file, get the LaTeX Error: Lonely \item--perhaps a missing list environment error, and then inspect the .tex file, this section appears to be incomplete:

\newlength{\cslhangindent}
\setlength{\cslhangindent}{1.5em}
\newlength{\csllabelwidth}
\setlength{\csllabelwidth}{3em}
\newenvironment{CSLReferences}[2] % #1 hanging-ident, #2 entry spacing
 {% 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
 }%
 {}
\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}

If I switch to papaja::apa6_pdf and rerender, it works fine. So, I can copy and paste the relevant section of the CSL code into the .tex file (after trying to render with papaja::revision_letter_pdf) and it works correctly. The code I am copy/pasting is the following:

% definitions for citeproc citations
\NewDocumentCommand\citeproctext{}{}
\NewDocumentCommand\citeproc{mm}{%
  \begingroup\def\citeproctext{#2}\cite{#1}\endgroup}
\makeatletter
 % allow citations to break across lines
 \let\@cite@ofmt\@firstofone
 % 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}
\newenvironment{CSLReferences}[2] % #1 hanging-indent, #2 entry-spacing
 {\begin{list}{}{%
  \setlength{\itemindent}{0pt}
  \setlength{\leftmargin}{0pt}
  \setlength{\parsep}{0pt}
  % turn on hanging indent if param 1 is 1
  \ifodd #1
   \setlength{\leftmargin}{\cslhangindent}
   \setlength{\itemindent}{-1\cslhangindent}
  \fi
  % set entry spacing
  \setlength{\itemsep}{#2\baselineskip}}}
 {\end{list}}

I assume this needs to be added to the template to fix this issue, which appears to be lines 173-194 of https://github.com/crsh/papaja/blob/main/inst/rmarkdown/templates/revision_letter/resources/revision_letter.tex.

cjvanlissa commented 2 months ago

@crsh thanks for fixing this! While you're at it: I had the same error when rendering an APA6 document recently; might have been a problem with my bib file, but if it happens again I will open an issue.

jvcasillas commented 1 month ago

I think that some change posterior to https://github.com/crsh/papaja/pull/593 has affected this, as I am not getting this error again.

Edit: I notice that if I reinstall the CRAN version the error is not present.

crsh commented 1 month ago

Thanks for letting us know! I plan to submit an update to CRAN shortly.