mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #4876 from tk0miya/4717_use_correct_mainlanguage_for_polyglossia
Fix #4717: latex: Compilation for German docs failed with LuaLaTeX and XeLaTeX
This commit is contained in:
commit
a2542cad0f
1
CHANGES
1
CHANGES
@ -31,6 +31,7 @@ Bugs fixed
|
|||||||
* #4838: htmlhelp: The entries in .hhp file is not ordered
|
* #4838: htmlhelp: The entries in .hhp file is not ordered
|
||||||
* toctree directive tries to glob for URL having query_string
|
* toctree directive tries to glob for URL having query_string
|
||||||
* #4871: html search: Upper characters problem in German
|
* #4871: html search: Upper characters problem in German
|
||||||
|
* #4717: latex: Compilation for German docs failed with LuaLaTeX and XeLaTeX
|
||||||
|
|
||||||
Testing
|
Testing
|
||||||
--------
|
--------
|
||||||
|
@ -186,10 +186,11 @@ class LaTeXWriter(writers.Writer):
|
|||||||
# Helper classes
|
# Helper classes
|
||||||
|
|
||||||
class ExtBabel(Babel):
|
class ExtBabel(Babel):
|
||||||
def __init__(self, language_code):
|
def __init__(self, language_code, use_polyglossia=False):
|
||||||
# type: (unicode) -> None
|
# type: (unicode, bool) -> None
|
||||||
super(ExtBabel, self).__init__(language_code or '')
|
super(ExtBabel, self).__init__(language_code or '')
|
||||||
self.language_code = language_code
|
self.language_code = language_code
|
||||||
|
self.use_polyglossia = use_polyglossia
|
||||||
|
|
||||||
def get_shorthandoff(self):
|
def get_shorthandoff(self):
|
||||||
# type: () -> unicode
|
# type: () -> unicode
|
||||||
@ -217,11 +218,28 @@ class ExtBabel(Babel):
|
|||||||
def get_language(self):
|
def get_language(self):
|
||||||
# type: () -> unicode
|
# type: () -> unicode
|
||||||
language = super(ExtBabel, self).get_language()
|
language = super(ExtBabel, self).get_language()
|
||||||
if not language:
|
if language == 'ngerman' and self.use_polyglossia:
|
||||||
|
# polyglossia calls new orthography (Neue Rechtschreibung) as
|
||||||
|
# german (with new spelling option).
|
||||||
|
return 'german'
|
||||||
|
elif not language:
|
||||||
return 'english' # fallback to english
|
return 'english' # fallback to english
|
||||||
else:
|
else:
|
||||||
return language
|
return language
|
||||||
|
|
||||||
|
def get_mainlanguage_options(self):
|
||||||
|
# type: () -> unicode
|
||||||
|
"""Return options for polyglossia's ``\setmainlanguage``."""
|
||||||
|
language = super(ExtBabel, self).get_language()
|
||||||
|
if self.use_polyglossia is False:
|
||||||
|
return None
|
||||||
|
elif language == 'ngerman':
|
||||||
|
return 'spelling=new'
|
||||||
|
elif language == 'german':
|
||||||
|
return 'spelling=old'
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
class Table(object):
|
class Table(object):
|
||||||
"""A table data"""
|
"""A table data"""
|
||||||
@ -513,7 +531,8 @@ class LaTeXTranslator(nodes.NodeVisitor):
|
|||||||
'\\sffamily}\n\\ChTitleVar{\\Large'
|
'\\sffamily}\n\\ChTitleVar{\\Large'
|
||||||
'\\normalfont\\sffamily}')
|
'\\normalfont\\sffamily}')
|
||||||
|
|
||||||
self.babel = ExtBabel(builder.config.language)
|
self.babel = ExtBabel(builder.config.language,
|
||||||
|
not self.elements['babel'])
|
||||||
if builder.config.language and not self.babel.is_supported_language():
|
if builder.config.language and not self.babel.is_supported_language():
|
||||||
# emit warning if specified language is invalid
|
# emit warning if specified language is invalid
|
||||||
# (only emitting, nothing changed to processing)
|
# (only emitting, nothing changed to processing)
|
||||||
@ -547,8 +566,15 @@ class LaTeXTranslator(nodes.NodeVisitor):
|
|||||||
# disable fncychap in Japanese documents
|
# disable fncychap in Japanese documents
|
||||||
self.elements['fncychap'] = ''
|
self.elements['fncychap'] = ''
|
||||||
elif self.elements['polyglossia']:
|
elif self.elements['polyglossia']:
|
||||||
self.elements['multilingual'] = '%s\n\\setmainlanguage{%s}' % \
|
options = self.babel.get_mainlanguage_options()
|
||||||
(self.elements['polyglossia'], self.babel.get_language())
|
if options:
|
||||||
|
mainlanguage = r'\setmainlanguage[%s]{%s}' % (options,
|
||||||
|
self.babel.get_language())
|
||||||
|
else:
|
||||||
|
mainlanguage = r'\setmainlanguage{%s}' % self.babel.get_language()
|
||||||
|
|
||||||
|
self.elements['multilingual'] = '%s\n%s' % (self.elements['polyglossia'],
|
||||||
|
mainlanguage)
|
||||||
|
|
||||||
if getattr(builder, 'usepackages', None):
|
if getattr(builder, 'usepackages', None):
|
||||||
def declare_package(packagename, options=None):
|
def declare_package(packagename, options=None):
|
||||||
|
@ -534,6 +534,50 @@ def test_babel_with_unknown_language(app, status, warning):
|
|||||||
assert "WARNING: no Babel option known for language 'unknown'" in warning.getvalue()
|
assert "WARNING: no Babel option known for language 'unknown'" in warning.getvalue()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.sphinx(
|
||||||
|
'latex', testroot='latex-babel',
|
||||||
|
confoverrides={'language': 'de', 'latex_engine': 'lualatex'})
|
||||||
|
def test_polyglossia_with_language_de(app, status, warning):
|
||||||
|
app.builder.build_all()
|
||||||
|
result = (app.outdir / 'Python.tex').text(encoding='utf8')
|
||||||
|
print(result)
|
||||||
|
print(status.getvalue())
|
||||||
|
print(warning.getvalue())
|
||||||
|
assert '\\documentclass[letterpaper,10pt,german]{sphinxmanual}' in result
|
||||||
|
assert '\\usepackage{polyglossia}' in result
|
||||||
|
assert '\\setmainlanguage[spelling=new]{german}' in result
|
||||||
|
assert '\\usepackage{times}' not in result
|
||||||
|
assert '\\usepackage[Sonny]{fncychap}' in result
|
||||||
|
assert ('\\addto\\captionsgerman{\\renewcommand{\\contentsname}{Table of content}}\n'
|
||||||
|
in result)
|
||||||
|
assert '\\addto\\captionsgerman{\\renewcommand{\\figurename}{Fig.}}\n' in result
|
||||||
|
assert '\\addto\\captionsgerman{\\renewcommand{\\tablename}{Table.}}\n' in result
|
||||||
|
assert '\\def\\pageautorefname{Seite}\n' in result
|
||||||
|
assert '\\shorthandoff' not in result
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.sphinx(
|
||||||
|
'latex', testroot='latex-babel',
|
||||||
|
confoverrides={'language': 'de-1901', 'latex_engine': 'lualatex'})
|
||||||
|
def test_polyglossia_with_language_de_1901(app, status, warning):
|
||||||
|
app.builder.build_all()
|
||||||
|
result = (app.outdir / 'Python.tex').text(encoding='utf8')
|
||||||
|
print(result)
|
||||||
|
print(status.getvalue())
|
||||||
|
print(warning.getvalue())
|
||||||
|
assert '\\documentclass[letterpaper,10pt,german]{sphinxmanual}' in result
|
||||||
|
assert '\\usepackage{polyglossia}' in result
|
||||||
|
assert '\\setmainlanguage[spelling=old]{german}' in result
|
||||||
|
assert '\\usepackage{times}' not in result
|
||||||
|
assert '\\usepackage[Sonny]{fncychap}' in result
|
||||||
|
assert ('\\addto\\captionsgerman{\\renewcommand{\\contentsname}{Table of content}}\n'
|
||||||
|
in result)
|
||||||
|
assert '\\addto\\captionsgerman{\\renewcommand{\\figurename}{Fig.}}\n' in result
|
||||||
|
assert '\\addto\\captionsgerman{\\renewcommand{\\tablename}{Table.}}\n' in result
|
||||||
|
assert '\\def\\pageautorefname{page}\n' in result
|
||||||
|
assert '\\shorthandoff' not in result
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.sphinx('latex')
|
@pytest.mark.sphinx('latex')
|
||||||
def test_footnote(app, status, warning):
|
def test_footnote(app, status, warning):
|
||||||
app.builder.build_all()
|
app.builder.build_all()
|
||||||
|
Loading…
Reference in New Issue
Block a user