TransWikia.com

Pandoc xelatex font-family with relative path

TeX - LaTeX Asked by Ewilan R. on May 8, 2021

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?

One Answer

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

Correct answer by DG' on May 8, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP