Fixed font rmarkdown pdf

I have the same question as this one , but I have a different error. I want to install mainfontroboto in yaml , but I get the error message "fontspec error:" font-not-found "when I embed it in a PDF.

---
title: "My Title"
header-includes:
  - \usepackage[sfdefault]{roboto}
  - \usepackage[T1]{fontenc}
output:
  pdf_document:
    latex_engine: xelatex
mainfont: roboto
---

Launch MacTex 2016

sessionInfo()
#R version 3.3.2 (2016-10-31)
#Platform: x86_64-apple-darwin13.4.0 (64-bit)
#Running under: macOS Sierra 10.12.4

Update 1

This works to define the font in header-includes, but it looks like the specification mainfontshould work too:

---
title: "My Title"
header-includes:
  - \usepackage[sfdefault]{roboto}
  - \renewcommand{\familydefault}{\sfdefault}
output:
  pdf_document:
    latex_engine: xelatex
---

Update 2

monofontalso failed for me, but header-includesworked:

---
title: "My Title"
header-includes:
  - \usepackage{fontspec}
  - \setmonofont[Mapping=tex-text]{inconsolata}
  - \usepackage[sfdefault]{roboto}
  - \renewcommand{\familydefault}{\sfdefault}
output:
  pdf_document:
    latex_engine: xelatex
---

What am I doing wrong with mainfontand monofontin yaml?

+7
source share
2 answers

. , latex_engine , pdf_document() . R Markdown yaml YAML, , latex_engine :

yaml::yaml.load(
'output:
  pdf_document:
    latex_engine: xelatex
mainfont: roboto')

:

$output
$output$pdf_document
$output$pdf_document$latex_engine
[1] "xelatex"

$mainfont
[1] "roboto"

rmarkdown::render(, pdf_document()) , rmarkdown::render(, pdf_document()):

yaml::yaml.load(
'output:
  pdf_document:
  latex_engine: xelatex
mainfont: roboto')

:

$output
$output$pdf_document
NULL

$output$latex_engine
[1] "xelatex"


$mainfont
[1] "roboto"

, pdf_document pdflatex .

, , roboto pdflatex. pdflatex pdflatex xelatex: roboto - pdflatex, mainfont - xelatex ( LaTeX \setmainfont{roboto} \setmainfont{roboto}). , .

xelatex, , , ( ). , , , Roboto. xelatex (, xelatex ), pdflatex pdflatex .

YAML: https://bookdown.org/yihui/bookdown/r-markdown.html

+7

: Yihui

, , RMarkdown YAML. latex_engine , . , pandoc latex_engine, pdf_output, output. :

---
title: "My Title"
header-includes:
    - \usepackage[sfdefault]{roboto}
    - \usepackage[T1]{fontenc}
output:
    pdf_document:
    latex_engine: xelatex
mainfont: roboto
---
+1

Source: https://habr.com/ru/post/1016502/


All Articles