Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select best image format using pandoc

Pandoc can easily render the same source file to html or LaTeX and then pdf. In many cases, I'd like to use different versions of the same image file depending on which backend is being used: When the original "image" is a vector figure, possibly containing text (e.g. PostScript, PDF, maybe SVG), I'd like to use that version to generate LaTeX and PDF, so there's not loss of quality. But browsers don't generally render those well, so I'd like to generate and use a raster (e.g. PNG) image when generating HTML.

Is there any way to do this in Pandoc? What I was hoping would "just work" was something like the \includegraphics{} LaTeX macro where, if you provide the filename with no extension, it identifies all the image files matching that stem and applies some heuristic to pick the best option.

like image 596
Eric Anderson Avatar asked Dec 12 '17 21:12

Eric Anderson


People also ask

What is pandoc used for?

Pandoc is a tool that runs from the command window or Linux shell to convert a markdown file to another file format. For this workflow, with the use of an appropriate CSS is available to help convert HTML, PDF, DOCX, and EPUB. You can also use your own or discovered CSS as well.

What are pandoc files?

Description. 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.

Can pandoc convert from PDF?

You can't. You can try opening the PDF in Word or Google Docs and saving in a format from which pandoc can convert directly.

Where are pandoc templates?

The default LaTeX template of Pandoc can be found at https://github.com/jgm/pandoc/tree/master/data/templates (named default. latex ).


1 Answers

You could call pandoc with --default-image-extension=png when generating html, and --default-image-extension=pdf (or whichever other extension you use) when generating the pdf. See

https://pandoc.org/MANUAL.html#reader-options

like image 145
Matthias C. M. Troffaes Avatar answered Oct 14 '22 22:10

Matthias C. M. Troffaes