Using additional fonts

There are two different usage scenarios for fonts:

  1. Editor fonts in Posit Workbench
  2. Fonts for creating documents (HTML, PDF)

Posit Workbench Editor Fonts

Our Workbench images include the following custom editor fonts by default:

If you want to use an additional fixed-width font, please contact us and we can bundle it within the image.

Document Fonts

If you are in need of additional fonts for creating documents, there are two steps:

  1. The fonts must be installed within the image -> please contact us
  2. The fonts must be configured and loaded within R

For (1): some fonts can be installed on the user-level (see this comment in the {extrafont} package README) though we recommend to install them system-wide into the image as most often a custom font is used by multiple people.

For (2), the extrafont package is helpful/required to use these fonts for PDF or other output formats. Please consult the package documentation for usage instructions.

Font rendering for PDFs depends on the LaTeX engine used. Some fonts also need additional LaTeX packages to be loaded. In case of Arial though, it is quite simple: one needs only to set mainfont in the YAML header in combination with either Lualatex or Xelatex as the engine. Here is an example .Rmd document with Arial which assumes that Arial is installed on the system running Workbench:

---
title: "Arial"
mainfont: Arial
output:
  pdf_document:
    latex_engine: xelatex
---

This is an example for Arial font.
Only the text font is Arial, the code font is not.

```r
library(extrafont)

fonts()
```

Additional LaTeX packages can be specified in the YAML header as follows (example for the Source Sans Pro font):

[...]
header-includes:
   - \usepackage[default]{sourcesanspro}
   - \usepackage[T1]{fontenc}
mainfont: SourceSansPro
[...]