From 1edf2a45b9873ce3a137c72667078989f0aaa6b3 Mon Sep 17 00:00:00 2001 From: jfbu Date: Wed, 21 Nov 2018 18:58:58 +0100 Subject: [PATCH] LaTeX: font choices for Greek and Cyrillic support, and (Xe|Lua)LaTeX --- CHANGES | 52 ++------- doc/conf.py | 12 +- doc/usage/builders/index.rst | 46 +++++--- doc/usage/configuration.rst | 181 ++++++++++++++--------------- sphinx/templates/latex/latex.tex_t | 1 + sphinx/texinputs/sphinx.sty | 24 ---- sphinx/writers/latex.py | 81 ++++++++----- 7 files changed, 187 insertions(+), 210 deletions(-) diff --git a/CHANGES b/CHANGES index 70a81d93f..cd330a70b 100644 --- a/CHANGES +++ b/CHANGES @@ -5,43 +5,16 @@ Dependencies ------------ * LaTeX builder now depends on TeX Live 2015 or above. -* LaTeX builder may need these additional LaTeX packages for PDF builds - (with ``'pdflatex'`` :confval:`latex_engine`): - - .. list-table:: Requirements - :header-rows: 1 - - * - LaTeX package (CTAN) - - Ubuntu xenial - - needed for - * - substitutefont - - texlive-latex-extra - - Greek or Cyrillic letters (in non-Cyrillic documents) - * - textalpha - - texlive-lang-greek - - Greek letters (in text, not math) - * - gfsartemisia - - fonts-gfs-artemisia (texlive-fonts-extra) - - Greek letters (in text, not math) - * - gfsneohellenic - - fonts-gfs-neohellenic (texlive-fonts-extra) - - Greek letters (in text, not math) - * - cbfonts - - texlive-lang-greek - - Greek letters (in text, not math) - * - cm-lgc - - texlive-fonts-extra - - Cyrillic letters (in non-Cyrillic documents) - - These extra package are not required by default. The first two are needed if - the :confval:`latex_elements`.\ ``'fontenc'`` key has been modify to declare - the use of the ``LGR`` (Greek) and/or ``T2A`` (Cyrillic) font encoding. Even - then, the last four are font packages arising in the default value for - :confval:`latex_elements`.\ ``'fontpkg'``, and may be replaced by other font - packages providing ``LGR`` and/or ``T2A`` support. +* LaTeX builder (with ``'pdflatex'`` :confval:`latex_engine`) will process + Unicode Greek letters in text (not in math mark-up) via the text font and + will not escape them to math mark-up. See the discussion of the + ``'fontenc'`` key of :confval:`latex_elements`; such (optional) support for + Greek adds, for example on Ubuntu xenial, the ``texlive-lang-greek`` and (if + default font set-up is not modified) ``cm-super(-minimal)`` as additional + Sphinx LaTeX requirements. * LaTeX builder with :confval:`latex_engine` set to ``'xelatex'`` or to - ``'lualatex'`` requires (by default) the ``Computer Modern Unicode`` fonts, - which in Ubuntu xenial are in ``texlive-fonts-extra``. + ``'lualatex'`` requires (by default) the ``FreeFont`` fonts, + which in Ubuntu xenial are provided by package ``fonts-freefont-otf``. Incompatible changes -------------------- @@ -53,10 +26,9 @@ Incompatible changes * LaTeX: Move message resources to ``sphinxmessage.sty`` * LaTeX: Stop using ``\captions`` macro for some labels * LaTeX: Greek letters in text are not escaped to math mode mark-up, and they - will use the text font not the math font. If (and only if) the document - contains such Greek Unicode letters *and* the :confval:`latex_engine` is - ``'pdflatex'`` then the :confval:`latex_elements`.\ ``'fontenc'`` key - **must** be used to declare usage of the ``LGR`` font encoding. + will use the text font not the math font. The ``LGR`` font encoding must be + added to the ``'fontenc'`` key of :confval:`latex_elements` for this to work + (only if it is needed by the document, of course). Deprecated ---------- diff --git a/doc/conf.py b/doc/conf.py index 661efb434..8d0762b45 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -56,17 +56,17 @@ latex_documents = [('contents', 'sphinx.tex', 'Sphinx Documentation', 'Georg Brandl', 'manual', 1)] latex_logo = '_static/sphinx.png' latex_elements = { - 'fontenc': r'\usepackage[LGR,T2A,T1]{fontenc}', + 'fontenc': r'\usepackage[LGR,X2,T1]{fontenc}', 'fontpkg': r''' \usepackage[sc]{mathpazo} \usepackage[scaled]{helvet} \usepackage{courier} -\substitutefont{LGR}{\rmdefault}{udidot} -\substitutefont{LGR}{\sfdefault}{neohellenic} +\substitutefont{LGR}{\rmdefault}{cmr} +\substitutefont{LGR}{\sfdefault}{cmss} \substitutefont{LGR}{\ttdefault}{cmtt} -\substitutefont{T2A}{\rmdefault}{fcm} -\substitutefont{T2A}{\sfdefault}{fcs} -\substitutefont{T2A}{\ttdefault}{fct} +\substitutefont{X2}{\rmdefault}{cmr} +\substitutefont{X2}{\sfdefault}{cmss} +\substitutefont{X2}{\ttdefault}{cmtt} ''', 'passoptionstopackages': '\\PassOptionsToPackage{svgnames}{xcolor}', 'preamble': '\\DeclareUnicodeCharacter{229E}{\\ensuremath{\\boxplus}}', diff --git a/doc/usage/builders/index.rst b/doc/usage/builders/index.rst index aa4aba76a..b9e107699 100644 --- a/doc/usage/builders/index.rst +++ b/doc/usage/builders/index.rst @@ -158,20 +158,34 @@ The builder's "name" must be given to the **-b** command-line option of chapter :ref:`latex-options` for details. The produced LaTeX file uses several LaTeX packages that may not be present - in a "minimal" TeX distribution installation. For example, on Ubuntu, the - following packages need to be installed for successful PDF builds: + in a "minimal" TeX distribution installation. + + On Ubuntu xenial, the following packages need to be installed for + successful PDF builds: * ``texlive-latex-recommended`` * ``texlive-fonts-recommended`` * ``texlive-latex-extra`` - * ``texlive-fonts-extra``, ``texlive-lang-greek`` (if needed to - support Greek or Cyrillic letters in non-cyrillic document) - * ``latexmk`` (for ``make latexpdf`` on GNU/Linux and MacOS X) - * ``texlive-luatex``, ``texlive-xetex``, ``texlive-fonts-extra`` - (if :confval:`latex_engine` is set to ``'xelatex'`` or ``'lualatex'``) + * ``latexmk`` (this is a Sphinx requirement on GNU/Linux and MacOS X + for functioning of ``make latexpdf``) - The testing of Sphinx LaTeX is done on Ubuntu xenial with the above mentioned - packages, which are from a TeXLive 2015 snapshot dated March 2016. + Additional packages are needed in some circumstances (see the discussion of + the ``'fontpkg'`` key of :confval:`latex_elements` for more information): + + * to support occasional Cyrillic letters or words, and a fortiori if + :confval:`language` is set to a Cyrillic language, the package + ``texlive-lang-cyrillic`` is required, and, with unmodified ``'fontpkg'``, + also ``cm-super`` or ``cm-super-minimal``, + * to support occasional Greek letters or words (in text, not in + :rst:dir:`math` directive contents), ``texlive-lang-greek`` is required, + and, with unmodified ``'fontpkg'``, also ``cm-super`` or + ``cm-super-minimal``, + * for ``'xelatex'`` or ``'lualatex'`` (see :confval:`latex_engine`), + ``texlive-xetex`` resp. ``texlive-luatex``, and, if leaving unchanged + ``'fontpkg'``, ``fonts-freefont-otf``. + + The testing of Sphinx LaTeX is done on Ubuntu xenial whose TeX distribution + is based on a TeXLive 2015 snapshot dated March 2016. .. versionchanged:: 1.6 Formerly, testing had been done on Ubuntu precise (TeXLive 2009). @@ -194,20 +208,16 @@ The builder's "name" must be given to the **-b** command-line option of reduces console output to a minimum. - Also, if ``latexmk`` version is 4.52b or higher (Jan 17) - ``LATEXMKOPTS="-xelatex"`` will speed up PDF builds via XeLateX in case + Also, if ``latexmk`` is at version 4.52b or higher (January 2017) + ``LATEXMKOPTS="-xelatex"`` speeds up PDF builds via XeLateX in case of numerous graphics inclusions. - .. code-block:: console - - make latexpdf LATEXMKOPTS="-xelatex" - - To pass options directly to the ``(pdf|xe|lua)latex`` executable, use - variable ``LATEXOPTS``. + To pass options directly to the ``(pdf|xe|lua)latex`` binary, use + variable ``LATEXOPTS``, for example: .. code-block:: console - make latexpdf LATEXOPTS="--interaction=nonstopmode" + make latexpdf LATEXOPTS="--halt-on-error" .. autoattribute:: name diff --git a/doc/usage/configuration.rst b/doc/usage/configuration.rst index 765431fe2..d133bbfe1 100644 --- a/doc/usage/configuration.rst +++ b/doc/usage/configuration.rst @@ -1796,42 +1796,18 @@ information. * ``'lualatex'`` -- LuaLaTeX * ``'platex'`` -- pLaTeX (default if :confval:`language` is ``'ja'``) - PDFLaTeX's support for Unicode characters covers those from the document - language (the LaTeX ``babel`` and ``inputenc`` packages map them to glyph - slots in the document font, at various encodings allowing each only 256 - characters; Sphinx uses by default (except for Cyrillic languages) the - ``times`` package), but stray characters from other scripts or special - symbols may require adding extra LaTeX packages or macros to the LaTeX - preamble. + ``'pdflatex'``\ 's support for Unicode characters is limited. - If your project uses such extra Unicode characters, switching the engine to - XeLaTeX or LuaLaTeX and setting up the document to use an OpenType font - with wide-enough glyph coverage is often easier than sticking with PDFLaTeX - and trying to get it to work with the Unicode characters. + If your project uses Unicode characters, setting the engine to + ``'xelatex'`` or ``'lualatex'`` and making sure to use an OpenType font + with wide-enough glyph coverage (since Sphinx 2.0, the default font is the + FreeFont family) is often easier than trying to make + ``'pdflatex'`` work with the extra Unicode characters. - The :confval:`latex_elements` ``'fontpkg'`` key allows to set up the - document fonts, see :ref:`this example `. Currently, for - XeLaTeX and LuaLaTeX, Sphinx leaves this key empty and LaTeX then defaults - to the `Latin Modern`_ font family (from the TeX distribution fonts). This - font family provides good coverage of Latin scripts (European languages, - Vietnamese) but Cyrillic requires some other OpenType font; for example - Computer Modern Unicode (see `babel-russian`_ documentation on how to load - it in the LaTeX document). In future, it is planned Sphinx will provide - another default choice of OpenType font than `Latin Modern`_, perhaps - `Libertinus`_, which is included in recent TeX distributions and supports - Latin and Cyrillic and also has an accompanying math font. + .. note:: - With XeLaTeX and LuaLaTeX, Sphinx configures the LaTeX document to use - `polyglossia`_. For some languages the `babel`_ support appears - preferable; Sphinx uses currently `babel`_ for French and perhaps will also - for some more languages in future. One can use the - :confval:`latex_elements` ``'babel'`` key to override Sphinx's default. - - .. _`Latin Modern`: http://www.gust.org.pl/projects/e-foundry/latin-modern - .. _`polyglossia`: https://ctan.org/pkg/polyglossia - .. _`babel`: https://ctan.org/pkg/babel - .. _`babel-russian`: https://ctan.org/pkg/babel-russian - .. _`Libertinus`: https://ctan.org/pkg/libertinus + 2.0 adds to ``'pdflatex'`` automatic support in Latin language document + of occasional Cyrillic or Greek letters or words. .. confval:: latex_documents @@ -2033,6 +2009,20 @@ information. ``english`` is used if no language.) For Japanese documents, the default is the empty string. + With XeLaTeX and LuaLaTeX, Sphinx configures the LaTeX document to use + `polyglossia`_, but one should be aware that current `babel`_ has + improved its support for Unicode engines in recent years and for some + languages it may make sense to prefer ``babel`` over ``polyglossia``. + + .. hint:: + + After modifiying a core LaTeX key like this one, clean up the LaTeX + build repertory before next PDF build, else left-over auxiliary + files are likely to break the build. + + .. _`polyglossia`: https://ctan.org/pkg/polyglossia + .. _`babel`: https://ctan.org/pkg/babel + .. versionchanged:: 1.5 For :confval:`latex_engine` set to ``'xelatex'``, the default is ``'\\usepackage{polyglossia}\n\\setmainlanguage{}'``. @@ -2060,28 +2050,38 @@ information. .. code-block:: latex - \substitutefont{LGR}{\rmdefault}{artemisia} - \substitutefont{LGR}{\sfdefault}{neohellenic} + \substitutefont{LGR}{\rmdefault}{cmr} + \substitutefont{LGR}{\sfdefault}{cmss} \substitutefont{LGR}{\ttdefault}{cmtt} - \substitutefont{T2A}{\rmdefault}{fcm} - \substitutefont{T2A}{\sfdefault}{fcs} - \substitutefont{T2A}{\ttdefault}{fct} + \substitutefont{X2}{\rmdefault}{cmr} + \substitutefont{X2}{\sfdefault}{cmss} + \substitutefont{X2}{\ttdefault}{cmtt} - For this however, the ``'fontenc'`` key must be used to tell - LaTeX to load the ``LGR`` (Greek) or ``T2A`` (partial Cyrillic) - font encoding. If ``'fontenc'`` is not modified the above lines - are not executed. + but this is activated only under the condition that the + ``'fontenc'`` key is configured to load the ``LGR`` (Greek) + and/or ``X2`` (Cyrillic) pdflatex-font encodings (if the + :confval:`language` is set to a Cyrillic language, this + ``'fontpkg'`` key must be used as "times" package has no direct + support for it; then keep only ``LGR`` lines from the above, + if support is needed for Greek in the text). - In a custom ``'fontpkg'`` setting, do not use ``\substitutefont`` - with a font encoding not also declared via ``'fontenc'``. + The ``\substitutefont`` command is from the eponymous LaTeX + package, which is loaded by Sphinx if needed (on Ubuntu xenial it + is part of ``texlive-latex-extra`` which is a Sphinx + requirement). - - For ``'xelatex'`` and ``'lualatex'``, the default is - ``'\\setmainfont{CMU Serif}'`` (and similar for sans - serif and monospace) . This OpenType font family supports - both Cyrillic and Greek scripts (contrarily to the - default font configured by LaTeX for ``xelatex/lualatex`` - if ``'fontpkg'`` is left to empty string, as was the case - prior to 2.0). + Only if the document actually does contain Unicode Greek letters + (in text) or Cyrillic letters, will the above default set-up + cause additional requirements for the PDF build. On Ubuntu + xenial, ``texlive-lang-greek``, ``texlive-lang-cyrillic``, and + (with the above choice of fonts) the ``cm-super`` (or + ``cm-super-minimal``) package. + + - For ``'xelatex'`` and ``'lualatex'``, the default is to + use the FreeFont family: this OpenType font family + supports both Cyrillic and Greek scripts and is available as + separate Ubuntu xenial package ``fonts-freefont-otf``, it is not + needed to install the big package ``texlive-fonts-extra``. - ``'platex'`` (Japanese documents) engine supports individual Cyrillic and Greek letters with no need of extra user set-up. @@ -2164,24 +2164,45 @@ information. "fontenc" package inclusion, defaults to ``'\\usepackage[T1]{fontenc}'``. + One can (``'pdflatex'`` only) add ``LGR`` for support of Greek letters + or words in the document, and ``X2`` (or ``T2A``) for Cyrillic ones: + + .. code-block:: latex + + r'\usepackage[LGR,X2,T1]{fontenc}' + + (A Cyrillic document will naturally use ``T2A`` or ``X2`` in last + position, as it has then to be the main encoding for the document + fonts). + + .. attention:: + + Prior to 2.0, Unicode Greek letters were escaped to use LaTeX math + mark-up. This is not the case anymore, thus if such Greek letters + are used in the text (we are not discussing here Greek letters + using the math font, from math markup ``\alpha`` etc...) it is then + mandatory to declare the ``LGR`` font encoding, i.e. + ``r'\usepackage[LGR,T1]{fontenc}'`` if no support for Cyrillic is + needed. On Ubuntu xenial, package ``texlive-lang-greek`` is then + required (and also ``cm-super`` if the ``'fontpkg'`` setting is not + modified). + + .. hint:: + + Ubuntu package ``cm-super-minimal`` requires that the LaTeX + document executes ``\usepackage[10pt]{type1ec}`` before loading + ``fontenc``. Thus, use this key with this extra at its start. + .. versionchanged:: 1.5 Defaults to ``'\\usepackage{fontspec}'`` when :confval:`latex_engine` is ``'xelatex'``. .. versionchanged:: 1.6 ``'lualatex'`` also uses ``fontspec`` per default. .. versionchanged:: 2.0 - With ``'pdflatex'`` you can add ``LGR`` and/or ``T2A`` - (before ``T1`` which should remain the last) to trigger - automatic support of occasional Greek and Cyrillic letters - in text. - - .. attention:: - - Prior to 2.0, Unicode Greek letters were escaped to use LaTeX - math mark-up. This is not the case anymore so it may be needed - to modify this key into ``'\\usepackage[LGR,T1]{fontenc}'`` and - also to make sure to have the suitable Greek font packages - as listed in :doc:`../changes` (or replacements). + Detection of ``LGR``, ``T2A``, ``X2`` to trigger support of + occasional Greek or Cyrillic (``'pdflatex'`` only, as this support + is provided natively by ``'platex'`` and only requires suitable + font with ``'xelatex'/'lualatex'``). ``'textgreek'`` The default (``'pdflatex'`` only) is @@ -2190,41 +2211,13 @@ information. value will be forced to be empty string. This is needed for ``pdfLaTeX`` to support Unicode input of Greek - letters such as φύσις. Expert users may want to load the ``textalpha`` + letters such as φύσις. Expert users may want to load the ``textalpha`` package with its option ``normalize-symbols``. - .. note:: - - - Unicode Greek letters in text were, prior to release 2.0, escaped - to LaTeX math markup in the produced LaTeX file, hence their - rendering in PDF used the math font. They are now copied over - unmodified to the LaTeX file and rendered in PDF by the text - font. But the ``LGR`` font encoding must be loaded. - - - Unicode Greek letters are not accepted in :rst:dir:`math` - contents. LaTeX math mark-up ``\alpha`` etc..., must be used - there. - - - With ``'xelatex'`` or ``'lualatex'``, this is ignored as the - support for Unicode Greek letters comes from using an OpenType - font which supports the Greek script. This is the case (since - 2.0) with the default fonts used by Sphinx for these engines. - - Besides, Unicode input in math (not only Greek symbols) can be - obtained by adding ``\usepackage{unicode-math}`` to the LaTeX - preamble (and perhaps use ``\setmathfont`` to switch to some - other OpenMath font than the XeLaTeX default). Then one can use - ``:math:`α=\alpha``` input. But take note that - ``\usepackage[math-style=literal]{unicode-math}`` is needed to - obtain in PDF similar output as in HTML+MathJaX, i.e. the ``α`` - remains upright, and the ``\alpha`` gives an italic letter. - - - With ``platex`` (Japanese), this key setting is ignored: - Greek (and Cyrillic) letters are handled natively by the engine - own default fonts. + With ``'platex'`` (Japanese), ``'xelatex'`` or ``'lualatex'``, this + key is ignored. .. versionadded:: 2.0 - ``'geometry'`` "geometry" package inclusion, the default definition is: diff --git a/sphinx/templates/latex/latex.tex_t b/sphinx/templates/latex/latex.tex_t index 06b94b0f2..c6586d6b7 100644 --- a/sphinx/templates/latex/latex.tex_t +++ b/sphinx/templates/latex/latex.tex_t @@ -27,6 +27,7 @@ <%= amsmath %> <%= multilingual %> <%= substitutefont %> +<%= textcyrillic %> <%= fontpkg %> <%= textgreek %> <%= fncychap %> diff --git a/sphinx/texinputs/sphinx.sty b/sphinx/texinputs/sphinx.sty index 5aa1d586a..249f2ece0 100644 --- a/sphinx/texinputs/sphinx.sty +++ b/sphinx/texinputs/sphinx.sty @@ -247,8 +247,6 @@ \DeclareStringOption[\inv@mag in]{vmargin} \DeclareStringOption[.5\dimexpr\inv@mag in\relax]{marginpar} \fi -% Allow Cyrillic letters in non-Cyrillic document (needed for pdflatex only) -\DeclareBoolOption[false]{cyrnocyr} \DeclareStringOption[0]{maxlistdepth}% \newcommand*\spx@opt@maxlistdepth{0} \DeclareStringOption[-1]{numfigreset} @@ -363,28 +361,6 @@ \newcommand\sphinxsetup[1]{\setkeys{sphinx}{#1}} -%% CYRILLIC IN NON-CYRILLIC DOCUMENTS (pdflatex only) -% -% refs: https://tex.stackexchange.com/q/460271/4686 -% -\ifspx@opt@cyrnocyr - \@tfor\@tempa:=% - {ae}{a}{b}{chrdsc}{chvcrs}{ch}{c}{dje}{dze}{dzhe}{d}{erev}{ery}{e}% - {f}{ghcrs}{gup}{g}{hdsc}{hrdsn}{h}{ie}{ii}{ishrt}{i}{je}% - {kbeak}{kdsc}{kvcrs}{k}{lje}{l}{m}{ndsc}{ng}{nje}{n}{otld}{o}{p}{r}% - {schwa}{sdsc}{sftsn}{shch}{shha}{sh}{s}{tshe}{t}{ushrt}{u}{v}% - {ya}{yhcrs}{yi}{yo}{yu}{y}{zdsc}{zhdsc}{zh}{z}\do - {% - \expandafter\DeclareTextSymbolDefault\expandafter - {\csname cyr\@tempa\endcsname}{T2A}% - \expandafter\uppercase\expandafter{\expandafter - \def\expandafter\@tempa\expandafter{\@tempa}}% - \expandafter\DeclareTextSymbolDefault\expandafter - {\csname CYR\@tempa\endcsname}{T2A}% - }% - \DeclareTextSymbolDefault{\CYRpalochka}{T2A}% -\fi - %% MAXLISTDEPTH % % remove LaTeX's cap on nesting depth if 'maxlistdepth' key used. diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index aa80d0776..e494c7e4f 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -64,23 +64,54 @@ ENUMERATE_LIST_STYLE = defaultdict(lambda: r'\arabic', 'lowerroman': r'\roman', 'upperroman': r'\Roman', }) # type: Dict[unicode, unicode] -PDFLATEX_DEFAULT_FONT_PKG = r''' +PDFLATEX_DEFAULT_FONTPKG = r''' \usepackage{times} \expandafter\ifx\csname T@LGR\endcsname\relax \else % LGR was declared as font encoding - \substitutefont{LGR}{\rmdefault}{artemisia} % gfsartemisia - \substitutefont{LGR}{\sfdefault}{neohellenic} % gfsneohellenic - \substitutefont{LGR}{\ttdefault}{cmtt} % cbfonts + \substitutefont{LGR}{\rmdefault}{cmr} + \substitutefont{LGR}{\sfdefault}{cmss} + \substitutefont{LGR}{\ttdefault}{cmtt} \fi -\expandafter\ifx\csname T@T2A\endcsname\relax +\expandafter\ifx\csname T@X2\endcsname\relax + \expandafter\ifx\csname T@T2A\endcsname\relax + \else + % T2A was declared as font encoding + \substitutefont{T2A}{\rmdefault}{cmr} + \substitutefont{T2A}{\sfdefault}{cmss} + \substitutefont{T2A}{\ttdefault}{cmtt} + \fi \else -% T2A was declared as font encoding - \substitutefont{T2A}{\rmdefault}{fcm} - \substitutefont{T2A}{\sfdefault}{fcs} - \substitutefont{T2A}{\ttdefault}{fct} +% X2 was declared as font encoding + \substitutefont{X2}{\rmdefault}{cmr} + \substitutefont{X2}{\sfdefault}{cmss} + \substitutefont{X2}{\ttdefault}{cmtt} \fi ''' +XELATEX_DEFAULT_FONTPKG = r''' +\setmainfont{FreeSerif}[ + Extension = .otf, + UprightFont = *, + ItalicFont = *Italic, + BoldFont = *Bold, + BoldItalicFont = *BoldItalic +] +\setsansfont{FreeSans}[ + Extension = .otf, + UprightFont = *, + ItalicFont = *Oblique, + BoldFont = *Bold, + BoldItalicFont = *BoldOblique, +] +\setmonofont{FreeMono}[ + Extension = .otf, + UprightFont = *, + ItalicFont = *Oblique, + BoldFont = *Bold, + BoldItalicFont = *BoldOblique, +] +''' +LUALATEX_DEFAULT_FONTPKG = XELATEX_DEFAULT_FONTPKG DEFAULT_SETTINGS = { 'latex_engine': 'pdflatex', @@ -103,8 +134,9 @@ DEFAULT_SETTINGS = { 'multilingual': '', 'babel': '\\usepackage{babel}', 'polyglossia': '', - 'fontpkg': PDFLATEX_DEFAULT_FONT_PKG, + 'fontpkg': PDFLATEX_DEFAULT_FONTPKG, 'substitutefont': '', + 'textcyrillic': '', 'textgreek': '\\usepackage{textalpha}', 'fncychap': '\\usepackage[Bjarne]{fncychap}', 'hyperref': ('% Include hyperref last.\n' @@ -158,18 +190,7 @@ ADDITIONAL_SETTINGS = { 'polyglossia': '\\usepackage{polyglossia}', 'babel': '', 'fontenc': '\\usepackage{fontspec}', - 'fontpkg': ('\\setmainfont{cmunrm.otf}[\n' - ' BoldFont = cmunbx.otf,\n' - ' ItalicFont = cmunti.otf,\n' - ' BoldItalicFont = cmunbi.otf]\n' - '\\setsansfont{cmunss.otf}[\n' - ' BoldFont = cmunsx.otf,\n' - ' ItalicFont = cmunsi.otf,\n' - ' BoldItalicFont = cmunso.otf]\n' - '\\setmonofont{cmuntt.otf}[\n' - ' BoldFont = cmuntb.otf,\n' - ' ItalicFont = cmunit.otf,\n' - ' BoldItalicFont = cmuntx.otf]'), + 'fontpkg': XELATEX_DEFAULT_FONTPKG, 'textgreek': '', 'utf8extra': ('\\catcode`^^^^00a0\\active\\protected\\def^^^^00a0' '{\\leavevmode\\nobreak\\ }'), @@ -180,9 +201,7 @@ ADDITIONAL_SETTINGS = { 'polyglossia': '\\usepackage{polyglossia}', 'babel': '', 'fontenc': '\\usepackage{fontspec}', - 'fontpkg': ('\\setmainfont{CMU Serif}\n' - '\\setsansfont{CMU Sans Serif}\n' - '\\setmonofont{CMU Typewriter Text}'), + 'fontpkg': LUALATEX_DEFAULT_FONTPKG, 'textgreek': '', 'utf8extra': ('\\catcode`^^^^00a0\\active\\protected\\def^^^^00a0' '{\\leavevmode\\nobreak\\ }'), @@ -585,9 +604,15 @@ class LaTeXTranslator(nodes.NodeVisitor): # set up multilingual module... if self.elements['latex_engine'] == 'pdflatex': - if 'T2A' in self.elements['fontenc'] and not self.babel.uses_cyrillic(): - self.elements['substitutefont'] = '\\usepackage{substitutefont}' - self.elements['sphinxpkgoptions'] += ',cyrnocyr' + if not self.babel.uses_cyrillic(): + if 'X2' in self.elements['fontenc']: + self.elements['substitutefont'] = '\\usepackage{substitutefont}' + self.elements['textcyrillic'] = ('\\usepackage[Xtwo]' + '{sphinxcyrillic}') + elif 'T2A' in self.elements['fontenc']: + self.elements['substitutefont'] = '\\usepackage{substitutefont}' + self.elements['textcyrillic'] = ('\\usepackage[TtwoA]' + '{sphinxcyrillic}') if 'LGR' in self.elements['fontenc']: self.elements['substitutefont'] = '\\usepackage{substitutefont}' else: