-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Automatically convert SVG to PDF images in the latex builder #2859
Conversation
* replace .svg images by .* in order that `make latexpdf` not to fail. * while [sphinx-doc #2859](sphinx-doc/sphinx#2859 is merged, add rule in Makefile to generate pdfs from svgs. * `make latexpdf` will still fail if inkscape is not installed. The alternative will be to do not include the rule "images" in "latexpdf" and include the pdfs in git.
"This branch has conflicts that must be resolved" - otherwise what's the status on this? |
Sorry for late response. I feel this is very nice PR, but it would be nice if other builders also support SVG format. Note: It would be great if we can support other tools for image conversion. |
the HTML builder already supports SVG. i suspect it may work with ePUB, depending on the reader, but I haven't tested that directly. while it would be great to have more generic support for arbitrary file formats, this can quickly get into a very complicated project: witness imagemagick and how many security vulnerability it has. i would personally keep only to a few formats (PNG, JPG, SVG) and convert SVGs as necessary. an alternative would be simply to refuse SVG files and explicitely require those to be converted by the user, since, in the end, that is what we effectively do for them... also note that certain tools use librsvg's rsvg-convert to convert files. it may be better than Inkscape, because there are less dependencies... in any case, conflicts need to be resolved here first. @alyjak are you still working on this PR? thanks all! |
We already have many builders. And some builders also does not support SVG images. For example devhelp, texinfo and other builders. Also 3rd party builders might not support them. Anyway, we still have 4-6 months duration until next major release; Sphinx-1.6. So I would not merge this for a while even if resolved. |
Sorry for the late response, i'll submit the updated PR later tonight |
memo: for mac os x, a note could be added that users should install a compiled binary, because the bundled (from http://www.inkscape.org) Mac OS X application working under XQuartz requires full path filenames when executed from the command line for input and output https://bugs.launchpad.net/inkscape/+bug/1449251 edit: perhaps this changes with 0.92 release and its macports install (not tested) |
* replace .svg images by .* in order that `make latexpdf` not to fail. * while [sphinx-doc #2859](sphinx-doc/sphinx#2859 is merged, add rule in Makefile to generate pdfs from svgs. * `make latexpdf` will still fail if inkscape is not installed. The alternative will be to do not include the rule "images" in "latexpdf" and include the pdfs in git.
* replace .svg images by .* in order that `make latexpdf` not to fail. * while [sphinx-doc #2859](sphinx-doc/sphinx#2859 is merged, add rule in Makefile to generate pdfs from svgs. * `make latexpdf` will still fail if inkscape is not installed. The alternative will be to do not include the rule "images" in "latexpdf" and include the pdfs in git.
sphinx/builders/latex.py
Outdated
except OSError: | ||
pass | ||
if not self.svg_support: | ||
self.info("Latex builder initialized without svg support. You can" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would print this line only if the project actually contains SVG images (i.e. move it below).
Also, please capitalize “LaTeX” and “SVG” properly.
… use in latexpdf builds
@mitya57, thanks for the feedback, I have updated the warning to capitalize LaTeX and SVG correctly, and I have moved the warning to only display if inkscape is not present and there are SVG images in the build |
Thank you. In our project we would like to use some SVG images too, so I fully support the idea of this PR. |
I just proposed a new extension; |
Now I merged #3653 instead. |
@tk0miya Sorry, but imagemagick is not a replacement for inkscape. Imagemagick rasterizes the SVG image, so the text layers are lost, and the resulting image is not scalable. The correct way to use SVG images with LaTeX is converting them to PDF with Inkscape or other program that understands vector graphics. |
I know, inkscape is a better choice. But there are many image converter tools. To use them, #3653 provides a way to enhance image converter. So you are able to make a converter using inkscape. |
OK, that is better. But it would be still nice if SVG to PDF using inkscape was available out of the box. |
Absolutely, but we don't have enough time to maintain all of extensions as you know. So our basic strategy is make sphinx extensible and slim. |
* replace .svg images by .* in order that `make latexpdf` not to fail. * while [sphinx-doc #2859](sphinx-doc/sphinx#2859 is merged, add rule in Makefile to generate pdfs from svgs. * `make latexpdf` will still fail if inkscape is not installed. The alternative will be to do not include the rule "images" in "latexpdf" and include the pdfs in git.
Found this thread, made this to convert my SVG images to PDF using https://gist.github.com/Balletie/a3ccf434f8ec492e47fff4589225d5cb Just put it somewhere in Edit: added inkscape one too |
This adds the ability to automatically convert svg images to pdfs using Inkscape when using the latex builder. This gets around the fact that latexpdf cannot natively handle svg images.
This change should be non invasive -- no new dependencies are required. Only if Inkscape is already installed will the code spawn a subprocess to call it to convert svgs into pdfs. If Inkscape is not available, the existing code should be unaffected besides an extra console print that lets users know that if they install Inkscape they will get this new feature.
Notes:
test_images()
works the same as it did. If it is installed,test_images()
expects to seesvgimg.svg: svgimg_svg2pdf.pdf
in its image map.CHANGES
, I also wasn't sure which section should be updated anyways.