'Change equations font in RMarkdown

I have math equations on my RMarkdown document that I'm knitting to a PDF file using knitr. I'm using the Arial font, specified in my YAML as:

title: "My document"
subtitle: "Draft"
output:
  pdf_document:
    latex_engine: xelatex
mainfont: Arial
geometry: margin = 1in
fontsize: 11pt 

The issue is that my equations use the default font instead of the one I set up in the YAML.

For example:

$$\mathrm{P}(Rain \mid Sun ) < \mathrm{P}(Rain \mid Cloud)$$

So I have two different fonts in my overall document, which is not what I want. How do I change the font for mathematical expressions in RMarkdown?



Solution 1:[1]

Try using the mathfont parameter for latex (https://bookdown.org/yihui/rmarkdown/pdf-document.html#latex-options):

title: "My document"
subtitle: "Draft"
output:
  pdf_document:
    latex_engine: xelatex
mainfont: Arial
mathfont: Arial
geometry: margin = 1in
fontsize: 11pt 

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Marcus