You many want to switch away from the default font in LaTex / R Markdown.
The standard YAML header to a document looks like this:
And the output like so:
To switch to another built-in font, change the header:
And the output text will resemble this:
Or this:
A full list of fonts is available at https://tug.org/FontCatalogue/. Hover over each font to see its shorthand name, and click through to the font’s page to see if you will need to download it.
For non-built-in fonts
If you need to download a font separately, i.e. if the method shown above will not compile properly, first navigate to the font’s page and find the appropriate package name.
I am using IM Fell English https://tug.org/FontCatalogue/imfellenglish/; [https://www.ctan.org/tex-archive/fonts/imfellenglish/] (https://www.ctan.org/tex-archive/fonts/imfellenglish/ “Tex Archive: IM Fell English”), which requires the imfellenglish Tex package.
In your RMarkdown document, or in your R session, use the tinytex package to install the font package:1
Then, create a new file in R (File, New File, then Text type), save it as a .tex file, and write a ‘use Tex package’ command in it, as follows:
Save the .tex file in the same folder as your RMD document.
Then, in your original R Markdown document, modify the header to call on your .tex file:
You can then print your document with the desired font:
You may notice that many fonts use the default LaTex font, Computer Modern, for math. If you do not want this to happen, look for a LaTex font with math support, here: https://tug.org/FontCatalogue/mathfonts.html.
Quick guide to writing math formulas here: https://rpruim.github.io/s341/S19/from-class/MathinRmd.html.
Have fun!
Footnotes
This installer can also be used to install “mdframed”, for borders around text or images. See https://quarto.org/docs/authoring/figures.html for more detail once it is installed.↩︎