X-Git-Url: https://git.llucax.com/z.facultad/75.00/informe.git/blobdiff_plain/dab5740413a8382ee3bfa3553dbc92f2ca1923c7..33ad3bc6cd7e5479744bb286797ae832135391d3:/ext/fig.py?ds=sidebyside diff --git a/ext/fig.py b/ext/fig.py index d258dea..ad24d18 100644 --- a/ext/fig.py +++ b/ext/fig.py @@ -67,6 +67,24 @@ class SubfigDirective(Directive): # fig ############################################################################ +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 pad(nodes.Part, nodes.TextElement): pass @@ -114,10 +132,28 @@ class FigDirective(Directive): fig_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] - cap = None - if isinstance(first_node, nodes.paragraph): - cap = nodes.caption(first_node.rawsource, '', *first_node.children) + 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 = [] @@ -130,8 +166,9 @@ class FigDirective(Directive): inches=fig_node['padding'])) children.append(n) fig_node += children - if cap: - fig_node += cap + if capt and capd: + fig_node += capt + fig_node += capd return [fig_node] @@ -139,6 +176,8 @@ class FigDirective(Directive): def setup(app): app.add_node(subcap, latex=(latex_visit_subcap, latex_depart_subcap)) app.add_node(subfig, latex=(latex_visit_subfig, latex_depart_subfig)) + 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(pad, latex=(latex_visit_pad, latex_depart_pad)) app.add_node(fig, latex=(latex_visit_fig, latex_depart_fig)) app.add_directive('fig', FigDirective)