Skip to content

Commit d3ebab0

Browse files
committed
Fix #1907: Support svg image format in LaTeX output.
1 parent 8b47cc5 commit d3ebab0

File tree

6 files changed

+13
-8
lines changed

6 files changed

+13
-8
lines changed

sphinx/texinputs/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ALLDVI = $(addsuffix .dvi,$(ALLDOCS))
77
# Prefix for archive names
88
ARCHIVEPRREFIX =
99
# Additional LaTeX options
10-
LATEXOPTS =
10+
LATEXOPTS = --shell-escape
1111

1212
LATEX = latex
1313
PDFLATEX = pdflatex

sphinx/writers/latex.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
%(longtable)s
4343
\usepackage{sphinx}
4444
\usepackage{multirow}
45+
%(svg)s
4546
%(usepackages)s
4647
%(contentsname)s
4748
%(numfig_format)s
@@ -159,6 +160,7 @@ class LaTeXTranslator(nodes.NodeVisitor):
159160
'fontpkg': '\\usepackage{times}',
160161
'fncychap': '\\usepackage[Bjarne]{fncychap}',
161162
'longtable': '\\usepackage{longtable}',
163+
'svg': '\\usepackage{svg}',
162164
'usepackages': '',
163165
'numfig_format': '',
164166
'contentsname': '',
@@ -1182,7 +1184,11 @@ def visit_image(self, node):
11821184
options = ''
11831185
if include_graphics_options:
11841186
options = '[%s]' % ','.join(include_graphics_options)
1185-
self.body.append('\\includegraphics%s{%s}' % (options, uri))
1187+
if node['uri'].lower().endswith('svg') or \
1188+
node['uri'].lower().endswith('svgz'):
1189+
self.body.append('\\includesvg%s{%s}' % (options, path.splitext(uri)[0]))
1190+
else:
1191+
self.body.append('\\includegraphics%s{%s}' % (options, uri))
11861192
self.body.extend(post)
11871193

11881194
def depart_image(self, node):

tests/root/images.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ Sphinx image handling
2525
.. image:: subdir/simg.*
2626

2727
.. an SVG image (for HTML at least)
28-
.. image:: svgimg.*
28+
.. image:: svgimg.svg

tests/test_build_latex.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def kpsetest(filename):
7878
os.chdir(app.outdir)
7979
try:
8080
try:
81-
p = Popen(['pdflatex', '--interaction=nonstopmode',
81+
p = Popen(['pdflatex', '--interaction=nonstopmode', '--shell-escape',
8282
'SphinxTests.tex'], stdout=PIPE, stderr=PIPE)
8383
except OSError:
8484
raise SkipTest # most likely pdflatex was not found
@@ -143,7 +143,7 @@ def kpsetest(filename):
143143
os.chdir(app.outdir)
144144
try:
145145
try:
146-
p = Popen(['pdflatex', '--interaction=nonstopmode',
146+
p = Popen(['pdflatex', '--interaction=nonstopmode', '--shell-escape',
147147
'SphinxTests.tex'], stdout=PIPE, stderr=PIPE)
148148
except OSError:
149149
raise SkipTest # most likely pdflatex was not found

tests/test_build_texinfo.py

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
TEXINFO_WARNINGS = ENV_WARNINGS + """\
2626
None:None: WARNING: citation not found: missing
2727
None:None: WARNING: no matching candidate for image URI u'foo.\\*'
28-
None:None: WARNING: no matching candidate for image URI u'svgimg.\\*'
2928
"""
3029

3130
if PY3:

tests/test_environment.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ def test_images():
7373
assert image_uri_message in app._warning.content[-1]
7474
assert set(latexbuilder.images.keys()) == \
7575
set(['subdir/img.png', 'subdir/simg.png', 'img.png', 'img.pdf',
76-
'svgimg.pdf'])
76+
'svgimg.svg'])
7777
assert set(latexbuilder.images.values()) == \
78-
set(['img.pdf', 'img.png', 'img1.png', 'simg.png', 'svgimg.pdf'])
78+
set(['img.pdf', 'img.png', 'img1.png', 'simg.png', 'svgimg.svg'])
7979

8080

8181
def test_second_update():

0 commit comments

Comments
 (0)