We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Use a utf8 friendly latex backend
The current sphinx configuration in docs/conf.py defaults to pdflatex. This is causing problems on #4169 which introduces API-level doctests with unicode characters in them. I tried several iterations of lualatex and xelatex to try and get it to work, but latex errors are never the most helpful.

I will open a PR to resolve this shortly. 

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `doc/conf.py`
Content:
```
1 from datetime import date
2 from sphinx_gallery.sorting import ExplicitOrder
3 import sphinx_rtd_theme
4 from warnings import filterwarnings
5 
6 filterwarnings(
7     "ignore", message="Matplotlib is currently using agg", category=UserWarning
8 )
9 
10 # General configuration
11 # ---------------------
12 
13 # Add any Sphinx extension module names here, as strings. They can be extensions
14 # coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
15 extensions = [
16     "sphinx.ext.autosummary",
17     "sphinx.ext.autodoc",
18     "sphinx.ext.coverage",
19     "sphinx.ext.doctest",
20     "sphinx.ext.intersphinx",
21     "sphinx.ext.mathjax",
22     "sphinx.ext.napoleon",
23     "sphinx.ext.todo",
24     "sphinx.ext.viewcode",
25     "sphinx_gallery.gen_gallery",
26     "nb2plots",
27     "texext",
28 ]
29 
30 # https://github.com/sphinx-gallery/sphinx-gallery
31 sphinx_gallery_conf = {
32     # path to your examples scripts
33     "examples_dirs": "../examples",
34     "subsection_order": ExplicitOrder(
35         [
36             "../examples/basic",
37             "../examples/drawing",
38             "../examples/graph",
39             "../examples/algorithms",
40             "../examples/advanced",
41             "../examples/3d_drawing",
42             "../examples/pygraphviz",
43             "../examples/geospatial",
44             "../examples/javascript",
45             "../examples/jit",
46             "../examples/applications",
47             "../examples/subclass",
48         ]
49     ),
50     # path where to save gallery generated examples
51     "gallery_dirs": "auto_examples",
52     "backreferences_dir": "modules/generated",
53 }
54 
55 # generate autosummary pages
56 autosummary_generate = True
57 
58 # Add any paths that contain templates here, relative to this directory.
59 templates_path = ["_templates"]
60 
61 suppress_warnings = ["ref.citation", "ref.footnote"]
62 
63 # The suffix of source filenames.
64 source_suffix = ".rst"
65 
66 # The encoding of source files.
67 source_encoding = "utf-8"
68 
69 # The master toctree document.
70 master_doc = "index"
71 
72 # Do not include release announcement template
73 exclude_patterns = ["release/release_template.rst"]
74 
75 # General substitutions.
76 project = "NetworkX"
77 copyright = f"2004-{date.today().year}, NetworkX Developers"
78 
79 # The default replacements for |version| and |release|, also used in various
80 # other places throughout the built documents.
81 #
82 # The short X.Y version.
83 import networkx
84 
85 version = networkx.__version__
86 # The full version, including dev info
87 release = networkx.__version__.replace("_", "")
88 
89 # There are two options for replacing |today|: either, you set today to some
90 # non-false value, then it is used:
91 # today = ''
92 # Else, today_fmt is used as the format for a strftime call.
93 # today_fmt = '%B %d, %Y'
94 
95 # List of documents that shouldn't be included in the build.
96 # unused_docs = ['']
97 
98 # If true, '()' will be appended to :func: etc. cross-reference text.
99 # add_function_parentheses = True
100 
101 # If true, the current module name will be prepended to all description
102 # unit titles (such as .. function::).
103 add_module_names = False
104 
105 # show_authors = True
106 
107 # The name of the Pygments (syntax highlighting) style to use.
108 # pygments_style = 'friendly'
109 pygments_style = "sphinx"
110 
111 # A list of prefixs that are ignored when creating the module index. (new in Sphinx 0.6)
112 modindex_common_prefix = ["networkx."]
113 
114 doctest_global_setup = "import networkx as nx"
115 
116 # treat ``x, y : type`` as vars x and y instead of default ``y(x,) : type``
117 napoleon_use_param = False
118 
119 # Options for HTML output
120 # -----------------------
121 
122 
123 html_theme = "sphinx_rtd_theme"
124 html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
125 
126 html_theme_options = {
127     "canonical_url": "https://networkx.org/documentation/stable/",
128     "navigation_depth": 3,
129     "logo_only": True,
130 }
131 
132 html_logo = "_static/networkx_logo.svg"
133 
134 # The style sheet to use for HTML and HTML Help pages. A file of that name
135 # must exist either in Sphinx' static/ path, or in one of the custom paths
136 # given in html_static_path.
137 # html_style = ''
138 
139 # Add any paths that contain custom static files (such as style sheets) here,
140 # relative to this directory. They are copied after the builtin static files,
141 # so a file named "default.css" will overwrite the builtin "default.css".
142 html_static_path = ["_static"]
143 
144 # If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
145 # using the given strftime format.
146 html_last_updated_fmt = "%b %d, %Y"
147 
148 # If true, SmartyPants will be used to convert quotes and dashes to
149 # typographically correct entities.
150 # html_use_smartypants = True
151 
152 # Content template for the index page.
153 # html_index = 'index.html'
154 
155 # Custom sidebar templates, maps page names to templates.
156 # html_sidebars = {}
157 
158 # Additional templates that should be rendered to pages, maps page names to
159 # templates.
160 # html_additional_pages = {'': ''}
161 
162 # If true, the reST sources are included in the HTML build as _sources/<name>.
163 html_copy_source = False
164 
165 html_use_opensearch = "https://networkx.org"
166 
167 # Output file base name for HTML help builder.
168 htmlhelp_basename = "NetworkX"
169 
170 # Options for LaTeX output
171 # ------------------------
172 
173 # The paper size ('letter' or 'a4').
174 latex_paper_size = "letter"
175 
176 # The font size ('10pt', '11pt' or '12pt').
177 # latex_font_size = '10pt'
178 
179 # Grouping the document tree into LaTeX files. List of tuples
180 # (source start file, target name, title, author, document class [howto/manual]).
181 latex_documents = [
182     (
183         "reference/index",
184         "networkx_reference.tex",
185         "NetworkX Reference",
186         "Aric Hagberg, Dan Schult, Pieter Swart",
187         "manual",
188         1,
189     )
190 ]
191 
192 latex_appendices = ["tutorial"]
193 
194 # Intersphinx mapping
195 intersphinx_mapping = {
196     "https://docs.python.org/3/": None,
197     "https://numpy.org/doc/stable/": None,
198 }
199 
200 # The reST default role (used for this markup: `text`) to use for all
201 # documents.
202 default_role = "obj"
203 
204 numpydoc_show_class_members = False
205 
206 
207 def setup(app):
208     app.add_css_file("custom.css")
209     app.add_js_file("copybutton.js")
210
```
--- 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/doc/conf.py b/doc/conf.py
--- a/doc/conf.py
+++ b/doc/conf.py
@@ -170,6 +170,8 @@
 # Options for LaTeX output
 # ------------------------
 
+# Use a latex engine that allows for unicode characters in docstrings
+latex_engine = "xelatex"
 # The paper size ('letter' or 'a4').
 latex_paper_size = "letter"

{"golden_diff": "diff --git a/doc/conf.py b/doc/conf.py\n--- a/doc/conf.py\n+++ b/doc/conf.py\n@@ -170,6 +170,8 @@\n # Options for LaTeX output\n # ------------------------\n \n+# Use a latex engine that allows for unicode characters in docstrings\n+latex_engine = \"xelatex\"\n # The paper size ('letter' or 'a4').\n latex_paper_size = \"letter\"\n", "issue": "Use a utf8 friendly latex backend\nThe current sphinx configuration in docs/conf.py defaults to pdflatex. This is causing problems on #4169 which introduces API-level doctests with unicode characters in them. I tried several iterations of lualatex and xelatex to try and get it to work, but latex errors are never the most helpful.\r\n\r\nI will open a PR to resolve this shortly. \n", "before_files": [{"content": "from datetime import date\nfrom sphinx_gallery.sorting import ExplicitOrder\nimport sphinx_rtd_theme\nfrom warnings import filterwarnings\n\nfilterwarnings(\n    \"ignore\", message=\"Matplotlib is currently using agg\", category=UserWarning\n)\n\n# General configuration\n# ---------------------\n\n# Add any Sphinx extension module names here, as strings. They can be extensions\n# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.\nextensions = [\n    \"sphinx.ext.autosummary\",\n    \"sphinx.ext.autodoc\",\n    \"sphinx.ext.coverage\",\n    \"sphinx.ext.doctest\",\n    \"sphinx.ext.intersphinx\",\n    \"sphinx.ext.mathjax\",\n    \"sphinx.ext.napoleon\",\n    \"sphinx.ext.todo\",\n    \"sphinx.ext.viewcode\",\n    \"sphinx_gallery.gen_gallery\",\n    \"nb2plots\",\n    \"texext\",\n]\n\n# https://github.com/sphinx-gallery/sphinx-gallery\nsphinx_gallery_conf = {\n    # path to your examples scripts\n    \"examples_dirs\": \"../examples\",\n    \"subsection_order\": ExplicitOrder(\n        [\n            \"../examples/basic\",\n            \"../examples/drawing\",\n            \"../examples/graph\",\n            \"../examples/algorithms\",\n            \"../examples/advanced\",\n            \"../examples/3d_drawing\",\n            \"../examples/pygraphviz\",\n            \"../examples/geospatial\",\n            \"../examples/javascript\",\n            \"../examples/jit\",\n            \"../examples/applications\",\n            \"../examples/subclass\",\n        ]\n    ),\n    # path where to save gallery generated examples\n    \"gallery_dirs\": \"auto_examples\",\n    \"backreferences_dir\": \"modules/generated\",\n}\n\n# generate autosummary pages\nautosummary_generate = True\n\n# Add any paths that contain templates here, relative to this directory.\ntemplates_path = [\"_templates\"]\n\nsuppress_warnings = [\"ref.citation\", \"ref.footnote\"]\n\n# The suffix of source filenames.\nsource_suffix = \".rst\"\n\n# The encoding of source files.\nsource_encoding = \"utf-8\"\n\n# The master toctree document.\nmaster_doc = \"index\"\n\n# Do not include release announcement template\nexclude_patterns = [\"release/release_template.rst\"]\n\n# General substitutions.\nproject = \"NetworkX\"\ncopyright = f\"2004-{date.today().year}, NetworkX Developers\"\n\n# The default replacements for |version| and |release|, also used in various\n# other places throughout the built documents.\n#\n# The short X.Y version.\nimport networkx\n\nversion = networkx.__version__\n# The full version, including dev info\nrelease = networkx.__version__.replace(\"_\", \"\")\n\n# There are two options for replacing |today|: either, you set today to some\n# non-false value, then it is used:\n# today = ''\n# Else, today_fmt is used as the format for a strftime call.\n# today_fmt = '%B %d, %Y'\n\n# List of documents that shouldn't be included in the build.\n# unused_docs = ['']\n\n# If true, '()' will be appended to :func: etc. cross-reference text.\n# add_function_parentheses = True\n\n# If true, the current module name will be prepended to all description\n# unit titles (such as .. function::).\nadd_module_names = False\n\n# show_authors = True\n\n# The name of the Pygments (syntax highlighting) style to use.\n# pygments_style = 'friendly'\npygments_style = \"sphinx\"\n\n# A list of prefixs that are ignored when creating the module index. (new in Sphinx 0.6)\nmodindex_common_prefix = [\"networkx.\"]\n\ndoctest_global_setup = \"import networkx as nx\"\n\n# treat ``x, y : type`` as vars x and y instead of default ``y(x,) : type``\nnapoleon_use_param = False\n\n# Options for HTML output\n# -----------------------\n\n\nhtml_theme = \"sphinx_rtd_theme\"\nhtml_theme_path = [sphinx_rtd_theme.get_html_theme_path()]\n\nhtml_theme_options = {\n    \"canonical_url\": \"https://networkx.org/documentation/stable/\",\n    \"navigation_depth\": 3,\n    \"logo_only\": True,\n}\n\nhtml_logo = \"_static/networkx_logo.svg\"\n\n# The style sheet to use for HTML and HTML Help pages. A file of that name\n# must exist either in Sphinx' static/ path, or in one of the custom paths\n# given in html_static_path.\n# html_style = ''\n\n# Add any paths that contain custom static files (such as style sheets) here,\n# relative to this directory. They are copied after the builtin static files,\n# so a file named \"default.css\" will overwrite the builtin \"default.css\".\nhtml_static_path = [\"_static\"]\n\n# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,\n# using the given strftime format.\nhtml_last_updated_fmt = \"%b %d, %Y\"\n\n# If true, SmartyPants will be used to convert quotes and dashes to\n# typographically correct entities.\n# html_use_smartypants = True\n\n# Content template for the index page.\n# html_index = 'index.html'\n\n# Custom sidebar templates, maps page names to templates.\n# html_sidebars = {}\n\n# Additional templates that should be rendered to pages, maps page names to\n# templates.\n# html_additional_pages = {'': ''}\n\n# If true, the reST sources are included in the HTML build as _sources/<name>.\nhtml_copy_source = False\n\nhtml_use_opensearch = \"https://networkx.org\"\n\n# Output file base name for HTML help builder.\nhtmlhelp_basename = \"NetworkX\"\n\n# Options for LaTeX output\n# ------------------------\n\n# The paper size ('letter' or 'a4').\nlatex_paper_size = \"letter\"\n\n# The font size ('10pt', '11pt' or '12pt').\n# latex_font_size = '10pt'\n\n# Grouping the document tree into LaTeX files. List of tuples\n# (source start file, target name, title, author, document class [howto/manual]).\nlatex_documents = [\n    (\n        \"reference/index\",\n        \"networkx_reference.tex\",\n        \"NetworkX Reference\",\n        \"Aric Hagberg, Dan Schult, Pieter Swart\",\n        \"manual\",\n        1,\n    )\n]\n\nlatex_appendices = [\"tutorial\"]\n\n# Intersphinx mapping\nintersphinx_mapping = {\n    \"https://docs.python.org/3/\": None,\n    \"https://numpy.org/doc/stable/\": None,\n}\n\n# The reST default role (used for this markup: `text`) to use for all\n# documents.\ndefault_role = \"obj\"\n\nnumpydoc_show_class_members = False\n\n\ndef setup(app):\n    app.add_css_file(\"custom.css\")\n    app.add_js_file(\"copybutton.js\")\n", "path": "doc/conf.py"}], "after_files": [{"content": "from datetime import date\nfrom sphinx_gallery.sorting import ExplicitOrder\nimport sphinx_rtd_theme\nfrom warnings import filterwarnings\n\nfilterwarnings(\n    \"ignore\", message=\"Matplotlib is currently using agg\", category=UserWarning\n)\n\n# General configuration\n# ---------------------\n\n# Add any Sphinx extension module names here, as strings. They can be extensions\n# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.\nextensions = [\n    \"sphinx.ext.autosummary\",\n    \"sphinx.ext.autodoc\",\n    \"sphinx.ext.coverage\",\n    \"sphinx.ext.doctest\",\n    \"sphinx.ext.intersphinx\",\n    \"sphinx.ext.mathjax\",\n    \"sphinx.ext.napoleon\",\n    \"sphinx.ext.todo\",\n    \"sphinx.ext.viewcode\",\n    \"sphinx_gallery.gen_gallery\",\n    \"nb2plots\",\n    \"texext\",\n]\n\n# https://github.com/sphinx-gallery/sphinx-gallery\nsphinx_gallery_conf = {\n    # path to your examples scripts\n    \"examples_dirs\": \"../examples\",\n    \"subsection_order\": ExplicitOrder(\n        [\n            \"../examples/basic\",\n            \"../examples/drawing\",\n            \"../examples/graph\",\n            \"../examples/algorithms\",\n            \"../examples/advanced\",\n            \"../examples/3d_drawing\",\n            \"../examples/pygraphviz\",\n            \"../examples/geospatial\",\n            \"../examples/javascript\",\n            \"../examples/jit\",\n            \"../examples/applications\",\n            \"../examples/subclass\",\n        ]\n    ),\n    # path where to save gallery generated examples\n    \"gallery_dirs\": \"auto_examples\",\n    \"backreferences_dir\": \"modules/generated\",\n}\n\n# generate autosummary pages\nautosummary_generate = True\n\n# Add any paths that contain templates here, relative to this directory.\ntemplates_path = [\"_templates\"]\n\nsuppress_warnings = [\"ref.citation\", \"ref.footnote\"]\n\n# The suffix of source filenames.\nsource_suffix = \".rst\"\n\n# The encoding of source files.\nsource_encoding = \"utf-8\"\n\n# The master toctree document.\nmaster_doc = \"index\"\n\n# Do not include release announcement template\nexclude_patterns = [\"release/release_template.rst\"]\n\n# General substitutions.\nproject = \"NetworkX\"\ncopyright = f\"2004-{date.today().year}, NetworkX Developers\"\n\n# The default replacements for |version| and |release|, also used in various\n# other places throughout the built documents.\n#\n# The short X.Y version.\nimport networkx\n\nversion = networkx.__version__\n# The full version, including dev info\nrelease = networkx.__version__.replace(\"_\", \"\")\n\n# There are two options for replacing |today|: either, you set today to some\n# non-false value, then it is used:\n# today = ''\n# Else, today_fmt is used as the format for a strftime call.\n# today_fmt = '%B %d, %Y'\n\n# List of documents that shouldn't be included in the build.\n# unused_docs = ['']\n\n# If true, '()' will be appended to :func: etc. cross-reference text.\n# add_function_parentheses = True\n\n# If true, the current module name will be prepended to all description\n# unit titles (such as .. function::).\nadd_module_names = False\n\n# show_authors = True\n\n# The name of the Pygments (syntax highlighting) style to use.\n# pygments_style = 'friendly'\npygments_style = \"sphinx\"\n\n# A list of prefixs that are ignored when creating the module index. (new in Sphinx 0.6)\nmodindex_common_prefix = [\"networkx.\"]\n\ndoctest_global_setup = \"import networkx as nx\"\n\n# treat ``x, y : type`` as vars x and y instead of default ``y(x,) : type``\nnapoleon_use_param = False\n\n# Options for HTML output\n# -----------------------\n\n\nhtml_theme = \"sphinx_rtd_theme\"\nhtml_theme_path = [sphinx_rtd_theme.get_html_theme_path()]\n\nhtml_theme_options = {\n    \"canonical_url\": \"https://networkx.org/documentation/stable/\",\n    \"navigation_depth\": 3,\n    \"logo_only\": True,\n}\n\nhtml_logo = \"_static/networkx_logo.svg\"\n\n# The style sheet to use for HTML and HTML Help pages. A file of that name\n# must exist either in Sphinx' static/ path, or in one of the custom paths\n# given in html_static_path.\n# html_style = ''\n\n# Add any paths that contain custom static files (such as style sheets) here,\n# relative to this directory. They are copied after the builtin static files,\n# so a file named \"default.css\" will overwrite the builtin \"default.css\".\nhtml_static_path = [\"_static\"]\n\n# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,\n# using the given strftime format.\nhtml_last_updated_fmt = \"%b %d, %Y\"\n\n# If true, SmartyPants will be used to convert quotes and dashes to\n# typographically correct entities.\n# html_use_smartypants = True\n\n# Content template for the index page.\n# html_index = 'index.html'\n\n# Custom sidebar templates, maps page names to templates.\n# html_sidebars = {}\n\n# Additional templates that should be rendered to pages, maps page names to\n# templates.\n# html_additional_pages = {'': ''}\n\n# If true, the reST sources are included in the HTML build as _sources/<name>.\nhtml_copy_source = False\n\nhtml_use_opensearch = \"https://networkx.org\"\n\n# Output file base name for HTML help builder.\nhtmlhelp_basename = \"NetworkX\"\n\n# Options for LaTeX output\n# ------------------------\n\n# Use a latex engine that allows for unicode characters in docstrings\nlatex_engine = \"xelatex\"\n# The paper size ('letter' or 'a4').\nlatex_paper_size = \"letter\"\n\n# The font size ('10pt', '11pt' or '12pt').\n# latex_font_size = '10pt'\n\n# Grouping the document tree into LaTeX files. List of tuples\n# (source start file, target name, title, author, document class [howto/manual]).\nlatex_documents = [\n    (\n        \"reference/index\",\n        \"networkx_reference.tex\",\n        \"NetworkX Reference\",\n        \"Aric Hagberg, Dan Schult, Pieter Swart\",\n        \"manual\",\n        1,\n    )\n]\n\nlatex_appendices = [\"tutorial\"]\n\n# Intersphinx mapping\nintersphinx_mapping = {\n    \"https://docs.python.org/3/\": None,\n    \"https://numpy.org/doc/stable/\": None,\n}\n\n# The reST default role (used for this markup: `text`) to use for all\n# documents.\ndefault_role = \"obj\"\n\nnumpydoc_show_class_members = False\n\n\ndef setup(app):\n    app.add_css_file(\"custom.css\")\n    app.add_js_file(\"copybutton.js\")\n", "path": "doc/conf.py"}]}