Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show footnote only after a pause in beamer with R Markdown

I am making a Beamer presentation and I use pauses between contents of a single slide. I can't figure out how to show a footnote only after a pause.

Here's an example:

---
title: ""
author: ""
date: ""
output:
  beamer_presentation
bibliography: test.bib
---

* one argument

\pause

* another argument^[This citation should appear only with point 2: @fargues2006]

# references

with test.bib:

@article{fargues2006,
  title = {The {{Demographic Benefit}} of {{International Migration}}: {{Hypothesis}} and {{Application}} to {{Middle Eastern}} and {{North African Contexts}}},
  author = {Fargues, Philippe},
  date = {2006},
  journaltitle = {World Bank Policy Research Paper},
  url = {http://documents.worldbank.org/curated/en/508301468280735279/pdf/wps4050.pdf},
  number = {4050}
}

In this example, the footnote should not appear when only the first point is shown, but instead when the second point is shown.

I tried to apply this answer from TeX StackExchange but without success.

How can I do that?

Edit: following @samcarter_is_at_topanswers.xyz's answer, I precise that I would prefer a solution that does not require to switch from markdown to LaTeX in the document depending on whether a slide has both pauses and footnotes. However, I'm okay with using a .tex file or adding pandoc arguments in YAML (because I think the solution has to be this way, but I may be wrong).

Edit #2: I would like to put references in these footnotes with @citationkey

Also asked on RStudio Community

like image 948
bretauv Avatar asked Jun 12 '20 13:06

bretauv


People also ask

How do you make a footnote in R markdown?

To create a footnote in R Markdown, you use the carrot ^ followed immediately by square brackets []. Put the text inside of the [] and it'll print that at the bottom of the page. Code for a footnote will look like this: ^[This sentence will be printed as a footnote.] .

How do you add a pause in Beamer?

The simplest overlay is simply to insert a pause command between text. The pause command tells Beamer to make a new PDF page for what follows. This can be done basically anywhere. <2-> The syntax is to insert e.g. <2-> to indicate that text should appear from image 2 of current slide onward.


2 Answers

Edit: update- to include @citationkey:

The issue is with how pandoc is translating the ^[] into \footnote in the output tex file.

This in the markdown:

another argument ^[This citation should appear only with point 2: @fargues2006]

Compiles into this in latex:

another argument\footnote<.->{This citation should appear only
    with point 2: Fargues (2006)}

In order to get the footnotes to show up only the slides your point appears on you really need this latex translation:

another argument\footnote\only<+->{This citation should appear only with point 2: Fargues (2006)}

In only<+->, the + is a special symbol to mean the current overlay.

To get this to work, you can redefine the \footnote command so when pandoc translates it it actually calls: \only<+->\footnote.

NOTE:

The the full command is \only<+->\footnote<.-> which could cause the itemized slides to duplicate because there is two pointers to where the footnotes should appear (\only<+-> and <.->) and since pandoc is auto-inserting one, I am not sure of a way to get rid of that.

This duplication could also be the result of using * and \pause and pandoc translating that to each item appearing in its own itemize environment- which also has setting options for where the footnotes need to appear and again is also a pandoc thing.

I haven't done enough digging to know which of these is the true culprit for the duplicates..But either way, latex should apply the first pointer formatting for the \footnotes command and the "most local" setting within an environment (i.e. it will take the footnotes over the itemize).. so each duplicate slide so you'll get the proper formatting at least with this method, but you will have to remove duplicates. If someone knows a way to prevent this- I would be interested to hear about it.

To use: Include this at the beginning of your markdown:

\let\oldfootnote\footnote
\renewcommand{\footnote}{\only<+->\oldfootnote}

Your full markdown:

---
title: ""
author: ""
date: ""
output:
  beamer_presentation:
    keep_tex: true
bibliography: test.bib
header-includes:
  - \let\oldfootnote\footnote
  - \renewcommand{\footnote}{\only<+->\oldfootnote}


---


* one argument

\pause

* another argument ^[This citation should appear only with point 2: @fargues2006]

\pause 

* and another argument ^[This citation should appear only with point 3]

The output:

enter image description here

like image 97
Anna Nevison Avatar answered Oct 17 '22 06:10

Anna Nevison


You can workaround the problem by using the proper latex syntax:

---
title: ""
author: ""
date: ""
output:
  beamer_presentation
---

* one argument

\pause

* ```{=latex}
another argument\footnote<.(1)->{This should appear only with point 2}
```

enter image description here

Or with hidden footnoterule:

---
title: ""
author: ""
date: ""
output:
  beamer_presentation:
    keep_tex: true
---

##  {.t}


* one argument

\pause

* ```{=latex}
another argument\only<.(1)->{\footnote{This should appear only with point 2}}
```

enter image description here

(the top alignment is to avoid jumpingn)

like image 34
samcarter_is_at_topanswers.xyz Avatar answered Oct 17 '22 04:10

samcarter_is_at_topanswers.xyz