0
votes

In a beamer presentation generated with rmarkdown::beamer_presentation, my aim is to apply a custom theme, which contains a beamerthemeTHEMENAME.sty (with sub files beamercolorthemeTHEMENAME.sty, beamerfontthemeTHEMENAME.sty, beamerinnerthemeTHEMENAME.sty, beamerouterthemeTHEMENAME.sty), as a template.tex and Includes.

Currently I source these files in the YAML-header as follows:

theme: "THEMENAME"
template: template.tex
includes:
  in_header: preamble.tex
  before_body: before_body.tex
  after_body: after_body.tex

To organize the presentation and its files more neatly, I would like to move these files ...

  • to a subfolder of the presentation directory (short-run solution)

  • to a general folder such the templates can likewise be sourced by/applied to other presentations (long-term solution).

How would I have to adjust the YAML header in each case to correctly source the above-mentioned files?

1

1 Answers

0
votes

Meanwhile, I found an answer which works for the short run.
(For hints regarding a long-term solution, see the answer from @Steven and comments by @Samcarter_is_at_topanswers.xyz.)

  • Drop all files of the custom theme THEMENAME as well as any includes (e.g., preamble.tex) into a subfolder termed beamer_files within the folder in which the Rmd file of the presentation is located in.

  • Modify the YAML header and beamerthemeTHEMENAME.sty as shown below. As per these SO answers (LaTex theme, colon), some LaTex hacks are necessary to apply the LaTex beamer theme smoothly in the rmarkdown::beamer_presentation.

MWE.Rmd

---
# COMMENT out "title" in YAML header: else markdown generates a second title page
# ==> if title contains no special characters: feed it straight into LaTex at the end of the YAML header
# ==> if title contains special characters, like ":", feed it in "preamble.tex" sourced in "LaTex Hacks"
subtitle: "Beamer presentation with R-markdown"
institute: "some place"
date: "`r format(Sys.time(), '%B %d, %Y')`"
output:
  # beamer_presentation: default
  bookdown::pdf_book:
    base_format: rmarkdown::beamer_presentation
    # Source below in "LaTex Hacks", if want theme to be stored in subfolder (else rmarkdown does not find it)
    # theme: "THEMENAME"
    # Source "includes" below in "LaTex Hacks" if using custom theme with custom title page
    # => else, markdown places the includes at inadequate position in LaTex file, which then either does not show the title or throws an error
    # includes: ...
    latex_engine: xelatex
    toc: false
    slide_level: 2
classoption: aspectratio=169 # fix aspect ratio of presentation (169 => 16:9, 149 => 14:9, default: 4:3)
#
# LaTex Hacks
# --------------------------
compact-title: false # to remove markdown generated title frame
header-includes:
  # - \title{Title if no special characters} 
  - \input{beamer_files/beamerthemeTHEMENAME.sty}
  - \input{beamer_files/preamble}       # feed title to LaTex in preamble.tex due to ":"
  - \def\titlefigure{img/my_bg}
  - \AtBeginDocument{\titleframe} # add title frame defined in beamerouterthemeTHEMENAME
  - \makeatletter\beamer@ignorenonframefalse\makeatother
  ---


​```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
​```

<!-- TOC - Table of Contents -->
<!-- ======================================================== -->

``` {=latex}
\end{frame}
\tocframe
\begin{frame}
```

## Slide with Bullets
<!-- ======================================================== -->

- Bullet 1
- Bullet 2
- Bullet 3

<!-- Appendix -->
<!-- ======================================================== -->
``` {=latex}
\end{frame}
\appendix
\begin{frame}
```

beamerthemeTHEMENAME.sty

% WAS:
% \usecolortheme{THEMENAME}
% \useoutertheme{THEMENAME}
% NOW:
\input{beamer_files/beamercolorthemeTHEMENAME.sty}
\input{beamer_files/beamerouterthemeTHEMENAME.sty}

\mode<all>

preamble.tex

% "title" is commented out in YAML header: else markdown generates a second title page
% if title contains no special characters: feed it straight into LaTex at the end of the YAML header
% if title contains special characters, like ":" or a forced linebreak feed it to LaTex here:
\title[short version]{First line of the title:\par second line of the title}