Skip to content

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

Closed

Description

@njbart

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.

Activity

  1. yihui commented on Sep 19, 2019

    @yihui
    Collaborator

    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.

  2. added
    bug
    on Nov 25, 2019
  3. yihui commented on Nov 25, 2019

    @yihui
    Collaborator

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

    remotes::install_github('rstudio/rmarkdown')

    Thanks for the report!

  4. changed the title [-]cslreferences environment missing in latex template[/-] [+]Pandoc 2.8 error "! LaTeX Error: Environment cslreferences undefined."[/+] on Dec 6, 2019
  5. firasm commented on Mar 3, 2020

    @firasm

    thanks this fixed the issue for me!

  6. added a commit that references this issue on Sep 26, 2020
  7. jokorn commented on Oct 3, 2020

    @jokorn

    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?

  8. yihui commented on Oct 4, 2020

    @yihui
    Collaborator

    @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'))
  9. jokorn commented on Oct 4, 2020

    @jokorn

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

  10. yihui commented on Oct 4, 2020

    @yihui
    Collaborator

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

  11. jokorn commented on Oct 4, 2020

    @jokorn

    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?

  12. jokorn commented on Oct 4, 2020

    @jokorn

    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.

  13. yihui commented on Oct 5, 2020

    @yihui
    Collaborator

    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.

  14. Nicktz commented on Oct 27, 2020

    @Nicktz

    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}

  15. github-actions commented on Apr 27, 2021

    @github-actions

    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.

  16. locked as resolved and limited conversation to collaborators on Apr 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions