Commits

Georg Brandl committed 25ac261 Merge

Merged in Brouznouf/sphinx (pull request #20)

  • Participants
  • Parent commits 132348d, 9b4e41b

Comments (0)

Files changed (1)

sphinx/writers/latex.py

 %(fncychap)s
 %(longtable)s
 \usepackage{sphinx}
+\usepackage{multirow}
 %(preamble)s
 
 \title{%(title)s}
         self.no_contractions = 0
         self.compact_list = 0
         self.first_param = 0
+        self.previous_spanning_row = 0
+        self.previous_spanning_column = 0
+        self.remember_multirow = {}
 
     def astext(self):
         return (HEADER % self.elements +
     def visit_row(self, node):
         self.table.col = 0
     def depart_row(self, node):
-        self.body.append('\\\\\\hline\n')
+        if self.previous_spanning_row == 1:
+            self.previous_spanning_row = 0
+            self.body.append('\\\\\n')
+        else:
+            self.body.append('\\\\\\hline\n')
         self.table.rowcount += 1
 
     def visit_entry(self, node):
-        if 'morerows' in node or 'morecols' in node:
-            raise UnsupportedError('%s:%s: column or row spanning cells are '
-                                   'not yet implemented.' %
-                                   (self.curfilestack[-1], node.line or ''))
+        if self.remember_multirow.has_key('0') and self.remember_multirow['0'] > 1:
+            self.body.append(' & ')
         if self.table.col > 0:
             self.body.append(' & ')
         self.table.col += 1
+        self.context.append('')
+        if 'morerows' in node:
+            self.body.append(' \multirow{')
+            self.previous_spanning_row = 1
+            self.body.append(str(node.get('morerows') + 1))
+            self.body.append('}{*}{')
+            self.context.append('}')
+            self.remember_multirow[str(self.table.col)] = node.get('morerows') + 1;
+        if 'morecols' in node:
+            self.body.append(' \multicolumn{')
+            self.body.append(str(node.get('morecols') + 1))
+            if self.table.col == 1:
+                self.body.append('}{|l|}{')
+            else:
+                self.body.append('}{l|}{')
+            self.context.append('}')
         if isinstance(node.parent.parent, nodes.thead):
             self.body.append('\\textbf{')
             self.context.append('}')
-        else:
-            self.context.append('')
+        if self.remember_multirow.has_key(str(self.table.col + 1)) and self.remember_multirow[str(self.table.col + 1)] > 1:
+            self.remember_multirow[str(self.table.col + 1)] -= 1
+            self.context.append(' & ')
     def depart_entry(self, node):
         self.body.append(self.context.pop()) # header