user2903730
user2903730

Reputation: 165

How to pass options to a LaTeX font in R Markdown?

rmarkdown, following {xe|lua}latex, allows to specify fonts for main text, sans-serif text, monspaced text (most notably code chunks !) and math fonts in the YAML header. At least for PDF rendering via xetex, this works.

However, I found no (documented) way to pass options to the underlying setxxxfont \LaTeX command. For example, the YAML fragment :

```
monofont: Inconsolata
```

generates the following \LaTeX fragment :

\setmonofont[Mapping=tex-ansi]{Inconsolata}

I have two questions with this:

  1. why is the Mapping=tex-ansi added ? And how to control it ? (I'm working in UTF8...).
  2. How could I set additional arguments for the font options i.e. \setmonofont[Scale=0.91]{TeX Gyre Cursor}?

The R Markdown book and the Pandoc's User's Guide did not reveal anything pertinent.

Upvotes: 2

Views: 1551

Answers (1)

Michael Harper
Michael Harper

Reputation: 15369

Background:

When R Markdown converts the knitted code to the output format (PDF), a pandoc template is used. The template is stored within the package, and any variables which get replaced by the YAML variables are contained in the $$ Notation

1. Encoding

The Mapping=tex-ansi is added to the code as a workaround an issue as reported on GitHub. Therefore I would be cautious of deleting this for potential side effects.

If you do indeed wish to change this code, you will have to make a copy of the LaTeX template file used to convert the document. You can find the default template here. See here for some more information on providing custom templates.

2. Additional Font Options

You can use the monofontoptions YAML argument to add additional arguments to the font options.

Documentation of the variables which can be parsed by the LaTeX output are available in the pandoc documentation

Upvotes: 5

Related Questions