RStudio Pandoc Beamer add \frame options
Asked Answered
R

2

10

I would like to be able to pass frame options to beamer via RStudio-Rmarkdown-Pandoc-Beamer path. This would allow to take advantage of beamer's options to suppress frames from being printed. Beamer allows the following:

\documentclass[handout]{beamer}
\begin{document}

\begin{frame}
Slide 1
\end{frame}

\begin{frame}<handout:0>
Slide 2 to be suppressed
\end{frame}

\end{document}

I am aware that the pandoc .tex template can be altered to statically add options to slide frames but would like to do this on the fly something like:

##Slide 1

## Slide 2 <handout:0>
Rifling answered 23/11, 2015 at 21:41 Comment(0)
T
4

The pandoc maual has the section Frame attributes in beamer.

But since handout is not on the list, you can use a pandoc filter to remove certain things instead. Put the following in a file named e.g. filter.lua

function Div(el)
  if el.classes[1] == 'hidden' then
    return {}
  else
    return el
  end
end

To use from rmarkdown:

---
output:
  beamer_presentation:
    pandoc_args: ["--lua-filter=filter.lua"]
---

# In the morning

::: hidden :::
## This part is removed

content
:::

## Breakfast

- Eat eggs
- Drink coffee

To keep the slide, simply run it without the filter.

Twila answered 3/11, 2019 at 11:58 Comment(3)
Thanks for your answer! This certainly solves the original problem of the OP. I will leave the bounty open a bit longer in the hope for an answer that actually adds overlay specifications, because my personal use case it not so much hiding frames in handout mode, but to make tricks like https://mcmap.net/q/1167865/-how-to-interrupt-an-incremental-list-of-items-in-rmarkdown-then-retake-it-after-a-plot-or-figure easierEndomorphic
Sure, I didn't realize the question itself was that old... Generally, you can also include pandoc.RawBlock('latex', 'my custom latex') or RawInline with a lua fiter. But for the <handout:0> case, I didn't manage to put it at the right place because the pandoc beamer writer adds quite a lot of additional latex markup... but depending on what exactly you're trying to do, that should work. People on the pandoc-discuss mailing list often are also willing to help write filters.Twila
I will have a look into the pandoc.RawBlock(...) functions. They look interesting, thanks for the pointer!Endomorphic
E
1

Dirty hack to hide a frame in handout mode:

---
output: 
  beamer_presentation:
    keep_tex: true
classoption: handout

---

# normal frame




``` {=latex}
\end{frame}
\begin{frame}<handout:0>
\frametitle{special}
```

hidden in handout


# normal frame
Endomorphic answered 31/10, 2019 at 16:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.