2 from docutils import nodes, utils
5 class r(nodes.Inline, nodes.TextElement):
8 def r_role(role, rawtext, text, lineno, inliner, options={}, content=[]):
9 latex = utils.unescape(text, restore_backslashes=True)
10 return [r(latex=latex)], []
12 def latex_visit_r(self, node):
13 self.body.append(r'\ref{' + node['latex'] + '}')
17 class vref(nodes.Inline, nodes.TextElement):
20 def vref_role(role, rawtext, text, lineno, inliner, options={}, content=[]):
21 latex = utils.unescape(text, restore_backslashes=True)
22 return [vref(latex=latex)], []
24 def latex_visit_vref(self, node):
25 self.body.append(r'\vref{' + node['latex'] + '}')
29 class vrefr(nodes.Inline, nodes.TextElement):
32 def vrefr_role(role, rawtext, text, lineno, inliner, options={}, content=[]):
33 latex = utils.unescape(text, restore_backslashes=True)
34 return [vrefr(latex=latex)], []
36 def latex_visit_vrefr(self, node):
37 range = tuple(node['latex'].split(',', 1))
38 self.body.append(r'\vrefrange{%s}{%s}' % range)
43 app.add_node(r, latex=(latex_visit_r, None))
44 app.add_node(vref, latex=(latex_visit_vref, None))
45 app.add_node(vrefr, latex=(latex_visit_vrefr, None))
46 app.add_role('r', r_role)
47 app.add_role('vref', vref_role)
48 app.add_role('vrefr', vrefr_role)