Using font IBM Plex Sans in RMarkdown

I am trying to switch the font of a report from Times New Roman to IBM Plex Sans, with no success.

Here is my failed attempt:

output: pdf_document
mainfont: "IBM Plex Sans"
geometry: margin = 3cm

<style type="text/css">
  font-family: "IBM Plex Sans";
  font-size: 16pt;

Is there a package or extension in LaTeX or CSS I can install to set this font as available?

Thank you in advance!

LaTeX can be tough and using it well is a big investment in time. It does provide the ability to put ink pixels anywhere at all, but with that power comes great labor.

There are a couple of issues. The first is likely a problem. In YAML white space is semantic. It's very picky about indentation.

    latex_engine: xelatex
    fontfamily:  IBM Plex Sans

The second is that the xelatex engine must be specifically set.

For as much as most of us need to know, there is The Book and those seeking higher knowledge have the pandoc documentation and its source code. In Haskell. So I won't send you there.

Thank you, @technocrat !
But this still do not run, fontfamily is supposed to be in the same level as output.
And after that, the file with the IBM Plex Sans (or even IBM Plex Sans Regular) does not exist:

! LaTeX Error: File `IBMPlexSansRegular.sty' not found.
1 Like

I’ll try again by installing on my box, which might be more useful than guessing.

You can use either "header-includes:" or "includes: in_header:".

title: Using IBM Plex Sans
    keep_tex: yes
    latex_engine: xelatex
  - \usepackage{fontspec}
  - \setmainfont{IBM Plex Sans}

You can find the usage in either 6.3 Add logo to title page or 6.1 Add LaTeX code to the preamble.


@MonsterSupreme nailed it

1 Like

Thank you very much @MonsterSupreme and @technocrat ! I see from the output that it is working for you. Unfortunately it does not work for me.

Sorry for taking so long to answer, I was busy with so many attemptives to upgrade tex. I finally could upgrade to the 2022 version.

The error for me is:

This is XeTeX, Version 3.141592653-2.6-0.999994 (TeX Live 2022) (preloaded format=xelatex)
 restricted \write18 enabled.
entering extended mode
! Package fontspec Error: The font "IBM Plex Sans" cannot be found.

Error: LaTeX failed to compile test.tex. See for debugging tips. See test.log for more info.
Execution halted

Do you have a LaTeX IDE you can try this in? That looks like where it is that the choke comes.

I have tried running xelatex in the command line with my tex document, and the same error appears:

! Package fontspec Error: The font "IBM Plex Sans" cannot be found.



as discussed in this thread

This error gives you a hint. Do you have the font installed? If so, what is the name your operating system calls the font? Find out the name of the installed font and try again.

Also, pls read the documentation: 3.3 PDF document | R Markdown: The Definitive Guide

The section II.2 in the fontspec documentation might also be relevant: CTAN: Package fontspec

1 Like

Thank you very much!

I have read both documentations, and downloaded the font. The problem was that I installed and reinstalled Tex Live and TinyTex, and my computer is a mess now.

I have just tried to run it in an RStudio docker container, and it worked wonderfully thanks to the code provided by @MonsterSupreme !

Thank you very much, everybody!

For those that find this afterwards, know that you need to download the font (an example here) and install it (you can find the instructions for linux here) before adding the code to your Rmd header.

1 Like

Yes, having TeX Live and tinytex installed at the same time gives you a lot of headaches. If you use TeX/LaTeX outside of R, then install TeX Live and use the tlmgr to install packages. But you should have a proficient understanding of the workings of TeX and the combination with RStudio is more work.

If you use TeX to get nice PDF output from your RMarkdown/Bookdown/Quarto documents, install tinytex and knit your PDFs worry-free. You can even write your occasional LaTeX documents from within the RStudio IDE. The Zotero integration is quite nice.

1 Like

Just a precision:

  • tinytex is an R package that is used by R Markdown to work with LaTeX on computer to render to PDF
  • TinyTeX is a lightweight distribution of TeX Live - It is same as TeX Live only repackage to make more usable easily for R users, and also tested against R Markdown rendering. tinytex :package: has helper to install this distribution but it can also be installed and used without R.

Not need to install TeX Live and TinyTeX, but you can have TeX Live installed and only use tinytex :package: - Not need to install TinyTeX with tinytex::install_tinytex() then

Hope it helps clarify


Thank you for clarifying. I have followed some instructions to remove all of TexLive and finally could reinstall TinyTeX using the tinytex :package: .

Thank you also @cderv for the clarification!


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.