rr-markdownknitrtinytex

How to render PDF from R Markdown with Chinese characters


I am unable to render PDF files from R Markdown properly due to the Chinese characters in an otherwise mostly English document, from a Windows 11 machine, using tinytex. I'm receiving the following error:

! Package fontspec Error: The font "SimHei" cannot be found.

MRE of the Rmd file:

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

位置適中,環境優美。                                                                                                                                                              
Central location, beautiful environment

I do have the SimHei font installed on my machine, which is causing me some confusion as to how to make tinytex be aware of it.


Solution

  • I had to install the fonts needed using the "Install for all users" admin option - initially I was only providing the font for my user privilege.