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:
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)
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?"
)
```
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
How to Include Custom CSS in HTMLwidgets for R And/Or Leafletr
How to Create a Hyperlink Interactively in Shiny App
Changing Multiple Column Values Given a Condition in Dplyr
R/Gis: How to Subset a Shapefile by a Lat-Long Bounding Box
Generating Non-Duplicate Combination Pairs in R
Suppress Automatic Output to Console in R
Preventing Column-Class Inference in Fread()
Flatten Nested List into 1-Deep List
R Leaflet - Use Date or Character Legend Labels with Colornumeric() Palette
Looping Through Covariates in Regression Using R
Adding Percentages to a Grouped Barchart Columns in Ggplot2
Problems with Dplyr and Posixlt Data
Renaming Multiple Columns with Dplyr Rename(Across(
How to Create a Plot with Customized Points in R
Gap in Polar Time Plot - How to Connect Start and End Points in Geom_Line or Remove Blank Space
Order Categorical Data in a Stacked Bar Plot with Ggplot2
R: Scatter Plot Matrix Using Ggplot2 with Themes That Vary by Facet Panel