We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Download buttons for all examples are broken for RTD
![Screenshot from 2020-06-11 19-10-01](https://user-images.githubusercontent.com/6849766/84418262-34e6fd00-ac17-11ea-8fdc-7a5cb5f9034d.png)

This is a bug in `sphinx-gallery` and should be fixed with sphinx-gallery/sphinx-gallery#706.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `docs/source/conf.py`
Content:
```
1 # Configuration file for the Sphinx documentation builder.
2 #
3 # This file only contains a selection of the most common options. For a full list see
4 # the documentation:
5 # https://www.sphinx-doc.org/en/master/usage/configuration.html
6 
7 # -- Imports ---------------------------------------------------------------------------
8 
9 import os
10 import re
11 import shutil
12 import warnings
13 from datetime import datetime
14 from distutils.util import strtobool
15 from importlib_metadata import metadata as extract_metadata
16 from os import path
17 from urllib.parse import urljoin
18 
19 from sphinx_gallery.sorting import ExampleTitleSortKey, ExplicitOrder
20 
21 import torch
22 
23 from pystiche.misc import download_file
24 
25 # -- Run config ------------------------------------------------------------------------
26 
27 
28 def get_bool_env_var(name, default=False):
29     try:
30         return bool(strtobool(os.environ[name]))
31     except KeyError:
32         return default
33 
34 
35 run_by_github_actions = get_bool_env_var("GITHUB_ACTIONS")
36 run_by_travis_ci = get_bool_env_var("TRAVIS")
37 run_by_appveyor = get_bool_env_var("APPVEYOR")
38 run_by_rtd = get_bool_env_var("READTHEDOCS")
39 run_by_ci = (
40     run_by_github_actions
41     or run_by_travis_ci
42     or run_by_appveyor
43     or run_by_rtd
44     or get_bool_env_var("CI")
45 )
46 
47 # -- Path setup ------------------------------------------------------------------------
48 
49 # If extensions (or modules to document with autodoc) are in another directory, add
50 # these directories to sys.path here. If the directory is relative to the documentation
51 # root, use os.path.abspath to make it absolute, like shown here.
52 #
53 # import os
54 # import sys
55 # sys.path.insert(0, os.path.abspath('.'))
56 
57 HERE = path.dirname(__file__)
58 PROJECT_ROOT = path.abspath(path.join(HERE, "..", ".."))
59 
60 
61 # -- Project information ---------------------------------------------------------------
62 
63 metadata = extract_metadata("pystiche")
64 
65 project = metadata["name"]
66 author = metadata["author"]
67 copyright = f"{datetime.now().year}, {author}"
68 release = metadata["version"]
69 canonical_version = release.split("+")[0]
70 version = ".".join(canonical_version.split(".")[:3])
71 
72 
73 # -- General configuration -------------------------------------------------------------
74 
75 # Add any Sphinx extension module names here, as strings. They can be extensions coming
76 # with Sphinx (named 'sphinx.ext.*') or your custom ones.
77 extensions = [
78     "sphinx.ext.autodoc",
79     "sphinx.ext.napoleon",
80     "sphinx.ext.coverage",
81     "sphinx.ext.intersphinx",
82     "sphinxcontrib.bibtex",
83     "sphinx_gallery.gen_gallery",
84     "sphinx_autodoc_typehints",
85 ]
86 
87 # Add any paths that contain templates here, relative to this directory.
88 templates_path = ["_templates"]
89 
90 # List of patterns, relative to source directory, that match files and directories to
91 # ignore when looking for source files. This pattern also affects html_static_path and
92 # html_extra_path.
93 exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
94 
95 # -- intersphinx configuration ---------------------------------------------------------
96 
97 intersphinx_mapping = {
98     "python": ("https://docs.python.org/3.6", None),
99     "torch": ("https://pytorch.org/docs/stable/", None),
100     "torchvision": ("https://pytorch.org/docs/stable/", None),
101     "PIL": ("https://pillow.readthedocs.io/en/stable/", None),
102     "numpy": ("https://numpy.org/doc/1.18/", None),
103     "requests": ("https://requests.readthedocs.io/en/stable/", None),
104     "matplotlib": ("https://matplotlib.org", None),
105 }
106 
107 
108 # -- sphinx-gallery configuration ------------------------------------------------------
109 
110 plot_gallery = get_bool_env_var("PYSTICHE_PLOT_GALLERY", default=True) and not run_by_ci
111 download_gallery = get_bool_env_var("PYSTICHE_DOWNLOAD_GALLERY") or run_by_ci
112 
113 if download_gallery:
114     base = "https://download.pystiche.org/galleries/"
115     is_dev = version != release
116     file = "master.zip" if is_dev else f"v{version}.zip"
117 
118     url = urljoin(base, file)
119     print(f"Downloading pre-built galleries from {url}")
120     download_file(url, file)
121 
122     try:
123         shutil.rmtree("galleries")
124     except FileNotFoundError:
125         pass
126     shutil.unpack_archive(file, extract_dir=".")
127     os.remove(file)
128 
129     # This is workaround for a bug in sphinx-gallery that replaces absolute with
130     # relative paths. See https://github.com/pmeier/pystiche/pull/325 for details.
131     index_file = path.join("galleries", "examples", "index.rst")
132     with open(index_file, "r") as fh:
133         content = fh.read()
134     content = re.sub(
135         r"(?P<file>examples_(python|jupyter)\.zip) <[\w/.]+>",
136         r"\g<file> <\g<file>>",
137         content,
138     )
139     with open(index_file, "w") as fh:
140         fh.write(content)
141 
142     extensions.remove("sphinx_gallery.gen_gallery")
143     extensions.append("sphinx_gallery.load_style")
144     plot_gallery = False
145 
146 if plot_gallery and not torch.cuda.is_available():
147     msg = (
148         "The galleries will be built, but CUDA is not available. "
149         "This will take a long time."
150     )
151     print(msg)
152 
153 
154 def show_cuda_memory(func):
155     torch.cuda.reset_peak_memory_stats()
156     out = func()
157 
158     stats = torch.cuda.memory_stats()
159     peak_bytes_usage = stats["allocated_bytes.all.peak"]
160     memory = peak_bytes_usage / 1024 ** 2
161 
162     return memory, out
163 
164 
165 class PysticheExampleTitleSortKey(ExampleTitleSortKey):
166     def __call__(self, filename):
167         # The beginner example *without* pystiche is placed before the example *with*
168         # to clarify the narrative.
169         if filename == "example_nst_without_pystiche.py":
170             return "1"
171         elif filename == "example_nst_with_pystiche.py":
172             return "2"
173         else:
174             return super().__call__(filename)
175 
176 
177 sphinx_gallery_conf = {
178     "examples_dirs": path.join(PROJECT_ROOT, "examples"),
179     "gallery_dirs": path.join("galleries", "examples"),
180     "filename_pattern": os.sep + "example_",
181     "line_numbers": True,
182     "remove_config_comments": True,
183     "plot_gallery": plot_gallery,
184     "subsection_order": ExplicitOrder(
185         [
186             path.join("..", "..", "examples", sub_gallery)
187             for sub_gallery in ("beginner", "advanced")
188         ]
189     ),
190     "within_subsection_order": PysticheExampleTitleSortKey,
191     "show_memory": show_cuda_memory if torch.cuda.is_available() else True,
192 }
193 
194 # Remove matplotlib agg warnings from generated doc when using plt.show
195 warnings.filterwarnings(
196     "ignore",
197     category=UserWarning,
198     message=(
199         "Matplotlib is currently using agg, which is a non-GUI backend, so cannot show "
200         "the figure."
201     ),
202 )
203 
204 
205 # -- Options for HTML output -----------------------------------------------------------
206 
207 # The theme to use for HTML and HTML Help pages.  See the documentation for a list of
208 # builtin themes.
209 html_theme = "sphinx_rtd_theme"
210 
211 # Add any paths that contain custom static files (such as style sheets) here, relative
212 # to this directory. They are copied after the builtin static files, so a file named
213 # "default.css" will overwrite the builtin "default.css".
214 # html_static_path = ["_static"]
215 
216 
217 # -- Latex / Mathjax config ------------------------------------------------------------
218 
219 with open(path.join(HERE, "custom_cmds.tex"), "r") as fh:
220     custom_cmds = fh.read()
221 
222 latex_elements = {"preamble": custom_cmds}
223 
224 mathjax_inline = [r"\(" + custom_cmds, r"\)"]
225 mathjax_display = [r"\[" + custom_cmds, r"\]"]
226
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/docs/source/conf.py b/docs/source/conf.py
--- a/docs/source/conf.py
+++ b/docs/source/conf.py
@@ -7,7 +7,6 @@
 # -- Imports ---------------------------------------------------------------------------
 
 import os
-import re
 import shutil
 import warnings
 from datetime import datetime
@@ -126,19 +125,6 @@
     shutil.unpack_archive(file, extract_dir=".")
     os.remove(file)
 
-    # This is workaround for a bug in sphinx-gallery that replaces absolute with
-    # relative paths. See https://github.com/pmeier/pystiche/pull/325 for details.
-    index_file = path.join("galleries", "examples", "index.rst")
-    with open(index_file, "r") as fh:
-        content = fh.read()
-    content = re.sub(
-        r"(?P<file>examples_(python|jupyter)\.zip) <[\w/.]+>",
-        r"\g<file> <\g<file>>",
-        content,
-    )
-    with open(index_file, "w") as fh:
-        fh.write(content)
-
     extensions.remove("sphinx_gallery.gen_gallery")
     extensions.append("sphinx_gallery.load_style")
     plot_gallery = False

{"golden_diff": "diff --git a/docs/source/conf.py b/docs/source/conf.py\n--- a/docs/source/conf.py\n+++ b/docs/source/conf.py\n@@ -7,7 +7,6 @@\n # -- Imports ---------------------------------------------------------------------------\n \n import os\n-import re\n import shutil\n import warnings\n from datetime import datetime\n@@ -126,19 +125,6 @@\n     shutil.unpack_archive(file, extract_dir=\".\")\n     os.remove(file)\n \n-    # This is workaround for a bug in sphinx-gallery that replaces absolute with\n-    # relative paths. See https://github.com/pmeier/pystiche/pull/325 for details.\n-    index_file = path.join(\"galleries\", \"examples\", \"index.rst\")\n-    with open(index_file, \"r\") as fh:\n-        content = fh.read()\n-    content = re.sub(\n-        r\"(?P<file>examples_(python|jupyter)\\.zip) <[\\w/.]+>\",\n-        r\"\\g<file> <\\g<file>>\",\n-        content,\n-    )\n-    with open(index_file, \"w\") as fh:\n-        fh.write(content)\n-\n     extensions.remove(\"sphinx_gallery.gen_gallery\")\n     extensions.append(\"sphinx_gallery.load_style\")\n     plot_gallery = False\n", "issue": "Download buttons for all examples are broken for RTD\n![Screenshot from 2020-06-11 19-10-01](https://user-images.githubusercontent.com/6849766/84418262-34e6fd00-ac17-11ea-8fdc-7a5cb5f9034d.png)\r\n\r\nThis is a bug in `sphinx-gallery` and should be fixed with sphinx-gallery/sphinx-gallery#706.\n", "before_files": [{"content": "# Configuration file for the Sphinx documentation builder.\n#\n# This file only contains a selection of the most common options. For a full list see\n# the documentation:\n# https://www.sphinx-doc.org/en/master/usage/configuration.html\n\n# -- Imports ---------------------------------------------------------------------------\n\nimport os\nimport re\nimport shutil\nimport warnings\nfrom datetime import datetime\nfrom distutils.util import strtobool\nfrom importlib_metadata import metadata as extract_metadata\nfrom os import path\nfrom urllib.parse import urljoin\n\nfrom sphinx_gallery.sorting import ExampleTitleSortKey, ExplicitOrder\n\nimport torch\n\nfrom pystiche.misc import download_file\n\n# -- Run config ------------------------------------------------------------------------\n\n\ndef get_bool_env_var(name, default=False):\n    try:\n        return bool(strtobool(os.environ[name]))\n    except KeyError:\n        return default\n\n\nrun_by_github_actions = get_bool_env_var(\"GITHUB_ACTIONS\")\nrun_by_travis_ci = get_bool_env_var(\"TRAVIS\")\nrun_by_appveyor = get_bool_env_var(\"APPVEYOR\")\nrun_by_rtd = get_bool_env_var(\"READTHEDOCS\")\nrun_by_ci = (\n    run_by_github_actions\n    or run_by_travis_ci\n    or run_by_appveyor\n    or run_by_rtd\n    or get_bool_env_var(\"CI\")\n)\n\n# -- Path setup ------------------------------------------------------------------------\n\n# If extensions (or modules to document with autodoc) are in another directory, add\n# these directories to sys.path here. If the directory is relative to the documentation\n# root, use os.path.abspath to make it absolute, like shown here.\n#\n# import os\n# import sys\n# sys.path.insert(0, os.path.abspath('.'))\n\nHERE = path.dirname(__file__)\nPROJECT_ROOT = path.abspath(path.join(HERE, \"..\", \"..\"))\n\n\n# -- Project information ---------------------------------------------------------------\n\nmetadata = extract_metadata(\"pystiche\")\n\nproject = metadata[\"name\"]\nauthor = metadata[\"author\"]\ncopyright = f\"{datetime.now().year}, {author}\"\nrelease = metadata[\"version\"]\ncanonical_version = release.split(\"+\")[0]\nversion = \".\".join(canonical_version.split(\".\")[:3])\n\n\n# -- General configuration -------------------------------------------------------------\n\n# Add any Sphinx extension module names here, as strings. They can be extensions coming\n# with Sphinx (named 'sphinx.ext.*') or your custom ones.\nextensions = [\n    \"sphinx.ext.autodoc\",\n    \"sphinx.ext.napoleon\",\n    \"sphinx.ext.coverage\",\n    \"sphinx.ext.intersphinx\",\n    \"sphinxcontrib.bibtex\",\n    \"sphinx_gallery.gen_gallery\",\n    \"sphinx_autodoc_typehints\",\n]\n\n# Add any paths that contain templates here, relative to this directory.\ntemplates_path = [\"_templates\"]\n\n# List of patterns, relative to source directory, that match files and directories to\n# ignore when looking for source files. This pattern also affects html_static_path and\n# html_extra_path.\nexclude_patterns = [\"_build\", \"Thumbs.db\", \".DS_Store\"]\n\n# -- intersphinx configuration ---------------------------------------------------------\n\nintersphinx_mapping = {\n    \"python\": (\"https://docs.python.org/3.6\", None),\n    \"torch\": (\"https://pytorch.org/docs/stable/\", None),\n    \"torchvision\": (\"https://pytorch.org/docs/stable/\", None),\n    \"PIL\": (\"https://pillow.readthedocs.io/en/stable/\", None),\n    \"numpy\": (\"https://numpy.org/doc/1.18/\", None),\n    \"requests\": (\"https://requests.readthedocs.io/en/stable/\", None),\n    \"matplotlib\": (\"https://matplotlib.org\", None),\n}\n\n\n# -- sphinx-gallery configuration ------------------------------------------------------\n\nplot_gallery = get_bool_env_var(\"PYSTICHE_PLOT_GALLERY\", default=True) and not run_by_ci\ndownload_gallery = get_bool_env_var(\"PYSTICHE_DOWNLOAD_GALLERY\") or run_by_ci\n\nif download_gallery:\n    base = \"https://download.pystiche.org/galleries/\"\n    is_dev = version != release\n    file = \"master.zip\" if is_dev else f\"v{version}.zip\"\n\n    url = urljoin(base, file)\n    print(f\"Downloading pre-built galleries from {url}\")\n    download_file(url, file)\n\n    try:\n        shutil.rmtree(\"galleries\")\n    except FileNotFoundError:\n        pass\n    shutil.unpack_archive(file, extract_dir=\".\")\n    os.remove(file)\n\n    # This is workaround for a bug in sphinx-gallery that replaces absolute with\n    # relative paths. See https://github.com/pmeier/pystiche/pull/325 for details.\n    index_file = path.join(\"galleries\", \"examples\", \"index.rst\")\n    with open(index_file, \"r\") as fh:\n        content = fh.read()\n    content = re.sub(\n        r\"(?P<file>examples_(python|jupyter)\\.zip) <[\\w/.]+>\",\n        r\"\\g<file> <\\g<file>>\",\n        content,\n    )\n    with open(index_file, \"w\") as fh:\n        fh.write(content)\n\n    extensions.remove(\"sphinx_gallery.gen_gallery\")\n    extensions.append(\"sphinx_gallery.load_style\")\n    plot_gallery = False\n\nif plot_gallery and not torch.cuda.is_available():\n    msg = (\n        \"The galleries will be built, but CUDA is not available. \"\n        \"This will take a long time.\"\n    )\n    print(msg)\n\n\ndef show_cuda_memory(func):\n    torch.cuda.reset_peak_memory_stats()\n    out = func()\n\n    stats = torch.cuda.memory_stats()\n    peak_bytes_usage = stats[\"allocated_bytes.all.peak\"]\n    memory = peak_bytes_usage / 1024 ** 2\n\n    return memory, out\n\n\nclass PysticheExampleTitleSortKey(ExampleTitleSortKey):\n    def __call__(self, filename):\n        # The beginner example *without* pystiche is placed before the example *with*\n        # to clarify the narrative.\n        if filename == \"example_nst_without_pystiche.py\":\n            return \"1\"\n        elif filename == \"example_nst_with_pystiche.py\":\n            return \"2\"\n        else:\n            return super().__call__(filename)\n\n\nsphinx_gallery_conf = {\n    \"examples_dirs\": path.join(PROJECT_ROOT, \"examples\"),\n    \"gallery_dirs\": path.join(\"galleries\", \"examples\"),\n    \"filename_pattern\": os.sep + \"example_\",\n    \"line_numbers\": True,\n    \"remove_config_comments\": True,\n    \"plot_gallery\": plot_gallery,\n    \"subsection_order\": ExplicitOrder(\n        [\n            path.join(\"..\", \"..\", \"examples\", sub_gallery)\n            for sub_gallery in (\"beginner\", \"advanced\")\n        ]\n    ),\n    \"within_subsection_order\": PysticheExampleTitleSortKey,\n    \"show_memory\": show_cuda_memory if torch.cuda.is_available() else True,\n}\n\n# Remove matplotlib agg warnings from generated doc when using plt.show\nwarnings.filterwarnings(\n    \"ignore\",\n    category=UserWarning,\n    message=(\n        \"Matplotlib is currently using agg, which is a non-GUI backend, so cannot show \"\n        \"the figure.\"\n    ),\n)\n\n\n# -- Options for HTML output -----------------------------------------------------------\n\n# The theme to use for HTML and HTML Help pages.  See the documentation for a list of\n# builtin themes.\nhtml_theme = \"sphinx_rtd_theme\"\n\n# Add any paths that contain custom static files (such as style sheets) here, relative\n# to this directory. They are copied after the builtin static files, so a file named\n# \"default.css\" will overwrite the builtin \"default.css\".\n# html_static_path = [\"_static\"]\n\n\n# -- Latex / Mathjax config ------------------------------------------------------------\n\nwith open(path.join(HERE, \"custom_cmds.tex\"), \"r\") as fh:\n    custom_cmds = fh.read()\n\nlatex_elements = {\"preamble\": custom_cmds}\n\nmathjax_inline = [r\"\\(\" + custom_cmds, r\"\\)\"]\nmathjax_display = [r\"\\[\" + custom_cmds, r\"\\]\"]\n", "path": "docs/source/conf.py"}], "after_files": [{"content": "# Configuration file for the Sphinx documentation builder.\n#\n# This file only contains a selection of the most common options. For a full list see\n# the documentation:\n# https://www.sphinx-doc.org/en/master/usage/configuration.html\n\n# -- Imports ---------------------------------------------------------------------------\n\nimport os\nimport shutil\nimport warnings\nfrom datetime import datetime\nfrom distutils.util import strtobool\nfrom importlib_metadata import metadata as extract_metadata\nfrom os import path\nfrom urllib.parse import urljoin\n\nfrom sphinx_gallery.sorting import ExampleTitleSortKey, ExplicitOrder\n\nimport torch\n\nfrom pystiche.misc import download_file\n\n# -- Run config ------------------------------------------------------------------------\n\n\ndef get_bool_env_var(name, default=False):\n    try:\n        return bool(strtobool(os.environ[name]))\n    except KeyError:\n        return default\n\n\nrun_by_github_actions = get_bool_env_var(\"GITHUB_ACTIONS\")\nrun_by_travis_ci = get_bool_env_var(\"TRAVIS\")\nrun_by_appveyor = get_bool_env_var(\"APPVEYOR\")\nrun_by_rtd = get_bool_env_var(\"READTHEDOCS\")\nrun_by_ci = (\n    run_by_github_actions\n    or run_by_travis_ci\n    or run_by_appveyor\n    or run_by_rtd\n    or get_bool_env_var(\"CI\")\n)\n\n# -- Path setup ------------------------------------------------------------------------\n\n# If extensions (or modules to document with autodoc) are in another directory, add\n# these directories to sys.path here. If the directory is relative to the documentation\n# root, use os.path.abspath to make it absolute, like shown here.\n#\n# import os\n# import sys\n# sys.path.insert(0, os.path.abspath('.'))\n\nHERE = path.dirname(__file__)\nPROJECT_ROOT = path.abspath(path.join(HERE, \"..\", \"..\"))\n\n\n# -- Project information ---------------------------------------------------------------\n\nmetadata = extract_metadata(\"pystiche\")\n\nproject = metadata[\"name\"]\nauthor = metadata[\"author\"]\ncopyright = f\"{datetime.now().year}, {author}\"\nrelease = metadata[\"version\"]\ncanonical_version = release.split(\"+\")[0]\nversion = \".\".join(canonical_version.split(\".\")[:3])\n\n\n# -- General configuration -------------------------------------------------------------\n\n# Add any Sphinx extension module names here, as strings. They can be extensions coming\n# with Sphinx (named 'sphinx.ext.*') or your custom ones.\nextensions = [\n    \"sphinx.ext.autodoc\",\n    \"sphinx.ext.napoleon\",\n    \"sphinx.ext.coverage\",\n    \"sphinx.ext.intersphinx\",\n    \"sphinxcontrib.bibtex\",\n    \"sphinx_gallery.gen_gallery\",\n    \"sphinx_autodoc_typehints\",\n]\n\n# Add any paths that contain templates here, relative to this directory.\ntemplates_path = [\"_templates\"]\n\n# List of patterns, relative to source directory, that match files and directories to\n# ignore when looking for source files. This pattern also affects html_static_path and\n# html_extra_path.\nexclude_patterns = [\"_build\", \"Thumbs.db\", \".DS_Store\"]\n\n# -- intersphinx configuration ---------------------------------------------------------\n\nintersphinx_mapping = {\n    \"python\": (\"https://docs.python.org/3.6\", None),\n    \"torch\": (\"https://pytorch.org/docs/stable/\", None),\n    \"torchvision\": (\"https://pytorch.org/docs/stable/\", None),\n    \"PIL\": (\"https://pillow.readthedocs.io/en/stable/\", None),\n    \"numpy\": (\"https://numpy.org/doc/1.18/\", None),\n    \"requests\": (\"https://requests.readthedocs.io/en/stable/\", None),\n    \"matplotlib\": (\"https://matplotlib.org\", None),\n}\n\n\n# -- sphinx-gallery configuration ------------------------------------------------------\n\nplot_gallery = get_bool_env_var(\"PYSTICHE_PLOT_GALLERY\", default=True) and not run_by_ci\ndownload_gallery = get_bool_env_var(\"PYSTICHE_DOWNLOAD_GALLERY\") or run_by_ci\n\nif download_gallery:\n    base = \"https://download.pystiche.org/galleries/\"\n    is_dev = version != release\n    file = \"master.zip\" if is_dev else f\"v{version}.zip\"\n\n    url = urljoin(base, file)\n    print(f\"Downloading pre-built galleries from {url}\")\n    download_file(url, file)\n\n    try:\n        shutil.rmtree(\"galleries\")\n    except FileNotFoundError:\n        pass\n    shutil.unpack_archive(file, extract_dir=\".\")\n    os.remove(file)\n\n    extensions.remove(\"sphinx_gallery.gen_gallery\")\n    extensions.append(\"sphinx_gallery.load_style\")\n    plot_gallery = False\n\nif plot_gallery and not torch.cuda.is_available():\n    msg = (\n        \"The galleries will be built, but CUDA is not available. \"\n        \"This will take a long time.\"\n    )\n    print(msg)\n\n\ndef show_cuda_memory(func):\n    torch.cuda.reset_peak_memory_stats()\n    out = func()\n\n    stats = torch.cuda.memory_stats()\n    peak_bytes_usage = stats[\"allocated_bytes.all.peak\"]\n    memory = peak_bytes_usage / 1024 ** 2\n\n    return memory, out\n\n\nclass PysticheExampleTitleSortKey(ExampleTitleSortKey):\n    def __call__(self, filename):\n        # The beginner example *without* pystiche is placed before the example *with*\n        # to clarify the narrative.\n        if filename == \"example_nst_without_pystiche.py\":\n            return \"1\"\n        elif filename == \"example_nst_with_pystiche.py\":\n            return \"2\"\n        else:\n            return super().__call__(filename)\n\n\nsphinx_gallery_conf = {\n    \"examples_dirs\": path.join(PROJECT_ROOT, \"examples\"),\n    \"gallery_dirs\": path.join(\"galleries\", \"examples\"),\n    \"filename_pattern\": os.sep + \"example_\",\n    \"line_numbers\": True,\n    \"remove_config_comments\": True,\n    \"plot_gallery\": plot_gallery,\n    \"subsection_order\": ExplicitOrder(\n        [\n            path.join(\"..\", \"..\", \"examples\", sub_gallery)\n            for sub_gallery in (\"beginner\", \"advanced\")\n        ]\n    ),\n    \"within_subsection_order\": PysticheExampleTitleSortKey,\n    \"show_memory\": show_cuda_memory if torch.cuda.is_available() else True,\n}\n\n# Remove matplotlib agg warnings from generated doc when using plt.show\nwarnings.filterwarnings(\n    \"ignore\",\n    category=UserWarning,\n    message=(\n        \"Matplotlib is currently using agg, which is a non-GUI backend, so cannot show \"\n        \"the figure.\"\n    ),\n)\n\n\n# -- Options for HTML output -----------------------------------------------------------\n\n# The theme to use for HTML and HTML Help pages.  See the documentation for a list of\n# builtin themes.\nhtml_theme = \"sphinx_rtd_theme\"\n\n# Add any paths that contain custom static files (such as style sheets) here, relative\n# to this directory. They are copied after the builtin static files, so a file named\n# \"default.css\" will overwrite the builtin \"default.css\".\n# html_static_path = [\"_static\"]\n\n\n# -- Latex / Mathjax config ------------------------------------------------------------\n\nwith open(path.join(HERE, \"custom_cmds.tex\"), \"r\") as fh:\n    custom_cmds = fh.read()\n\nlatex_elements = {\"preamble\": custom_cmds}\n\nmathjax_inline = [r\"\\(\" + custom_cmds, r\"\\)\"]\nmathjax_display = [r\"\\[\" + custom_cmds, r\"\\]\"]\n", "path": "docs/source/conf.py"}]}