@@ -304,33 +304,95 @@ def _check_dependencies():
304
304
# the title page.
305
305
latex_logo = None
306
306
307
+ # Use Unicode aware LaTeX engine
308
+ latex_engine = 'xelatex' # or 'lualatex'
309
+
307
310
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
+
308
361
# Additional stuff for the LaTeX preamble.
309
362
latex_elements ['preamble' ] = r"""
310
363
% One line per author on title page
311
364
\DeclareRobustCommand{\and}%
312
365
{\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).
316
366
\usepackage{expdlist}
317
367
\let\latexdescription=\description
318
368
\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
331
385
"""
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'
332
391
latex_elements ['pointsize' ] = '11pt'
333
392
393
+ # Better looking general index in PDF
394
+ latex_elements ['printindex' ] = r'\footnotesize\raggedright\printindex'
395
+
334
396
# Documents to append as an appendix to all manuals.
335
397
latex_appendices = []
336
398
@@ -358,13 +420,6 @@ def _check_dependencies():
358
420
359
421
numpydoc_show_class_members = False
360
422
361
- latex_engine = 'xelatex' # or 'lualatex'
362
-
363
- latex_elements = {
364
- 'babel' : r'\usepackage{babel}' ,
365
- 'fontpkg' : r'\setmainfont{DejaVu Serif}' ,
366
- }
367
-
368
423
html4_writer = True
369
424
370
425
inheritance_node_attrs = dict (fontsize = 16 )
0 commit comments