Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Embedded SVG in PDF #265

Closed
candlerb opened this issue Jun 13, 2011 · 17 comments
Closed

Embedded SVG in PDF #265

candlerb opened this issue Jun 13, 2011 · 17 comments

Comments

@candlerb
Copy link

The syntax:

![whee](foo.svg)

works for generating HTML pages, but not for PDF. LaTeX barfs with Unknown graphics extension: .svg

It would be really useful to support this. SVG is a standard, portable vector image format which is natively editable by tools such as inkscape.

Currently I have a workaround which is to convert the SVG to PDF externally, but this also requires the markdown source to be changed to ![whee](foo.pdf) by piping through sed. At worst, this could perhaps be done as a (pandoc or gitit) plugin.

@adityam
Copy link
Contributor

adityam commented Jun 14, 2011

FWIW, if inkscape is installed, ConTeXt will use it to convert a svg file to pdf on the fly. So, changing the filename extension is not needed in ConTeXt.

But, it general, handling multiple image types is a pain in markdown. One option could be to use TeX like smart extension completion. For example, in LaTeX

\includegraphics{file}

will search for file.ps, file.pdf, file.jpg, file.png depending on the engine. Can we have a similar feature in Pandoc? If an image without an extension is specified, search for .pdf, .png, .jpg, etc and make the appropriate substitution depending on the output format.

@candlerb
Copy link
Author

Yes, I'm told that ConTeXt should be able to handle svg, but I've not been able to get it to work so far. Full details of what I tried are at http://groups.google.com/group/pandoc-discuss/browse_thread/thread/5ec939abcc8e1361

The magic incantation luatools --generate gets me part of the way, and I can see that ConTeXt is in fact invoking inkscape to convert svg to pdf, but then it barfs with a stack overflow error.

So I doubt this is a particularly portable way to make this work.

@adityam
Copy link
Contributor

adityam commented Jun 16, 2011

As I commented on that thread, the error is because TL packages almost a year old version of ConTeXt.

In any case, ConTeXt is simply calling inkscape to convert svg to pdf on the fly. It should be possible to do the same with Pandoc by writing a custom export filter that inspects the image names and if an svg image is found, changes the image name to pdf and runs inkscpae to convert svg to pdf.

@candlerb
Copy link
Author

Thanks for the update. I don't know Haskell and don't have the bandwidth to learn, so writing an export filter isn't an option for me. Using sed + a Makefile gets the job done for standalone use, but unfortunately doesn't work within gitit.

ranft pushed a commit to ranft/pandoc that referenced this issue Jul 15, 2011
@jacobus
Copy link

jacobus commented Oct 29, 2013

Just a nudge to say that including SVG in documents is a sorely missed feature.

@jgm
Copy link
Owner

jgm commented Oct 29, 2013

I think that this issue should be closed. LaTeX doesn't support SVG natively; you need to convert the file with an external tool. It's not something pandoc can do anything about.

Currently I have a workaround which is to convert the SVG to PDF externally, but this also requires the markdown > source to be changed to whee by piping through sed. At worst, this could perhaps be done as a (pandoc > or gitit) plugin.

See the --default-image-extension option, which may allow you to avoid modifying the source.

Note also: It would not be hard to write a filter (in Haskell or python) that converted each .svg image referenced in the source to PDF, and converted the images to link to the PDF version instead of SVG. See
http://johnmacfarlane.net/pandoc/scripting.html
and the examples in https://github.com/jgm/pandocfilters/tree/master/examples.

@jeromerobert
Copy link

Here is the filter I wrote, based on jgm tip : https://gist.github.com/jeromerobert/3996eca3acd12e4c3d40

@jacobus
Copy link

jacobus commented Aug 3, 2014

Thanks Jerome,

Would you mind giving a sample of how your filters should be used (i.e. how
should one set up to use them). I had a quick look at the code, and it
seams that you only support JSON input.

Say for example you are generating PDF from Markdown and using a Latex
template for the generation, would one be able to use your filters?

Thanks again for sharing,
Jacobus

On Sun, Aug 3, 2014 at 2:09 PM, Jerome Robert [email protected]
wrote:

Here is the filter I wrote, based on jgm tip :
https://gist.github.com/jeromerobert/3996eca3acd12e4c3d40


Reply to this email directly or view it on GitHub
#265 (comment).

@mpickering
Copy link
Collaborator

@jacobus - the documentation for using filters can be seen here.

To use this specific filter you will need a command such as

pandoc -o out.pdf -f markdown --template=template.tex --filter=pandoc-svg.py input.md

The filter is then applied after the originally document is parsed and before being converted to latex.

@jacobus
Copy link

jacobus commented Aug 3, 2014

Thank you very much :-)

On Sun, Aug 3, 2014 at 2:40 PM, mpickering [email protected] wrote:

@jacobus https://github.com/jacobus - the documentation for using
filters can be seen here http://johnmacfarlane.net/pandoc/scripting.html
.

To use this specific filter you will need a command such as

pandoc -o out.pdf -f markdown --template=template.tex --filter=pandoc-svg.py input.md

The filter is then applied after the originally document is parsed and
before being converted to latex.


Reply to this email directly or view it on GitHub
#265 (comment).

@ousia
Copy link
Contributor

ousia commented Aug 3, 2014

@jeromerobert and @mpickering, I wonder whether it would be feasible that pandoc could automatically invoke the filter when it detects that an SVG image has to be included in a PDF file using LaTeX.

@hoxnox
Copy link

hoxnox commented Apr 25, 2015

Can anybody write filter, that will use rsvg-convert tool from librsvg package? I have no expirience in filter writing to pandoc...

@jgm
Copy link
Owner

jgm commented Apr 25, 2015

+++ Merder Kim [Apr 25 15 01:58 ]:

Can anybody write filter, that will use rsvg-convert tool from librsvg package? I have no expirience in filter writing to pandoc...

If you post on pandoc-discuss, someone may be able to help
(indeed, if you search that list you may find something relevant.)

nealmcb added a commit to FreeAndFair/ColoradoRLA that referenced this issue Jul 31, 2017
It seems that neither latex nor pandoc support the svg format that our build status indicator come in:
jgm/pandoc#265
And it probably isn't appropriate for static documentation anyway.
So remove the image from 25_developer.md
nealmcb added a commit to FreeAndFair/ColoradoRLA that referenced this issue Jul 31, 2017
It seems that neither latex nor pandoc support the svg format that our build status indicator come in:
jgm/pandoc#265
And it probably isn't appropriate for static documentation anyway.
So remove the image from 25_developer.md
nealmcb added a commit to FreeAndFair/ColoradoRLA that referenced this issue Jul 31, 2017
It seems that neither latex nor pandoc support the svg format that our build status indicator come in:
jgm/pandoc#265
And it probably isn't appropriate for static documentation anyway.
So remove the image from 25_developer.md
@HaoZeke
Copy link

HaoZeke commented Nov 8, 2017

This still seems to be a relevant problem... Particularly for automatic pdf generation from project README files which typically have svg badges...

@jgm
Copy link
Owner

jgm commented Nov 9, 2017 via email

@HaoZeke
Copy link

HaoZeke commented Nov 9, 2017

Ah, I guess in my use case I need to first download the image...

@yuwash
Copy link

yuwash commented May 13, 2018

@hoxnox Thanks for the tip, librsvg is actually a very nice alternative to inkscape for being so much smaller to install. I think, based on @jeromerobert's work you just need to change the line

cmd_line = ['inkscape', option[0], eps_name, src]

to something like

cmd_line = ['rsvg-convert', '--format', option[0], '-o', eps_name, src]

I personally converted it to ps instead of pdf and further used ps2eps to create eps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants