2

I use Pandoc to generate PDF file from MD file with XeLaTeX engine.

# in documentation directory
pandoc file.md --pdf-engine=xelatex -o file.pdf

I've a problem with font-family relative in YML part in markdown file.Here you can see files herarchy:

+-- documentation
|   +-- file.md
|   +-- OpenSans-Regular.ttf
+-- fonts
|   +-- FiraCode-Regular.ttf
|   +-- OpenSans-Bold.ttf
|   +-- OpenSans-BoldItalic.ttf
|   +-- OpenSans-Italic.ttf
|   +-- OpenSans-Regular.ttf
|   +-- Quicksand-Regular.ttf

In documentation/file.md

---
# ...
mainfont: OpenSans-Regular.ttf
mainfontoptions: 
- Scale=1.1
- BoldFont=../fonts/OpenSans-Bold.ttf
- ItalicFont=../fonts/OpenSans-Italic.ttf
- BoldItalicFont=../fonts/OpenSans-BoldItalic.ttf
sansfont: "../fonts/Quicksand-Regular.ttf"
monofont: "../fonts/FiraCode-Regular.ttf"
---

# My document

Content of my document

With this configuration everything works. But if I want to set mainfont with relative path like this:

---
# ...
mainfont: "../fonts/OpenSans-Regular.ttf"
# ...

Now, it's not work while sansfont (for example) works with relative path sansfont: "../fonts/Quicksand-Regular.ttf". I've this error:

Error producing PDF.
! Missing number, treated as zero.
<to be read again>
                   m
l.19     \setsansfont

So I need to place mainfont at the root of markdown file when I want to generate PDF file.

Do you know how to use relative path with mainfont like other fonts?

2
  • Welcome to TeX-SX! As a new member, it is recommended to visit the Welcome and the Tour pages to be informed about our format and also to know about Minimal Example.
    – R. N
    Commented Jan 27, 2021 at 14:12
  • Oh thanks, I will check this!
    – Ewilan R.
    Commented Jan 27, 2021 at 14:24

1 Answer 1

4

You can specify the path in mainfontoptions:

---
mainfont: OpenSans-Regular.ttf
mainfontoptions:
- Path=../fonts/
- Scale=1.1
- BoldFont=OpenSans-Bold.ttf
- ItalicFont=OpenSans-Italic.ttf
- BoldItalicFont=OpenSans-BoldItalic.ttf
---

# My document

Content of my document

enter image description here

Pandoc passes the options directly through to fontspec, so you might want to check the manual: http://mirrors.ctan.org/macros/unicodetex/latex/fontspec/fontspec.pdf

3
  • Thanks, it's exactly what I wanted!
    – Ewilan R.
    Commented Jan 27, 2021 at 18:18
  • Of course, thanks again for your pedagogy I didn't know how to accept an answer ^-^''
    – Ewilan R.
    Commented Jan 28, 2021 at 7:45
  • 1
    Thank you so much! This is exaclty what I was looking for. I figured out that you can also use this to configure your monospace font like this: mainfont: SourceSansPro-Regular.ttf mainfontoptions: - Path=./fonts/ - BoldFont=SourceSansPro-Bold.ttf - ItalicFont=SourceSansPro-It.ttf - BoldItalicFont=SourceSansPro-BoldIt.ttf monofont: IBMPlexMono-Regular.ttf monofontoptions: - Path=./fonts/ - BoldFont=IBMPlexMono-Bold.ttf
    – cor
    Commented Nov 15, 2022 at 15:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .