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.
output:
pdf_document:
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.
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 https://yihui.org/tinytex/r/#debugging for debugging tips. See test.log for more info.
Execution halted
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.
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.
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.
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 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 - Not need to install TinyTeX with tinytex::install_tinytex() then