summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docutils/docs/dev/todo.txt18
-rw-r--r--docutils/docutils/transforms/parts.py21
-rw-r--r--docutils/docutils/writers/latex2e/__init__.py43
3 files changed, 50 insertions, 32 deletions
diff --git a/docutils/docs/dev/todo.txt b/docutils/docs/dev/todo.txt
index 2b2af99e2..2ea4c7321 100644
--- a/docutils/docs/dev/todo.txt
+++ b/docutils/docs/dev/todo.txt
@@ -2048,21 +2048,9 @@ Which packages do we want to use?
table of contents
^^^^^^^^^^^^^^^^^
-Problem:
- when I specify a :depth: to a contents directive, this value is used but
- not preserved in the doctree.
-
-David wrote:
-
- There is a setting, use_latex_toc. Unfortunately its implementation is
- suboptimal. When use_latex_toc is True, the Docutils-generated ToC
- shouldn't be built at all. It's a waste of time.
-
- Instead, the docutils.transforms.parts.Contents transform should be
- made aware of use_latex_toc, and do the right thing for LaTeX. Or the
- LaTeX writer should override that transform and substitute a custom
- version.
-
+* support non-numbered sections with use-latex-toc
+ (now easy because of the \addtocontents lines)
+* use-latex-doc by default?
Default layout
--------------
diff --git a/docutils/docutils/transforms/parts.py b/docutils/docutils/transforms/parts.py
index 56d20c8ab..64de5b5da 100644
--- a/docutils/docutils/transforms/parts.py
+++ b/docutils/docutils/transforms/parts.py
@@ -79,6 +79,14 @@ class Contents(Transform):
default_priority = 720
def apply(self):
+ # build a contents list from the section headings?
+ # if False, the writer (or output software) builds the contents list
+ # Example: the LaTeX writer with option "use-latex-toc".
+ try:
+ build = not(self.document.settings.use_latex_toc)
+ except AttributeError:
+ build = True
+
details = self.startnode.details
if 'local' in details:
startnode = self.startnode.parent.parent
@@ -93,11 +101,16 @@ class Contents(Transform):
self.backlinks = details['backlinks']
else:
self.backlinks = self.document.settings.toc_backlinks
- contents = self.build_contents(startnode)
- if len(contents):
- self.startnode.replace_self(contents)
+ if build:
+ contents = self.build_contents(startnode)
+ if len(contents):
+ self.startnode.replace_self(contents)
+ else:
+ self.startnode.parent.parent.remove(self.startnode.parent)
else:
- self.startnode.parent.parent.remove(self.startnode.parent)
+ # pass customization settings to the parent node
+ self.startnode.parent.attributes.update(details)
+ self.startnode.parent.remove(self.startnode)
def build_contents(self, node, level=0):
level += 1
diff --git a/docutils/docutils/writers/latex2e/__init__.py b/docutils/docutils/writers/latex2e/__init__.py
index 581b1b718..4d4abcc0e 100644
--- a/docutils/docutils/writers/latex2e/__init__.py
+++ b/docutils/docutils/writers/latex2e/__init__.py
@@ -186,6 +186,13 @@ class Writer(writers.Writer):
writers.Writer.__init__(self)
self.translator_class = LaTeXTranslator
+ # TODO: footnote collection transform
+ # Override parent method to add latex-specific transforms
+ ## def get_transforms(self):
+ ## # call the parent class' method
+ ## # return writers.Writer.get_transforms(self) + [footnotes.collect]
+ ## return writers.Writer.get_transforms(self)
+
def translate(self):
visitor = self.translator_class(self.document)
self.document.walkabout(visitor)
@@ -1440,6 +1447,7 @@ class LaTeXTranslator(nodes.NodeVisitor):
if node['ids']:
self.title += self.labels(node)
self.body_prefix.append('\\maketitle\n\n')
+
def depart_document(self, node):
# Complete header with information gained from walkabout
# a) conditional requirements (before style sheet)
@@ -2067,7 +2075,7 @@ class LaTeXTranslator(nodes.NodeVisitor):
def visit_paragraph(self, node):
# no newline if the paragraph is first in a list item
if ((isinstance(node.parent, nodes.list_item) or
- isinstance(node.parent, nodes.description)) and
+ isinstance(node.parent, nodes.description)) and
node is node.parent[0]):
return
index = node.parent.index(node)
@@ -2359,7 +2367,7 @@ class LaTeXTranslator(nodes.NodeVisitor):
if self.settings.use_titlepage_env:
self.body.append('\\end{titlepage}\n')
if self.use_latex_toc:
- self.body.append('\\renewcommand{\\contentsname}{')
+ self.body.append('\n\\renewcommand{\\contentsname}{')
self.context.append('}\n\\tableofcontents\n\n\\bigskip\n')
self.has_latex_toc = True
else:
@@ -2368,7 +2376,7 @@ class LaTeXTranslator(nodes.NodeVisitor):
self.body.append('\\subsubsection*{~\\hfill ')
self.context.append('\\hfill ~%s}\n' % self.bookmark(node))
else: # other topic titles
- # TODO: user DUtopictitle:
+ # TODO: use DUtopictitle:
# self.body.append('\n\\DUtopictitle{')
# self.context.append('}\n')
self.body.append('\n\\subsubsection*{~\\hfill ')
@@ -2433,12 +2441,12 @@ class LaTeXTranslator(nodes.NodeVisitor):
# name-prefix for current section level
section_name = self.d_class.section(self.section_level)
if section_name == 'part':
- level = 'part'
+ minitoc_name = 'part'
elif section_name == 'chapter':
- level = 'mini'
+ minitoc_name = 'mini'
elif (section_name == 'section' and
'chapter' not in self.d_class.sections):
- level = 'sect'
+ minitoc_name = 'sect'
else: # minitoc only supports local toc in part- or top-level
warn = self.document.reporter.warning
warn('Skipping local ToC at %s level.\n' % section_name +
@@ -2446,19 +2454,28 @@ class LaTeXTranslator(nodes.NodeVisitor):
return
# Requirements/Setup
self.requirements['minitoc'] = PreambleCmds.minitoc
- self.requirements['minitoc-%s' % level] = r'\do%stoc' % level
+ self.requirements['minitoc-%s' %
+ minitoc_name] = r'\do%stoc' % minitoc_name
# depth: (Docutils defaults to unlimited depth)
- depth = len(self.d_class.sections)
- self.requirements['minitoc-%s-depth' % level] = (
- r'\mtcsetdepth{%stoc}{%d}' % (level, depth))
+ max_depth = len(self.d_class.sections)
+ self.requirements['minitoc-%s-depth' % minitoc_name] = (
+ r'\mtcsetdepth{%stoc}{%d}' % (minitoc_name, max_depth))
# TODO: set the depth according to the :depth: argument
# Attention: Docutils stores a relative depth while minitoc
# expects an absolute depth!
- ## self.body.append('\\setcounter{%stocdepth}{%d}' % (level, depth))
+ offset = {'sect': 1, 'mini': 0, 'part': 0}
+ if 'chapter' in self.d_class.sections:
+ offset['part'] = -1
+ depth = node.get('depth', 0)
+ if depth:
+ # depth += self.section_level
+ self.body.append('\\setcounter{%stocdepth}{%d}' %
+ (minitoc_name, depth + offset[minitoc_name]))
# title:
- self.body.append('\\mtcsettitle{%stoc}{%s}\n' % (level, toctitle))
+ self.body.append('\\mtcsettitle{%stoc}{%s}\n' %
+ (minitoc_name, toctitle))
# the toc-generating command:
- self.body.append('\\%stoc\n' % level)
+ self.body.append('\\%stoc\n' % minitoc_name)
def visit_topic(self, node):
self.topic_classes = node['classes']