diff --git a/sphinxcontrib/plantuml.py b/sphinxcontrib/plantuml.py index f82bfb0..347b1d3 100644 --- a/sphinxcontrib/plantuml.py +++ b/sphinxcontrib/plantuml.py @@ -632,7 +632,7 @@ def _lookup_latex_format(fmt): ) -def _latex_adjustbox_options(self, node): +def _latex_adjustbox_options(self, node): # noqa: C901 adjustbox_options = [] if 'width' in node: if 'scale' in node: @@ -651,6 +651,13 @@ def _latex_adjustbox_options(self, node): if 'scale' in node: if not adjustbox_options: adjustbox_options.append('scale=%s' % (float(node['scale']) / 100.0)) + if 'max-width' in node: + if 'scale' in node: + w = self.latex_image_length(node['max-width'], node['scale']) + else: + w = self.latex_image_length(node['max-width']) + if w: + adjustbox_options.append('max width=%s' % w) return adjustbox_options diff --git a/tests/test_functional.py b/tests/test_functional.py index 77cce9b..697b01d 100644 --- a/tests/test_functional.py +++ b/tests/test_functional.py @@ -309,6 +309,19 @@ def test_buildlatex_simple_height_with_tikz(): readfile('plantuml_fixture.tex')) +@with_runsphinx('latex', plantuml_latex_output_format='tikz') +def test_buildlatex_simple_max_width_with_tikz(): + """Generate simple LaTeX with TikZ + + .. uml:: + :max-width: 50mm + + Hello + """ + assert re.search(br'\\adjustbox\{max width=50mm\}\{\\input\{+plantuml-', + readfile('plantuml_fixture.tex')) + + @with_runsphinx('latex', plantuml_latex_output_format='pdf') def test_buildlatex_simple_with_pdf(): """Generate simple LaTeX with PDF