]> git.llucax.com Git - z.facultad/75.00/informe.git/commitdiff
Agregar ext/ftable para tablas flotantes
authorLeandro Lucarella <llucax@gmail.com>
Sun, 3 Oct 2010 17:36:52 +0000 (14:36 -0300)
committerLeandro Lucarella <llucax@gmail.com>
Fri, 8 Oct 2010 01:34:10 +0000 (22:34 -0300)
ext/fig.py
ext/ftable.py [new file with mode: 0644]
source/conf.py

index ad24d18bbdb9eb6df5888bbf1b840beddd708618..f777222dc54e8d1cd6dc68b10de4349405536d43 100644 (file)
@@ -27,7 +27,7 @@ class subfig(nodes.General, nodes.Element):
 def latex_visit_subfig(self, node):
     space = '\\hspace{%sin}\n' % node['space'] if node['space'] else ''
     self.body.append(space)
-    self.body.append('\\subfigure')
+    self.body.append('\\subfloat')
 
 def latex_depart_subfig(self, node):
     self.body.append('}\n')
diff --git a/ext/ftable.py b/ext/ftable.py
new file mode 100644 (file)
index 0000000..e9c27c6
--- /dev/null
@@ -0,0 +1,187 @@
+
+from docutils import nodes, utils
+from docutils.parsers.rst import directives
+from sphinx.util.compat import Directive
+
+
+DEFAULT_PLACES  = 'hbtp'
+DEFAULT_PADDING = '0.1'
+
+
+# subtable
+############################################################################
+
+class subtcap(nodes.Part, nodes.TextElement):
+    pass
+
+def latex_visit_subtcap(self, node):
+    self.body.append('[')
+
+def latex_depart_subtcap(self, node):
+    self.body.append(']{')
+
+
+class subtable(nodes.General, nodes.Element):
+    pass
+
+def latex_visit_subtable(self, node):
+    space = '\\hspace{%sin}\n' % node['space'] if node['space'] else ''
+    self.body.append(space)
+    self.body.append('\\subfloat')
+
+def latex_depart_subtable(self, node):
+    self.body.append('}\n')
+
+
+class SubtableDirective(Directive):
+
+    has_content = True
+    required_arguments = 0
+    optional_arguments = 1
+    final_argument_whitespace = True
+    option_spec = dict(
+        label   = directives.unchanged,
+        space   = float,
+    )
+
+    def run(self):
+        self.assert_has_content()
+        subtable_node = subtable('\n'.join(self.content))
+        subtable_node['label'] = self.options.get('label', None)
+        subtable_node['space'] = self.options.get('space', None)
+        if self.arguments and self.arguments[0]:
+            subtable_node['label'] = self.arguments[0]
+        node = nodes.Element() # anonymous container for parsing
+        self.state.nested_parse(self.content, self.content_offset, node)
+        first_node = node[0]
+        if isinstance(first_node, nodes.paragraph):
+            cap = subtcap(first_node.rawsource, '', *first_node.children)
+            subtable_node += cap
+            subtable_node += node[1:]
+        else:
+            subtable_node += subtcap('', '', nodes.Text(''))
+            subtable_node += node[:]
+        return [subtable_node]
+
+
+# ftable
+############################################################################
+
+class captitle(nodes.Part, nodes.TextElement):
+    pass
+
+def latex_visit_captitle(self, node):
+    self.body.append('\\caption[')
+
+def latex_depart_captitle(self, node):
+    self.body.append(']')
+
+class capdesc(nodes.Part, nodes.TextElement):
+    pass
+
+def latex_visit_capdesc(self, node):
+    self.body.append('{')
+
+def latex_depart_capdesc(self, node):
+    self.body.append('}\n')
+
+class tpad(nodes.Part, nodes.TextElement):
+    pass
+
+def latex_visit_tpad(self, node):
+    self.body.append('\\hspace{%sin}\n' % node['inches'])
+
+def latex_depart_tpad(self, node):
+    pass
+    #self.body.append('\\hspace{%sin}\n' % DEFAULT_PADDING) #node['inches'])
+
+
+class ftable(nodes.General, nodes.Element):
+    pass
+
+def latex_visit_ftable(self, node):
+    self.body.append('\\begin{table}[%s]\n' % node['placement'])
+    self.body.append('' if node['nocenter'] else '\\centering\n')
+
+def latex_depart_ftable(self, node):
+    label = '\\label{%s}\n' % node['label'] if node['label'] else ''
+    self.body.append(label)
+    self.body.append('\\end{table}\n\n')
+
+class FTableDirective(Directive):
+
+    has_content = True
+    required_arguments = 0
+    optional_arguments = 1
+    final_argument_whitespace = True
+    option_spec = dict(
+        label     = directives.unchanged,
+        placement = directives.unchanged,
+        padding   = float,
+        nocenter  = directives.flag,
+    )
+
+    def run(self):
+        self.assert_has_content()
+        ftable_node = ftable('\n'.join(self.content))
+        ftable_node['label'] = self.options.get('label', None)
+        ftable_node['placement'] = self.options.get('placement', DEFAULT_PLACES)
+        ftable_node['padding'] = self.options.get('padding', DEFAULT_PADDING)
+        ftable_node['nocenter'] = 'nocenter' in self.options
+        if self.arguments and self.arguments[0]:
+            ftable_node['label'] = self.arguments[0]
+        node = nodes.Element() # anonymous container for parsing
+        self.state.nested_parse(self.content, self.content_offset, node)
+        first_node = None
+        second_node = None
+        try:
+            first_node = node[0]
+            second_node = node[1]
+        except IndexError:
+            pass
+        is_first_para = isinstance(first_node, nodes.paragraph)
+        is_second_para = isinstance(second_node, nodes.paragraph)
+        capt = None
+        capd = None
+        if is_first_para and is_second_para:
+            capt = captitle(first_node.rawsource, '', *first_node.children)
+            capd = capdesc(second_node.rawsource, '', *second_node.children)
+            node = node[2:]
+        elif is_first_para:
+            capt = captitle(first_node.rawsource, '', *first_node.children)
+            capd = capdesc(first_node.rawsource, '', *first_node.children)
+            node = node[1:]
+        elif is_second_para:
+            capt = captitle(second_node.rawsource, '', *second_node.children)
+            capd = capdesc(second_node.rawsource, '', *second_node.children)
+            node = node[1:]
+        first = True
+        children = []
+        for n in node:
+            if isinstance(n, subtable):
+                if first:
+                    first = False
+                else:
+                    children.append(tpad('', '', nodes.Text(''),
+                            inches=ftable_node['padding']))
+            children.append(n)
+        ftable_node += children
+        if capt and capd:
+            ftable_node += capt
+            ftable_node += capd
+        return [ftable_node]
+
+
+
+def setup(app):
+    app.add_node(subtcap, latex=(latex_visit_subtcap, latex_depart_subtcap))
+    app.add_node(subtable, latex=(latex_visit_subtable, latex_depart_subtable))
+    app.add_node(captitle, latex=(latex_visit_captitle, latex_depart_captitle))
+    app.add_node(capdesc, latex=(latex_visit_capdesc, latex_depart_capdesc))
+    app.add_node(tpad, latex=(latex_visit_tpad, latex_depart_tpad))
+    app.add_node(ftable, latex=(latex_visit_ftable, latex_depart_ftable))
+    app.add_directive('ftable', FTableDirective)
+    app.add_directive('subtable', SubtableDirective)
+
+
+# vim: set et sw=4 sts=4 :
index c6e161e935c3dbcffc84b8a890f37ebff610ee6b..59891b93ff5ec3ea13142a0daa399a740070bc72 100644 (file)
@@ -25,6 +25,7 @@ sys.path.append(os.path.abspath('../ext'))
 extensions = [
        'aafig',
        'fig',
+       'ftable',
        'vref',
        'sphinx.ext.graphviz',
        'sphinx.ext.pngmath',
@@ -196,7 +197,7 @@ latex_logo = 'fiuba.png'
 # Additional stuff for the LaTeX preamble.
 latex_preamble = r'''
 \usepackage[draft]{varioref} % XXX: breaks PDF index, use [final] when done
-\usepackage{subfigure}
+\usepackage{subfig}
 \setcounter{tocdepth}{2}
 '''