'How do I include a footnote in a figure caption?

I am using R Markdown to generate both HTML and PDF versions of the same document. Some figure captions have footnotes referencing the source of the figure. The following code generates figure captions with footnotes in the HTML.

{r, echo=FALSE, out.width="75%", fig.align = "center", fig.show='hold', fig.cap="My figure caption. ^[footnote text.]"}
knitr::include_graphics("My figure.png")

However, when I try to generate the PDF it returns the following error message:

! Missing $ inserted.
<inserted text> 
                $

I have been unable to determine how $ $ is used in this context. Can anyone help me?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source