@@ -342,33 +342,113 @@ def _check_dependencies():
342
342
# the title page.
343
343
latex_logo = None
344
344
345
+ # Use Unicode aware LaTeX engine
346
+ latex_engine = 'xelatex' # or 'lualatex'
347
+
345
348
latex_elements = {}
349
+
350
+ # Keep babel usage also with xelatex (Sphinx default is polyglossia)
351
+ # If this key is removed or changed, latex build directory must be cleaned
352
+ latex_elements ['babel' ] = r'\usepackage{babel}'
353
+
354
+ # Font configuration
355
+ # Fix fontspec converting " into right curly quotes in PDF
356
+ # cf https://github.com/sphinx-doc/sphinx/pull/6888/
357
+ latex_elements ['fontenc' ] = r'''
358
+ \usepackage{fontspec}
359
+ \defaultfontfeatures[\rmfamily,\sffamily,\ttfamily]{}
360
+ '''
361
+
362
+ # Sphinx 2.0 adopts GNU FreeFont by default, but it does not have all
363
+ # the Unicode codepoints needed for the section about Mathtext
364
+ # "Writing mathematical expressions"
365
+ fontpkg = r"""
366
+ \IfFontExistsTF{XITS}{
367
+ \setmainfont{XITS}
368
+ }{
369
+ \setmainfont{XITS}[
370
+ Extension = .otf,
371
+ UprightFont = *-Regular,
372
+ ItalicFont = *-Italic,
373
+ BoldFont = *-Bold,
374
+ BoldItalicFont = *-BoldItalic,
375
+ ]}
376
+ \IfFontExistsTF{FreeSans}{
377
+ \setsansfont{FreeSans}
378
+ }{
379
+ \setsansfont{FreeSans}[
380
+ Extension = .otf,
381
+ UprightFont = *,
382
+ ItalicFont = *Oblique,
383
+ BoldFont = *Bold,
384
+ BoldItalicFont = *BoldOblique,
385
+ ]}
386
+ \IfFontExistsTF{FreeMono}{
387
+ \setmonofont{FreeMono}
388
+ }{
389
+ \setmonofont{FreeMono}[
390
+ Extension = .otf,
391
+ UprightFont = *,
392
+ ItalicFont = *Oblique,
393
+ BoldFont = *Bold,
394
+ BoldItalicFont = *BoldOblique,
395
+ ]}
396
+ % needed for \mathbb (blackboard alphabet) to actually work
397
+ \usepackage{unicode-math}
398
+ \IfFontExistsTF{XITS Math}{
399
+ \setmathfont{XITS Math}
400
+ }{
401
+ \setmathfont{XITSMath-Regular}[
402
+ Extension = .otf,
403
+ ]}
404
+ """
405
+ latex_elements ['fontpkg' ] = fontpkg
406
+
407
+ # Sphinx <1.8.0 or >=2.0.0 does this by default, but the 1.8.x series
408
+ # did not for latex_engine = 'xelatex' (as it used Latin Modern font).
409
+ # We need this for code-blocks as FreeMono has wide glyphs.
410
+ latex_elements ['fvset' ] = r'\fvset{fontsize=\small}'
411
+ # Fix fancyhdr complaining about \headheight being too small
412
+ latex_elements ['passoptionstopackages' ] = r"""
413
+ \PassOptionsToPackage{headheight=14pt}{geometry}
414
+ """
415
+
346
416
# Additional stuff for the LaTeX preamble.
347
417
latex_elements ['preamble' ] = r"""
348
418
% One line per author on title page
349
419
\DeclareRobustCommand{\and}%
350
420
{\end{tabular}\kern-\tabcolsep\\\begin{tabular}[t]{c}}%
351
- % In the parameters section, place a newline after the Parameters
352
- % header. (This is stolen directly from Numpy's conf.py, since it
353
- % affects Numpy-style docstrings).
421
+ \usepackage{etoolbox}
422
+ \AtBeginEnvironment{sphinxthebibliography}{\appendix\part{Appendices}}
354
423
\usepackage{expdlist}
355
424
\let\latexdescription=\description
356
425
\def\description{\latexdescription{}{} \breaklabel}
357
-
358
- \usepackage{amsmath}
359
- \usepackage{amsfonts}
360
- \usepackage{amssymb}
361
- \usepackage{txfonts}
362
-
363
- % The enumitem package provides unlimited nesting of lists and
364
- % enums. Sphinx may use this in the future, in which case this can
365
- % be removed. See
366
- % https://bitbucket.org/birkenfeld/sphinx/issue/777/latex-output-too-deeply-nested
367
- \usepackage{enumitem}
368
- \setlistdepth{2048}
426
+ % But expdlist old LaTeX package requires fixes:
427
+ % 1) remove extra space
428
+ \makeatletter
429
+ \patchcmd\@item{{\@breaklabel} }{{\@breaklabel}}{}{}
430
+ \makeatother
431
+ % 2) fix bug in expdlist's way of breaking the line after long item label
432
+ \makeatletter
433
+ \def\breaklabel{%
434
+ \def\@breaklabel{%
435
+ \leavevmode\par
436
+ % now a hack because Sphinx inserts \leavevmode after term node
437
+ \def\leavevmode{\def\leavevmode{\unhbox\voidb@x}}%
438
+ }%
439
+ }
440
+ \makeatother
369
441
"""
442
+ # Sphinx 1.5 provides this to avoid "too deeply nested" LaTeX error
443
+ # and usage of "enumitem" LaTeX package is unneeded.
444
+ # Value can be increased but do not set it to something such as 2048
445
+ # which needlessly would trigger creation of thousands of TeX macros
446
+ latex_elements ['maxlistdepth' ] = '10'
370
447
latex_elements ['pointsize' ] = '11pt'
371
448
449
+ # Better looking general index in PDF
450
+ latex_elements ['printindex' ] = r'\footnotesize\raggedright\printindex'
451
+
372
452
# Documents to append as an appendix to all manuals.
373
453
latex_appendices = []
374
454
@@ -393,13 +473,6 @@ def _check_dependencies():
393
473
394
474
numpydoc_show_class_members = False
395
475
396
- latex_engine = 'xelatex' # or 'lualatex'
397
-
398
- latex_elements = {
399
- 'babel' : r'\usepackage{babel}' ,
400
- 'fontpkg' : r'\setmainfont{DejaVu Serif}' ,
401
- }
402
-
403
476
<
F438
code class="diff-text syntax-highlighted-line">html4_writer = True
404
477
405
478
inheritance_node_attrs = dict (fontsize = 16 )
0 commit comments