From 4a913e5cee23986bd87e4879848e12071417fbe6 Mon Sep 17 00:00:00 2001 From: Roman Kapl Date: Sun, 11 Feb 2018 15:32:59 +0100 Subject: [PATCH] Fit graphviz images to page. Use \sphinxincludegraphics, that's what the core image directives use and it handles fitting properly. --- sphinx/ext/graphviz.py | 2 +- tests/test_ext_graphviz.py | 8 ++++---- tests/test_ext_inheritance_diagram.py | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/sphinx/ext/graphviz.py b/sphinx/ext/graphviz.py index 2986bf9c1..08707b733 100644 --- a/sphinx/ext/graphviz.py +++ b/sphinx/ext/graphviz.py @@ -341,7 +341,7 @@ def render_dot_latex(self, node, code, options, prefix='graphviz'): post = r'\hspace*{\fill}}' self.body.append('\n%s' % pre) - self.body.append(r'\includegraphics{%s}' % fname) + self.body.append(r'\sphinxincludegraphics[]{%s}' % fname) if not is_inline: self.body.append('%s\n' % post) diff --git a/tests/test_ext_graphviz.py b/tests/test_ext_graphviz.py index ef77135d7..3efab6b56 100644 --- a/tests/test_ext_graphviz.py +++ b/tests/test_ext_graphviz.py @@ -91,20 +91,20 @@ def test_graphviz_latex(app, status, warning): content = (app.outdir / 'SphinxTests.tex').text() macro = ('\\\\begin{figure}\\[htbp\\]\n\\\\centering\n\\\\capstart\n\n' - '\\\\includegraphics{graphviz-\\w+.pdf}\n' + '\\\\sphinxincludegraphics\\[\\]{graphviz-\\w+.pdf}\n' '\\\\caption{caption of graph}\\\\label{.*}\\\\end{figure}') assert re.search(macro, content, re.S) - macro = 'Hello \\\\includegraphics{graphviz-\\w+.pdf} graphviz world' + macro = 'Hello \\\\sphinxincludegraphics\\[\\]{graphviz-\\w+.pdf} graphviz world' assert re.search(macro, content, re.S) macro = ('\\\\begin{wrapfigure}{r}{0pt}\n\\\\centering\n' - '\\\\includegraphics{graphviz-\\w+.pdf}\n' + '\\\\sphinxincludegraphics\\[\\]{graphviz-\\w+.pdf}\n' '\\\\caption{on right}\\\\label{.*}\\\\end{wrapfigure}') assert re.search(macro, content, re.S) macro = (r'\{\\hfill' - r'\\includegraphics{graphviz-.*}' + r'\\sphinxincludegraphics\[\]{graphviz-.*}' r'\\hspace\*{\\fill}}') assert re.search(macro, content, re.S) diff --git a/tests/test_ext_inheritance_diagram.py b/tests/test_ext_inheritance_diagram.py index ed79729e6..ad106e6c6 100644 --- a/tests/test_ext_inheritance_diagram.py +++ b/tests/test_ext_inheritance_diagram.py @@ -40,7 +40,7 @@ def test_inheritance_diagram_latex(app, status, warning): content = (app.outdir / 'Python.tex').text() pattern = ('\\\\begin{figure}\\[htbp]\n\\\\centering\n\\\\capstart\n\n' - '\\\\includegraphics{inheritance-\\w+.pdf}\n' + '\\\\sphinxincludegraphics\\[\\]{inheritance-\\w+.pdf}\n' '\\\\caption{Test Foo!}\\\\label{\\\\detokenize{index:id1}}\\\\end{figure}') assert re.search(pattern, content, re.M)