Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4c5ae23

Browse filesBrowse files
authored
Merge pull request #18948 from QuLogic/doc-pdf
DOC: Fix latexpdf build
2 parents 03a3d21 + 2fd6983 commit 4c5ae23
Copy full SHA for 4c5ae23

File tree

Expand file treeCollapse file tree

3 files changed

+109
-46
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+109
-46
lines changed

‎doc/conf.py

Copy file name to clipboardExpand all lines: doc/conf.py
+95-22Lines changed: 95 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -342,33 +342,113 @@ def _check_dependencies():
342342
# the title page.
343343
latex_logo = None
344344

345+
# Use Unicode aware LaTeX engine
346+
latex_engine = 'xelatex' # or 'lualatex'
347+
345348
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+
346416
# Additional stuff for the LaTeX preamble.
347417
latex_elements['preamble'] = r"""
348418
% One line per author on title page
349419
\DeclareRobustCommand{\and}%
350420
{\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}}
354423
\usepackage{expdlist}
355424
\let\latexdescription=\description
356425
\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
369441
"""
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'
370447
latex_elements['pointsize'] = '11pt'
371448

449+
# Better looking general index in PDF
450+
latex_elements['printindex'] = r'\footnotesize\raggedright\printindex'
451+
372452
# Documents to append as an appendix to all manuals.
373453
latex_appendices = []
374454

@@ -393,13 +473,6 @@ def _check_dependencies():
393473

394474
numpydoc_show_class_members = False
395475

396-
latex_engine = 'xelatex' # or 'lualatex'
397-
398-
latex_elements = {
399-
'babel': r'\usepackage{babel}',
400-
'fontpkg': r'\setmainfont{DejaVu Serif}',
401-
}
402-
403476
html4_writer = True
404477

405478
inheritance_node_attrs = dict(fontsize=16)

‎doc/sphinxext/math_symbol_table.py

Copy file name to clipboardExpand all lines: doc/sphinxext/math_symbol_table.py
+13-23Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -100,38 +100,28 @@
100100

101101

102102
def run(state_machine):
103-
def get_n(n, l):
104-
part = []
105-
for x in l:
106-
part.append(x)
107-
if len(part) == n:
108-
yield part
109-
part = []
110-
yield part
103+
def render_symbol(sym):
104+
if sym.startswith("\\"):
105+
sym = sym[1:]
106+
if sym not in {*mathtext.Parser._overunder_functions,
107+
*mathtext.Parser._function_names}:
108+
sym = chr(mathtext.tex2uni[sym])
109+
return f'\\{sym}' if sym in ('\\', '|') else sym
111110

112111
lines = []
113112
for category, columns, syms in symbols:
114113
syms = sorted(syms.split())
114+
columns = min(columns, len(syms))
115115
lines.append("**%s**" % category)
116116
lines.append('')
117117
max_width = max(map(len, syms)) * 2 + 16
118118
header = " " + (('=' * max_width) + ' ') * columns
119119
lines.append(header)
120-
for part in get_n(columns, syms):
121-
line = (
122-
" " +
123-
" ".join(
124-
"{} ``{}``".format(
125-
sym
126-
if not sym.startswith("\\")
127-
else sym[1:]
128-
if (sym[1:] in mathtext.Parser._overunder_functions
129-
or sym[1:] in mathtext.Parser._function_names)
130-
else chr(mathtext.tex2uni[sym[1:]]),
131-
sym)
132-
.rjust(max_width)
133-
for sym in part))
134-
lines.append(line)
120+
for part in range(0, len(syms), columns):
121+
row = " ".join(
122+
f"{render_symbol(sym)} ``{sym}``".rjust(max_width)
123+
for sym in syms[part:part + columns])
124+
lines.append(f" {row}")
135125
lines.append(header)
136126
lines.append('')
137127

‎tutorials/text/mathtext.py

Copy file name to clipboardExpand all lines: tutorials/text/mathtext.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
9595
.. math::
9696
97-
\frac{3}{4} \binom{3}{4} \genfrac{}{}{0}{}{3}{4}
97+
\frac{3}{4} \binom{3}{4} \genfrac{}{}{0pt}{}{3}{4}
9898
9999
Fractions can be arbitrarily nested::
100100

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.