Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't I include images in pdf using Pandoc?

Tags:

pandoc

I can successfully produce the images when output is HTML, but errors out when attempting pdf output.

input file text for image,

  ![](images\icon.png "test")

Error produced,

pandoc: Error producing PDF from TeX source. ! Undefined control sequence. images\icon

l.535 \includegraphics{images\icon.png}

like image 553
zerogiant Avatar asked Jul 25 '13 20:07

zerogiant


People also ask

Can pandoc convert from PDF?

You can use the program pandoc on the SCF Linux and Mac machines (via the terminal window) to convert from formats such as HTML, LaTeX and Markdown to formats such as HTML, LaTeX, Word, OpenOffice, and PDF, among others.

What are pandoc files?

Pandoc is a Haskell library for converting from one markup format to another, and a command-line tool that uses this library. Pandoc can convert between numerous markup and word processing formats, including, but not limited to, various flavors of Markdown, HTML, LaTeX and Word docx.

What is pandoc used for?

Pandoc is a command-line tool for converting files from one markup language to another. Markup languages use tags to annotate sections of a document. Commonly used markup languages include Markdown, ReStructuredText, HTML, LaTex, ePub, and Microsoft Word DOCX.


1 Answers

Note that pandoc produces the PDF via LaTeX, as the error message reveals. Your input

![](images\icon.png "test")

is converted into LaTeX

\includegraphics{images\icon.png}

\ in LaTeX has a special meaning: it begins a control sequence. So LaTeX is looking for an \icon command here and not finding it. The fix is to use a forward slash / instead of a backslash \ as path separator. LaTeX allows you to use / for paths even in Windows.

Of course, this may cause problems in some other output formats. I suppose I should change pandoc to convert backslashes in paths to forward slashes when writing LaTeX.

like image 175
John MacFarlane Avatar answered Sep 30 '22 19:09

John MacFarlane