Skip to content

Instantly share code, notes, and snippets.

@dantonnoriega
Created May 24, 2017 03:31
Show Gist options
  • Save dantonnoriega/eab3851ab60e1f35fb17afbf3c0a4cd4 to your computer and use it in GitHub Desktop.
Save dantonnoriega/eab3851ab60e1f35fb17afbf3c0a4cd4 to your computer and use it in GitHub Desktop.
how to get a percent sign when spinning with latex or html
---
title: TEST
output:
pdf_document:
latex_engine: xelatex
html_document:
fig_caption: true
---
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
echo = TRUE,
cache = FALSE,
comment = "#>",
fig.path = "fig-",
fig.pos = "h"
)
# this will check what the output format is going to be
getOutputFormat <- function() {
knitr::opts_knit$get("rmarkdown.pandoc.to")
}
```
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
```{r, warning=FALSE, message=FALSE, echo=FALSE, eval=TRUE, results='asis'}
s <- "$$\\text{\\% change} = \\frac{x_2 - x_1}{x_1} \\times 100$$"
if(getOutputFormat() == 'html') s <- gsub('\\\\%', '%', s) # dont escape if html
knitr::asis_output(s)
```
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment