From 24cecfd0bc4bc3e9910d09e8bd1326cbff41e525 Mon Sep 17 00:00:00 2001 From: jfbu Date: Tue, 5 Jun 2018 09:56:36 +0200 Subject: [PATCH 1/4] LaTeX: update list of language codes with " active cf docutils.writers.latex2e and LaTeX babel package main documentation, section \babelshorthand which gives a list of shorthands used per language. --- sphinx/writers/latex.py | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index bd88ca842..84c80ccda 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -201,9 +201,36 @@ class ExtBabel(Babel): def get_shorthandoff(self): # type: () -> unicode shortlang = self.language.split('_')[0] - if shortlang in ('de', 'ngerman', 'sl', 'slovene', 'pt', 'portuges', - 'es', 'spanish', 'nl', 'dutch', 'pl', 'polish', 'it', - 'italian', 'pt-BR', 'brazil'): + if shortlang in ('br', 'breton', + 'bg', 'bulgarian', + 'ca', 'catalan', + 'cs', 'czech', + 'da', 'danish', + 'de', 'ngerman', + 'de-1901', 'german', + 'de-AT', 'naustrian', + 'de-AT-1901', 'austrian', + 'es', 'spanish', + 'et', 'estonian', + 'eu', 'basque', + 'hsb', 'uppersorbian', + 'gl', 'galician', + 'is', 'icelandic', + 'it', 'italian', + 'fi', 'finnish', + 'nn', 'nynorsk', + 'no', 'norsk', + 'nl', 'dutch', + 'pl', 'polish', + 'pt', 'pt-PT', 'portuges', + 'pt-BR', 'brazil', + 'ru', 'russian', + 'sh-Latn', 'serbian', + 'sk', 'slovak', + 'sl', 'slovene', + 'sq', 'albanian', + 'sv', 'swedish', + 'uk', 'ukrainian'): return '\\ifnum\\catcode`\\"=\\active\\shorthandoff{"}\\fi' elif shortlang in ('tr', 'turkish'): # memo: if ever Sphinx starts supporting 'Latin', do as for Turkish From 66741b1ee9040d7f4d30e4ee5f79e87b2d2a3074 Mon Sep 17 00:00:00 2001 From: jfbu Date: Tue, 5 Jun 2018 10:08:40 +0200 Subject: [PATCH 2/4] LaTeX: make deactivation of = and " systematic This avoids maintaining list of languages making " (or worse =) active TeX characters. --- sphinx/writers/latex.py | 41 +++++---------------------------------- tests/test_build_latex.py | 4 ++-- 2 files changed, 7 insertions(+), 38 deletions(-) diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index 84c80ccda..0e5462ea2 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -200,42 +200,10 @@ class ExtBabel(Babel): def get_shorthandoff(self): # type: () -> unicode - shortlang = self.language.split('_')[0] - if shortlang in ('br', 'breton', - 'bg', 'bulgarian', - 'ca', 'catalan', - 'cs', 'czech', - 'da', 'danish', - 'de', 'ngerman', - 'de-1901', 'german', - 'de-AT', 'naustrian', - 'de-AT-1901', 'austrian', - 'es', 'spanish', - 'et', 'estonian', - 'eu', 'basque', - 'hsb', 'uppersorbian', - 'gl', 'galician', - 'is', 'icelandic', - 'it', 'italian', - 'fi', 'finnish', - 'nn', 'nynorsk', - 'no', 'norsk', - 'nl', 'dutch', - 'pl', 'polish', - 'pt', 'pt-PT', 'portuges', - 'pt-BR', 'brazil', - 'ru', 'russian', - 'sh-Latn', 'serbian', - 'sk', 'slovak', - 'sl', 'slovene', - 'sq', 'albanian', - 'sv', 'swedish', - 'uk', 'ukrainian'): - return '\\ifnum\\catcode`\\"=\\active\\shorthandoff{"}\\fi' - elif shortlang in ('tr', 'turkish'): - # memo: if ever Sphinx starts supporting 'Latin', do as for Turkish - return '\\ifnum\\catcode`\\=\\string=\\active\\shorthandoff{=}\\fi' - return '' + return ('\\ifdefined\\shorthandoff\n' + ' \\ifnum\\catcode`\\=\\string=\\active\\shorthandoff{=}\\fi\n' + ' \\ifnum\\catcode`\\"=\\active\\shorthandoff{"}\\fi\n' + '\\fi') def uses_cyrillic(self): # type: () -> bool @@ -595,6 +563,7 @@ class LaTeXTranslator(nodes.NodeVisitor): self.elements['classoptions'] = ',dvipdfmx' # disable babel which has not publishing quality in Japanese self.elements['babel'] = '' + self.elements['shorthandoff'] = '' self.elements['multilingual'] = '' # disable fncychap in Japanese documents self.elements['fncychap'] = '' diff --git a/tests/test_build_latex.py b/tests/test_build_latex.py index 96ae14089..68704d9a3 100644 --- a/tests/test_build_latex.py +++ b/tests/test_build_latex.py @@ -467,7 +467,7 @@ def test_babel_with_language_ru(app, status, warning): assert '\\addto\\captionsrussian{\\renewcommand{\\tablename}{Table.}}\n' in result assert (u'\\addto\\extrasrussian{\\def\\pageautorefname' u'{\u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430}}\n' in result) - assert '\\shorthandoff' not in result + assert '\\shorthandoff' in result @pytest.mark.sphinx( @@ -529,7 +529,7 @@ def test_babel_with_unknown_language(app, status, warning): assert '\\addto\\captionsenglish{\\renewcommand{\\figurename}{Fig.}}\n' in result assert '\\addto\\captionsenglish{\\renewcommand{\\tablename}{Table.}}\n' in result assert '\\addto\\extrasenglish{\\def\\pageautorefname{page}}\n' in result - assert '\\shorthandoff' not in result + assert '\\shorthandoff' in result assert "WARNING: no Babel option known for language 'unknown'" in warning.getvalue() From 88cbd6a5975ce089de9f85b9bec3820aad9b37f7 Mon Sep 17 00:00:00 2001 From: jfbu Date: Tue, 5 Jun 2018 18:43:19 +0200 Subject: [PATCH 3/4] Update CHANGES for PR #5040 --- CHANGES | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES b/CHANGES index bca34a529..d8f7b4b1b 100644 --- a/CHANGES +++ b/CHANGES @@ -16,6 +16,8 @@ Features added Bugs fixed ---------- +* #5037: LaTeX ``\sphinxupquote{}`` breaks in Russian + Testing -------- From fb41dcefab5e00ab8022f543bfc84f111b7a38b5 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Fri, 1 Jun 2018 14:39:43 +0900 Subject: [PATCH 4/4] Fix sphinx.testing uses deprecated pytest API; Node.get_marker(name) --- CHANGES | 1 + sphinx/testing/fixtures.py | 10 ++++++++-- tests/test_ext_apidoc.py | 5 ++++- tests/test_setup_command.py | 5 ++++- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/CHANGES b/CHANGES index d8f7b4b1b..0c049318d 100644 --- a/CHANGES +++ b/CHANGES @@ -17,6 +17,7 @@ Bugs fixed ---------- * #5037: LaTeX ``\sphinxupquote{}`` breaks in Russian +* sphinx.testing uses deprecated pytest API; ``Node.get_marker(name)`` Testing -------- diff --git a/sphinx/testing/fixtures.py b/sphinx/testing/fixtures.py index be0037b70..741dbb353 100644 --- a/sphinx/testing/fixtures.py +++ b/sphinx/testing/fixtures.py @@ -39,7 +39,10 @@ def app_params(request, test_params, shared_result, sphinx_test_tempdir, rootdir # ##### process pytest.mark.sphinx - markers = request.node.get_marker("sphinx") + if hasattr(request.node, 'iter_markers'): # pytest-3.6.0 or newer + markers = request.node.iter_markers("sphinx") + else: + markers = request.node.get_marker("sphinx") pargs = {} kwargs = {} # type: Dict[str, str] @@ -86,7 +89,10 @@ def test_params(request): have same 'shared_result' value. **NOTE**: You can not specify shared_result and srcdir in same time. """ - env = request.node.get_marker('test_params') + if hasattr(request.node, 'get_closest_marker'): # pytest-3.6.0 or newer + env = request.node.get_closest_marker('test_params') + else: + env = request.node.get_marker('test_params') kwargs = env.kwargs if env else {} result = { 'shared_result': None, diff --git a/tests/test_ext_apidoc.py b/tests/test_ext_apidoc.py index d3d61d1e0..8c81a6e12 100644 --- a/tests/test_ext_apidoc.py +++ b/tests/test_ext_apidoc.py @@ -32,7 +32,10 @@ def apidoc(rootdir, tempdir, apidoc_params): @pytest.fixture def apidoc_params(request): - markers = request.node.get_marker("apidoc") + if hasattr(request.node, 'iter_markers'): # pytest-3.6.0 or newer + markers = request.node.iter_markers("apidoc") + else: + markers = request.node.get_marker("apidoc") pargs = {} kwargs = {} diff --git a/tests/test_setup_command.py b/tests/test_setup_command.py index facb8879d..cd1f89c0c 100644 --- a/tests/test_setup_command.py +++ b/tests/test_setup_command.py @@ -27,7 +27,10 @@ def setup_command(request, tempdir, rootdir): Run `setup.py build_sphinx` with args and kwargs, pass it to the test and clean up properly. """ - marker = request.node.get_marker('setup_command') + if hasattr(request.node, 'get_closest_marker'): # pytest-3.6.0 or newer + marker = request.node.get_closest_marker('setup_command') + else: + marker = request.node.get_marker('setup_command') args = marker.args if marker else [] pkgrootdir = tempdir / 'test-setup'