From 5608428dc856451bc7c1afc0b5fce3dce0f9792f Mon Sep 17 00:00:00 2001 From: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> Date: Thu, 9 Dec 2021 20:29:00 +0100 Subject: [PATCH] Backport PR #21890: Drop retina images when building PDF docs --- doc/conf.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/doc/conf.py b/doc/conf.py index 669957fe3ef4..018255694033 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -167,6 +167,21 @@ def _check_dependencies(): # Sphinx gallery configuration +def matplotlib_reduced_latex_scraper(block, block_vars, gallery_conf, + **kwargs): + """ + Reduce srcset when creating a PDF. + + Because sphinx-gallery runs *very* early, we cannot modify this even in the + earliest builder-inited signal. Thus we do it at scraping time. + """ + from sphinx_gallery.scrapers import matplotlib_scraper + + if gallery_conf['builder_name'] == 'latex': + gallery_conf['image_srcset'] = [] + return matplotlib_scraper(block, block_vars, gallery_conf, **kwargs) + + sphinx_gallery_conf = { 'examples_dirs': ['../examples', '../tutorials', '../plot_types'], 'filename_pattern': '^((?!sgskip).)*$', @@ -183,6 +198,7 @@ def _check_dependencies(): 'remove_config_comments': True, 'min_reported_time': 1, 'thumbnail_size': (320, 224), + 'image_scrapers': (matplotlib_reduced_latex_scraper, ), # Compression is a significant effort that we skip for local and CI builds. 'compress_images': ('thumbnails', 'images') if is_release_build else (), 'matplotlib_animations': True,