[Tex/LaTex] Pandoc Markdown to PDF doesn’t show images


I used knitR to convert R Markdown files to Markdown, and I'm trying to use Pandoc to convert them into HTML/PDF.

Markdown to HTML includes all my images in the output, using

pandoc test.md -o test.html

However, Markdown to PDF doesn't include any of my images in the output, using

pandoc test.md -o test.pdf

(there are other options because I am doing syntax highlighting that will show up in printed output, but no combination of them seem to include images in the PDF output).

In the actual Markdown file, images are referenced as:

<img src="images/image_to_include.png" title="Default title" alt="alt text" style="display: block; margin: auto;" />

where image_to_include.png is in the images subdirectory. The alternate text is not displaying either.

I would like to know how to get images to appear in the PDF output of Pandoc, but I am also curious to know why HTML seems to allow it and PDF doesn't.

My OS is Yosemite and I have installed MacTeX.

Best Answer

Pandoc includes raw HTML only if the output format is HTML-like. From the web-site:

The raw HTML is passed through unchanged in HTML, S5, Slidy, Slideous, DZSlides, EPUB, Markdown, and Textile output, and suppressed in other formats.

In order to get images to work for both, HTML and PDF writer, you have to use pandoc's own format:

 ![la lune](lalune.jpg "Voyage to the moon")