How to Write Special Characters in Rmarkdown Latex Documents

How can I write special characters in RMarkdown latex documents?

HTML codes for Turkish characters will work (example from wikipedia):

---
title: "My doc"
output: pdf_document
---

HTML char detail anglicized
------- -- ------------------------------ ---
Ğ Ğ Uppercase "G" with breve accent gh1
İ İ Uppercase dotted "I"² i (as in "tree")
Ş Ş Uppercase "S" with cedilla sh
ğ ğ Lowercase "g" with breve accent gh1
ı ı Lowercase dotless "i"³ ou (as in "in")
ş ş Lowercase "s" with cedilla sh
------- -- ------------------------------- --

Which renders the PDF like this:

Sample Image

For article templates, see the rticles package, or make your own

For book templates, have a look at pandoc ebook, gitbook and bookdown


This xelatex option I initially suggested will not work for Turkish characters:

The xelatex engine is recommended for this kind of thing. Then you can access your system fonts with the mainfont argument:

---
title: "My doc"
output:
pdf_document:
latex_engine: xelatex
mainfont: "name of your system font that has all those characters"
---

PDF output will be in the font you specify.

Just type as normal with no special codes.

Can I type \LaTeX or other special symbols inside verbatim code in Rmarkdown?

Solved in TeX SE. Essentially, just copy and paste the corresponding symbol β.

r markdown, knitr and latex symbols

You can use those column names in a data frame, but you need to tell the data.frame function not to mangle them using check.names = FALSE.
However, this isn't enough to fix your example, because $%$ is not legal LaTeX.
You need to escape the percent sign or it will be taken to be a comment character.
So this works:

my_data <- data.frame("$^3$" = "a",
"$\\epsilon^2$" = "b",
"$\\%$" = "c",
check.names = FALSE)
kable(my_data)

Sample Image

Knit a kable to PDF in RMarkdown that includes special characters in the table values

Could use the textcomp package and \textpertenthousand

---
output:
pdf_document:
latex_engine: xelatex
header-includes:
- \usepackage{textcomp}
---

```{r, echo = FALSE}
library(magrittr)
what_should_this_be <- "\\textpertenthousand"

knitr::kable(
head(mtcars) %>%
dplyr::select(mpg) %>%
tibble::rownames_to_column("car") %>%
dplyr::mutate(mpg = paste0(mpg, what_should_this_be)),
align = "cc",
escape = F,
booktabs = T,
caption = "Works with character $\\sigma$, but what about permyriad?"
)
```

Sample Image

Knitr escape latex special characters (e.g., ~, $) in R code

You need to add [fragile] option if your frame contains a knitr chunk with special latex characters:

\begin{frame}[fragile]

Source: knitr webpage.

How to print a filepath in R Markdown

Replace it by / or \\\\ - the latter one "escapes" the backslash actually twice.



Related Topics



Leave a reply



Submit