6

I was trying for two hours to simply change the font family to a Sans Serif font, but whatever I try it will always end up with serifs...

My setup is a Mac with Pandoc installed. I want to use markdown files to create PDFs. Within the file I setup a YAML block with my desired options. However I can not find a font installed which is Sans Serif.

I use this:

---
title: bla
fontfamily: merriweather
--- 

However this never works out, I get merriweather with serif font. If I try to set 'merriweathersans' it will throw the error message: "merriweathersans.sty" not installed. However with sudo tlmgr install merriweathersans I can not find this package to install anyway.

And all other Sans Serif packages I try always end in total disaster (like fontfamily: arev; this will end in a 'LaTeX Error: This NFSS system isn't set up properly.'

4
  • Welcome to TeX.SX! I'm not sure this question, in the current form, is on topic.
    – egreg
    Commented Feb 27, 2018 at 13:19
  • It is a bit unclear what your input is exactly, maybe tex.stackexchange.com/questions/234786/… is related?
    – Marijn
    Commented Feb 27, 2018 at 13:25
  • My setup is a simple xy.md file which I open in a texteditor (sublime text) and use Pandoc to convert this file into a PDF. On the way to the PDF Pandoc will integrate LaTeX to create the PDF. However I have nearly 0 knowledge on LaTeX. However as I understand the font packages must be available for LaTeX (installed with tlmgr install <package> within console). So I think this is related to TeX? I struggle to define a fontfamily that is installed and is Sans Serif. Lets take "merriweather" as an example: why do I get the "merriweathersans.sty" package not installed error message? Commented Feb 27, 2018 at 13:44
  • @michaelsinner So you have installed texlive 2017, yes? Because merriweather is rather new.
    – Keks Dose
    Commented Feb 27, 2018 at 15:22

1 Answer 1

10

You need to specify fontfamilyoptions: sfdefault in your YAML header.

If you were using LaTeX directly, you would have to write this line:

\usepackage[sfdefault]{merriweather}

The part in square brackets is the package option, which you have to specify to get sans-serif text as the default. This is the case for most sans-serif font packages (look on the LaTeX Font Catalogue).

---
title: bla
fontfamily: merriweather  
fontfamilyoptions: sfdefault
...

# Test

Hello, world!

enter image description here

Note that the package options are not the same for every package. You can look on the Font Catalogue linked above or you can read the package documentation using the command texdoc merriweather in the terminal (for example).

Alternative: Use system fonts with xelatex

The above answer assumes you (or your editor) use pdflatex to compile to PDF. Then you have to select one of LaTeX's font packages with the proper options.

If you can use xelatex to compile, then you can use any font installed on your system (including True-Type and Open-Type fonts that come with a TeXLive installation), without worrying about packages. Then in your YAML header you can just write this:

---
mainfont: Source Sans Pro
...

To convert the document, now you must specify the non-default engine on the command line. You can probably set this in your editor's configuration somewhere.

pandoc --latex-engine xelatex file.md -o file.pdf 

If you were using xelatex directly (as Pandoc is now doing behind the scenes), you would include these commands:

\usepackage{fontspec}
\setmainfont{Source Sans Pro}

See Pandoc's documentation (man pandoc) for more information.

2
  • Thanks god - finally!! The "fontfamilyoptions: sfdefault" was exactly what I was looking for. I googled my ass off searching for possible "fontfamilyoptions" values, but I just couldn't find anything. Beeing really new to LaTeX I dont know the lingo so it is difficult to find the keywords to find what one is looking for... On the other side I have to say LaTeX seems to be invented genuinely hardcore nerdy... so you have learn basics first, which are a masters degree level entry. Commented Feb 27, 2018 at 15:58
  • I was trying to use some of the default latex fonts with Pandoc, and only Bookman worked without error. I found a solution which involves setting up some MikTex stuff, but using xetex (which I hadn't heard of before) is much simpler for my use case...I agree with michaelsinner that it's way easier if you just want to use your system fonts
    – drojf
    Commented Nov 12, 2018 at 2:58

You must log in to answer this question.

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