8000 Closes #15796 via `latex_elements['maxlistdepth']` · matplotlib/matplotlib@6800644 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6800644

Browse files
committed
Closes #15796 via latex_elements['maxlistdepth']
Already sphinx>=1.8.1 is a requirement, and 'maxlistdepth' is available since Sphinx 1.5. This commit also suppresses usage of LaTeX expdlist package as it breaks PDF builds with recent LaTeX (2019 at least). The April 2018 code at scipy/scipy#8657 which patched expdlist for other reasons appears to fix also this issue and could be added here. Also, this commit sets up XITS as main document font: usage of XITS achieves that the section documenting Mathtext does not report missing glyphs during the LaTeX build. Probably STIX2 would work too. (with DejaVu Serif, there were 134 unique Unicode glyphs needed by the PDF build and reported missing from the font). XITS font is available in LaTeX distributions of recent years. This commit was tested with Sphinx v1.8.5 and Sphinx v2.2.1. (and using current TeXLive TeX distribution)
1 parent 3d1a1bc commit 6800644

File tree

1 file changed

+74
-27
lines changed

1 file changed

+74
-27
lines changed

doc/conf.py

Lines changed: 74 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -308,29 +308,83 @@ def _check_dependencies():
308308
latex_logo = None
309309

310310
latex_elements = {}
311+
312+
latex_engine = 'xelatex' # many Unicode glyphs in our docs...
313+
# By default Sphinx with latex_engine = 'xelatex' uses polyglossia
314+
# If this key is changed, clean the build/latex directory before next build
315+
latex_elements['babel'] = r'\usepackage{babel}'
316+
311317
# Additional stuff for the LaTeX preamble.
312-
latex_elements['preamble'] = r"""
313-
% In the parameters section, place a newline after the Parameters
314-
% header. (This is stolen directly from Numpy's conf.py, since it
315-
% affects Numpy-style docstrings).
316-
\usepackage{expdlist}
317-
\let\latexdescription=\description
318-
\def\description{\latexdescription{}{} \breaklabel}
319-
320-
\usepackage{amsmath}
321-
\usepackage{amsfonts}
322-
\usepackage{amssymb}
323-
\usepackage{txfonts}
324-
325-
% The enumitem package provides unlimited nesting of lists and
326-
% enums. Sphinx may use this in the future, in which case this can
327-
% be removed. See
328-
% https://bitbucket.org/birkenfeld/sphinx/issue/777/latex-output-too-deeply-nested
329-
\usepackage{enumitem}
330-
\setlistdepth{2048}
331-
"""
318+
319+
# Usage of expdlist package (as originally copied over from Numpy's confpy)
320+
# is removed because it breaks the PDF build with recent LaTeX:
321+
# ! Extra }, or forgotten \endgroup.
322+
# \@endpbox ...\@arstrutbox \color@endgroup \egroup
323+
# The https://github.com/scipy/scipy/pull/8657 code would actually fix this
324+
#
325+
# latex_elements['preamble'] = r"""
326+
# % In the parameters section, place a newline after the Parameters
327+
# % header. (This is stolen directly from Numpy's conf.py, since it
328+
# % affects Numpy-style docstrings).
329+
# \usepackage{expdlist}
330+
# \let\latexdescription=\description
331+
# \def\description{\latexdescription{}{} \breaklabel}
332+
# """
333+
332334
latex_elements['pointsize'] = '11pt'
333335

336+
# Fix fancyhdr complaining about \headheight too small
337+
latex_elements['passoptionstopackages'] = r"""
338+
\PassOptionsToPackage{headheight=14pt}{geometry}
339+
"""
340+
341+
# Sphinx 1.5 provides this to avoid "too deeply nested" LaTeX error
342+
# and usage of "enumitem" LaTeX package is unneeded.
343+
# Value can be increased but do not set it to something such as 2048
344+
# which needlessly would trigger creation of thousands of TeX macros
345+
latex_elements['maxlistdepth'] = '10'
346+
347+
# Use OpenType font with wide-enough glyph coverage
348+
# Sphinx 2.0 adopts GNU FreeFont by default, but it does not have all
349+
# the Unicode codepoints needed for the section about Mathtext
350+
# "Writing mathematical expressions"
351+
latex_elements['fontpkg'] = r"""
352+
\setmainfont{XITS}[
353+
Extension = .otf,
354+
UprightFont = *-Regular,
355+
ItalicFont = *-Italic,
356+
BoldFont = *-Bold,
357+
BoldItalicFont = *-BoldItalic,
358+
]
359+
\setsansfont{FreeSans}[
360+
Extension = .otf,
361+
UprightFont = *,
362+
ItalicFont = *Oblique,
363+
BoldFont = *Bold,
364+
BoldItalicFont = *BoldOblique,
365+
]
366+
\setmonofont{FreeMono}[
367+
Extension = .otf,
368+
UprightFont = *,
369+
ItalicFont = *Oblique,
370+
BoldFont = *Bold,
371+
BoldItalicFont = *BoldOblique,
372+
]
373+
% \usepackage{unicode-math}
374+
% \setmathfont{XITS Math}
375+
"""
376+
# Last two lines commented out because only there to fix missing glyphs from
377+
# one \mathbb{blackboard}, and anyhow the whole section about Mathtext Fonts
378+
# is broken as it would need extra LaTeX raw directives to actually switch
379+
# math fonts from main one and illustrate the "five global font sets". For
380+
# this one must define math versions in the LaTeX preamble and it is all quite
381+
# cumbersome.
382+
383+
# Sphinx <1.8.0 or >=2.0.0 does this by default, but the 1.8.x series
384+
# did not for latex_engine = 'xelatex' (used Latin Modern font).
385+
# We need it as FreeMono has wide character glyphs.
386+
latex_elements['fvset'] = r'\fvset{fontsize=\small}'
387+
334388
# Documents to append as an appendix to all manuals.
335389
latex_appendices = []
336390

@@ -358,13 +412,6 @@ def _check_dependencies():
358412

359413
numpydoc_show_class_members = False
360414

361-
latex_engine = 'xelatex' # or 'lualatex'
362-
363-
latex_elements = {
364-
'babel': r'\usepackage{babel}',
365-
'fontpkg': r'\setmainfont{DejaVu Serif}',
366-
}
367-
368415
html4_writer = True
369416

370417
inheritance_node_attrs = dict(fontsize=16)

0 commit comments

Comments
 (0)
0