How to create a pdf file in reStructuredText?

Documentation for Uncertainty Python package in reStructuredText, for the Sphinx documentation system . HTML looks great . I would like to create a PDF version. The goal is to have a β€œchapter” for each of the web pages.

However, what happens is that the PDF created by the ReST files converts the sections (HTML) index.htmlinto separate chapters (which I don’t want: the PDF should have them as sections too). Another problem is that all HTML pages after the main page are displayed in PDF as subsections of the section where the directive appears toctree(i.e., in the "Confirmation" section on the main page).

So, what a ReST file should look like so that (1) web documents look the same as they are now , and (2)) each web page corresponds to a PDF chapter. Any help would be greatly appreciated!

+3
source share
1 answer

There is a solution . If I remember correctly, the key points were:

  • Use a special table of contents as the main document (I used index_TOC.rstinstead of the standard one index.rst): inconf.py
    • master_doc = 'index_TOC'
    • latex_documents = [('index_TOC', 'uncertaintiesPythonpackage.tex',…]
  • The new table of contents file index_TOC.rstcontains a ToC similar to

    TOC
    ===
    
    .. toctree::
       :hidden:
       :maxdepth: 1
    
       index
       user_guide
       numpy_guide
       tech_guide
    

Thus, the web version is still opened on the main text index.rst, and the PDF version (LaTeX) has each REST file in a separate chapter.

+2
source

Source: https://habr.com/ru/post/1781894/


All Articles