예제 #1
0
    def do_formula(self, node):
        """Read latex formula from xml file
        and post-process it for swig/sphinx-apidoc.

        Parameters
        ----------
        content : xml node

        The current formula is appended to latex_forms.

        Note
        ----
        * latex formula in doxygen comments leads to a real mess
        during xml->doxy2swig-->swig ... process.

        """
        # ret = doctools.xml_formula_to_swig(node.firstChild.data.strip())
        # self.add_text(' ')
        # self.add_text(ret[0])

        content = node.firstChild.data.strip()
        __id = next(self.__ids)
        node_factory = nf.create_node_factory()
        rst_node = None
        latex = content
        # Either inline
        if latex.startswith("$") and latex.endswith("$"):
            latex = latex[1:-1]
            latex = r':math:`' + latex.strip() + r'`'
            # If we're inline create a math node like the :math: role
            rst_node = node_factory.math()
        else:
            # Else we're multiline
            rst_node = node_factory.displaymath()

        # Or multiline
        if latex.startswith("\[") and latex.endswith("\]"):
            latex = latex[2:-2:]

        # Here we steal the core of the mathbase "math" directive handling code from:
        #    sphinx.ext.mathbase
        rst_node["latex"] = latex

        # Required parameters which we don't have values for
        rst_node["label"] = 'inline'
        rst_node["nowrap"] = False
        rst_node["docname"] = None
        rst_node["number"] = None
        self.latex_forms[__id] = rst_node
        # !!  '_' is required
        # e.g. replace('FORMULA1') leads to wrong behavior because of FORMULA10
        # while 'FORMULA1_' works.
        id_formula = 'FORMULA' + str(__id) + '_'
        #self.add_text(' ')
        if self.replace_latex:
            self.add_text(id_formula)
        else:
            self.add_text(latex)
예제 #2
0
    def do_formula(self, node):
        """Read latex formula from xml file
        and post-process it for swig/sphinx-apidoc.
        
        Parameters
        ----------
        content : xml node
    
        The current formula is appended to latex_forms.
        
        Note
        ----
        * latex formula in doxygen comments leads to a real mess 
        during xml->doxy2swig-->swig ... process.
        
        """
        # ret = doctools.xml_formula_to_swig(node.firstChild.data.strip())
        # self.add_text(' ')
        # self.add_text(ret[0])

        content = node.firstChild.data.strip()
        __id = next(self.__ids)
        node_factory = nf.create_node_factory()
        rst_node = None
        latex = content
        # Either inline
        if latex.startswith("$") and latex.endswith("$"):
            latex = latex[1:-1]
            latex = r':math:`' + latex.strip() + r'`'
            # If we're inline create a math node like the :math: role
            rst_node = node_factory.math()
        else:
            # Else we're multiline
            rst_node = node_factory.displaymath()

        # Or multiline
        if latex.startswith("\[") and latex.endswith("\]"):
            latex = latex[2:-2:]

        # Here we steal the core of the mathbase "math" directive handling code from:
        #    sphinx.ext.mathbase
        rst_node["latex"] = latex

        # Required parameters which we don't have values for
        rst_node["label"] = 'inline'
        rst_node["nowrap"] = False
        rst_node["docname"] = None
        rst_node["number"] = None
        self.latex_forms[__id] = rst_node
        # !!  '_' is required
        # e.g. replace('FORMULA1') leads to wrong behavior because of FORMULA10
        # while 'FORMULA1_' works.
        id_formula = 'FORMULA' + str(__id) + '_'
        #self.add_text(' ')
        if self.replace_latex:
            self.add_text(id_formula)
        else:
            self.add_text(latex)
예제 #3
0
def render(member_def, domain=None, show_define_initializer=False):
    """Render Doxygen *member_def* with *renderer_class*."""
    renderer = SphinxRenderer(MockProjectInfo(show_define_initializer),
                              None,  # renderer_factory
                              create_node_factory(),
                              None,  # state
                              None,  # document
                              MockTargetHandler(),
                              None,   # compound_parser
                              OpenFilter())
    renderer.context = MockContext([member_def], domain)
    return renderer.render(member_def)
예제 #4
0
def render(member_def, domain=None, show_define_initializer=False):
    """Render Doxygen *member_def* with *renderer_class*."""
    renderer = SphinxRenderer(MockProjectInfo(show_define_initializer),
                              None,  # renderer_factory
                              create_node_factory(),
                              None,  # state
                              None,  # document
                              MockTargetHandler(),
                              None,   # compound_parser
                              OpenFilter())
    renderer.context = MockContext([member_def], domain)
    return renderer.render(member_def)
예제 #5
0
def render(member_def):
    """Render Doxygen *member_def* with *renderer_class*."""
    renderer = SphinxRenderer(MockProjectInfo(),
                              None,  # renderer_factory
                              create_node_factory(),
                              None,  # state
                              None,  # document
                              MockTargetHandler(),
                              None,   # compound_parser
                              OpenFilter())
    renderer.context = MockContext([member_def])
    return renderer.render(member_def)
예제 #6
0
def render(member_def):
    """Render Doxygen *member_def* with *renderer_class*."""
    renderer = SphinxRenderer(
        MockProjectInfo(),
        None,  # renderer_factory
        create_node_factory(),
        None,  # state
        None,  # document
        MockTargetHandler(),
        None,  # compound_parser
        OpenFilter())
    renderer.context = MockContext([member_def])
    return renderer.render(member_def)
예제 #7
0
    def do_verbatim(self, node):
        """Read latex or other verbatim rst from xml file
        and post-process it for swig sphinx-apidoc.

        Parameters
        ----------
        node : xml node

        The current formula is appended to latex_forms.

        Note
        ----
        * latex formula in doxygen comments leads to a real mess
        during xml->doxy2swig-->swig ... process.
        Use \rst / \endrst in doxygen files to make it work!

        """
        self.start_new_paragraph()

        if not node.firstChild.data.strip().startswith("embed:rst"):
            self.subnode_parse(node, pieces=[''], indent=4)
        else:
            content = node.firstChild.data
            if content.strip().startswith("embed:rst:leading-asterisk"):

                lines = content.splitlines()
                # Replace the first * on each line with a blank space
                lines = map(lambda text: text.replace("*", " ", 1), lines)
                content = "\n".join(lines)

            # Remove the first line which is "embed:rst[:leading-asterisk]"
            text = '\n'.join(content.split(u'\n')[1:])

            # Remove starting whitespace
            text = textwrap.dedent(text)
            __id = next(self.__ids)
            node_factory = nf.create_node_factory()
            rst_node = node_factory.displaymath()
            rst_node["latex"] = text
            rst_node["label"] = None
            rst_node["nowrap"] = False
            rst_node["docname"] = None
            rst_node["number"] = None

            self.latex_forms[__id] = rst_node
            id_formula = 'FORMULA' + str(__id) + '_'
            #self.add_text(' ')
            self.add_text(id_formula)
예제 #8
0
    def do_verbatim(self, node):
        """Read latex or other verbatim rst from xml file
        and post-process it for swig/sphinx-apidoc.

        Parameters
        ----------
        node : xml node

        The current formula is appended to latex_forms.

        Note
        ----
        * latex formula in doxygen comments leads to a real mess 
        during xml->doxy2swig-->swig ... process. 
        Use \rst / \endrst in doxygen files to make it work!

        """
        self.start_new_paragraph()

        if not node.firstChild.data.strip().startswith("embed:rst"):
            self.subnode_parse(node, pieces=[''], indent=4)
        else:
            content = node.firstChild.data
            if content.strip().startswith("embed:rst:leading-asterisk"):

                lines = content.splitlines()
                # Replace the first * on each line with a blank space
                lines = map(lambda text: text.replace("*", " ", 1), lines)
                content = "\n".join(lines)

            # Remove the first line which is "embed:rst[:leading-asterisk]"
            text = '\n'.join(content.split(u'\n')[1:])

            # Remove starting whitespace
            text = textwrap.dedent(text)
            __id = next(self.__ids)
            node_factory = nf.create_node_factory()
            rst_node = node_factory.displaymath()
            rst_node["latex"] = text
            rst_node["label"] = None
            rst_node["nowrap"] = False
            rst_node["docname"] = None
            rst_node["number"] = None

            self.latex_forms[__id] = rst_node
            id_formula = 'FORMULA' + str(__id) + '_'
            #self.add_text(' ')
            self.add_text(id_formula)