Giter Club home page Giter Club logo

sphinxcontrib-svg2pdfconverter's Introduction

Sphinx SVG to PDF Converter Extension

This extension converts SVG images to PDF in case the builder does not support SVG images natively (e.g. LaTeX).

Internally, either Inkscape, rsvg-convert from libRSVG or CairoSVG as progressively more lightweight alternatives are used to convert images.

Installation

Just install via pip:

$ pip install sphinxcontrib-svg2pdfconverter

You can choose between Inkscape, libRSVG and CairoSVG by adding sphinxcontrib.inkscapeconverter, sphinxcontrib.rsvgconverter or sphinxcontrib.cairosvgconverter to the extensions list in your conf.py.

Make sure to have either inkscape or the rsvg-convert command available in your systems PATH and, if necessary, adapt the inkscape_converter_bin or rsvg_converter_bin config value respectively.

CairoSVG requires additional dependencies to be installed with:

$ pip install sphinxcontrib-svg2pdfconverter[CairoSVG]

CairoSVG and its dependencies may require additional tools during the installation depending on the OS you are using; see the CairoSVG documentation for further details.

Configuration

Inkscape

inkscape_converter_bin
Path to Inkscape binary. By default, this is inkscape.
inkscape_converter_args
Additional command-line arguments for Inkscape, as a list. By default, this is ['--export-area-drawing'].

RSVG

rsvg_converter_bin
Path to RSVG converter binary. By default, this is rsvg-convert.
rsvg_converter_format
The value provided to the RSVG converter's --format argument. In more recent RSVG builds, the pdf1.5 format will generate the fewest warnings with LaTeX backends. By default, this is pdf.
rsvg_converter_args
Additional command-line arguments for the RSVG converter, as a list. By default, this is the empty list [].

CairoSVG

No configuration is required.

sphinxcontrib-svg2pdfconverter's People

Contributors

bollwyvl avatar gatherer avatar kianmeng avatar kohtala avatar locutusofborg avatar lukeprince20 avatar qulogic avatar sephalon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

sphinxcontrib-svg2pdfconverter's Issues

ENOENT missing in Sphinx 4.0 (= master branch)

When using the Sphinx master branch (which will eventually become Sphinx 4.0), I get this error:

Extension error:
Could not import extension sphinxcontrib.rsvgconverter (exception: cannot import name 'ENOENT' from 'sphinx.util.osutil'

This constant was marked for removal in in sphinx-doc/sphinx#5797 and removed in sphinx-doc/sphinx#7416.

According to https://www.sphinx-doc.org/en/master/extdev/deprecated.html, the replacement is errno.ENOENT or FileNotFoundError.

Same problem with EPIPE and EINVAL.

After pip install --upgrade your package, I still have the old behavior (--export-pdf)

I use Inkscape 1.0. I saw in your code that you have updated the export functionality by testing the Inkscape version number if it begins with 1.

However, after updating (pip install --upgrade sphinxcontrib-svg2pdfconverter), I see in inkscapeconverter.py that it is still the old functionality (no test for Inkscape version), but pip reports the 1.0.1 version of your package. Sphinx still gives an error: unknown option --export-pdf.

I am doing something wrong?

updated call procedure lead to build fail multi document configuration

During tests with Sphinx 5.x it show that the sub class calling procedure changed. Due to this the Inkscape version check will fail on a multi project configuration.

latex documents setup

latex_documents = [
    ('index_1' , 'titile_1, project_1, author_1, 'manual'),
    ('index_2 , 'titile_2, project_2, author_2, 'manual'),
]

While the configuration works if only one document is active

latex_documents = [
#    ('index_1' , 'titile_1, project_1, author_1, 'manual'),
    ('index_2 , 'titile_2, project_2, author_2, 'manual'),
]

or

latex_documents = [
    ('index_1' , 'titile_1, project_1, author_1, 'manual'),
#    ('index_2 , 'titile_2, project_2, author_2, 'manual'),
]

building both at the same time do fail with the following error.

Traceback (most recent call last):
.....
in apply_transforms
    transform.apply(**kwargs)
  File ".../documentation/venv/lib/python3.8/site-packages/sphinx/transforms/post_transforms/images.py", line 27, in apply
    self.handle(node)
  File ".../documentation/venv/lib/python3.8/site-packages/sphinx/transforms/post_transforms/images.py", line 244, in handle
    if self.convert(abs_srcpath, destpath):
  File "..../documentation/venv/lib/python3.8/site-packages/sphinxcontrib/inkscapeconverter.py", line 68, in convert
    if self._inkscape_version.startswith('1.'):
AttributeError: 'InkscapeConverter' object has no attribute '_inkscape_version'

It is always the second build which do fail.

After digging in deeper I found a changed call procedure.
In 2.x the calling procedure is as follow

"""first document"""
is_available()
convert()
convert()
convert()

"""second document"""
is_available()
convert()
convert()
convert()

In 5.x the is_available function is called only once which leads to the failed version check on the second document.

"""first document"""
is_available()
convert()
convert()
convert()

"""second document"""
convert()
convert()
convert()

Because Inkscape 0.x is still widely used bot version need to be supported.

build failure with python 3.10 prerelease

Build failure with python-3.10a4 was reported for Fedora:


Traceback (most recent call last):
  File "/builddir/build/BUILD/sphinxcontrib-svg2pdfconverter-1.1.1/setup.py", line 14, in <module>
    setup(
  File "/usr/lib/python3.10/site-packages/setuptools/__init__.py", line 153, in setup
    return distutils.core.setup(**attrs)
  File "/usr/lib64/python3.10/distutils/core.py", line 148, in setup
    dist.run_commands()
  File "/usr/lib64/python3.10/distutils/dist.py", line 966, in run_commands
    self.run_command(cmd)
  File "/usr/lib64/python3.10/distutils/dist.py", line 985, in run_command
    cmd_obj.run()
  File "/usr/lib/python3.10/site-packages/setuptools/command/test.py", line 232, in run
    self.run_tests()
  File "/usr/lib/python3.10/site-packages/setuptools/command/test.py", line 250, in run_tests
    test = unittest.main(
  File "/usr/lib64/python3.10/unittest/main.py", line 100, in __init__
    self.parseArgs(argv)
  File "/usr/lib64/python3.10/unittest/main.py", line 124, in parseArgs
    self._do_discovery(argv[2:])
  File "/usr/lib64/python3.10/unittest/main.py", line 244, in _do_discovery
    self.createTests(from_discovery=True, Loader=Loader)
  File "/usr/lib64/python3.10/unittest/main.py", line 154, in createTests
    self.test = loader.discover(self.start, self.pattern, self.top)
  File "/usr/lib64/python3.10/unittest/loader.py", line 349, in discover
    tests = list(self._find_tests(start_dir, pattern))
  File "/usr/lib64/python3.10/unittest/loader.py", line 405, in _find_tests
    tests, should_recurse = self._find_test_path(
  File "/usr/lib64/python3.10/unittest/loader.py", line 483, in _find_test_path
    tests = self.loadTestsFromModule(package, pattern=pattern)
  File "/usr/lib/python3.10/site-packages/setuptools/command/test.py", line 42, in loadTestsFromModule
    for file in resource_listdir(module.__name__, ''):
  File "/usr/lib/python3.10/site-packages/pkg_resources/__init__.py", line 1147, in resource_listdir
    return get_provider(package_or_requirement).resource_listdir(
  File "/usr/lib/python3.10/site-packages/pkg_resources/__init__.py", line 349, in get_provider
    return _find_adapter(_provider_factories, loader)(module)
  File "/usr/lib/python3.10/site-packages/pkg_resources/__init__.py", line 1378, in __init__
    self.module_path = os.path.dirname(getattr(module, '__file__', ''))
  File "/usr/lib64/python3.10/posixpath.py", line 152, in dirname
    p = os.fspath(p)
TypeError: expected str, bytes or os.PathLike object, not NoneType

https://bugzilla.redhat.com/show_bug.cgi?id=1914879

Extension does not work with Inkscape 1.0beta2 on macOS

> inkscape --version
Inkscape 1.0beta2 (ab38949, 2019-12-24)
    Pango version: 1.43.0
> make latexpdf
Running Sphinx v2.3.1
building [mo]: targets for 0 po files that are out of date
building [latex]: all documents
updating environment: [new config] 7 added, 0 changed, 0 removed
reading sources... [100%] script_objects
looking for now-outdated files... none found
pickling environment... done
checking consistency... done
processing nsi.tex... index background interface nodes script_objects guidelines acknowledgments
resolving references...
    Pango version: 1.43.0
Unknown option --export-pdf=/Users/moritz/code/nsi-docs/docs/_build/doctrees/images/nsi_logo.pdf
failed

Extension error:
Inkscape exited with error:
[stderr]
None
[stdout]
b''
make: *** [latexpdf] Error 1

On MacOS, even ``make clean html`` seems to invoke inkscape

I have Inkscape installed 0.92.2 installed on my Mac as a Mac application.

The extension ๐Ÿ‘ works fine with PATH extended to contain /Applications/Inkscape.app/Contents/Resources/bin.

When using make clean html on a simple project with

extensions = [
    'sphinxcontrib.inkscapeconverter',
]

there seems to be some Inkscape related activity because an XQuartz session is launched, which induces a small delay. But, the HTML ouput will use foo.svg as is, so I am wondering if this sllght delay could be avoided. This is minor because once XQuartz got launched and remains open, no noticeable delay seems to arise from subsequent make clean html.

Support for --export-latex

I usually use the --export-latex feature:

inkscape -D -z --file=image.svg --export-pdf=image.pdf --export-latex

But in this case I need to include my figure as follow:

\def\svgwidth{\columnwidth}
\input{image.pdf_tex}

Is this possible?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.