Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
3 tasks
njbart opened this issue Sep 19, 2019 · 12 comments
Closed
3 tasks

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

njbart opened this issue Sep 19, 2019 · 12 comments
Labels
bug an unexpected problem or unintended behavior

Comments

@njbart
Copy link

njbart commented Sep 19, 2019

pandoc now requires a cslreferences environment to be defined in the latex template (see jgm/pandoc@0fe635d).

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 have fully read the issue guide at https://yihui.name/issue/.
  • I have provided the necessary information about my issue.
    • If I'm asking a question, I have already asked it on Stack Overflow or RStudio Community, waited for at least 24 hours, and included a link to my question there.
    • If I'm filing a bug report, I have included a minimal, self-contained, and reproducible example, and have also included xfun::session_info('rmarkdown'). I have upgraded all my packages to their latest versions (e.g., R, RStudio, and R packages), and also tried the development version: remotes::install_github('rstudio/rmarkdown').
    • If I have posted the same issue elsewhere, I have also mentioned it in this issue.
  • I have learned the Github Markdown syntax, and formatted my issue correctly.

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

@yihui
Copy link
Member

yihui commented Sep 19, 2019

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 yihui added the bug an unexpected problem or unintended behavior label Nov 25, 2019
@yihui yihui closed this as completed in b2adfda Nov 25, 2019
@yihui
Copy link
Member

yihui commented Nov 25, 2019

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

remotes::install_github('rstudio/rmarkdown')

Thanks for the report!

muziejus added a commit to plain-plain-text/simple-essay that referenced this issue Nov 30, 2019
@yihui yihui changed the title cslreferences environment missing in latex template Pandoc 2.8 error "! LaTeX Error: Environment cslreferences undefined." Dec 6, 2019
@firasm
Copy link

firasm commented Mar 3, 2020

thanks this fixed the issue for me!

@jokorn
Copy link

jokorn commented Oct 3, 2020

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):

  • pandoc 2.10.1
  • pandoc-citeproc 0.17.0.2

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
Copy link
Member

yihui commented Oct 4, 2020

@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
Copy link

jokorn commented Oct 4, 2020

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
Copy link
Member

yihui commented Oct 4, 2020

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

@jokorn
Copy link

jokorn commented Oct 4, 2020

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
Copy link

jokorn commented Oct 4, 2020

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
Copy link
Member

yihui commented Oct 5, 2020

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
Copy link

Nicktz commented Oct 27, 2020

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
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 27, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

5 participants