mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
This commit is contained in:
commit
d8616219cf
@ -34,6 +34,7 @@ HEADER = r'''%% Generated by Sphinx.
|
|||||||
%(babel)s
|
%(babel)s
|
||||||
%(fontpkg)s
|
%(fontpkg)s
|
||||||
%(fncychap)s
|
%(fncychap)s
|
||||||
|
%(longtable)s
|
||||||
\usepackage{sphinx}
|
\usepackage{sphinx}
|
||||||
%(preamble)s
|
%(preamble)s
|
||||||
|
|
||||||
@ -111,9 +112,11 @@ class Table(object):
|
|||||||
self.col = 0
|
self.col = 0
|
||||||
self.colcount = 0
|
self.colcount = 0
|
||||||
self.colspec = None
|
self.colspec = None
|
||||||
|
self.rowcount = 0
|
||||||
self.had_head = False
|
self.had_head = False
|
||||||
self.has_verbatim = False
|
self.has_verbatim = False
|
||||||
self.caption = None
|
self.caption = None
|
||||||
|
self.longtable = False
|
||||||
|
|
||||||
|
|
||||||
class Desc(object):
|
class Desc(object):
|
||||||
@ -140,6 +143,7 @@ class LaTeXTranslator(nodes.NodeVisitor):
|
|||||||
'babel': '\\usepackage{babel}',
|
'babel': '\\usepackage{babel}',
|
||||||
'fontpkg': '\\usepackage{times}',
|
'fontpkg': '\\usepackage{times}',
|
||||||
'fncychap': '\\usepackage[Bjarne]{fncychap}',
|
'fncychap': '\\usepackage[Bjarne]{fncychap}',
|
||||||
|
'longtable': '\\usepackage{longtable}',
|
||||||
'preamble': '',
|
'preamble': '',
|
||||||
'title': '',
|
'title': '',
|
||||||
'date': '',
|
'date': '',
|
||||||
@ -593,16 +597,21 @@ class LaTeXTranslator(nodes.NodeVisitor):
|
|||||||
'%s:%s: nested tables are not yet implemented.' %
|
'%s:%s: nested tables are not yet implemented.' %
|
||||||
(self.curfilestack[-1], node.line or ''))
|
(self.curfilestack[-1], node.line or ''))
|
||||||
self.table = Table()
|
self.table = Table()
|
||||||
|
self.table.longtable = 'longtable' in node['classes']
|
||||||
self.tablebody = []
|
self.tablebody = []
|
||||||
# Redirect body output until table is finished.
|
# Redirect body output until table is finished.
|
||||||
self._body = self.body
|
self._body = self.body
|
||||||
self.body = self.tablebody
|
self.body = self.tablebody
|
||||||
def depart_table(self, node):
|
def depart_table(self, node):
|
||||||
|
if self.table.rowcount > 30:
|
||||||
|
self.table.longtable = True
|
||||||
self.body = self._body
|
self.body = self._body
|
||||||
if self.table.caption is not None:
|
if not self.table.longtable and self.table.caption is not None:
|
||||||
self.body.append('\n\\begin{threeparttable}\n'
|
self.body.append('\n\\begin{threeparttable}\n'
|
||||||
'\\caption{%s}\n' % self.table.caption)
|
'\\caption{%s}\n' % self.table.caption)
|
||||||
if self.table.has_verbatim:
|
if self.table.longtable:
|
||||||
|
self.body.append('\n\\begin{longtable}')
|
||||||
|
elif self.table.has_verbatim:
|
||||||
self.body.append('\n\\begin{tabular}')
|
self.body.append('\n\\begin{tabular}')
|
||||||
else:
|
else:
|
||||||
self.body.append('\n\\begin{tabulary}{\\textwidth}')
|
self.body.append('\n\\begin{tabulary}{\\textwidth}')
|
||||||
@ -614,14 +623,35 @@ class LaTeXTranslator(nodes.NodeVisitor):
|
|||||||
colspec = ('p{%.3f\\textwidth}|' % colwidth) * \
|
colspec = ('p{%.3f\\textwidth}|' % colwidth) * \
|
||||||
self.table.colcount
|
self.table.colcount
|
||||||
self.body.append('{|' + colspec + '}\n')
|
self.body.append('{|' + colspec + '}\n')
|
||||||
|
elif self.table.longtable:
|
||||||
|
self.body.append('{|' + ('l|' * self.table.colcount) + '}\n')
|
||||||
else:
|
else:
|
||||||
self.body.append('{|' + ('L|' * self.table.colcount) + '}\n')
|
self.body.append('{|' + ('L|' * self.table.colcount) + '}\n')
|
||||||
|
if self.table.longtable and self.table.caption is not None:
|
||||||
|
self.body.append('\\caption{%s} \\\\\n' % self.table.caption)
|
||||||
|
|
||||||
|
if self.table.longtable:
|
||||||
|
self.body.append('\\hline\n')
|
||||||
|
self.body.append('\\endfirsthead\n\n')
|
||||||
|
self.body.append('\multicolumn{%s}{c}%%\n' % self.table.colcount)
|
||||||
|
self.body.append('{{\\bfseries \\tablename\\ \\thetable{} -- %s}} \\\\\n' % _('continued from previous page'))
|
||||||
|
self.body.append('\\hline\n')
|
||||||
|
self.body.append('\\endhead\n\n')
|
||||||
|
self.body.append('\\hline \multicolumn{%s}{|r|}{{%s}} \\\\ \\hline\n' % (
|
||||||
|
self.table.colcount, _('Continued on next page')))
|
||||||
|
self.body.append('\\endfoot\n\n')
|
||||||
|
self.body.append('\\hline\n')
|
||||||
|
self.body.append('\\endlastfoot\n\n')
|
||||||
|
else:
|
||||||
|
self.body.append('\\hline\n')
|
||||||
self.body.extend(self.tablebody)
|
self.body.extend(self.tablebody)
|
||||||
if self.table.has_verbatim:
|
if self.table.longtable:
|
||||||
|
self.body.append('\\end{longtable}\n\n')
|
||||||
|
elif self.table.has_verbatim:
|
||||||
self.body.append('\\end{tabular}\n\n')
|
self.body.append('\\end{tabular}\n\n')
|
||||||
else:
|
else:
|
||||||
self.body.append('\\end{tabulary}\n\n')
|
self.body.append('\\end{tabulary}\n\n')
|
||||||
if self.table.caption is not None:
|
if not self.table.longtable and self.table.caption is not None:
|
||||||
self.body.append('\\end{threeparttable}\n\n')
|
self.body.append('\\end{threeparttable}\n\n')
|
||||||
self.table = None
|
self.table = None
|
||||||
self.tablebody = None
|
self.tablebody = None
|
||||||
@ -640,8 +670,8 @@ class LaTeXTranslator(nodes.NodeVisitor):
|
|||||||
if self.next_table_colspec:
|
if self.next_table_colspec:
|
||||||
self.table.colspec = '{%s}\n' % self.next_table_colspec
|
self.table.colspec = '{%s}\n' % self.next_table_colspec
|
||||||
self.next_table_colspec = None
|
self.next_table_colspec = None
|
||||||
self.body.append('\\hline\n')
|
# self.body.append('\\hline\n')
|
||||||
self.table.had_head = True
|
# self.table.had_head = True
|
||||||
def depart_thead(self, node):
|
def depart_thead(self, node):
|
||||||
self.body.append('\\hline\n')
|
self.body.append('\\hline\n')
|
||||||
|
|
||||||
@ -655,6 +685,7 @@ class LaTeXTranslator(nodes.NodeVisitor):
|
|||||||
self.table.col = 0
|
self.table.col = 0
|
||||||
def depart_row(self, node):
|
def depart_row(self, node):
|
||||||
self.body.append('\\\\\n')
|
self.body.append('\\\\\n')
|
||||||
|
self.table.rowcount += 1
|
||||||
|
|
||||||
def visit_entry(self, node):
|
def visit_entry(self, node):
|
||||||
if node.has_key('morerows') or node.has_key('morecols'):
|
if node.has_key('morerows') or node.has_key('morecols'):
|
||||||
|
Loading…
Reference in New Issue
Block a user