rstudio / rmarkdown-cookbook

R Markdown Cookbook. A range of tips and tricks to make better use of R Markdown.
https://bookdown.org/yihui/rmarkdown-cookbook/
578 stars 224 forks source link

Print LaTeX command in HTML #382

Open cderv opened 1 year ago

cderv commented 1 year ago

See https://github.com/rstudio/rmarkdown/issues/2420

```{r}
#| label: html-specific
#| echo: false
#| include: false
#| eval: true

latexString <- if (knitr::is_html_output()) {
  r"($\mathrm{\LaTeX{}}$)"
} else {
  r"(\LaTeX{})"
}

Then use r latexString in the text.