From ad9fe7205e2f331f67048b96fc98299b44ac5c86 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Thu, 9 Dec 2021 04:40:17 -0500 Subject: [PATCH] Drop retina images when building PDF docs This doubles the size of the PDF, and makes it impossible to upload to GitHub Pages. --- doc/conf.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/doc/conf.py b/doc/conf.py index 3311e73b046c..b08fb93b82b8 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,