Better replacement for LaTeX's enumerated list support macros

This commit is contained in:
jfbu 2018-05-26 15:14:57 +02:00
parent 600c948ff9
commit a08321f962
2 changed files with 20 additions and 13 deletions

View File

@ -1525,12 +1525,14 @@ class LaTeXTranslator(nodes.NodeVisitor):
return get_nested_level(node.parent)
enum = "enum%s" % toRoman(get_nested_level(node)).lower()
enumnext = "enum%s" % toRoman(get_nested_level(node) + 1).lower()
style = ENUMERATE_LIST_STYLE.get(get_enumtype(node))
self.body.append('\\begin{enumerate}\n')
self.body.append('\\renewcommand{\\the%s}{%s{%s}}\n' % (enum, style, enum))
self.body.append('\\makeatletter\\renewcommand{\\p@%s}{%s\\the%s%s}\\makeatother\n' %
(enum, node['prefix'], enum, node['suffix']))
self.body.append('\\def\\the%s{%s{%s}}\n' % (enum, style, enum))
self.body.append('\\def\\label%s{\\the%s.}\n' % (enum, enum))
self.body.append('\\makeatletter\\def\\p@%s{\\p@%s\\the%s.}\\makeatother\n' %
(enumnext, enum, enum))
if 'start' in node:
self.body.append('\\setcounter{%s}{%d}\n' % (enum, node['start'] - 1))
if self.table:

View File

@ -1229,20 +1229,25 @@ def test_latex_nested_enumerated_list(app, status, warning):
app.builder.build_all()
result = (app.outdir / 'test.tex').text(encoding='utf8')
assert ('\\renewcommand{\\theenumi}{\\arabic{enumi}}\n'
'\\makeatletter\\renewcommand{\\p@enumi}{\\theenumi.}\\makeatother\n'
assert ('\\def\\theenumi{\\arabic{enumi}}\n'
'\\def\\labelenumi{\\theenumi.}\n'
'\\makeatletter\\def\\p@enumii{\\p@enumi\\theenumi.}\\makeatother\n'
'\\setcounter{enumi}{4}\n' in result)
assert ('\\renewcommand{\\theenumii}{\\alph{enumii}}\n'
'\\makeatletter\\renewcommand{\\p@enumii}{\\theenumii.}\\makeatother\n'
assert ('\\def\\theenumii{\\alph{enumii}}\n'
'\\def\\labelenumii{\\theenumii.}\n'
'\\makeatletter\\def\\p@enumiii{\\p@enumii\\theenumii.}\\makeatother\n'
'\\setcounter{enumii}{3}\n' in result)
assert ('\\renewcommand{\\theenumiii}{\\arabic{enumiii}}\n'
'\\makeatletter\\renewcommand{\\p@enumiii}{\\theenumiii)}\\makeatother\n'
assert ('\\def\\theenumiii{\\arabic{enumiii}}\n'
'\\def\\labelenumiii{\\theenumiii.}\n'
'\\makeatletter\\def\\p@enumiv{\\p@enumiii\\theenumiii.}\\makeatother\n'
'\\setcounter{enumiii}{9}\n' in result)
assert ('\\renewcommand{\\theenumiv}{\\arabic{enumiv}}\n'
'\\makeatletter\\renewcommand{\\p@enumiv}{(\\theenumiv)}\\makeatother\n'
assert ('\\def\\theenumiv{\\arabic{enumiv}}\n'
'\\def\\labelenumiv{\\theenumiv.}\n'
'\\makeatletter\\def\\p@enumv{\\p@enumiv\\theenumiv.}\\makeatother\n'
'\\setcounter{enumiv}{23}\n' in result)
assert ('\\renewcommand{\\theenumii}{\\roman{enumii}}\n'
'\\makeatletter\\renewcommand{\\p@enumii}{\\theenumii.}\\makeatother\n'
assert ('\\def\\theenumii{\\roman{enumii}}\n'
'\\def\\labelenumii{\\theenumii.}\n'
'\\makeatletter\\def\\p@enumiii{\\p@enumii\\theenumii.}\\makeatother\n'
'\\setcounter{enumii}{2}\n' in result)