def _process_node(self, node): # Avoid literals etc if not isinstance(node.parent, nodes.paragraph): return in_str = node.rawsource processed = txt_dollars_to_math(in_str) if MATH_MARKER not in processed: return parts = processed.split(MATH_MARKER) new_nodes = [] for i, part in enumerate(parts): with_nulls = escape2null(part) to_backslashes = unescape(with_nulls, restore_backslashes=True) if part == '': continue if i % 2: # See sphinx.ext.mathbase new_node = math(latex=to_backslashes) else: new_node = nodes.Text(unescape(with_nulls), to_backslashes) new_node.parent = node.parent new_nodes.append(new_node) # Put new nodes into parent's list of children new_children = [] for child in node.parent.children: if not child is node: new_children.append(child) else: new_children += new_nodes node.parent.children = new_children
def math_role(role, rawtext, text, lineno, inliner, options={}, content=[]): latex = text.replace('\x00', '\\') # WP strips single backslash obj = math(latex=latex) obj.document = inliner.document # docutils crashes w/o this return [obj], []
def ext_math_role(role, raw, text, line, inliner, options = {}, content = []): text = replace_mathdefs(inliner.document, raw.split('`')[1]) return [math(raw, text)], []
def my_math_role(role, rawtext, text, lineno, inliner, options={}, content=[]): return [math(latex='E = mc^2')], []