[Tex/LaTex] pandoc: Undefined control sequence … unless I include some “`code“`

markdownpandoc

this markdown document:

---
author: BenoƮt
toc: true
papersize: a4
pagenumbering: true
---

# test

Hello.

\textcolor{green}{green}

makes pandoc --from=markdown foo.md -o foo.pdf fail and output:

Error producing PDF.
! Undefined control sequence.
l.70 \textcolor

However, if I include at the end of the document a simple:

```sh
hello
```

then pandoc is happy.

What's going on here ?

Best Answer

Ok, i think that xcolors is only included when some features are used, like code verbatim.

Adding this in header solves the problem:

header-includes: |
        \usepackage{xcolor}