def html_visit_displaymath(self: HTMLTranslator, node: nodes.math_block) -> None: self.body.append(self.starttag(node, 'div', CLASS='math notranslate nohighlight')) if node['nowrap']: self.body.append(self.encode(node.astext())) self.body.append('</div>') raise nodes.SkipNode # necessary to e.g. set the id property correctly if node['number']: number = get_node_equation_number(self, node) self.body.append('<span class="eqno">(%s)' % number) self.add_permalink_ref(node, _('Permalink to this equation')) self.body.append('</span>') self.body.append(self.builder.config.mathjax_display[0]) parts = [prt for prt in node.astext().split('\n\n') if prt.strip()] if len(parts) > 1: # Add alignment if there are more than 1 equation self.body.append(r' \begin{align}\begin{aligned}') for i, part in enumerate(parts): part = self.encode(part) if r'\\' in part: self.body.append(r'\begin{split}' + part + r'\end{split}') else: self.body.append(part) if i < len(parts) - 1: # append new line if not the last equation self.body.append(r'\\') if len(parts) > 1: # Add alignment if there are more than 1 equation self.body.append(r'\end{aligned}\end{align} ') self.body.append(self.builder.config.mathjax_display[1]) self.body.append('</div>\n') raise nodes.SkipNode
def html_visit_displaymath(self: HTMLTranslator, node: nodes.math_block) -> None: if node['nowrap']: latex = node.astext() else: latex = wrap_displaymath(node.astext(), None, False) try: fname, depth = render_math(self, latex) except MathExtError as exc: msg = str(exc) sm = nodes.system_message(msg, type='WARNING', level=2, backrefs=[], source=node.astext()) sm.walkabout(self) logger.warning(__('inline latex %r: %s'), node.astext(), msg) raise nodes.SkipNode from exc self.body.append(self.starttag(node, 'div', CLASS='math')) self.body.append('<p>') if node['number']: number = get_node_equation_number(self, node) self.body.append('<span class="eqno">(%s)' % number) self.add_permalink_ref(node, _('Permalink to this equation')) self.body.append('</span>') if fname is None: # something failed -- use text-only as a bad substitute self.body.append('<span class="math">%s</span></p>\n</div>' % self.encode(node.astext()).strip()) else: self.body.append(('<img src="%s"' % fname) + get_tooltip(self, node) + '/></p>\n</div>') raise nodes.SkipNode
def html_visit_displaymath(self: HTMLTranslator, node: nodes.math_block) -> None: if node['nowrap']: self.body.append( self.starttag(node, 'div', CLASS='math notranslate nohighlight')) self.body.append(self.encode(node.astext())) self.body.append('</div>') raise nodes.SkipNode for i, part in enumerate(node.astext().split('\n\n')): part = self.encode(part) if i == 0: # necessary to e.g. set the id property correctly if node['number']: number = get_node_equation_number(self, node) self.body.append('<span class="eqno">(%s)' % number) self.add_permalink_ref(node, _('Permalink to this equation')) self.body.append('</span>') self.body.append( self.starttag(node, 'div', CLASS='math notranslate nohighlight')) else: # but only once! self.body.append('<div class="math">') if '&' in part or '\\\\' in part: self.body.append('\\begin{split}' + part + '\\end{split}') else: self.body.append(part) self.body.append('</div>\n') raise nodes.SkipNode
def html_visit_displaymath(self: HTMLTranslator, node: nodes.math_block) -> None: """Override for sphinx.ext.mathjax.html_visit_displaymath to handle amsmath. By default displaymath, are normally wrapped in a prefix/suffix, defined by mathjax_display, and labelled nodes are numbered. However, this is not the case if the math_block is set as 'nowrap', as for amsmath. Therefore, we need to override this behaviour. """ if "amsmath" in node.get("classes", []): self.body.append( self.starttag(node, "div", CLASS="math notranslate nohighlight amsmath")) if node["number"]: number = get_node_equation_number(self, node) self.body.append('<span class="eqno">(%s)' % number) self.add_permalink_ref(node, _("Permalink to this equation")) self.body.append("</span>") prefix, suffix = self.builder.config.mathjax_display self.body.append(prefix) self.body.append(self.encode(node.astext())) self.body.append(suffix) self.body.append("</div>\n") raise nodes.SkipNode return mathjax.html_visit_displaymath(self, node)
def html_visit_displaymath(self: HTMLTranslator, node: nodes.math_block) -> None: if node.get('label') and node['number']: label = "equation:%s:%s" % (node['docname'], node['label']) number = get_node_equation_number(self, node) else: label = None number = None self.body.append( self.starttag(node, 'div', CLASS='math notranslate nohighlight')) if node.get('nowrap'): if label: self.body.append(r'\label{%s}' % label) if number: self.body.append(r'\tag{%s}' % label) self.body.append(node.astext()) else: self.body.append(tag_displaymath(node.astext(), label, number, False)) self.body.append('</div>\n') # if node.get('label'): # label = "equation:%s:%s" % (node['docname'], node['label']) # else: # label = None # self.body.append(self.starttag(node, 'div', CLASS='math notranslate nohighlight')) # if node.get('nowrap'): # if label: # self.body.append(r'\label{%s}' % label) # self.body.append(node.astext()) # else: # self.body.append(wrap_displaymath(node.astext(), label, False)) # self.body.append('</div>\n') # self.body.append(self.starttag(node, 'div', CLASS='math notranslate nohighlight')) # if node['nowrap']: # self.body.append(self.encode(node.astext())) # self.body.append('</div>') # raise nodes.SkipNode # # necessary to e.g. set the id property correctly # if node['number']: # # number = get_node_equation_number(self, node) # # self.body.append('<span class="eqno">(%s)' % number) # # self.add_permalink_ref(node, _('Permalink to this equation')) # # self.body.append('</span>') # self.body.append(self.builder.config.mathjax_display[0]) # parts = [prt for prt in node.astext().split('\n\n') if prt.strip()] # if len(parts) > 1: # Add alignment if there are more than 1 equation # self.body.append(r' \begin{aligned}') # for i, part in enumerate(parts): # part = self.encode(part) # if r'\\' in part: # self.body.append(r'\begin{split}' + part + r'\end{split}') # else: # self.body.append(part) # if i < len(parts) - 1: # append new line if not the last equation # self.body.append(r'\\') # if len(parts) > 1: # Add alignment if there are more than 1 equation # self.body.append(r'\end{aligned} ') # self.body.append(self.builder.config.mathjax_display[1]) # self.body.append('</div>\n') # self.body.append(self.builder.config.mathjax_display[0] + # self.encode(node.astext()) + # self.builder.config.mathjax_display[1]) raise nodes.SkipNode