Visual Editor Preview - ! LaTeX Error: Environment CSLReferences undefined.

The new RStudio with the visual editor looks intriguing but I have been reluctant to risk a major upgrade in the middle of a busy school term. I have a complicated book written using RMDs, bookdown, and the tufte package. I got a new laptop over the weekend and thought that as long as I had the old laptop to fall back on I would try the new developer preview of the latest RStudio environment.

Cloning the repository and trying to render the book generates an error message:

! LaTeX Error: Environment CSLReferences undefined.

After some digging around, I found that I could partially get past this error by adding a few lines to my preamble.tex . This seems to work but then I get an error message:
! LaTeX Error: Missing \begin{document}.
The error message points to the ending line of the CSLReferences.

It seems like this may be an issue with the big leap forward in the pandoc (2.7.3 to and perhaps some of the other packages such as tufte.

I've sunk a lot of time and need to move on. I'm sure the new version will be very helpful but I may need to give a little time for things to get worked out.

I can share the repo for anyone that would like to experiment but I'll probably just uninstall the preview (1.4.1013) and keep fingers crossed that the problem is solved for now by installing the current version of RStudio (1.3.1093) and the older pandoc.

Indeed the upgrade in Pandoc version is a big change. You would need to use the last version of most of the packages relying on pandoc (Rmarkdown, tufte, rticles, bookdown...)

This error is directly linked to the upgrade to Pandoc 2.11+ : CSLReferences environment is now expected by pandoc and it should be defined in the Pandoc template used for PDF generation. Default PDF template from Pandoc as it but it seems you can be using a custom template or a format using a custom template.

I believe if you are using tufte as you said, so we may have missed an update and you may have found an issue. Thank you ! I'll check this and push a fix in the dev version.

It would be nice to be sure to fix the issue. I would be interested by some details:

  • Which Rmd output format are you using ?
  • Can you confirm you are not using natbib or bibtex ?

Thank you.

FWIW, I pushed a fix in tufte package:
If you are using this format, you may need to use the last dev version so that it works with Pandoc 2.11 and citeproc.
If you are using tufte format with natbib or bibtex, there should no be any issue and this fix was not related to your issue.

Super. Thanks much for the very quick and helpful responses.

Installing the tufte package from github fixed it. I'm able to generate my full PDF.

Blockquote Which Rmd output format are you using ?

Is this what you are asking?

 rmarkdown::render_site(output_format = 'bookdown::tufte_book2', encoding = 'UTF-8')

Blockquote Can you confirm you are not using natbib or bibtex ?

Perhaps the bibliography question is irrelevant now but my _output.yml sets " citation_package: natbib" but I see that my creation command ends with --citeproc.

"C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS --to latex --from markdown+autolink_bare_uris+tex_math_single_backslash --output Optimization-Modeling-Using-R.tex --lua-filter "C:\Users\profa\OneDrive\Documents\R\win-library\4.0\bookdown\rmarkdown\lua\custom-environment.lua" --lua-filter "C:\Users\profa\OneDrive\Documents\R\win-library\4.0\rmarkdown\rmarkdown\lua\pagebreak.lua" --lua-filter "C:\Users\profa\OneDrive\Documents\R\win-library\4.0\rmarkdown\rmarkdown\lua\latex-div.lua" --metadata-file "C:\Users\profa\AppData\Local\Temp\Rtmp4w3Bul\file173017a17f02" --self-contained --table-of-contents --toc-depth 2 --template "C:\Users\profa\OneDrive\Documents\R\win-library\4.0\tufte\rmarkdown\templates\tufte_handout\resources\tufte-handout.tex" --number-sections --highlight-style tango --pdf-engine pdflatex --include-in-header preamble.tex --wrap preserve --variable "documentclass:tufte-book" --top-level-division=chapter --include-in-header "C:\Users\profa\AppData\Local\Temp\Rtmp4w3Bul\rmarkdown-str17306d6117bf.html" --variable tables=yes --standalone -Mhas-frontmatter=false --citeproc 

Strange quirk in the PDF is that the title of my book has changed to "References". Perhaps a byproduct of my attempted fixes on other issues but reverting changes to the repo still maintains the wrong book title.
I confirmed that the correct title still appears in the rendered book from the RStudio 1.3.1091 release with the older pandoc.

Yes this is not correct. This is maybe another issue :thinking:

Have you correctly formatted your YAML ?

  citation_package: natbib

That is really strange. You would need to share more details on this if you want me to look into.
For example, what is your correct title ? Is this happening with a small example you can share ?

I can't reproduce using bookdown-demo and bookdown::tufte_book2

Thanks. I did some more digging and found that the changed title was because I was making the mistake of repeating yaml at the top of each RMD (chapter/appendix in my case.) It seems that the new update was exposing a longstanding problem in my bookdown project. It might have been the new pandoc that was using the last title: rather than the first title: for the book.

I fixed my RMDs so that only the index. rmd had yaml info for the project. That solved the problem.

Thanks again!

1 Like

Thanks. Your pointer on updating packages helped solve most of my problems.

The second problem, the wrong title for the book, turned out to be from me mistakenly repeating YAML in each RMD of a bookdown project. It worked fine in the past and I didn't appreciate it violated bookdown practices. I guess the old toolsets (rmarkdown/bookdown/pandoc) let me keep that mistake but the new versions interpreted the last YAML as taking precedence. Eliminating the extra YAML fixed the second problem.

Thanks again,

I believe this is a change related to Pandoc:

Change merge behavior for metadata. Previously, if a document contained two YAML metadata blocks that set the same field, the conflict would be resolved in favor of the first. Now it is resolved in favor of the second (due to a change in pandoc-types). This makes the behavior more uniform with other things in pandoc (such as reference links and --metadata-file ).

That means if there is several blocks in the document, depending on the Pandoc version, first or last fields will be used. As bookdown will merge all the Rmd into one for Pandoc to convert it, you encounter this behavior. With new RStudio version 1.4, it is Pandoc 2.11.2 and with previous it was 2.7.3 - the change happened in 2.8.

Glad you found the solution, I did not thought of that until you mentioned it.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.