I have some reports written in MultiMarkDown and want to convert them to pdf (via xelatex) with pandoc. As I am in an professional environment, a certain font-family is mandatory. The fonts are sitting right in the windows/fonts folder, named font-regular.otf
, font-italic.otf
and so on.
I know about the command line switch -V mainfont:font-regular.otf
and I am able to switch font with it, but that only sets the regular font. I can do the run for a .tex
instead of a .pdf
and edit the file manualy like
\setmainfont[
BoldFont = Font-Bold.otf,
ItalicFont = Font-Italic.otf,
BoldItalicFont = Font-BoldItalic.otf
]{Font-Regular.otf}
But that is cumbersome, since it is additional work for each document to be converted.
Is there a way to:
- easily create a "font-family" that I can pass, or
- pass the fout
.otf
via command line (and therefore via script or batch)
Best Answer
YAML header
command line
Since my answer to the original question, a lot has changed. So here is an update on how to set fonts with pandoc. There are several ways to change the font in
pandoc
and they are quite well documented nowadays. Here is a brief overview:1. Changing fonts for XeLaTeX and LuaLaTeX:
You can specify any font on your system that can be used with
fontspec
In the YAML header of your markdown file, set the variables like this for XeLaTeX:
or, for LuaLaTex:
If you need more fine grained control, you can specify options:
Call pandoc with
--pdf-engine
set toxelatex
orlualatex
:You can also set the fonts on the command line:
or
And again, with options:
Note, that
xelatex
wants the filename, whilelualatex
is content with the fontfamily name.2. Change the template
Some packages like
dejavu-otf
orlibertinus-otf
do the fontspec setup for you, but you have to modify the template in order for them to work.Get the default template and save it to some file:
Open the file and remove all the font configuration code and replace it with, e.g.:
3. Setting the
fontfamily
for pdflatexIf you are using neither
lualatex
norxelatex
butpdflatex
, you can use:or
4. Setting the font for context
or