pandoc icon indicating copy to clipboard operation
pandoc copied to clipboard

Allow specifying Inkspace for svg conversion tool (as well as rsvg-convert)

Open fuhrmanator opened this issue 1 year ago • 5 comments

Describe your proposed improvement and the problem it solves.

Some SVG files (those with certain foreignObject?) get (better) conversion to PDF (or other destinations) with Inkscape rather than rsvg-convert. It would be good to have a way to specify which SVG converter to use.

Describe alternatives you've considered.

I've considered various filters (gists, python, hs), but they seem to be unmaintained by a community. ConTeXt apparently supports inkscape (if it's installed), but for my project I can't use ConTeXt.

fuhrmanator avatar Jul 11 '22 23:07 fuhrmanator

What would be the command for converting on the command line via inkscape?

jgm avatar Jul 12 '22 07:07 jgm

I'm not sure I understand the question, but I could suggest for pandoc:

--svg-converter=CONVERTER

CONVERTER is either rsvg-convert or inkscape

Or are you asking about how to convert with inkscape:

inkscape --export-filename=sample.pdf sample.svg

I believe the extension of the export filename determines the destination format (pdf, png, etc.)

There is documtation here.

fuhrmanator avatar Jul 12 '22 14:07 fuhrmanator

Is inkscape strictly better than rsvg-convert? Or is it better in some cases and worse in others? If it's strictly better, perhaps we could always use inkscape if available and fall back on rsvg-convert. Then we wouldn't need a new option.

jgm avatar Jul 12 '22 17:07 jgm

Is inkscape strictly better than rsvg-convert? Or is it better in some cases and worse in others?

I think it's the latter. I know that Inkscape has been involved in SVG as a standard for a while, e.g., https://inkscape.org/support-us/svg-standards-work/

Inkscape as a creation tool is very powerful and the things you can create with it are converted well to PDF (maintaining vectors -- there are examples I know of, especially with paths, that rsvg-convert rasterizes in the PDF).

But, the tool itself is likely much bigger (it's a pretty big install on windows, 0.5 G for example). image

I suspect the performance of both will also be different. Given a large batch of SVG files, rsvg-convert might be faster overall.

If it's strictly better, perhaps we could always use inkscape if available and fall back on rsvg-convert.

I like that idea, but I'm biased in wanting to use Inkscape. It's easy enough to remove inkscape from one's path to avoid pandoc from using it, I suppose.

fuhrmanator avatar Jul 12 '22 18:07 fuhrmanator

For the necessary commands see the respective function in the diagram-generator.lua filter. As can be seen there, the whole process is made more complex by having to check for the installed inkscape version, as the parameter names are not the same in v1 and v2.

tarleb avatar Jul 12 '22 23:07 tarleb

If you arrived here because of some SVG produce by mermaid, you can get rid of the foreignObjects by adding %%{init: {"flowchart": { "htmlLabels": false}} }%% before the flowchart or graph line to solve the problem

matclab avatar Dec 21 '23 14:12 matclab

Regarding the original suggestion, inkscape continues to be problematic for scripted CLI usage. An unpredictable set of actions and/or input/output formats trigger the GUI to start and close even when running CLI actions, the options regarding bounding boxes (page, bleed, crop boxes, etc.) are not tested from the CLI before releases and regularly break, etc. I would suggest it is not well suited to baking into pandoc. Perhas allowing a custom converter command to be specified at runtime would serve the purpose for specific scenarios, but it is a relatively unstable target to try to bake in support for (speaking as someone who maintains baked in support for scripted use in casile).

alerque avatar Dec 21 '23 19:12 alerque