rlatexr-markdownxelatextinytex

Rmarkdown fails at using xelatex engine


I am trying to specify a font style in my document and I found out I should use a specific latex engine: xelatex. However when I specify the following instruction inside the YAML header:

---
title: BLABLA - me
output:
  pdf_document: default
  engine: xelatex
header-includes:
  - \usepackage{fontspec}
  - \setmainfont{Times New Roman} 
fontsize: 12pt
---

I could not get my document compiled because of the error:

    ! Fatal Package fontspec Error: The fontspec package requires either XeTeX or
(fontspec)                      LuaTeX.
(fontspec)                      
(fontspec)                      You must change your typesetting engine to,
(fontspec)                      e.g., "xelatex" or "lualatex"instead of
(fontspec)                      "latex" or "pdflatex".

I have installed the package tinytex and I do not know much about latex


Solution

  • Check your header. Some posts (i.e. here) report that the correct way to specify engine is

    output:
      pdf_document:
        latex_engine: xelatex