Merge pull request #4639 from tk0miya/4577_nested_enumlist

Fix #4577: Enumerated sublists with explicit start with wrong number
This commit is contained in:
Takeshi KOMIYA 2018-02-19 23:26:52 +09:00 committed by GitHub
commit f318cbe1e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 45 additions and 1 deletions

View File

@ -33,6 +33,7 @@ Bugs fixed
been changed
* #4630: Have order on msgids in sphinx.pot deterministic
* #4563: autosummary: Incorrect end of line punctuation detection
* #4577: Enumerated sublists with explicit start with wrong number
Testing
--------

View File

@ -1581,9 +1581,19 @@ class LaTeXTranslator(nodes.NodeVisitor):
def visit_enumerated_list(self, node):
# type: (nodes.Node) -> None
def get_nested_level(node):
# type: (nodes.Node) -> int
if node is None:
return 0
elif isinstance(node, nodes.enumerated_list):
return get_nested_level(node.parent) + 1
else:
return get_nested_level(node.parent)
self.body.append('\\begin{enumerate}\n')
if 'start' in node:
self.body.append('\\setcounter{enumi}{%d}\n' % (node['start'] - 1))
nested = get_nested_level(node)
self.body.append('\\setcounter{enum%s}{%d}\n' % ('i' * nested, node['start'] - 1))
if self.table:
self.table.has_problematic = True

View File

@ -0,0 +1,7 @@
# -*- coding: utf-8 -*-
master_doc = 'index'
latex_documents = [
(master_doc, 'test.tex', 'The basic Sphinx documentation for testing', 'Sphinx', 'report')
]

View File

@ -0,0 +1,15 @@
nested-enumerated-list
======================
5. Sphinx
d. Documentation builder
e. Egypt
10) Pyramid
11) Nile River
6. Markup
iii. reStructuredText
iv. Markdown

View File

@ -1143,3 +1143,14 @@ def test_latex_image_in_parsed_literal(app, status, warning):
assert ('{\\sphinxunactivateextrasandspace \\raisebox{-0.5\\height}'
'{\\scalebox{2.000000}{\\sphinxincludegraphics[height=1cm]{{pic}.png}}}'
'}AFTER') in result
@pytest.mark.sphinx('latex', testroot='nested-enumerated-list')
def test_latex_nested_enumerated_list(app, status, warning):
app.builder.build_all()
result = (app.outdir / 'test.tex').text(encoding='utf8')
assert r'\setcounter{enumi}{4}' in result
assert r'\setcounter{enumii}{3}' in result
assert r'\setcounter{enumiii}{9}' in result
assert r'\setcounter{enumii}{2}' in result