Rmarkdown pandoc error using tinytex: beamer class is somehow changed to article class

First of all, I have already posed my issue on stack overflow without any luck so far.. This is the reason why I'm trying to ask here as well (link: https://stackoverflow.com/questions/75126145/error-undefined-sequence-control-setbeamertemplate-trying-render-rmarkdown?noredirect=1#comment132620913_75126145).

I can start of by saying, that I've tried re-installing, R, Rstudio, and tinytex + TinyTex. Here is my Rstudio version from the output of sessionInfo(): RStudio version is 2022.12.0+353 (2022.12.0+353)

I hope someone can help me with my knitting problems from .rmd to beamer_presentation (I don't have problem producing Powerpoints or Html's.)

DOCUMENTATION:

I have the following .rmd-script (which is basically just a template):

---
title: "test"
author: "Asger Balsby Kromand"
date: "2023-01-17"
output: 
  beamer_presentation:
    keep_tex: true
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
options(tinytex.verbose = TRUE)
```

## R Markdown

This is an R Markdown presentation. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see xx.

When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document.

## Slide with Bullets

- Bullet 1
- Bullet 2
- Bullet 3

## Slide with R Output

```{r cars, echo = TRUE}
summary(cars)
```

## Slide with Plot

```{r pressure}
plot(pressure)
```

When knitting I get the following error in the render-window:

processing file: test.Rmd
  |..........                                                            |  14%
  ordinary text without R code
  |....................                                                  |  29%
label: setup (with options) 
List of 1
$include: logi FALSE
  |..............................                                        |  43%
  ordinary text without R code
  |........................................                              |  57%
label: cars (with options) 
List of 1
 $echo: logi TRUE
  |..................................................                    |  71%
  ordinary text without R code
  |............................................................          |  86%
label: pressure
  |......................................................................| 100%
  ordinary text without R code
/Applications/RStudio.app/Contents/Resources/app/quarto/bin/tools/pandoc +RTS -K512m -RTS test.knit.md --to beamer --from markdown+autolink_bare_uris+tex_math_single_backslash --output test.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: test.knit.md
This is pdfTeX, Version 3.141592653-2.6-1.40.24 (TeX Live 2022) (preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode
I was unable to find any missing LaTeX packages from the error log test.log.

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

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

As you can see above the pandoc function recognizes that a beamer-file should be made.

But when I open the latex-file, which I also produce, due to 'keep_tex: true', I see that the documentclass has been changed to \documentclass[12pt]{article} instead of \documentclass[ignorenonframetext,]{beamer}, which would have been correct. You can see the latex-file here - it's called test.tex.

I've learned that this error can be reproduced, if you add this line to the YAML header in the .rmd-file: documentclass: article.

So... when I then try to open up the corresponding .tex file in Rstudio and press 'Compile PDF', I get the following errors seen in below photo:

Due to space-limits of the post, I added the log-file from the compiling of the .tex-file the same place as the tex-file, see link above.

Can you format your Rmd code correctly so that it easier for us to look at it ?

FAQ: How to Format R Markdown Source

Of course. Should be edited now

Still in need of assistance

This script works for me using latest version of packages and in a clean new project.

Try in a new session, new project to render it.

If you still get an issue, please share your RStudio version , and rmarkdown::pandoc_version() thanks

@cderv. Thanks for the reply. When you say 'packages', which ones do you refer to then?
This is what I got from pandoc-version:

> rmarkdown::pandoc_version()
[1] ‚Äė2.19.2‚Äô

This my Rstudio

Skærmbillede 2023-01-21 kl. 09.07.51

This is my sessionInfo()

> 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  methods   base     

loaded via a namespace (and not attached):
[1] compiler_4.2.2 tools_4.2.2  

Here's what I get from knitting the file, which renders as beamer from TexShop even though it has the article class.

I can also output to pdf with pdflatex from the shell.

1 Like

Ok so you got recent enough tool.

As I said, I can't reproduced your issue when I copy paste the Rmd content you shared.

Did you try that ?

@cderv Okay, so I've tried making both a new, clean project, this didn't work. I get the exact same errors.



processing file: test.Rmd
  |..........                                                            |  14%
  ordinary text without R code

  |....................                                                  |  29%
label: setup (with options) 
List of 1
 $ include: logi FALSE

  |..............................                                        |  43%
  ordinary text without R code

  |........................................                              |  57%
label: cars (with options) 
List of 1
 $ echo: logi TRUE

  |..................................................                    |  71%
  ordinary text without R code

  |............................................................          |  86%
label: pressure
  |......................................................................| 100%
  ordinary text without R code


output file: test.knit.md

/Applications/RStudio.app/Contents/Resources/app/quarto/bin/tools/pandoc +RTS -K512m -RTS test.knit.md --to beamer --from markdown+autolink_bare_uris+tex_math_single_backslash --output test.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 
! Undefined control sequence.
l.16 \setbeamertemplate
                       {caption}[numbered] 

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

And in my tex-file I can see, that Latex still doesn't recognize my tex-file as a beamer-class, but still produces a tex-file with documentclass: article:

\PassOptionsToPackage{unicode}{hyperref}
\PassOptionsToPackage{hyphens}{url}
%
\documentclass[12pt]{article}
\usepackage[a4paper, hmargin={2.8cm, 2.8cm}, vmargin={2.5cm, 2.5cm}]{geometry}
\usepackage[document]{ragged2e}
\usepackage{siunitx}
\usepackage{dcolumn}
\usepackage{pdflscape}
\sisetup{output-decimal-marker = {,}}
\usepackage[british, danish]{babel}
\usepackage{multirow}
\usepackage{pgfpages}
\usepackage{ragged2e}
\raggedright
\setbeamertemplate{caption}[numbered]
\setbeamertemplate{caption label separator}{: }
\setbeamercolor{caption name}{fg=normal text.fg}
\beamertemplatenavigationsymbolsempty
% Prevent slide breaks in the middle of a paragraph
\widowpenalties 1 10000
\raggedbottom
\setbeamertemplate{part page}{
  \centering
  \begin{beamercolorbox}[sep=16pt,center]{part title}
    \usebeamerfont{part title}\insertpart\par
  \end{beamercolorbox}
}
\setbeamertemplate{section page}{
  \centering
  \begin{beamercolorbox}[sep=12pt,center]{part title}
    \usebeamerfont{section title}\insertsection\par
  \end{beamercolorbox}
}
\setbeamertemplate{subsection page}{
  \centering
  \begin{beamercolorbox}[sep=8pt,center]{part title}
    \usebeamerfont{subsection title}\insertsubsection\par
  \end{beamercolorbox}
}
\AtBeginPart{
  \frame{\partpage}
}
\AtBeginSection{
  \ifbibliography
  \else
    \frame{\sectionpage}
  \fi
}
\AtBeginSubsection{
  \frame{\subsectionpage}
}
%\usepackage{lmodern}
\usepackage[]{kpfonts}
%\usepackage{sansmathfonts}
%\usepackage[scaled=0.95]{helvet}
%\renewcommand{\rmdefault}{\sfdefault}
\usepackage{xfrac}
%\renewcommand{\familydefault}{\sfdefault}
%\linespread{1.25}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{amssymb}
\usepackage{bm}
\usepackage{microtype}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{sectsty}
\allsectionsfont{\color[HTML]{96160B}}
%\usepackage{amssymb,amsmath}
\newcommand{\vektor}[2]{ \begin{pmatrix} #1 \\ #2 \end{pmatrix} }
\usepackage{ifxetex,ifluatex}
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
  \usepackage[T1]{fontenc}
  \usepackage[utf8]{inputenc}
  \usepackage{textcomp} % provide euro and other symbols
\else % if luatex or xetex
  \usepackage{unicode-math}
  \defaultfontfeatures{Scale=MatchLowercase}
  \defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1}
\fi
% Use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\IfFileExists{microtype.sty}{% use microtype if available
  \usepackage[]{microtype}
  \UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
\makeatletter
\@ifundefined{KOMAClassName}{% if non-KOMA class
  \IfFileExists{parskip.sty}{%
    \usepackage{parskip}
  }{% else
    \setlength{\parindent}{0pt}
    \setlength{\parskip}{6pt plus 2pt minus 1pt}}
}{% if KOMA class
  \KOMAoptions{parskip=half}}
\makeatother
\usepackage{xcolor}
\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
\IfFileExists{bookmark.sty}{\usepackage{bookmark}}{\usepackage{hyperref}}
\hypersetup{
  pdftitle={test},
  pdfauthor={Asger Balsby Kromand},
  hidelinks,
  pdfcreator={LaTeX via pandoc}}
\urlstyle{same} % disable monospaced font for URLs
\newif\ifbibliography
\usepackage{color}
\usepackage{fancyvrb}
\newcommand{\VerbBar}{|}
\newcommand{\VERB}{\Verb[commandchars=\\\{\}]}
\DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\}}
% Add ',fontsize=\small' for more characters per line
\usepackage{framed}
\definecolor{shadecolor}{RGB}{248,248,248}
\newenvironment{Shaded}{\begin{snugshade}}{\end{snugshade}}
\newcommand{\AlertTok}[1]{\textcolor[rgb]{0.94,0.16,0.16}{#1}}
\newcommand{\AnnotationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\AttributeTok}[1]{\textcolor[rgb]{0.77,0.63,0.00}{#1}}
\newcommand{\BaseNTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
\newcommand{\BuiltInTok}[1]{#1}
\newcommand{\CharTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\CommentTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textit{#1}}}
\newcommand{\CommentVarTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\ConstantTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\ControlFlowTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}}
\newcommand{\DataTypeTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{#1}}
\newcommand{\DecValTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
\newcommand{\DocumentationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\ErrorTok}[1]{\textcolor[rgb]{0.64,0.00,0.00}{\textbf{#1}}}
\newcommand{\ExtensionTok}[1]{#1}
\newcommand{\FloatTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
\newcommand{\FunctionTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\ImportTok}[1]{#1}
\newcommand{\InformationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\KeywordTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}}
\newcommand{\NormalTok}[1]{#1}
\newcommand{\OperatorTok}[1]{\textcolor[rgb]{0.81,0.36,0.00}{\textbf{#1}}}
\newcommand{\OtherTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{#1}}
\newcommand{\PreprocessorTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textit{#1}}}
\newcommand{\RegionMarkerTok}[1]{#1}
\newcommand{\SpecialCharTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\SpecialStringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\StringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\VariableTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\VerbatimStringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\WarningTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\usepackage{graphicx,grffile}
\makeatletter
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}
\def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi}
\makeatother
% Scale images if necessary, so that they will not overflow the page
% margins by default, and it is still possible to overwrite the defaults
% using explicit options in \includegraphics[width, height, ...]{}
\setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio}
% Set default figure placement to htbp
\makeatletter
\def\fps@figure{htbp}
\makeatother
\setlength{\emergencystretch}{3em} % prevent overfull lines
\providecommand{\tightlist}{%
  \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\setcounter{secnumdepth}{-\maxdimen} % remove section numbering

\title{test}
\author{Asger Balsby Kromand}
\date{2023-01-23}

\begin{document}
\frame{\titlepage}

\begin{frame}{R Markdown}
\protect\hypertarget{r-markdown}{}
This is an R Markdown presentation. Markdown is a simple formatting
syntax for authoring HTML, PDF, and MS Word documents. For more details
on using R Markdown see \url{http://rmarkdown.rstudio.com}.

When you click the \textbf{Knit} button a document will be generated
that includes both content as well as the output of any embedded R code
chunks within the document.
\end{frame}

\begin{frame}{Slide with Bullets}
\protect\hypertarget{slide-with-bullets}{}
\begin{itemize}
\tightlist
\item
  Bullet 1
\item
  Bullet 2
\item
  Bullet 3
\end{itemize}
\end{frame}

\begin{frame}[fragile]{Slide with R Output}
\protect\hypertarget{slide-with-r-output}{}
\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{summary}\NormalTok{(cars)}
\end{Highlighting}
\end{Shaded}

\begin{verbatim}
##      speed           dist       
##  Min.   : 4.0   Min.   :  2.00  
##  1st Qu.:12.0   1st Qu.: 26.00  
##  Median :15.0   Median : 36.00  
##  Mean   :15.4   Mean   : 42.98  
##  3rd Qu.:19.0   3rd Qu.: 56.00  
##  Max.   :25.0   Max.   :120.00
\end{verbatim}
\end{frame}

\begin{frame}{Slide with Plot}
\protect\hypertarget{slide-with-plot}{}
\includegraphics{test_files/figure-beamer/pressure-1.pdf}
\end{frame}

\end{document}

I don' think you can reproduce my error, just by copying the rmd-script. I've tried to explain this in my post above.

@technocrat: Another user in my issue-post on stackoverflow, said he was able to reproduce this error by adding a explicit documentclass in the YAML-header. Please see the comments in this links: r - Error: ! Undefined sequence control \setbeamertemplate, trying render rmarkdown-file to beamer presentation - Stack Overflow

Somehow when knitting on my computer, the documentclass of beamer is changed to article.
It's very hard to make a script that can reproduce my error, as I dont know why the error happens. But clearly, your computer don't have the same compiling-troubles as mine, as you don't have any troubles recompiling.

I somehow get the sense, that there is some old package/dependency within my bin, that is interferering with the rendering of the rmd to beamer. But this is a wild guess, as I'm no expert and just can't get a grip of what it is...

Sorry I missed that.

How can I reproduce your issue of beamer_presentation() creating a documentclass: article for you ? Can you send me a project ? A file ? If this is something we can't reproduce, then somehow it is tied to your computer environment. Hard to know what could be :thinking: Ideas:

  • RStudio version ?
  • TinyTeX (TeX Live) version ?
  • CTAN packages (start from a clean state) ?
  • Pandoc version used (if any on PATH that would override a more recent one).

But it seems you tried all that.

Did you tweak some Pandoc's default file (or template) by any chance ? If you don't know what I mean then ignore.

Can you share again your Pandoc version ? I don't find the answer above.

rmarkdown::pandoc_version()

yes that is very hard issue to find those ones ... :frowning:

This topic was automatically closed 45 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.