Use a custom font with Asciidoctor-PDF

I wanted to show to myself that it works, and it does. Here’s how: Set the font in a theme file (this one’s called nik-theme.yml):

font:
  catalog:
    merge: false
    Garamond:
      normal: EBGaramond12-Regular.ttf
      italic: EBGaramond12-Italic.ttf
      bold: EBGaramond12-Bold.ttf
      bold_italic: EBGaramond12-Bold.ttf

base:
  font-family: Garamond

Note that we say base here to set the font for the whole document. You can also say something like heading to set a font for headings. But we don’t.

Also note that I use the bold font for bold_italic. I didn’t find a bold, italic font file for Garamond.

The fonts have been copied over to a local dir called fonts. Alternatively, you can also point to the font dir on your machine, which may be something like

/usr/share/fonts/truetype/ebgaramond

Not sure if you always wanna save the fonts locally, but it makes you independent of the machine setup where paths may change or fonts may even be missing.

Now compile:

asciidoctor-pdf --theme nik-theme.yml  -a pdf-fontsdir=./fonts pilze.asciidoc

And here’s the result:

asciidoctor pdf garamond

The spacing is not really good, but we can clearly see that the document is done in the oldstylish Garamond font.

Also, the headings, Maipilze and Morcheln right under the first image and Peziza before the last paragraph, have the same font size as the paragraphs because we use twelve point Garamond for everything.

links

social