From: Leandro Lucarella Date: Wed, 27 May 2009 01:51:29 +0000 (-0300) Subject: Agregar más tipos de referencia a la extensión vref X-Git-Tag: entrega-2010-10-08~73 X-Git-Url: https://git.llucax.com/z.facultad/75.00/informe.git/commitdiff_plain/a2c006d745e80674a39d7b034e8b18e131493010 Agregar más tipos de referencia a la extensión vref Agregar el rol "r" equivalente a \ref y "vrefr" equivalente a \vref. --- diff --git a/ext/vref.py b/ext/vref.py index 564e000..5245a30 100644 --- a/ext/vref.py +++ b/ext/vref.py @@ -1,7 +1,19 @@ - from docutils import nodes, utils + +class r(nodes.Inline, nodes.TextElement): + pass + +def r_role(role, rawtext, text, lineno, inliner, options={}, content=[]): + latex = utils.unescape(text, restore_backslashes=True) + return [r(latex=latex)], [] + +def latex_visit_r(self, node): + self.body.append(r'\ref{' + node['latex'] + '}') + raise nodes.SkipNode + + class vref(nodes.Inline, nodes.TextElement): pass @@ -13,7 +25,25 @@ def latex_visit_vref(self, node): self.body.append(r'\vref{' + node['latex'] + '}') raise nodes.SkipNode + +class vrefr(nodes.Inline, nodes.TextElement): + pass + +def vrefr_role(role, rawtext, text, lineno, inliner, options={}, content=[]): + latex = utils.unescape(text, restore_backslashes=True) + return [vrefr(latex=latex)], [] + +def latex_visit_vrefr(self, node): + range = tuple(node['latex'].split(',', 1)) + self.body.append(r'\vrefrange{%s}{%s}' % range) + raise nodes.SkipNode + + def setup(app): + app.add_node(r, latex=(latex_visit_r, None)) app.add_node(vref, latex=(latex_visit_vref, None)) + app.add_node(vrefr, latex=(latex_visit_vrefr, None)) + app.add_role('r', r_role) app.add_role('vref', vref_role) + app.add_role('vrefr', vrefr_role)