Skip to content

Commit 99a8b7f

Browse files
committed
LaTeX: update default font configuration
This replaces times package with tgtermes and tgheros (clones of Times and Helvetica with better LaTeX support) and the monospace font from txfonts package (txtt). This font is better matched with Times-like fonts than Courier clones. The changes applies to pdflatex/platex/uplatex. Fixes: #8711
1 parent 3ed7590 commit 99a8b7f

File tree

9 files changed

+116
-129
lines changed

9 files changed

+116
-129
lines changed

CHANGES

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Dependencies
66

77
* Drop python 3.5 support
88
* Drop docutils 0.12 and 0.13 support
9+
* LaTeX: add ``tex-gyre`` font dependency
910

1011
Incompatible changes
1112
--------------------
@@ -56,6 +57,8 @@ Bugs fixed
5657
* #8380: html search: Paragraphs in search results are not identified as ``<p>``
5758
* #8342: Emit a warning if a unknown domain is given for directive or role (ex.
5859
``:unknown:doc:``)
60+
* #8711: LaTeX: backticks in code-blocks trigger latexpdf build warning (and font
61+
change) with late TeXLive 2019
5962

6063
Testing
6164
--------

bindep.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ texlive-luatex85 [platform:rpm]
1212
texlive-anyfontsize [platform:rpm]
1313
texlive-ctablestack [platform:rpm]
1414
texlive-gnu-freefont [platform:rpm]
15+
texlive-tex-gyre [platform:rpm]
1516
latexmk [platform:rpm]
1617

1718
texlive-latex-recommended [platform:dpkg]
1819
texlive-fonts-recommended [platform:dpkg]
20+
tex-gyre [platform:dpkg]
1921
texlive-latex-extra [platform:dpkg]
2022
texlive-luatex [platform:dpkg]
2123
latexmk [platform:dpkg]

doc/conf.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,8 @@
5858
latex_logo = '_static/sphinx.png'
5959
latex_elements = {
6060
'fontenc': r'\usepackage[LGR,X2,T1]{fontenc}',
61-
'fontpkg': r'''
62-
\usepackage[sc]{mathpazo}
63-
\usepackage[scaled]{helvet}
64-
\usepackage{courier}
65-
\substitutefont{LGR}{\rmdefault}{cmr}
66-
\substitutefont{LGR}{\sfdefault}{cmss}
67-
\substitutefont{LGR}{\ttdefault}{cmtt}
68-
\substitutefont{X2}{\rmdefault}{cmr}
69-
\substitutefont{X2}{\sfdefault}{cmss}
70-
\substitutefont{X2}{\ttdefault}{cmtt}
71-
''',
7261
'passoptionstopackages': '\\PassOptionsToPackage{svgnames}{xcolor}',
7362
'preamble': '\\DeclareUnicodeCharacter{229E}{\\ensuremath{\\boxplus}}',
74-
'fvset': '\\fvset{fontsize=auto}',
7563
# fix missing index entry due to RTD doing only once pdflatex after makeindex
7664
'printindex': r'''
7765
\IfFileExists{\jobname.ind}

doc/latex.rst

Lines changed: 72 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -133,57 +133,33 @@ Keys that you may want to override include:
133133
``babel``, not ``polyglossia``.
134134

135135
``'fontpkg'``
136-
Font package inclusion. The default of ``'\\usepackage{times}'`` uses Times
137-
for text, Helvetica for sans serif and Courier for monospace.
138-
139-
In order to support occasional Cyrillic (физика частиц) or Greek
140-
letters (Σωματιδιακή φυσική) in a document whose language is
141-
English or a Latin European one, the default set-up is enhanced (only for
142-
``'pdflatex'`` engine) to do:
143-
144-
.. code-block:: latex
145-
146-
\substitutefont{LGR}{\rmdefault}{cmr}
147-
\substitutefont{LGR}{\sfdefault}{cmss}
148-
\substitutefont{LGR}{\ttdefault}{cmtt}
149-
\substitutefont{X2}{\rmdefault}{cmr}
150-
\substitutefont{X2}{\sfdefault}{cmss}
151-
\substitutefont{X2}{\ttdefault}{cmtt}
152-
153-
This is activated only under the condition that the ``'fontenc'`` key is
154-
configured to load the ``LGR`` (Greek) and/or ``X2`` (Cyrillic)
155-
pdflatex-font encodings (if the :confval:`language` is set to a Cyrillic
156-
language, this ``'fontpkg'`` key must be used as "times" package has no
157-
direct support for it; then keep only ``LGR`` lines from the above, if
158-
support is needed for Greek in the text).
159-
160-
The ``\substitutefont`` command is from the eponymous LaTeX package, which
161-
is loaded by Sphinx if needed (on Ubuntu Xenial it is part of
162-
``texlive-latex-extra`` which is a Sphinx requirement).
163-
164-
Only if the document actually does contain Unicode Greek letters (in text)
165-
or Cyrillic letters, will the above default set-up cause additional
166-
requirements for the PDF build. On Ubuntu Xenial, these are the
167-
``texlive-lang-greek``, ``texlive-lang-cyrillic``, and (with the above
168-
choice of fonts) the ``cm-super`` (or ``cm-super-minimal``) packages.
169-
170-
For ``'xelatex'`` and ``'lualatex'``, the default is to use the FreeFont
171-
family: this OpenType font family supports both Cyrillic and Greek scripts
172-
and is available as separate Ubuntu Xenial package ``fonts-freefont-otf``.
173-
It is not necessary to install the much larger ``texlive-fonts-extra``
174-
package.
175-
176-
``'platex'`` (Japanese documents) engine supports individual Cyrillic and
177-
Greek letters with no need of extra user set-up.
178-
179-
Default: ``'\\usepackage{times}'`` (or ``''`` when using a Cyrillic script)
136+
Font package inclusion. The default is::
137+
138+
r"""\usepackage{tgtermes}
139+
\usepackage{tgheros}
140+
\renewcommand\ttdefault{txtt}
141+
"""
142+
143+
For ``'xelatex'`` and ``'lualatex'`` however the default is to use
144+
the GNU FreeFont.
180145

181146
.. versionchanged:: 1.2
182147
Defaults to ``''`` when the :confval:`language` uses the Cyrillic
183148
script.
184149

185150
.. versionchanged:: 2.0
186-
Added support for individual Greek and Cyrillic letters:
151+
Incorporates some font substitution commands to help support occasional
152+
Greek or Cyrillic in a document using ``'pdflatex'`` engine.
153+
154+
.. versionchanged:: 4.0.0
155+
- The font substitution commands added at ``2.0`` have been moved
156+
to the ``'fontsubstitution'`` key, as their presence here made
157+
it complicated for user to customize the value of ``'fontpkg'``.
158+
- The default font setting has changed: it still uses Times and
159+
Helvetica clones for serif and sans serif, but via better, more
160+
complete TeX fonts and associated LaTeX packages. The
161+
monospace font has been changed to better match the Times clone.
162+
187163

188164
``'fncychap'``
189165
Inclusion of the "fncychap" package (which makes fancy chapter titles),
@@ -314,37 +290,28 @@ Keys that don't need to be overridden unless in special cases are:
314290
.. versionadded:: 1.2
315291

316292
``'fontenc'``
317-
"fontenc" package inclusion.
293+
Customize this from its default ``'\\usepackage[T1]{fontenc}'`` to:
318294

319-
If ``'pdflatex'`` is the :confval:`latex_engine`, one can add ``LGR``
320-
for support of Greek letters in the document, and also ``X2`` (or
321-
``T2A``) for Cyrillic letters, like this:
295+
- ``'\\usepackage[X2,T1]{fontenc}'`` if you need occasional
296+
Cyrillic letters (физика частиц),
322297

323-
.. code-block:: latex
298+
- ``'\\usepackage[LGR,T1]{fontenc}'`` if you need occasional
299+
Greek letters (Σωματιδιακή φυσική).
324300

325-
r'\usepackage[LGR,X2,T1]{fontenc}'
301+
Use ``[LGR,X2,T1]`` rather if both are needed.
326302

327303
.. attention::
328304

329-
If Greek is main language, do not use this key. Since Sphinx 2.2.1,
330-
``xelatex`` will be used automatically as :confval:`latex_engine`.
331-
Formerly, Sphinx did not support producing PDF via LaTeX with Greek as
332-
main language.
333-
334-
Prior to 2.0, Unicode Greek letters were escaped to use LaTeX math
335-
mark-up. This is not the case anymore, and the above must be used
336-
(only in case of ``'pdflatex'`` engine) if the source contains such
337-
Unicode Greek.
305+
- Do not use this key for a :confval:`latex_engine` other than
306+
``'pdflatex'``.
338307

339-
On Ubuntu xenial, packages ``texlive-lang-greek`` and ``cm-super``
340-
(for the latter, only if the ``'fontpkg'`` setting is left to its
341-
default) are needed for ``LGR`` to work. In place of ``cm-super``
342-
one can install smaller ``cm-super-minimal``, but it requires the
343-
LaTeX document to execute ``\usepackage[10pt]{type1ec}`` before
344-
loading ``fontenc``. Thus, use this key with this extra at its
345-
start if needed.
308+
- If Greek is main language, do not use this key. Since Sphinx 2.2.1,
309+
``xelatex`` will be used automatically as :confval:`latex_engine`.
346310

347-
Default: ``'\\usepackage[T1]{fontenc}'``
311+
- The TeX installation may need some extra packages. For example,
312+
on Ubuntu xenial, packages ``texlive-lang-greek`` and ``cm-super``
313+
are needed for ``LGR`` to work. And ``texlive-lang-cyrillic`` and
314+
``cm-super`` are needed for support of Cyrillic.
348315

349316
.. versionchanged:: 1.5
350317
Defaults to ``'\\usepackage{fontspec}'`` when
@@ -361,35 +328,40 @@ Keys that don't need to be overridden unless in special cases are:
361328

362329
.. versionchanged:: 2.0
363330
Detection of ``LGR``, ``T2A``, ``X2`` to trigger support of
364-
occasional Greek or Cyrillic (``'pdflatex'`` only, as this support
365-
is provided natively by ``'platex'`` and only requires suitable
366-
font with ``'xelatex'/'lualatex'``).
331+
occasional Greek or Cyrillic letters (``'pdflatex'``).
367332

368333
.. versionchanged:: 2.3.0
369-
``'xelatex'`` also executes
334+
``'xelatex'`` executes
370335
``\defaultfontfeatures[\rmfamily,\sffamily]{}`` in order to avoid
371336
contractions of ``--`` into en-dash or transforms of straight quotes
372337
into curly ones in PDF (in non-literal text paragraphs) despite
373338
:confval:`smartquotes` being set to ``False``.
374339

375-
``'textgreek'``
376-
This is needed for ``pdflatex`` to support Unicode input of Greek
377-
letters such as φύσις. Expert users may want to load the ``textalpha``
378-
package with its option ``normalize-symbols``.
340+
``'fontsubstitution'``
341+
Ignored if ``'fontenc'`` was not configured to use ``LGR`` or ``X2`` (or
342+
``T2A``). In case ``'fontpkg'`` key is configured for usage with some
343+
TeX fonts known to be available in the ``LGR`` or ``X2`` encodings, set
344+
this one to be the empty string. Else leave to its default.
379345

380-
.. hint::
346+
Ignored with :confval:`latex_engine` other than ``'pdflatex'``.
381347

382-
Unicode Greek (but no further Unicode symbols) in :rst:dir:`math`
383-
can be supported by ``'pdflatex'`` from setting this key to
384-
``r'\usepackage{textalpha,alphabeta}'``. Then ``:math:`α``` (U+03B1)
385-
will render as :math:`\alpha`. For wider Unicode support in math
386-
input, see the discussion of :confval:`latex_engine`.
348+
.. versionadded:: 4.0.0
387349

388-
With ``'platex'`` (Japanese), ``'xelatex'`` or ``'lualatex'``, this
389-
key is ignored.
350+
``'textgreek'``
351+
For the support of occasional Greek letters.
352+
353+
It is ignored with ``'platex'``, ``'xelatex'`` or ``'lualatex'`` as
354+
:confval:`latex_engine` and defaults to either the empty string or
355+
to ``'\\usepackage{textalpha}'`` for ``'pdflatex'`` depending on
356+
whether the ``'fontenc'`` key was used with ``LGR`` or not. Only
357+
expert LaTeX users may want to customize this key.
358+
359+
It can also be used as ``r'\usepackage{textalpha,alphabeta}'`` to let
360+
``'pdflatex'`` support Greek Unicode input in :rst:dir:`math` context.
361+
For example ``:math:`α``` (U+03B1) will render as :math:`\alpha`.
390362

391-
Default: ``'\\usepackage{textalpha}'`` or ``''`` if ``fontenc`` does not
392-
include the ``LGR`` option.
363+
For wider Unicode support in math input, see the discussion of
364+
:confval:`latex_engine`.
393365

394366
.. versionadded:: 2.0
395367

@@ -500,19 +472,25 @@ Keys that don't need to be overridden unless in special cases are:
500472
Default: ``'\\printindex'``
501473

502474
``'fvset'``
503-
Customization of ``fancyvrb`` LaTeX package. The default value of
504-
``'\\fvset{fontsize=\\small}'`` is used to adjust for the large character
505-
width of the monospace font, used in code-blocks. You may need to modify
506-
this if you use custom fonts.
475+
Customization of ``fancyvrb`` LaTeX package.
507476

508-
Default: ``'\\fvset{fontsize=\\small}'``
477+
The default value is ``'\\fvset{fontsize=auto}'`` which means that the
478+
font size will adjust correctly if a code-block ends up in a footnote.
479+
You may need to modify this if you use custom fonts:
480+
``'\\fvset{fontsize=\\small}'`` if the monospace font is Courier-like.
481+
482+
Default: ``'\\fvset{fontsize=auto}'``
509483

510484
.. versionadded:: 1.8
511485

512486
.. versionchanged:: 2.0
513-
Due to new default font choice for ``'xelatex'`` and ``'lualatex'``
514-
(FreeFont), Sphinx does ``\\fvset{fontsize=\\small}`` also with these
515-
engines (and not ``\\fvset{fontsize=auto}``).
487+
For ``'xelatex'`` and ``'lualatex'`` defaults to
488+
``'\\fvset{fontsize=\\small}'`` as this
489+
is adapted to the relative widths of the FreeFont family.
490+
491+
.. versionchanged:: 4.0.0
492+
Changed default for ``'pdflatex'``. Previously it was using
493+
``'\\fvset{fontsize=\\small}'``.
516494

517495
Keys that are set by other options and therefore should not be overridden are:
518496

doc/usage/builders/index.rst

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -179,24 +179,22 @@ The builder's "name" must be given to the **-b** command-line option of
179179

180180
* ``texlive-latex-recommended``
181181
* ``texlive-fonts-recommended``
182+
* ``tex-gyre`` (if :confval:`latex_engine` is ``'pdflatex'``)
182183
* ``texlive-latex-extra``
183184
* ``latexmk`` (this is a Sphinx requirement on GNU/Linux and MacOS X
184185
for functioning of ``make latexpdf``)
185186

186187
Additional packages are needed in some circumstances (see the discussion of
187188
the ``'fontpkg'`` key of :confval:`latex_elements` for more information):
188189

189-
* to support occasional Cyrillic letters or words, and a fortiori if
190-
:confval:`language` is set to a Cyrillic language, the package
191-
``texlive-lang-cyrillic`` is required, and, with unmodified ``'fontpkg'``,
192-
also ``cm-super`` or ``cm-super-minimal``,
193-
* to support occasional Greek letters or words (in text, not in
194-
:rst:dir:`math` directive contents), ``texlive-lang-greek`` is required,
195-
and, with unmodified ``'fontpkg'``, also ``cm-super`` or
196-
``cm-super-minimal``,
197-
* for ``'xelatex'`` or ``'lualatex'`` (see :confval:`latex_engine`),
198-
``texlive-xetex`` resp. ``texlive-luatex``, and, if leaving unchanged
199-
``'fontpkg'``, ``fonts-freefont-otf``.
190+
* ``texlive-lang-cyrillic`` for Cyrillic (even individual letters), and,
191+
``cm-super`` or ``cm-super-minimal`` (if default fonts),
192+
* ``texlive-lang-greek`` for Greek (even individual letters), and,
193+
``cm-super`` or ``cm-super-minimal`` (if default fonts),
194+
* ``texlive-xetex`` if :confval:`latex_engine` is ``'xelatex'``,
195+
* ``texlive-luatex`` if :confval:`latex_engine` is ``'lualatex'``,
196+
* ``fonts-freefont-otf`` if :confval:`latex_engine` is ``'xelatex'``
197+
or ``'lualatex'``.
200198

201199
The testing of Sphinx LaTeX is done on Ubuntu xenial whose TeX distribution
202200
is based on a TeXLive 2015 snapshot dated March 2016.
@@ -207,6 +205,9 @@ The builder's "name" must be given to the **-b** command-line option of
207205
.. versionchanged:: 2.0
208206
Formerly, testing had been done on Ubuntu trusty (TeXLive 2013).
209207

208+
.. versionchanged:: 4.0.0
209+
TeX Gyre fonts dependency for the default LaTeX font configuration.
210+
210211
.. note::
211212

212213
Since 1.6, ``make latexpdf`` uses ``latexmk`` (not on Windows). This

sphinx/builders/latex/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ def init_multilingual(self) -> None:
224224
self.context['substitutefont'] = '\\usepackage{substitutefont}'
225225
else:
226226
self.context['textgreek'] = ''
227+
if self.context['substitutefont'] == '':
228+
self.context['fontsubstitution'] = ''
227229

228230
# 'babel' key is public and user setting must be obeyed
229231
if self.context['babel']:

sphinx/builders/latex/constants.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@
1111
from typing import Any, Dict
1212

1313
PDFLATEX_DEFAULT_FONTPKG = r'''
14-
\usepackage{times}
14+
\usepackage{tgtermes}
15+
\usepackage{tgheros}
16+
\renewcommand{\ttdefault}{txtt}
17+
'''
18+
19+
PDFLATEX_DEFAULT_FONTSUBSTITUTION = r'''
1520
\expandafter\ifx\csname T@LGR\endcsname\relax
1621
\else
1722
% LGR was declared as font encoding
@@ -76,7 +81,7 @@
7681
'maxlistdepth': '',
7782
'sphinxpkgoptions': '',
7883
'sphinxsetup': '',
79-
'fvset': '\\fvset{fontsize=\\small}',
84+
'fvset': '\\fvset{fontsize=auto}',
8085
'passoptionstopackages': '',
8186
'geometry': '\\usepackage{geometry}',
8287
'inputenc': '',
@@ -88,6 +93,7 @@
8893
'babel': '\\usepackage{babel}',
8994
'polyglossia': '',
9095
'fontpkg': PDFLATEX_DEFAULT_FONTPKG,
96+
'fontsubstitution': PDFLATEX_DEFAULT_FONTSUBSTITUTION,
9197
'substitutefont': '',
9298
'textcyrillic': '',
9399
'textgreek': '\\usepackage{textalpha}',
@@ -142,6 +148,8 @@
142148
'fontenc': ('\\usepackage{fontspec}\n'
143149
'\\defaultfontfeatures[\\rmfamily,\\sffamily,\\ttfamily]{}'),
144150
'fontpkg': XELATEX_DEFAULT_FONTPKG,
151+
'fvset': '\\fvset{fontsize=\\small}',
152+
'fontsubstitution': '',
145153
'textgreek': '',
146154
'utf8extra': ('\\catcode`^^^^00a0\\active\\protected\\def^^^^00a0'
147155
'{\\leavevmode\\nobreak\\ }'),
@@ -153,6 +161,8 @@
153161
'fontenc': ('\\usepackage{fontspec}\n'
154162
'\\defaultfontfeatures[\\rmfamily,\\sffamily,\\ttfamily]{}'),
155163
'fontpkg': LUALATEX_DEFAULT_FONTPKG,
164+
'fvset': '\\fvset{fontsize=\\small}',
165+
'fontsubstitution': '',
156166
'textgreek': '',
157167
'utf8extra': ('\\catcode`^^^^00a0\\active\\protected\\def^^^^00a0'
158168
'{\\leavevmode\\nobreak\\ }'),
@@ -161,7 +171,8 @@
161171
'latex_engine': 'platex',
162172
'babel': '',
163173
'classoptions': ',dvipdfmx',
164-
'fontpkg': '\\usepackage{times}',
174+
'fontpkg': PDFLATEX_DEFAULT_FONTPKG,
175+
'fontsubstitution': '',
165176
'textgreek': '',
166177
'fncychap': '',
167178
'geometry': '\\usepackage[dvipdfm]{geometry}',
@@ -170,7 +181,8 @@
170181
'latex_engine': 'uplatex',
171182
'babel': '',
172183
'classoptions': ',dvipdfmx',
173-
'fontpkg': '\\usepackage{times}',
184+
'fontpkg': PDFLATEX_DEFAULT_FONTPKG,
185+
'fontsubstitution': '',
174186
'textgreek': '',
175187
'fncychap': '',
176188
'geometry': '\\usepackage[dvipdfm]{geometry}',

0 commit comments

Comments
 (0)