title | author |
---|---|
Pref Image Extension - Pandoc lua filter to use "best" image file available |
Christophe Agathon |
Choose the "best" image extension depending on image files which are available and on the output format
v1.0. Copyright: © 2022 Christophe Agathon [email protected] License: MIT - see LICENSE file for details.
As an author I want to produce multiple document format from the same sources using the more appropriate image file available in order to get the "best" result (image quality, document weight, ...).
Simply use normal image insertion synthax that Pandoc can process. You can omit the file extension
![Image 2](media/image2)
Copy pref-image-extension.lua
in your document folder or in your
pandoc data directory (details in
Pandoc's manual).
Run it on your document with a --luafilter
option:
pandoc --luafilter pref-image-extension.lua SOURCE.md -o OUTPUT.pdf
or specify it in a defaults file (details in Pandoc's manual).
The "best" image file extension will be used :
- html documents :
- by order of preference : 'svg'; 'jpg'; 'jpeg'; 'png'
- if no files are found with one of these extensions, the image file path is kept unchanged.
- latex and pdf documents :
- by order of preference : 'pdf'; 'png'; 'jpg'; 'jpeg'
- if no files are found with one of these extensions, the image file extension is stripped. We rely on LaTeX to choose one if/when an image file will be available.
This filter is active only for LaTeX, PDF and HTML output. It does nothing with other output document format.
The working directory where the pandoc
command is invoked must
be the main document directory in order to process relative image
file paths.
PRs welcome.