4

I'm using Bookdown to generate an ePub and a PDF of a book I'm writing. The book is generating fine, but I am trying to make a change to the font for the PDF from a serif font to a sans serif font. I tried what was listed in this StackOverflow post but it didn't work for me. Here are the contents of my preamble.tex file:

\usepackage{fontspec}
\setmainfont{Arial} # also have tried sansfont and arial, which I've seen in other places

and the contents of the _output.yml file:

bookdown::pdf_book:
  pandoc_args: --listings
  includes:
    in_header: preamble.tex
  latex_engine: xelatex # with this line, I get an error that the font can't be found; if I remove it, then the error doesn't show up and the font is still the default one

As far as I can tell, this should work, but it hasn't so far. Any suggestions on what to do to change the font?

pjlamb12
  • 2,300
  • 2
  • 32
  • 64
  • This should work (and it does for me). Are you sure that your output format really is `bookdown::pdf_book`? – Martin C. Arnold Nov 23 '20 at 18:47
  • [Here's a gist](https://gist.github.com/pjlamb12/f5d10989aa49fe6f445c31df78485b93) with the files that are related, _output.yaml, preamble.tex, and index.Rmd. This is the command I run to generate the PDF: Rscript -e 'bookdown::render_book("chapters/index.rmd", "bookdown::pdf_book")'. To double check, I deleted the old PDF, ran the script, opened the new PDF and it is still using a serif font. – pjlamb12 Nov 24 '20 at 03:39
  • I just ran this with the settings shown in your gist in macOS shell. Works like a charm. I suggest you provide a fully reproducible minimal example. – Martin C. Arnold Nov 24 '20 at 09:38

1 Answers1

0

I had this same problem,

mainfont: Arial

in the index.Rmd YAML ended up working:)

Karen Y.
  • 1
  • 1