Add latexpdf support for Greek as main language (via xelatex use)

Closes: #6710
This commit is contained in:
jfbu 2019-09-30 11:52:34 +02:00
parent 59890a3b6d
commit 7be68b7c4b
6 changed files with 37 additions and 1 deletions

View File

@ -17,6 +17,7 @@ Bugs fixed
---------- ----------
* #6641: LaTeX: Undefined control sequence ``\sphinxmaketitle`` * #6641: LaTeX: Undefined control sequence ``\sphinxmaketitle``
* #6710: LaTeX not well configured for Greek language as main language
Testing Testing
-------- --------

View File

@ -289,6 +289,11 @@ into the generated ``.tex`` files. Its ``'sphinxsetup'`` key is described
.. attention:: .. attention::
If Greek is main language, do not use this key. Since Sphinx 2.2.1,
``xelatex`` will be used automatically as :confval:`latex_engine`.
Formerly, Sphinx did not support producing PDF via LaTeX with Greek as
main language.
Prior to 2.0, Unicode Greek letters were escaped to use LaTeX math Prior to 2.0, Unicode Greek letters were escaped to use LaTeX math
mark-up. This is not the case anymore, and the above must be used mark-up. This is not the case anymore, and the above must be used
(only in case of ``'pdflatex'`` engine) if the source contains such (only in case of ``'pdflatex'`` engine) if the source contains such

View File

@ -1841,7 +1841,17 @@ These options influence LaTeX output.
``'xelatex'`` or ``'lualatex'`` and making sure to use an OpenType font ``'xelatex'`` or ``'lualatex'`` and making sure to use an OpenType font
with wide-enough glyph coverage is often easier than trying to make with wide-enough glyph coverage is often easier than trying to make
``'pdflatex'`` work with the extra Unicode characters. Since Sphinx 2.0 ``'pdflatex'`` work with the extra Unicode characters. Since Sphinx 2.0
the default is the GNU FreeFont which covers well Latin, Cyrillic and Greek. the default is the GNU FreeFont which covers well Latin, Cyrillic and
Greek.
.. versionchanged:: 2.1.0
Use ``xelatex`` (and LaTeX package ``xeCJK``) by default for Chinese
documents.
.. versionchanged:: 2.2.1
Use ``xelatex`` by default for Greek documents.
Contrarily to :ref:`MathJaX math rendering in HTML output <math-support>`, Contrarily to :ref:`MathJaX math rendering in HTML output <math-support>`,
LaTeX requires some extra configuration to support Unicode literals in LaTeX requires some extra configuration to support Unicode literals in

View File

@ -418,6 +418,8 @@ def default_latex_engine(config: Config) -> str:
return 'platex' return 'platex'
elif (config.language or '').startswith('zh'): elif (config.language or '').startswith('zh'):
return 'xelatex' return 'xelatex'
elif (config.language or '') == 'el':
return 'xelatex'
else: else:
return 'pdflatex' return 'pdflatex'

View File

@ -116,6 +116,10 @@ XELATEX_DEFAULT_FONTPKG = r'''
BoldItalicFont = *BoldOblique, BoldItalicFont = *BoldOblique,
] ]
''' '''
XELATEX_GREEK_DEFAULT_FONTPKG = (XELATEX_DEFAULT_FONTPKG +
'\n\\newfontfamily\\greekfont{FreeSerif}' +
'\n\\newfontfamily\\greekfontsf{FreeSans}' +
'\n\\newfontfamily\\greekfonttt{FreeMono}')
LUALATEX_DEFAULT_FONTPKG = XELATEX_DEFAULT_FONTPKG LUALATEX_DEFAULT_FONTPKG = XELATEX_DEFAULT_FONTPKG
DEFAULT_SETTINGS = { DEFAULT_SETTINGS = {
@ -226,6 +230,9 @@ ADDITIONAL_SETTINGS = {
('xelatex', 'zh'): { ('xelatex', 'zh'): {
'fontenc': '\\usepackage{xeCJK}', 'fontenc': '\\usepackage{xeCJK}',
}, },
('xelatex', 'el'): {
'fontpkg': XELATEX_GREEK_DEFAULT_FONTPKG,
},
} # type: Dict[Any, Dict[str, Any]] } # type: Dict[Any, Dict[str, Any]]
EXTRA_RE = re.compile(r'^(.*\S)\s+\(([^()]*)\)\s*$') EXTRA_RE = re.compile(r'^(.*\S)\s+\(([^()]*)\)\s*$')

View File

@ -175,6 +175,17 @@ def test_latex_additional_settings_for_language_code(app, status, warning):
assert r'\usepackage{xeCJK}' in result assert r'\usepackage{xeCJK}' in result
@pytest.mark.sphinx('latex', testroot='basic', confoverrides={'language': 'el'})
def test_latex_additional_settings_for_greek(app, status, warning):
app.builder.build_all()
result = (app.outdir / 'test.tex').text(encoding='utf8')
print(result)
print(status.getvalue())
print(warning.getvalue())
assert '\\usepackage{polyglossia}\n\\setmainlanguage{greek}' in result
assert '\\newfontfamily\\greekfonttt{FreeMono}' in result
@pytest.mark.sphinx('latex', testroot='latex-title') @pytest.mark.sphinx('latex', testroot='latex-title')
def test_latex_title_after_admonitions(app, status, warning): def test_latex_title_after_admonitions(app, status, warning):
app.builder.build_all() app.builder.build_all()