2

I get the following latex error when rendering to rmarkdown file to beamer-presentation.

! Undefined control sequence.
l.16 \setbeamertemplate
                       {caption}[numbered] 

My rmarkdownscript looks as following, and the problem occurs when i knit the rmarkdown-file.

---
title: "Habits"
author: "John Doe"
date: "March 22, 2005"
output: beamer_presentation
---

# Goddag

----

I have installed and uninstalled TinyTex with tinytex package several times, and I have no problems making powerpoints or html.

What can cause the problem?

UPDATE(a) 17/01/23: Printed the sessionInfo() of the Markdown-file:


    > sessionInfo() 
    R version 4.2.2 (2022-10-31)
    Platform: x86_64-apple-darwin17.0 (64-bit)
    Running under: macOS Big Sur 11.7
    
    Matrix products: default
    LAPACK: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib
    
    locale:
    [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
    
    attached base packages:
    [1] stats     graphics  grDevices utils     datasets 
    [6] methods   base     
    
    loaded via a namespace (and not attached):
     [1] compiler_4.2.2  fastmap_1.1.0   cli_3.6.0      
     [4] htmltools_0.5.4 tools_4.2.2     rstudioapi_0.14
     [7] yaml_2.3.6      rmarkdown_2.19  knitr_1.41     
    [10] xfun_0.36       digest_0.6.31   pacman_0.5.1   
    [13] rlang_1.0.6     evaluate_0.19

UPDATE(b) 17/01/23: Output of the render-window knitting the .rmd-file from Rstudio.

    processing file: oplaeg.Rmd
      |.......................                                               |  33%
      ordinary text without R code
    
      |...............................................                       |  67%
    label: unnamed-chunk-1
      |......................................................................| 100%
      ordinary text without R code
    
    
    /Applications/RStudio.app/Contents/Resources/app/quarto/bin/tools/pandoc +RTS -K512m -RTS oplaeg.knit.md --to beamer --from markdown+autolink_bare_uris+tex_math_single_backslash --output oplaeg.tex --lua-filter /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rmarkdown/rmarkdown/lua/pagebreak.lua --lua-filter /Library/Frameworks/R.framework/Versions/4.2/Resources/library/rmarkdown/rmarkdown/lua/latex-div.lua --highlight-style tango --pdf-engine pdflatex --embed-resources --standalone 
    output file: oplaeg.knit.md
    
    ! Undefined control sequence.
    l.16 \setbeamertemplate
                           {caption}[numbered] 
    
    Error: LaTeX failed to compile oplaeg.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See oplaeg.log for more info.
    Execution halted 
Asger
  • 21
  • 2
  • This is likely to be caused by a defective LaTeX installation. You probably had earlier error messages, e.g. about missing LaTeX packages. If not, change the YAML header to include `output:\n beamer_presentation:\n keep_tex: true` (where "\n" marks line breaks), then run it, and run the resulting .tex file through latex directly. It should give more informative errors than you've shown us so far. – user2554330 Jan 15 '23 at 17:26
  • I've tried to run the latex-file now, and I've edited the post with the log-file – Asger Jan 16 '23 at 01:14
  • Can you check which version of rmarkdown and/or pandoc you have? I don't think this has anything to do with your tex installation, but rather a wrong class is used for your intermediate .tex file. Also double check if there are any problems in your header, maybe some similar unicode character instead of the `-` signs, an incorrect quotation mark, or something similar. – samcarter_is_at_topanswers.xyz Jan 16 '23 at 09:18
  • 1
    I agree with @samcarter_is_at_topanswers.xyz. Something is wrong in the `.tex` file: LaTeX sees document class "article", but it should have document class "beamer", i.e. `\documentclass[ignorenonframetext,]{beamer}`. (I get a spurious comma in the options; maybe that's causing trouble now?) – user2554330 Jan 16 '23 at 09:54
  • @user2554330 The spurious comma isn't pretty, but latex should be able to cope with that. And even if not, it wouldn't load a random other class instead. – samcarter_is_at_topanswers.xyz Jan 16 '23 at 09:56
  • @samcarter_is_at_topanswers.xyz, I agree it wouldn't load something at random, but the log indicates that for some reason it loaded "article" instead of "beamer". Finding out why should be the next step. – user2554330 Jan 16 '23 at 10:15
  • Thanks for the indications. I will try out some of the suggestions, and hopefully get it to work. – Asger Jan 16 '23 at 14:52
  • @samcarter_is_at_topanswers.xyz fyi: RStudio version is 2022.12.0+353 (2022.12.0+353) – Asger Jan 16 '23 at 14:54
  • @Asger Can you run `sessionInfo() ` and show the output? – samcarter_is_at_topanswers.xyz Jan 16 '23 at 15:03
  • It would also be useful to see the Pandoc command that `rmarkdown` issued. If you are knitting from RStudio, it will show up in the `Render` pane. – user2554330 Jan 16 '23 at 17:09
  • @samcarter_is_at_topanswers.xyz I have updated the output from the sessinInfo() function (not an expert in Rstudio, but supposed you meant from the .rmd-file). – Asger Jan 17 '23 at 19:35
  • @user2554330 made a second edit (b), where I outputted the render-window. – Asger Jan 17 '23 at 19:38
  • @Asger Thanks for the update! Looks pretty much up-to-date. Very curious problem! – samcarter_is_at_topanswers.xyz Jan 17 '23 at 19:45
  • 1
    It has me stumped. `pandoc` was asked to produce `beamer`, but it didn't. As a wild guess: maybe some existing file should be replaced but isn't being replaced because of permissions. Could you try renaming the source file to something you've never used before? – user2554330 Jan 17 '23 at 20:24
  • I can reproduce your error by adding this line to the YAML header: `documentclass: article`. That switches the document class from `beamer` to `article`, which is what we saw. Is there any chance that you have that line in your header, or somewhere nearby that Pandoc is interpreting as part of your header? – user2554330 Jan 17 '23 at 20:30
  • A possible workaround: add `documentclass: beamer` to the YAML block (with no indentation). If you have two `documentclass` settings, you'll get an error from `parse_yaml_front_matter`. If you only have this one, it should replace the bad documentclass with the right one. – user2554330 Jan 17 '23 at 20:47
  • Your suggetions are much appreciated both @samcarter_is_at_topanswers.xyz and @user2554330! I will try them out. – Asger Jan 17 '23 at 22:36
  • Unfortunately the suggestion these suggestions didn't work: (a) renaming the source file (@user2554330 you meant the .Rmd-file, right?), (b) I tried making a knit of a 'clean' template, and it gave the same error, which makes me think that it shouldn't be the anything with the headers, and (c) trying to add documentclass: beamer to the header. Still the same error. It's tough.. – Asger Jan 17 '23 at 22:48
  • I don't think I have any other ideas. If you ever do figure this out, you should post an answer to your own question. Mention my id in it and I should be notified: I'm very curious about it. – user2554330 Jan 18 '23 at 00:17

0 Answers0