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