Created
November 12, 2018 21:57
-
-
Save carlbfrederick/2b9af78e0153c35b21195fbf0812d587 to your computer and use it in GitHub Desktop.
Windows Fonts in Rmd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
title: "Sample Lato .Rmd" | |
author: "Carl Frederick" | |
date: "11/12/2018" | |
mainfont: Lato | |
output: | |
pdf_document: | |
latex_engine: xelatex | |
--- | |
```{r, include = FALSE, echo = FALSE} | |
library(extrafont) | |
loadfonts(device = "win") | |
``` | |
# Intro | |
This is Lato, cheers! | |
Apparently, the font doesn't carry over to tables made via `knitr::kable()`. | |
I have found this all works better with [TinyTeX](https://yihui.name/tinytex/) | |
rather than [MiKTeX](https://miktex.org/). To install TinyTeX: | |
```{r, eval = FALSE, echo = TRUE} | |
install.packages('tinytex') | |
tinytex::install_tinytex() | |
``` | |
# Prerequisites | |
All of this is in the extrafont package readme | |
<https://cran.r-project.org/web/packages/extrafont/README.html>, but to | |
summarize: | |
In order to use Lato, you need to use the `extrafont` package: | |
```{r, eval = FALSE, echo = TRUE} | |
install.packages(extrafont) | |
``` | |
The first time you load extrafont you need to import the fonts on your | |
computer: | |
```{r, eval = FALSE, echo = TRUE} | |
library(extrafont) | |
font_import() | |
``` | |
After the first time, you simply need to load the imported fonts via: | |
```{r, eval = FALSE, echo = TRUE} | |
loadfonts(device = "win") | |
``` | |
For each file you create you need to embed the fonts (requires GhostScript) | |
using `embed_fonts()`. See the package readme for details on this. | |
# Specifying which font to use | |
In the YAML header (between the --- --- lines at the top), specify | |
`mainfont: Lato` and set the latex_engine to xelatex as in: | |
``` | |
--- | |
title: "title" | |
author: "author" | |
date: "MM/DD/YYYY" | |
mainfont: Lato | |
output: | |
pdf_document: | |
latex_engine: xelatex | |
--- | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment