Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a LaTeX symbol to fig.cap in R markdown?

Is there a way to add LaTeX symbols, like infinity \infty to figure captions within R markdown?

I can get LaTeX text formatting to work, but I can't figure out a way to use symbols.

Here is a working example using LaTeX text formatting:

---
output: 
  pdf_document:
    fig_caption: yes
---

```{r setup, include=FALSE}
library(knitr)
opts_chunk$set(
  echo=FALSE,
  message=FALSE,
  warning=FALSE,
  fig.align = 'center'
  )
```

## Testing LaTeX syntax within captions

```{r pressure, fig.cap="\\label{testPlot}This caption has LaTeX with 
{\\small small text} and some {\\footnotesize footnote text and 
\\textbf{bold footnote}} and \\textit{italic}"}
plot(pressure)
```

I have tried every combination I can think of an none have worked. For instance, double escape \\infty, brackets {\infty}, double escape within brackets {\\infty}, using the inline LaTeX $\infty$, inline with escape, etc. etc.

Any advice will be greatly appreciated.

like image 686
SubstantiaN Avatar asked Sep 06 '18 20:09

SubstantiaN


People also ask

How do I insert a symbol in markdown?

In side a text chunk, you can use mathematical notation if you surround it by dollar signs $ for “inline mathematics” and $$ for “displayed equations”. Do not leave a space between the $ and your mathematical notation. Example: $\sum_{n=1}^{10} n^2$ is rendered as ∑10n=1n2.

How do I write the symbol in Latex?

How to write Latex symbol belongs to : \in means "is an element of", "a member of" or "belongs to".

How do I get all the symbols in Latex?

How to write Latex symbol for all x : \forall . Given any or for all in predicate logic is a a type of quantifier.


1 Answers

$\\infty$ works. You need to escape the \ in \infty and IIRC this is a math mode symbol, so you need to invoke that too.

```{r pressure, fig.cap="\\label{testPlot}This caption has LaTeX with {\\small small text} and some {\\footnotesize footnote text and \\textbf{bold footnote}} and \\textit{italic} and $\\infty$"}
plot(1:10)
```
like image 63
Gavin Simpson Avatar answered Nov 07 '22 01:11

Gavin Simpson