Пример #1
0
 def write(self, *ignored):
     super(CustomLaTeXBuilder, self).write(*ignored)
     
     backup_translator = sphinx.writers.latex.LaTeXTranslator
     sphinx.writers.latex.LaTeXTranslator = CustomLaTeXTranslator
     backup_doc = sphinx.writers.latex.BEGIN_DOC
     sphinx.writers.latex.BEGIN_DOC = ''
     
     # output these as include files
     for docname in ['abstract', 'dedication', 'acknowledgements']:
         destination = FileOutput(
                 destination_path=os.path.join(self.outdir, '%s.inc' % docname),
                 encoding='utf-8')
         
         docwriter = LaTeXWriter(self)
         doctree = self.env.get_doctree(docname)
         
         docsettings = OptionParser(
             defaults=self.env.settings,
             components=(docwriter,)).get_default_values()
         doctree.settings = docsettings
         docwriter.write(doctree, destination)
     
     sphinx.writers.latex.LaTeXTranslator = backup_translator
     sphinx.writers.latex.BEGIN_DOC = backup_doc
Пример #2
0
    def write(self, *ignored):
        docwriter = LaTeXWriter(self)
        docsettings = OptionParser(
            defaults=self.env.settings,
            components=(docwriter,)).get_default_values()

        self.init_document_data()

        for entry in self.document_data:
            docname, targetname, title, author, docclass = entry[:5]
            toctree_only = False
            if len(entry) > 5:
                toctree_only = entry[5]
            destination = FileOutput(
                destination_path=path.join(self.outdir, targetname),
                encoding='utf-8')
            self.info("processing " + targetname + "... ", nonl=1)
            doctree = self.assemble_doctree(docname, toctree_only,
                appendices=((docclass != 'howto') and
                            self.config.latex_appendices or []))
            self.post_process_images(doctree)
            self.info("writing... ", nonl=1)
            doctree.settings = docsettings
            doctree.settings.author = author
            doctree.settings.title = title
            doctree.settings.docname = docname
            doctree.settings.docclass = docclass
            docwriter.write(doctree, destination)
            self.info("done")
Пример #3
0
    def write(self, *ignored):
        docwriter = LaTeXWriter(self)
        docsettings = OptionParser(defaults=self.env.settings, components=(docwriter,)).get_default_values()

        self.init_document_data()

        for entry in self.document_data:
            docname, targetname, title, author, docclass = entry[:5]
            toctree_only = False
            if len(entry) > 5:
                toctree_only = entry[5]
            destination = FileOutput(destination_path=path.join(self.outdir, targetname), encoding="utf-8")
            self.info("processing " + targetname + "... ", nonl=1)
            doctree = self.assemble_doctree(
                docname, toctree_only, appendices=((docclass != "howto") and self.config.latex_appendices or [])
            )
            self.post_process_images(doctree)
            self.info("writing... ", nonl=1)
            doctree.settings = docsettings
            doctree.settings.author = author
            doctree.settings.title = title
            doctree.settings.docname = docname
            doctree.settings.docclass = docclass
            docwriter.write(doctree, destination)
            self.info("done")
Пример #4
0
    def write(self, *ignored):
        super(CustomLaTeXBuilder, self).write(*ignored)

        backup_translator = sphinx.writers.latex.LaTeXTranslator
        sphinx.writers.latex.LaTeXTranslator = CustomLaTeXTranslator
        backup_doc = sphinx.writers.latex.BEGIN_DOC
        sphinx.writers.latex.BEGIN_DOC = ''

        # output these as include files
        for docname in ['abstract', 'dedication', 'acknowledgements']:
            destination = FileOutput(destination_path=os.path.join(
                self.outdir, '%s.inc' % docname),
                                     encoding='utf-8')

            docwriter = LaTeXWriter(self)
            doctree = self.env.get_doctree(docname)

            docsettings = OptionParser(
                defaults=self.env.settings,
                components=(docwriter, )).get_default_values()
            doctree.settings = docsettings
            docwriter.write(doctree, destination)

        sphinx.writers.latex.LaTeXTranslator = backup_translator
        sphinx.writers.latex.BEGIN_DOC = backup_doc
Пример #5
0
    def write(self, *ignored: Any) -> None:
        docwriter = LaTeXWriter(self)
        with warnings.catch_warnings():
            warnings.filterwarnings('ignore', category=DeprecationWarning)
            # DeprecationWarning: The frontend.OptionParser class will be replaced
            # by a subclass of argparse.ArgumentParser in Docutils 0.21 or later.
            docsettings: Any = OptionParser(
                defaults=self.env.settings,
                components=(docwriter, ),
                read_config_files=True).get_default_values()

        self.init_document_data()
        self.write_stylesheet()

        for entry in self.document_data:
            docname, targetname, title, author, themename = entry[:5]
            theme = self.themes.get(themename)
            toctree_only = False
            if len(entry) > 5:
                toctree_only = entry[5]
            destination = SphinxFileOutput(destination_path=path.join(
                self.outdir, targetname),
                                           encoding='utf-8',
                                           overwrite_if_changed=True)
            with progress_message(__("processing %s") % targetname):
                doctree = self.env.get_doctree(docname)
                toctree = next(doctree.findall(addnodes.toctree), None)
                if toctree and toctree.get('maxdepth') > 0:
                    tocdepth = toctree.get('maxdepth')
                else:
                    tocdepth = None

                doctree = self.assemble_doctree(
                    docname,
                    toctree_only,
                    appendices=(self.config.latex_appendices
                                if theme.name != 'howto' else []))
                doctree['docclass'] = theme.docclass
                doctree['contentsname'] = self.get_contentsname(docname)
                doctree['tocdepth'] = tocdepth
                self.post_process_images(doctree)
                self.update_doc_context(title, author, theme)
                self.update_context()

            with progress_message(__("writing")):
                docsettings._author = author
                docsettings._title = title
                docsettings._contentsname = doctree['contentsname']
                docsettings._docname = docname
                docsettings._docclass = theme.name

                doctree.settings = docsettings
                docwriter.theme = theme
                docwriter.write(doctree, destination)
Пример #6
0
    def write(self, *ignored: Any) -> None:
        docwriter = LaTeXWriter(self)
        docsettings = OptionParser(
            defaults=self.env.settings,
            components=(docwriter, ),
            read_config_files=True).get_default_values()  # type: Any
        patch_settings(docsettings)

        self.init_document_data()
        self.write_stylesheet()

        for entry in self.document_data:
            docname, targetname, title, author, themename = entry[:5]
            theme = self.themes.get(themename)
            toctree_only = False
            if len(entry) > 5:
                toctree_only = entry[5]
            destination = SphinxFileOutput(destination_path=path.join(
                self.outdir, targetname),
                                           encoding='utf-8',
                                           overwrite_if_changed=True)
            with progress_message(__("processing %s") % targetname):
                doctree = self.env.get_doctree(docname)
                toctree = next(iter(doctree.traverse(addnodes.toctree)), None)
                if toctree and toctree.get('maxdepth') > 0:
                    tocdepth = toctree.get('maxdepth')
                else:
                    tocdepth = None

                doctree = self.assemble_doctree(
                    docname,
                    toctree_only,
                    appendices=(self.config.latex_appendices
                                if theme.name != 'howto' else []))
                doctree['docclass'] = theme.docclass
                doctree['contentsname'] = self.get_contentsname(docname)
                doctree['tocdepth'] = tocdepth
                self.post_process_images(doctree)
                self.update_doc_context(title, author, theme)
                self.update_context()

            with progress_message(__("writing")):
                docsettings._author = author
                docsettings._title = title
                docsettings._contentsname = doctree['contentsname']
                docsettings._docname = docname
                docsettings._docclass = theme.name

                doctree.settings = docsettings
                docwriter.theme = theme
                docwriter.write(doctree, destination)
Пример #7
0
    def write(self, *ignored):
        # type: (Any) -> None
        docwriter = LaTeXWriter(self)
        docsettings = OptionParser(
            defaults=self.env.settings,
            components=(docwriter, ),
            read_config_files=True).get_default_values()  # type: Any

        self.init_document_data()
        self.write_stylesheet()

        for entry in self.document_data:
            docname, targetname, title, author, docclass = entry[:5]
            toctree_only = False
            if len(entry) > 5:
                toctree_only = entry[5]
            destination = SphinxFileOutput(destination_path=path.join(
                self.outdir, targetname),
                                           encoding='utf-8',
                                           overwrite_if_changed=True)
            logger.info(__("processing %s..."), targetname, nonl=1)
            toctrees = self.env.get_doctree(docname).traverse(addnodes.toctree)
            if toctrees:
                if toctrees[0].get('maxdepth') > 0:
                    tocdepth = toctrees[0].get('maxdepth')
                else:
                    tocdepth = None
            else:
                tocdepth = None
            doctree = self.assemble_doctree(
                docname,
                toctree_only,
                appendices=((docclass != 'howto')
                            and self.config.latex_appendices or []))
            doctree['tocdepth'] = tocdepth
            self.apply_transforms(doctree)
            self.post_process_images(doctree)
            self.update_doc_context(title, author)

            logger.info(__("writing... "), nonl=1)
            docsettings.author = author
            docsettings.title = title
            docsettings.contentsname = self.get_contentsname(docname)
            docsettings.docname = docname
            docsettings.docclass = docclass

            doctree.settings = docsettings
            docwriter.write(doctree, destination)
            logger.info(__("done"))
Пример #8
0
    def write_latex_document(self, latex_document_node,
                             all_latex_document_nodes):
        output_filename = latex_document_node["multilatex-filename"]
        variables       = latex_document_node["multilatex-variables"]
        content         = latex_document_node["multilatex-content"]
        options         = latex_document_node["multilatex-options"]
        docname         = latex_document_node["multilatex-docname"]
        doctree         = latex_document_node["multilatex-doctree"]

        if not output_filename.endswith(".tex"):
            output_filename += ".tex"
        self.info("processing {0}...".format(output_filename), nonl=1)

#        for node in doctree.traverse(latex_document):
#            node.parent.remove(node)
#        parent_node = latex_document_node.parent
#        parent_node.remove(latex_document_node)

        self.post_process_images(doctree)

        self.info("writing...", nonl=1)
        docwriter = LaTeXWriter(self)
        option_parser = OptionParser(
            defaults=self.env.settings,
            components=(docwriter,),
            read_config_files=True)

        doctree.settings = option_parser.get_default_values()
        settings = doctree.settings
        settings.contentsname = None
        settings.docname = docname
        for name, value in options.items():
            setattr(settings, name, value)
        settings.multilatex_options = options
        settings.multilatex_variables = variables
        settings.multilatex_content = content
        settings.multilatex_output_filename = output_filename
        settings.multilatex_all_latex_document_nodes = all_latex_document_nodes

        destination = FileOutput(
            destination_path=os.path.join(self.outdir, output_filename),
            encoding="utf-8")

        docwriter.write(doctree, destination)
        self.info("done")
Пример #9
0
    def write(self, *ignored):
        # type: (Any) -> None
        docwriter = LaTeXWriter(self)
        docsettings = OptionParser(
            defaults=self.env.settings,
            components=(docwriter,),
            read_config_files=True).get_default_values()  # type: Any

        self.init_document_data()
        self.write_stylesheet()

        for entry in self.document_data:
            docname, targetname, title, author, docclass = entry[:5]
            toctree_only = False
            if len(entry) > 5:
                toctree_only = entry[5]
            destination = SphinxFileOutput(destination_path=path.join(self.outdir, targetname),
                                           encoding='utf-8', overwrite_if_changed=True)
            logger.info(__("processing %s..."), targetname, nonl=1)
            toctrees = self.env.get_doctree(docname).traverse(addnodes.toctree)
            if toctrees:
                if toctrees[0].get('maxdepth') > 0:
                    tocdepth = toctrees[0].get('maxdepth')
                else:
                    tocdepth = None
            else:
                tocdepth = None
            doctree = self.assemble_doctree(
                docname, toctree_only,
                appendices=((docclass != 'howto') and self.config.latex_appendices or []))
            doctree['tocdepth'] = tocdepth
            self.apply_transforms(doctree)
            self.post_process_images(doctree)
            self.update_doc_context(title, author)

            logger.info(__("writing... "), nonl=1)
            docsettings.author = author
            docsettings.title = title
            docsettings.contentsname = self.get_contentsname(docname)
            docsettings.docname = docname
            docsettings.docclass = docclass

            doctree.settings = docsettings
            docwriter.write(doctree, destination)
            logger.info("done")
Пример #10
0
    def write_latex_document(self, latex_document_node,
                             all_latex_document_nodes):
        output_filename = latex_document_node["multilatex-filename"]
        variables = latex_document_node["multilatex-variables"]
        content = latex_document_node["multilatex-content"]
        options = latex_document_node["multilatex-options"]
        docname = latex_document_node["multilatex-docname"]
        doctree = latex_document_node["multilatex-doctree"]

        if not output_filename.endswith(".tex"):
            output_filename += ".tex"
        self.info("processing {0}...".format(output_filename), nonl=1)

        #        for node in doctree.traverse(latex_document):
        #            node.parent.remove(node)
        #        parent_node = latex_document_node.parent
        #        parent_node.remove(latex_document_node)

        self.post_process_images(doctree)

        self.info("writing...", nonl=1)
        docwriter = LaTeXWriter(self)
        option_parser = OptionParser(defaults=self.env.settings,
                                     components=(docwriter, ),
                                     read_config_files=True)

        doctree.settings = option_parser.get_default_values()
        settings = doctree.settings
        settings.contentsname = None
        settings.docname = docname
        for name, value in options.items():
            setattr(settings, name, value)
        settings.multilatex_options = options
        settings.multilatex_variables = variables
        settings.multilatex_content = content
        settings.multilatex_output_filename = output_filename
        settings.multilatex_all_latex_document_nodes = all_latex_document_nodes

        destination = FileOutput(destination_path=os.path.join(
            self.outdir, output_filename),
                                 encoding="utf-8")

        docwriter.write(doctree, destination)
        self.info("done")
Пример #11
0
    def write(self, *ignored):
        docwriter = LaTeXWriter(self)
        docsettings = OptionParser(
            defaults=self.env.settings,
            components=(docwriter, ),
            read_config_files=True).get_default_values()

        self.init_document_data()

        for entry in self.document_data:
            docname, targetname, title, author, docclass = entry[:5]
            toctree_only = False
            if len(entry) > 5:
                toctree_only = entry[5]
            destination = FileOutput(destination_path=path.join(
                self.outdir, targetname),
                                     encoding='utf-8')
            self.info("processing " + targetname + "... ", nonl=1)
            toctrees = self.env.get_doctree(docname).traverse(addnodes.toctree)
            if toctrees:
                if toctrees[0].get('maxdepth'):
                    tocdepth = int(toctrees[0].get('maxdepth'))
                else:
                    tocdepth = None
            else:
                tocdepth = None
            doctree = self.assemble_doctree(
                docname,
                toctree_only,
                appendices=((docclass != 'howto')
                            and self.config.latex_appendices or []))
            doctree['tocdepth'] = tocdepth
            self.post_process_images(doctree)
            self.info("writing... ", nonl=1)
            doctree.settings = docsettings
            doctree.settings.author = author
            doctree.settings.title = title
            doctree.settings.contentsname = self.get_contentsname(docname)
            doctree.settings.docname = docname
            doctree.settings.docclass = docclass
            docwriter.write(doctree, destination)
            self.info("done")
Пример #12
0
    def write(self, *ignored):
        docwriter = LaTeXWriter(self)
        docsettings = OptionParser(
            defaults=self.env.settings,
            components=(docwriter,),
            read_config_files=True).get_default_values()

        self.init_document_data()

        for entry in self.document_data:
            docname, targetname, title, author, docclass = entry[:5]
            toctree_only = False
            if len(entry) > 5:
                toctree_only = entry[5]
            destination = FileOutput(
                destination_path=path.join(self.outdir, targetname),
                encoding='utf-8')
            self.info("processing " + targetname + "... ", nonl=1)
            toctrees = self.env.get_doctree(docname).traverse(addnodes.toctree)
            if toctrees:
                if toctrees[0].get('maxdepth'):
                    tocdepth = int(toctrees[0].get('maxdepth'))
                else:
                    tocdepth = None
            else:
                tocdepth = None
            doctree = self.assemble_doctree(
                docname, toctree_only,
                appendices=((docclass != 'howto') and self.config.latex_appendices or []))
            doctree['tocdepth'] = tocdepth
            self.post_process_images(doctree)
            self.info("writing... ", nonl=1)
            doctree.settings = docsettings
            doctree.settings.author = author
            doctree.settings.title = title
            doctree.settings.contentsname = self.get_contentsname(docname)
            doctree.settings.docname = docname
            doctree.settings.docclass = docclass
            docwriter.write(doctree, destination)
            self.info("done")
Пример #13
0
    def write(self, *ignored: Any) -> None:
        assert self.env is not None

        docwriter = LaTeXWriter(self)
        docsettings: Any = OptionParser(
            defaults=self.env.settings,
            components=(docwriter, ),
            read_config_files=True,
        ).get_default_values()

        if sphinx.version_info <= (4, 0):
            # 3rd party
            from sphinx.builders.latex import patch_settings  # type: ignore
            patch_settings(docsettings)

        self.init_document_data()
        self.write_stylesheet()

        for entry in self.document_data:
            docname, targetname, title, author, themename = entry[:5]
            theme = self.themes.get(themename)
            toctree_only = False
            if len(entry) > 5:
                toctree_only = entry[5]
            destination = SphinxFileOutput(destination_path=os.path.join(
                self.outdir, targetname),
                                           encoding="utf-8",
                                           overwrite_if_changed=True)
            with progress_message(__("processing %s") % targetname):
                doctree = self.env.get_doctree(docname)
                process_only_nodes(doctree, self.tags)
                toctree = next(iter(doctree.traverse(addnodes.toctree)), None)
                if toctree and toctree.get("maxdepth") > 0:
                    tocdepth = toctree.get("maxdepth")
                else:
                    tocdepth = None

                doctree = self.assemble_doctree(
                    docname,
                    toctree_only,
                    appendices=(self.config.latex_appendices
                                if theme.name != "howto" else []))
                doctree["docclass"] = theme.docclass
                doctree["contentsname"] = self.get_contentsname(docname)
                doctree["tocdepth"] = tocdepth
                self.post_process_images(doctree)
                self.update_doc_context(title, author, theme)

                if hasattr(self, "update_context"):  # pragma: no cover
                    # Only present in newer Sphinx versions
                    self.update_context()

            with progress_message(__("writing")):
                docsettings._author = author
                docsettings._title = title
                docsettings._contentsname = doctree["contentsname"]
                docsettings._docname = docname
                docsettings._docclass = theme.name

                doctree.settings = docsettings
                docwriter.theme = theme
                docwriter.write(doctree, destination)