def math(role, rawtext, text, lineno, inliner, options={}, content=[]): # In order to properly preserve backslashes (well, and backticks) text = rawtext[rawtext.find('`') + 1:rawtext.rfind('`')] # Fallback rendering as code requested if settings['M_MATH_RENDER_AS_CODE']: set_classes(options) classes = [] if 'classes' in options: classes += options['classes'] del options['classes'] content = nodes.raw('', html.escape(utils.unescape(text)), format='html') node = nodes.literal(rawtext, '', **options) node.append(content) return [node], [] # Apply classes to the <svg> element instead of some outer <span> set_classes(options) classes = 'm-math' if 'classes' in options: classes += ' ' + ' '.join(options['classes']) del options['classes'] depth, svg = latex2svgextra.fetch_cached_or_render("$" + text + "$") attribs = ' class="{}"'.format(classes) node = nodes.raw(rawtext, latex2svgextra.patch(text, svg, depth, attribs), format='html', **options) return [node], []
def math(role, rawtext, text, lineno, inliner, options={}, content=[]): # Otherwise the backslashes do quite a mess there i = rawtext.find('`') text = rawtext.split('`')[1] # Fallback rendering as code requested if render_as_code: set_classes(options) classes = [] if 'classes' in options: classes += options['classes'] del options['classes'] content = nodes.raw('', html.escape(utils.unescape(text)), format='html') node = nodes.literal(rawtext, '', **options) node.append(content) return [node], [] # Apply classes to the <svg> element instead of some outer <span> set_classes(options) classes = 'm-math' if 'classes' in options: classes += ' ' + ' '.join(options['classes']) del options['classes'] depth, svg = latex2svgextra.fetch_cached_or_render("$" + text + "$") attribs = ' class="{}"'.format(classes) node = nodes.raw(rawtext, latex2svgextra.patch(text, svg, depth, attribs), format='html', **options) return [node], []
def run(self): set_classes(self.options) self.assert_has_content() # Fallback rendering as code requested if render_as_code: content = nodes.raw('', html.escape('\n'.join(self.content)), format='html') pre = nodes.literal_block('') pre.append(content) return [pre] # join lines, separate blocks content = '\n'.join(self.content).split('\n\n') _nodes = [] for block in content: if not block: continue _, svg = latex2svgextra.fetch_cached_or_render("$$" + block + "$$") container = nodes.container(**self.options) container['classes'] += ['m-math'] node = nodes.raw(self.block_text, latex2svgextra.patch(block, svg, None, ''), format='html') node.line = self.content_offset + 1 self.add_name(node) container.append(node) _nodes.append(container) return _nodes
def math(role, rawtext, text, lineno, inliner, options={}, content=[]): # Otherwise the backslashes do quite a mess there i = rawtext.find('`') text = rawtext.split('`')[1] # Fallback rendering as code requested if settings['M_MATH_RENDER_AS_CODE']: set_classes(options) classes = [] if 'classes' in options: classes += options['classes'] del options['classes'] content = nodes.raw('', html.escape(utils.unescape(text)), format='html') node = nodes.literal(rawtext, '', **options) node.append(content) return [node], [] # Apply classes to the <svg> element instead of some outer <span> set_classes(options) classes = 'm-math' if 'classes' in options: classes += ' ' + ' '.join(options['classes']) del options['classes'] depth, svg = latex2svgextra.fetch_cached_or_render("$" + text + "$") attribs = ' class="{}"'.format(classes) node = nodes.raw(rawtext, latex2svgextra.patch(text, svg, depth, attribs), format='html', **options) return [node], []
def run(self): set_classes(self.options) self.assert_has_content() parent = self.state.parent # Fallback rendering as code requested if settings['M_MATH_RENDER_AS_CODE']: # If this is a math figure, replace the figure CSS class to have a # matching border if _is_math_figure(parent): parent['classes'][parent['classes'].index( 'm-figure')] = 'm-code-figure' content = nodes.raw('', html.escape('\n'.join(self.content)), format='html') pre = nodes.literal_block('') pre.append(content) return [pre] content = '\n'.join(self.content) _, svg = latex2svgextra.fetch_cached_or_render("$$" + content + "$$") # If this is the first real node inside a math figure, put the SVG # directly inside if _is_math_figure(parent): node = nodes.raw( self.block_text, latex2svgextra.patch( content, svg, None, ' class="{}"'.format( ' '.join(['m-math'] + self.options.get('classes', [])))), format='html') node.line = self.content_offset + 1 self.add_name(node) return [node] # Otherwise wrap it in a <div class="m-math"> node = nodes.raw(self.block_text, latex2svgextra.patch(content, svg, None, ''), format='html') node.line = self.content_offset + 1 self.add_name(node) container = nodes.container(**self.options) container['classes'] += ['m-math'] container.append(node) return [container]
def run(self): set_classes(self.options) self.assert_has_content() parent = self.state.parent # Fallback rendering as code requested if settings['M_MATH_RENDER_AS_CODE']: # If this is a math figure, replace the figure CSS class to have a # matching border if _is_math_figure(parent): parent['classes'][parent['classes'].index('m-figure')] = 'm-code-figure' content = nodes.raw('', html.escape('\n'.join(self.content)), format='html') pre = nodes.literal_block('') pre.append(content) return [pre] content = '\n'.join(self.content) _, svg = latex2svgextra.fetch_cached_or_render("$$" + content + "$$") # If this is the first real node inside a math figure, put the SVG # directly inside if _is_math_figure(parent): node = nodes.raw(self.block_text, latex2svgextra.patch(content, svg, None, ' class="{}"'.format(' '.join(['m-math'] + self.options.get('classes', [])))), format='html') node.line = self.content_offset + 1 self.add_name(node) return [node] # Otherwise wrap it in a <div class="m-math"> node = nodes.raw(self.block_text, latex2svgextra.patch(content, svg, None, ''), format='html') node.line = self.content_offset + 1 self.add_name(node) container = nodes.container(**self.options) container['classes'] += ['m-math'] container.append(node) return [container]