As @RalfStubner has already mentioned, you can use TeX Gyre Termes
to embed a font like Times New Roman
.
Install tex-gyre
In order to use TeX Gyre Termes
, you need to install tex-gyre
package from CTAN. If you have installed @Yihui's TinyTeX
, type the following code to R console.
tinytex::tlmgr_install("tex-gyre")
The code above is equivalent to executing the code below in your bash.
tlmgr install tex-gyre
Provide .tex
file to specify font(s) you want
Setting mainfont:
in the YAML header should also work. However, here I show how to set fonts by including a .tex
file, say font-config.tex
for instance, to the YAML section. By the font-config.tex
file, you can configure more detailed options, like Scale=MatchUppercase
.
In the following font-config.tex
, TeX Gyre Termes
, or Times New Roman is set as the main font (\rmfamily
) and TeX Gyre Heros
, so-called Helvetica or Arial is specified as the san serif font (\sffamily
). Save the file in your current directory.
font-config.tex
\usepackage{fontspec}
%rmfamily
\setmainfont[Scale=MatchUppercase]{TeX Gyre Termes} %Times New Roman
%sffamily
\setsansfont[Scale=1]{TeX Gyre Heros} %So called Helvetica, Arial
Include font-config.tex
into the YAML header
You can call the font-config.tex
from the YAML header, as shown below.
---
title: "The definitive MWE"
subtitle: "Oh, yeah"
author: "CLR"
output:
bookdown::pdf_document2:
number_sections: true
latex_engine: xelatex #or lualatex
keep_tex: true
includes:
in_header:
- font-config.tex
---
*Hellow world!* in Times New Roman.
\textsf{Hellow world!} in Helvetica.