mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
LaTeX writer: symmetrize footnote restrictions for tables
Memo 1: footnotes from captions are inserted by this commit via table templates, so it is easy to put caption at foot of table rather than at head, if wanted. Memo 2: footnotes from table header need restriction due to longtable only. But one can not tell in advance if table will be rendered by longtable or not, hence one must restrict always.
This commit is contained in:
parent
9a8e36568d
commit
e39d58a530
@ -26,6 +26,8 @@
|
||||
\endfoot
|
||||
|
||||
\endlastfoot
|
||||
|
||||
<% if table.caption_footnotetexts -%>
|
||||
<%= ''.join(table.caption_footnotetexts) %>
|
||||
<% endif -%>
|
||||
<%= ''.join(table.body) %>
|
||||
\end{longtable}\end{savenotes}
|
||||
|
@ -17,6 +17,9 @@
|
||||
\begin{tabular}<%= table.get_colspec() -%>
|
||||
\hline
|
||||
<%= ''.join(table.header) %>
|
||||
<%- if table.caption_footnotetexts -%>
|
||||
<%= ''.join(table.caption_footnotetexts) -%>
|
||||
<%- endif -%>
|
||||
<%=- ''.join(table.body) %>
|
||||
\end{tabular}
|
||||
<%- if table.caption %>
|
||||
|
@ -17,6 +17,9 @@
|
||||
\begin{tabulary}{\linewidth}<%= table.get_colspec() -%>
|
||||
\hline
|
||||
<%= ''.join(table.header) %>
|
||||
<%- if table.caption_footnotetexts -%>
|
||||
<%= ''.join(table.caption_footnotetexts) -%>
|
||||
<%- endif -%>
|
||||
<%=- ''.join(table.body) %>
|
||||
\end{tabulary}
|
||||
<%- if table.caption %>
|
||||
|
@ -327,6 +327,8 @@ class Table(object):
|
||||
self.has_problematic = False
|
||||
self.has_verbatim = False
|
||||
self.caption = None # type: List[unicode]
|
||||
self.caption_footnotetexts = [] # type: List[unicode]
|
||||
self.header_footnotetexts = [] # type: List[unicode]
|
||||
|
||||
# current position
|
||||
self.col = 0
|
||||
@ -1052,6 +1054,7 @@ class LaTeXTranslator(nodes.NodeVisitor):
|
||||
elif isinstance(parent, nodes.table):
|
||||
# Redirect body output until title is finished.
|
||||
self.pushbody([])
|
||||
self.restrict_footnote(node)
|
||||
else:
|
||||
logger.warning('encountered title node not in section, topic, table, '
|
||||
'admonition or sidebar',
|
||||
@ -1065,9 +1068,14 @@ class LaTeXTranslator(nodes.NodeVisitor):
|
||||
self.in_title = 0
|
||||
if isinstance(node.parent, nodes.table):
|
||||
self.table.caption = self.popbody()
|
||||
# temporary buffer for footnotes from caption
|
||||
self.pushbody([])
|
||||
self.unrestrict_footnote(node)
|
||||
# the footnote texts from caption
|
||||
self.table.caption_footnotetexts = self.popbody()
|
||||
else:
|
||||
self.body.append(self.context.pop())
|
||||
self.unrestrict_footnote(node)
|
||||
self.unrestrict_footnote(node)
|
||||
|
||||
def visit_subtitle(self, node):
|
||||
# type: (nodes.Node) -> None
|
||||
@ -1294,7 +1302,6 @@ class LaTeXTranslator(nodes.NodeVisitor):
|
||||
if self.next_table_colspec:
|
||||
self.table.colspec = '{%s}\n' % self.next_table_colspec
|
||||
self.next_table_colspec = None
|
||||
self.restrict_footnote(node)
|
||||
|
||||
def depart_table(self, node):
|
||||
# type: (nodes.Node) -> None
|
||||
@ -1333,18 +1340,27 @@ class LaTeXTranslator(nodes.NodeVisitor):
|
||||
|
||||
def visit_thead(self, node):
|
||||
# type: (nodes.Node) -> None
|
||||
self.pushbody(self.table.header) # Redirect head output until header is finished.
|
||||
# Redirect head output until header is finished.
|
||||
self.pushbody(self.table.header)
|
||||
# footnotes in longtable header must be restricted
|
||||
self.restrict_footnote(node)
|
||||
|
||||
def depart_thead(self, node):
|
||||
# type: (nodes.Node) -> None
|
||||
self.popbody()
|
||||
# temporary buffer for footnotes from table header
|
||||
self.pushbody([])
|
||||
self.unrestrict_footnote(node)
|
||||
# the footnote texts from header
|
||||
self.table.header_footnotetexts = self.popbody()
|
||||
|
||||
def visit_tbody(self, node):
|
||||
# type: (nodes.Node) -> None
|
||||
self.pushbody(self.table.body) # Redirect body output until table is finished.
|
||||
if self.footnote_restricted:
|
||||
# releases footnotetexts from header in first non header cell
|
||||
self.unrestrict_footnote(node.parent.parent)
|
||||
# Redirect body output until table is finished.
|
||||
self.pushbody(self.table.body)
|
||||
# insert footnotetexts from header at start of body (due to longtable)
|
||||
# those from caption are handled by templates (to allow caption at foot)
|
||||
self.body.extend(self.table.header_footnotetexts)
|
||||
|
||||
def depart_tbody(self, node):
|
||||
# type: (nodes.Node) -> None
|
||||
|
Loading…
Reference in New Issue
Block a user