8000 Closes #15796: latex_elements defined twice in doc/conf.py · matplotlib/matplotlib@3b8f0e5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3b8f0e5

Browse files
committed
Closes #15796: latex_elements defined twice in doc/conf.py
- remove loading of amsmath, amssymb, amsfonts (already done by sphinx.sty) - remove loading of txfonts (not compatible with xetex/fontspec) - patch old obsolete expdlist.sty - resolve "Too deeply nested" error without using enumitem package. This Imports the fix already applied to NumPy and SciPy numpy/numpy#15028 scipy/scipy@c881fde - use XITS and XITS Math for wide enough Unicode coverage. As XITS has all the Unicode mathematical symbols needed for the section of the documentation related to Mathtext. (DejaVu Serif was missing 134 of them, and GNU FreeFont 19 of them) The Ubuntu package texlive-fonts-extra provides these latex dependencies. - better looking general index in PDF documentation - backport sphinx-doc/sphinx/pull/6888 to fix double quote issue
1 parent e92685a commit 3b8f0e5

File tree

1 file changed

+77
-22
lines changed

1 file changed

+77
-22
lines changed

doc/conf.py

Lines changed: 77 additions & 22 deletions
10000
Original file line numberDiff line numberDiff line change
@@ -304,33 +304,95 @@ def _check_dependencies():
304304
# the title page.
305305
latex_logo = None
306306

307+
# Use Unicode aware LaTeX engine
308+
latex_engine = 'xelatex' # or 'lualatex'
309+
307310
latex_elements = {}
311+
312+
# Keep babel usage also with xelatex (Sphinx default is polyglossia)
313+
# If this key is removed or changed, latex build directory must be cleaned
314+
latex_elements['babel'] = r'\usepackage{babel}'
315+
316+
# Font configuration
317+
# Fix fontspec converting " into right curly quotes in PDF
318+
# cf https://github.com/sphinx-doc/sphinx/pull/6888/
319+
latex_elements['fontenc'] = r'''
320+
\usepackage{fontspec}
321+
\defaultfontfeatures[\rmfamily,\sffamily,\ttfamily]{}
322+
'''
323+
# Sphinx 2.0 adopts GNU FreeFont by default, but it does not have all
324+
# the Unicode codepoints needed for the section about Mathtext
325+
# "Writing mathematical expressions"
326+
latex_elements['fontpkg'] = r"""
327+
\setmainfont{XITS}[
328+
Extension = .otf,
329+
UprightFont = *-Regular,
330+
ItalicFont = *-Italic,
331+
BoldFont = *-Bold,
332+
BoldItalicFont = *-BoldItalic,
333+
]
334+
\setsansfont{FreeSans}[
335+
Extension = .otf,
336+
UprightFont = *,
337+
ItalicFont = *Oblique,
338+
BoldFont = *Bold,
339+
BoldItalicFont = *BoldOblique,
340+
]
341+
\setmonofont{FreeMono}[
342+
Extension = .otf,
343+
UprightFont = *,
344+
ItalicFont = *Oblique,
345+
BoldFont = *Bold,
346+
BoldItalicFont = *BoldOblique,
347+
]
348+
% needed for \mathbb (blackboard alphabet) to actually work
349+
\usepackage{unicode-math}
350+
\setmathfont{XITS Math}
351+
"""
352+
# Sphinx <1.8.0 or >=2.0.0 does this by default, but the 1.8.x series
353+
# did not for latex_engine = 'xelatex' (as it used Latin Modern font).
354+
# We need this for code-blocks as FreeMono has wide glyphs.
355+
latex_elements['fvset'] = r'\fvset{fontsize=\small}'
356+
# Fix fancyhdr complaining about \headheight being too small
357+
latex_elements['passoptionstopackages'] = r"""
358+
\PassOptionsToPackage{headheight=14pt}{geometry}
359+
"""
360+
308361
# Additional stuff for the LaTeX preamble.
309362
latex_elements['preamble'] = r"""
310363
% One line per author on title page
311364
\DeclareRobustCommand{\and}%
312365
{\end{tabular}\kern-\tabcolsep\\\begin{tabular}[t]{c}}%
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).
316366
\usepackage{expdlist}
317367
\let\latexdescription=\description
318368
\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}
369+
% But expdlist old LaTeX package requires fixes:
370+
% 1) remove extra space
371+
\usepackage{etoolbox}
372+
\makeatletter
373+
\patchcmd\@item{{\@breaklabel} }{{\@breaklabel}}{}{}
374+
\makeatother
375+
% 2) fix bug in expdlist's way of breaking the line after long item label
376+
\makeatletter
377+
\def\breaklabel{%
378+
\def\@breaklabel{%
379+
\leavevmode\par
380+
% now a hack because Sphinx inserts \leavevmode after term node
381+
\def\leavevmode{\def\leavevmode{\unhbox\voidb@x}}%
382+
}%
383+
}
384+
\makeatother
331385
"""
386+
# Sphinx 1.5 provides this to avoid "too deeply nested" LaTeX error
387+
# and usage of "enumitem" LaTeX package is unneeded.
388+
# Value can be increased but do not set it to something such as 2048
389+
# which needlessly would trigger creation of thousands of TeX macros
390+
latex_elements['maxlistdepth'] = '10'
332391
latex_elements['pointsize'] = '11pt'
333392

393+
# Better looking general index in PDF
394+
latex_elements['printindex'] = r'\footnotesize\raggedright\printindex'
395+
334396
# Documents to append as an appendix to all manuals.
335397
latex_appendices = []
336398

@@ -358,13 +420,6 @@ def _check_dependencies():
358420

359421
numpydoc_show_class_members = False
360422

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

370425
inheritance_node_attrs = dict(fontsize=16)

0 commit comments

Comments
 (0)
0