def make_math_node(self, latex): node = displaymath() node['latex'] = latex node['label'] = None # Otherwise equations are numbered node['nowrap'] = False node['docname'] = self.state.document.settings.env.docname return node
def make_math_node(latex, docname, nowrap): node = mathbase.displaymath() node['latex'] = latex node['label'] = None # Otherwise equations are numbered node['nowrap'] = nowrap node['docname'] = docname node['number'] = None return node
def run(self): latex = '\n'.join(self.content) if self.arguments and self.arguments[0]: latex = self.arguments[0] + '\n\n' + latex node = displaymath() node['latex'] = latex node['label'] = self.options.get('label', None) node['nowrap'] = 'nowrap' in self.options ret = [node] if node['label']: tnode = nodes.target('', '', ids=['equation-' + node['label']]) self.state.document.note_explicit_target(tnode) ret.insert(0, tnode) return ret
def run(self): context = self.get_context(self.options.get('newcontext', False)) val = eval_code('\n'.join(self.content), context) if val is None: return [] node = displaymath() node['latex'] = latex(val) node['label'] = self.options.get('name', None) if node['label'] is None: node['label'] = self.options.get('label', None) node['nowrap'] = 'nowrap' in self.options node['docname'] = self.state.document.settings.env.docname ret = [node] set_source_info(self, node) if hasattr(self, 'src'): node.source = self.src if node['label']: tnode = nodes.target('', '', ids=['equation-' + node['label']]) self.state.document.note_explicit_target(tnode) ret.insert(0, tnode) return ret
def cell_output_to_nodes(cell, data_priority, dir): """Convert a jupyter cell with outputs and filenames to doctree nodes. Parameters ========== cell : jupyter cell data_priority : list of mime types Which media types to prioritize. dir : string Sphinx "absolute path" to the output folder, so it is a relative path to the source folder prefixed with ``/``. """ to_add = [] for index, output in enumerate(cell.get('outputs', [])): output_type = output['output_type'] if (output_type == 'stream' and output['name'] == 'stdout'): to_add.append( docutils.nodes.literal_block( text=output['text'], rawsource=output['text'], language='ipython', )) elif (output_type == 'error'): traceback = '\n'.join(output['traceback']) text = nbconvert.filters.strip_ansi(traceback) to_add.append( docutils.nodes.literal_block( text=text, rawsource=text, language='ipythontb', )) elif (output_type in ('display_data', 'execute_result')): try: # First mime_type by priority that occurs in output. mime_type = next(x for x in data_priority if x in output['data']) except StopIteration: continue data = output['data'][mime_type] if mime_type.startswith('image'): # Sphinx treats absolute paths as being rooted at the source # directory, so make a relative path, which Sphinx treats # as being relative to the current working directory. filename = os.path.basename( output.metadata['filenames'][mime_type]) uri = os.path.join(dir, filename) to_add.append(docutils.nodes.image(uri=uri)) elif mime_type == 'text/html': to_add.append(docutils.nodes.raw(text=data, format='html')) elif mime_type == 'text/latex': to_add.append( displaymath( latex=data, nowrap=False, number=None, )) elif mime_type == 'text/plain': to_add.append( docutils.nodes.literal_block( text=data, rawsource=data, language='ipython', )) elif mime_type == WIDGET_VIEW_MIMETYPE: to_add.append( docutils.nodes.raw( text='<script type="{mime_type}">{data}</script>'. format(mime_type=mime_type, data=json.dumps(data)), format='html', )) return to_add
def run(self): return [displaymath(latex='E = mc^2')]