Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Backport PR #14683: For non-html output, let sphinx pick the best format #15190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 3 additions & 22 deletions lib/matplotlib/sphinxext/plot_directive.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ def remove_coding(text):
TEMPLATE = """
{{ source_code }}

{{ only_html }}
.. only:: html

{% if source_link or (html_show_formats and not multi_image) %}
(
Expand Down Expand Up @@ -403,27 +403,15 @@ def remove_coding(text):
{{ caption }}
{% endfor %}

{{ only_latex }}
.. only:: not html

{% for img in images %}
{% if 'pdf' in img.formats -%}
.. figure:: {{ build_dir }}/{{ img.basename }}.pdf
.. figure:: {{ build_dir }}/{{ img.basename }}.*
{% for option in options -%}
{{ option }}
{% endfor %}

{{ caption }}
{% endif -%}
{% endfor %}

{{ only_texinfo }}

{% for img in images %}
.. image:: {{ build_dir }}/{{ img.basename }}.png
{% for option in options -%}
{{ option }}
{% endfor %}

{% endfor %}

"""
Expand Down Expand Up @@ -794,10 +782,6 @@ def run(arguments, content, options, state_machine, state, lineno):
':%s: %s' % (key, val) for key, val in options.items()
if key in ('alt', 'height', 'width', 'scale', 'align', 'class')]

only_html = ".. only:: html"
only_latex = ".. only:: latex"
only_texinfo = ".. only:: texinfo"

# Not-None src_link signals the need for a source link in the generated
# html
if j == 0 and config.plot_html_show_source_link:
Expand All @@ -811,9 +795,6 @@ def run(arguments, content, options, state_machine, state, lineno):
build_dir=build_dir_link,
source_link=src_link,
multi_image=len(images) > 1,
only_html=only_html,
only_latex=only_latex,
only_texinfo=only_texinfo,
options=opts,
images=images,
source_code=source_code,
Expand Down