Skip to content

Commit

Permalink
Fix sphinx-doc#1907: Support svg image format in LaTeX output.
Browse files Browse the repository at this point in the history
  • Loading branch information
xuhdev committed Dec 11, 2015
1 parent 8b47cc5 commit d3ebab0
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion sphinx/texinputs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ALLDVI = $(addsuffix .dvi,$(ALLDOCS))
# Prefix for archive names
ARCHIVEPRREFIX =
# Additional LaTeX options
LATEXOPTS =
LATEXOPTS = --shell-escape

LATEX = latex
PDFLATEX = pdflatex
Expand Down
8 changes: 7 additions & 1 deletion sphinx/writers/latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
%(longtable)s
\usepackage{sphinx}
\usepackage{multirow}
%(svg)s
%(usepackages)s
%(contentsname)s
%(numfig_format)s
Expand Down Expand Up @@ -159,6 +160,7 @@ class LaTeXTranslator(nodes.NodeVisitor):
'fontpkg': '\\usepackage{times}',
'fncychap': '\\usepackage[Bjarne]{fncychap}',
'longtable': '\\usepackage{longtable}',
'svg': '\\usepackage{svg}',
'usepackages': '',
'numfig_format': '',
'contentsname': '',
Expand Down Expand Up @@ -1182,7 +1184,11 @@ def visit_image(self, node):
options = ''
if include_graphics_options:
options = '[%s]' % ','.join(include_graphics_options)
self.body.append('\\includegraphics%s{%s}' % (options, uri))
if node['uri'].lower().endswith('svg') or \
node['uri'].lower().endswith('svgz'):
self.body.append('\\includesvg%s{%s}' % (options, path.splitext(uri)[0]))
else:
self.body.append('\\includegraphics%s{%s}' % (options, uri))
self.body.extend(post)

def depart_image(self, node):
Expand Down
2 changes: 1 addition & 1 deletion tests/root/images.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ Sphinx image handling
.. image:: subdir/simg.*

.. an SVG image (for HTML at least)
.. image:: svgimg.*
.. image:: svgimg.svg
4 changes: 2 additions & 2 deletions tests/test_build_latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def kpsetest(filename):
os.chdir(app.outdir)
try:
try:
p = Popen(['pdflatex', '--interaction=nonstopmode',
p = Popen(['pdflatex', '--interaction=nonstopmode', '--shell-escape',
'SphinxTests.tex'], stdout=PIPE, stderr=PIPE)
except OSError:
raise SkipTest # most likely pdflatex was not found
Expand Down Expand Up @@ -143,7 +143,7 @@ def kpsetest(filename):
os.chdir(app.outdir)
try:
try:
p = Popen(['pdflatex', '--interaction=nonstopmode',
p = Popen(['pdflatex', '--interaction=nonstopmode', '--shell-escape',
'SphinxTests.tex'], stdout=PIPE, stderr=PIPE)
except OSError:
raise SkipTest # most likely pdflatex was not found
Expand Down
1 change: 0 additions & 1 deletion tests/test_build_texinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
TEXINFO_WARNINGS = ENV_WARNINGS + """\
None:None: WARNING: citation not found: missing
None:None: WARNING: no matching candidate for image URI u'foo.\\*'
None:None: WARNING: no matching candidate for image URI u'svgimg.\\*'
"""

if PY3:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ def test_images():
assert image_uri_message in app._warning.content[-1]
assert set(latexbuilder.images.keys()) == \
set(['subdir/img.png', 'subdir/simg.png', 'img.png', 'img.pdf',
'svgimg.pdf'])
'svgimg.svg'])
assert set(latexbuilder.images.values()) == \
set(['img.pdf', 'img.png', 'img1.png', 'simg.png', 'svgimg.pdf'])
set(['img.pdf', 'img.png', 'img1.png', 'simg.png', 'svgimg.svg'])


def test_second_update():
Expand Down

0 comments on commit d3ebab0

Please sign in to comment.