mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
#18: put footnotes at the correct location in the LaTeX writer.
This commit is contained in:
14
CHANGES
14
CHANGES
@@ -85,12 +85,11 @@ New features added
|
||||
``build-finished``.
|
||||
|
||||
* Other changes:
|
||||
|
||||
- Added a distutils command `build_sphinx`: When Sphinx is installed,
|
||||
you can call ``python setup.py build_sphinx`` for projects that have
|
||||
Sphinx documentation, which will build the docs and place them in
|
||||
the standard distutils build directory.
|
||||
|
||||
- Footnotes are now properly handled in the LaTeX builder: they appear
|
||||
at the location of the footnote reference in text, not at the end of
|
||||
a section. Thanks to Andrew McNamara for the initial patch.
|
||||
|
||||
- "System Message" warnings are now automatically removed from the
|
||||
built documentation, and only written to stderr. If you want the
|
||||
old behavior, set the new config value ``keep_warnings`` to True.
|
||||
@@ -100,6 +99,11 @@ New features added
|
||||
- Figures with captions can now be referred to like section titles,
|
||||
using the ``:ref:`` role without an explicit link text.
|
||||
|
||||
- Added a distutils command `build_sphinx`: When Sphinx is installed,
|
||||
you can call ``python setup.py build_sphinx`` for projects that have
|
||||
Sphinx documentation, which will build the docs and place them in
|
||||
the standard distutils build directory.
|
||||
|
||||
- In quickstart, if the selected root path already contains a Sphinx
|
||||
project, complain and abort.
|
||||
|
||||
|
||||
@@ -129,6 +129,11 @@ The special document names (and pages generated for them) are:
|
||||
documents or document-containing directories with such names. (Using ``_`` as
|
||||
a prefix for a custom template directory is fine.)
|
||||
|
||||
.. toctree::
|
||||
|
||||
x
|
||||
|
||||
note [#]_.
|
||||
|
||||
.. rubric:: Footnotes
|
||||
|
||||
@@ -142,3 +147,5 @@ The special document names (and pages generated for them) are:
|
||||
constructs ``*``, ``?``, ``[...]`` and ``[!...]`` with the feature that
|
||||
these all don't match slashes. A double star ``**`` can be used to match
|
||||
any sequence of characters *including* slashes.
|
||||
|
||||
.. [#] 3rd note.
|
||||
|
||||
@@ -1019,8 +1019,9 @@ class LaTeXBuilder(Builder):
|
||||
self.warn('%s: toctree contains ref to nonexisting file %r' %
|
||||
(docname, includefile))
|
||||
else:
|
||||
newnodes.append(addnodes.start_of_file())
|
||||
newnodes.extend(subtree.children)
|
||||
sof = addnodes.start_of_file()
|
||||
sof.children = subtree.children
|
||||
newnodes.append(sof)
|
||||
toctreenode.parent.replace(toctreenode, newnodes)
|
||||
return tree
|
||||
tree = self.env.get_doctree(indexfile)
|
||||
@@ -1046,7 +1047,7 @@ class LaTeXBuilder(Builder):
|
||||
newnodes = [nodes.emphasis(sectname, sectname)]
|
||||
for subdir, title in self.titles:
|
||||
if docname.startswith(subdir):
|
||||
newnodes.append(nodes.Text(' (in ', ' (in '))
|
||||
newnodes.append(nodes.Text(_(' (in '), _(' (in ')))
|
||||
newnodes.append(nodes.emphasis(title, title))
|
||||
newnodes.append(nodes.Text(')', ')'))
|
||||
break
|
||||
|
||||
@@ -195,6 +195,7 @@ class LaTeXTranslator(nodes.NodeVisitor):
|
||||
self.highlightlang = builder.config.highlight_language
|
||||
self.highlightlinenothreshold = sys.maxint
|
||||
self.written_ids = set()
|
||||
self.footnotestack = []
|
||||
if self.elements['docclass'] == 'manual':
|
||||
if builder.config.latex_use_parts:
|
||||
self.top_sectionlevel = 0
|
||||
@@ -216,6 +217,7 @@ class LaTeXTranslator(nodes.NodeVisitor):
|
||||
u''.join(self.body) + FOOTER % self.elements)
|
||||
|
||||
def visit_document(self, node):
|
||||
self.footnotestack.append(self.collect_footnotes(node))
|
||||
if self.first_document == 1:
|
||||
# the first document is all the regular content ...
|
||||
self.body.append(BEGIN_DOC % self.elements)
|
||||
@@ -244,7 +246,28 @@ class LaTeXTranslator(nodes.NodeVisitor):
|
||||
# This marks the begin of a new file; therefore the current module and
|
||||
# class must be reset
|
||||
self.body.append('\n\\resetcurrentobjects\n')
|
||||
raise nodes.SkipNode
|
||||
# and also, new footnotes
|
||||
self.footnotestack.append(self.collect_footnotes(node))
|
||||
|
||||
def collect_footnotes(self, node):
|
||||
fnotes = {}
|
||||
def footnotes_under(n):
|
||||
if isinstance(n, nodes.footnote):
|
||||
yield n
|
||||
else:
|
||||
for c in n.children:
|
||||
if isinstance(c, addnodes.start_of_file):
|
||||
continue
|
||||
for k in footnotes_under(c):
|
||||
yield k
|
||||
for fn in footnotes_under(node):
|
||||
num = fn.children[0].astext().strip()
|
||||
fnotes[num] = fn
|
||||
fn.parent.remove(fn)
|
||||
return fnotes
|
||||
|
||||
def depart_start_of_file(self, node):
|
||||
self.footnotestack.pop()
|
||||
|
||||
def visit_highlightlang(self, node):
|
||||
self.highlightlang = node['lang']
|
||||
@@ -478,11 +501,9 @@ class LaTeXTranslator(nodes.NodeVisitor):
|
||||
self.body.append(self.context.pop())
|
||||
|
||||
def visit_footnote(self, node):
|
||||
# XXX not optimal, footnotes are at section end
|
||||
num = node.children[0].astext().strip()
|
||||
self.body.append('\\footnotetext[%s]{' % num)
|
||||
pass
|
||||
def depart_footnote(self, node):
|
||||
self.body.append('}')
|
||||
pass
|
||||
|
||||
def visit_label(self, node):
|
||||
if isinstance(node.parent, nodes.citation):
|
||||
@@ -918,8 +939,16 @@ class LaTeXTranslator(nodes.NodeVisitor):
|
||||
raise nodes.SkipNode
|
||||
|
||||
def visit_footnote_reference(self, node):
|
||||
self.body.append('\\footnotemark[%s]' % node.astext())
|
||||
raise nodes.SkipNode
|
||||
num = node.astext().strip()
|
||||
try:
|
||||
fn = self.footnotestack[-1][num]
|
||||
except (KeyError, IndexError):
|
||||
raise nodes.SkipNode
|
||||
self.body.append('\\footnote{')
|
||||
fn.walkabout(self)
|
||||
raise nodes.SkipChildren
|
||||
def depart_footnote_reference(self, node):
|
||||
self.body.append('}')
|
||||
|
||||
def visit_literal_block(self, node):
|
||||
self.verbatim = ''
|
||||
|
||||
Reference in New Issue
Block a user