Show footnote only after a pause in beamer with R Markdown
Asked Answered
P

2

8

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

Palpate answered 12/6, 2020 at 13:15 Comment(0)
R
4

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

Rosenberg answered 20/6, 2020 at 3:6 Comment(3)
That is similar to the first answer, but the problem is the same: it does not work if I put citations in the footnote with @citationkeyPalpate
@Palpate oh thought you were just looking for a way to not jump between latex and markdown in the doc. can you update the question with a reproducible example of the citation key problem?Rosenberg
Nice answer! One drawback though is that when two footnotes appear at the same time, the second one does not work but shows <.-> The content of the footnote in the body of the text. To see that, remove \pause between bullets 2 and 3 in the example. I can live with that since I just need to add a pause between the two bullets but I think it's worth mentioning.Palpate
E
3

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)

Eriha answered 12/6, 2020 at 13:53 Comment(7)
That's nice, do you know how to remove the line above the footnote as well when the footnote is not displayed?Palpate
@Palpate Do you have slides with more than one footnote?Eriha
Yes, some have three or fourPalpate
Well that works but it means that we have to jump between latex and markdown in the document, depending on whether there are footnotes with pauses or not in the frames, which is not very convenient. That also causes trouble when references are in footnote as we can't use @citationkey as in the rest of the document. Do you think there's a way to do that by using code in a .tex file as a preamble?Palpate
@Palpate The easiest way to do this is to forgo the markdown and just use latex :) This way you avoid having to jump between different syntaxEriha
Sure but then we kind of lose half of the interest of making beamer presentations with r markdown (I find markdown much easier than latex and cleaner to read in .Rmd files)Palpate
I edited my post to specify my preferences but keep your answer anywayPalpate

© 2022 - 2024 — McMap. All rights reserved.