rstudio / rmarkdown

Dynamic Documents for R
https://rmarkdown.rstudio.com
GNU General Public License v3.0
2.87k stars 973 forks source link

Pandoc 2.8 error "! LaTeX Error: Environment cslreferences undefined." #1649

Closed njbart closed 4 years ago

njbart commented 5 years ago

pandoc now requires a cslreferences environment to be defined in the latex template (see https://github.com/jgm/pandoc/commit/0fe635d3ecdc362f11c380c2e0b9518aa03424e9).

This would require the addition of

$if(csl-refs)$
\newlength{\cslhangindent}
\setlength{\cslhangindent}{1.5em}
\newenvironment{cslreferences}%
  {$if(csl-hanging-indent)$\setlength{\parindent}{0pt}%
  \everypar{\setlength{\hangindent}{\cslhangindent}}\ignorespaces$endif$}%
  {\par}
$endif$

to https://github.com/rstudio/rmarkdown/blob/master/inst/rmd/latex/default-1.17.0.2.tex.

If useful, I could submit a pull request, but I need to understand one thing first:

Is there any reason why rmarkdown (and bookdown, blogdown) do not just use pandoc’s own default templates?


By filing an issue to this repo, I promise that

I understand that my issue may be closed if I don't fulfill my promises.

yihui commented 5 years ago

I have been hoping to use Pandoc's own template for long. I just haven't had the time to review the PR #1563 yet.

Here is what you do if you want to use Pandoc's template:

output:
  pdf_document:
    template: null

See ?rmarkdown::pdf_document.

yihui commented 4 years ago

Should be fixed now. Please test the development version of rmarkdown with

remotes::install_github('rstudio/rmarkdown')

Thanks for the report!

firasm commented 4 years ago

thanks this fixed the issue for me!

jokorn commented 4 years ago

I still receive this error:

/usr/local/bin/pandoc +RTS -K512m -RTS test.utf8.md --to latex --from markdown+autolink_bare_uris+tex_math_single_backslash --output test.tex --lua-filter /Library/Frameworks/R.framework/Versions/4.0/Resources/library/rmarkdown/rmarkdown/lua/pagebreak.lua --lua-filter /Library/Frameworks/R.framework/Versions/4.0/Resources/library/rmarkdown/rmarkdown/lua/latex-div.lua --self-contained --highlight-style tango --pdf-engine xelatex --variable graphics --variable 'geometry:margin=1in' --filter /usr/local/bin/pandoc-citeproc 
output file: test.knit.md

! LaTeX Error: Environment cslreferences undefined.

Fejl: LaTeX failed to compile test.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See test.log for more info.

even though I am using rmarkdown installed from Github.

My pandoc versions are (installed via Homebrew to usr/local/bin):

My .rmd file:

---
references:
- id: test2020
  title: test_cslreferences_undefined
  author:
  - family: test
    given: test
output: 
  pdf_document:
    latex_engine: xelatex
---

[@test2020]

My sessionInfo:

R version 4.0.2 (2020-06-22)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Mojave 10.14.6

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

locale:
[1] da_DK.UTF-8/da_DK.UTF-8/da_DK.UTF-8/C/da_DK.UTF-8/da_DK.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.5          compiler_4.0.2      cellranger_1.1.0    RColorBrewer_1.1-2  later_1.1.0.1      
 [6] pdftools_2.3.1      tools_4.0.2         digest_0.6.25       jsonlite_1.7.1      evaluate_0.14      
[11] lifecycle_0.2.0     viridisLite_0.3.0   rlang_0.4.7         rstudioapi_0.11     yaml_2.2.1         
[16] xfun_0.18           fastmap_1.0.1       kableExtra_1.2.1    httr_1.4.2          stringr_1.4.0      
[21] xml2_1.3.2          knitr_1.30.1        webshot2_0.0.0.9000 askpass_1.1         websocket_1.3.1    
[26] rprojroot_1.3-2     webshot_0.5.2       chromote_0.0.0.9002 glue_1.4.2          here_0.1           
[31] qpdf_1.1            R6_2.4.1            processx_3.4.4      readxl_1.3.1        rmarkdown_2.4.1    
[36] magrittr_1.5        ps_1.3.4            scales_1.1.1        backports_1.1.10    promises_1.1.1     
[41] htmltools_0.5.0     rvest_0.3.6         colorspace_1.4-1    stringi_1.5.3       munsell_0.5.0 

Can you help me resolve this?

yihui commented 4 years ago

@jokorn That's odd. I'm unable to reproduce your issue with either Pandoc 2.9.2.1 (bundled with RStudio) or 2.10.1. You may check if the environment cslreferences is defined in the template:

system2('pandoc', c('-D', 'latex'))
jokorn commented 4 years ago

Hm, it seems to be defined as:

$if(csl-refs)$
\newlength{\cslhangindent}
\setlength{\cslhangindent}{1.5em}
\newenvironment{cslreferences}%
  {$if(csl-hanging-indent)$\setlength{\parindent}{0pt}%
  \everypar{\setlength{\hangindent}{\cslhangindent}}\ignorespaces$endif$}%
  {\par}
$endif$

I uninstalled the homebrew version and used the rstudio version of pandoc (version 2.7.3 for my rstudio Version 1.3.1093) instead and then it completed without any errors. I then reinstalled pandoc via homebrew and the error was back. I will just uninstall the homebrew version and use the rstudio version instead (and symlink it to /usr/local/bin).

yihui commented 4 years ago

I was also testing with the Homebrew version of Pandoc, and wasn't able to reproduce the problem. That's really odd...

jokorn commented 4 years ago

That is weird. Are there any other steps I can take to find the error? Or should we just leave it for now until (if) someone else experiences the same bug?

jokorn commented 4 years ago

I managed to find the cause of the error. I had an old template directory in $HOME/.pandoc with a template called default.latex. This old template was used instead of pandoc's build in template and this old template did not include the cslreferences environment.

From the pandoc manual:

You can find the default user data directory on your system by looking at the output of pandoc --version. A reference.odt, reference.docx, epub.css, templates, slidy, slideous, or s5 directory placed in this directory will override pandoc’s normal defaults.

I deleted this old template folder and everything now works as expected.

Sorry for the inconvenience and thank you for the help.

yihui commented 4 years ago

Excellent! I'm very glad that you figured it out, and thanks for sharing the solution! I think it will be helpful to future users.

Nicktz commented 3 years ago

I added the following in my latex template file and it worked:

\newlength{\cslhangindent} \setlength{\cslhangindent}{1.5em} \newenvironment{CSLReferences}% {\setlength{\parindent}{0pt}% \everypar{\setlength{\hangindent}{\cslhangindent}}\ignorespaces}% {\par}

github-actions[bot] commented 3 years ago

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.