useblocks / sphinx-simplepdf

A simple PDF builder for Sphinx documentations
https://sphinx-simplepdf.readthedocs.io
MIT License
36 stars 15 forks source link

Improvement: Generate separate PDFs based on TOC #50

Closed sachin-suresh-rapyuta closed 1 year ago

sachin-suresh-rapyuta commented 1 year ago

Just an improvement suggestion:

I have a multiple TOC's in my index.rst. I intend to create separate PDFs for each TOC. Is there a way where I can generate a PDF on the command line or configure it in conf.py for each TOC (using some flags or caption text of the TOC)?

Currently, I am commenting out the TOC which I don't need in the PDF.

danwos commented 1 year ago

You can use the if-collection directive from https://sphinx-collections.readthedocs.io/en/latest/directives.html to control the toc to use via Sphinx tags.

Then you can build docs like: sphinx-build -t docs_for_A -b pdf . _build/A/simplepdf or sphinx-build -t docs_for_B b pdf . _build/B/simplepdf

Do not use the in-build only directive from Sphinx, it does nearly the same, but can not be used to manipulate the final doc structure.

sachin-suresh-rapyuta commented 1 year ago

Here is my conf.py:

.. if-builder:: simplepdf

   .. if-collection:: guide_1

      .. toctree::
         :maxdepth: 2
         :caption: Guide 1

         /guide_1/something
         /guide_1/something

   .. if-collection:: guide_2   

       .. toctree::
          :maxdepth: 2
          :caption: Guide 2

           /guide_2/something
           /guide_2/something

  .. if-collection:: common_guide

        .. toctree::
          :maxdepth: 2
          :caption: Common Guide

           /common/something
           /common/something

I need Common Guide TOC to appear for Guides 1 and 2.

The below command generates only front and back cover PDF pages:

sphinx-build -t guide_1 -b simplepdf . build/guide_1/simplepdf

Is my logic/syntax correctly used?

danwos commented 1 year ago

Argh, I was wrong. if-collection needs a configured collection and it can be configured to listen on specific sphinx-tags. https://sphinx-collections.readthedocs.io/en/latest/collections/index.html#tags

So some dummy collection is needed, to use this mechanism. Maybe there are better ways, but I don't know any.

I would like to close this issue, as it is not sphinx-SimplePDF related and it's more discussing a general Sphinx topic like "variant handling in sphinx".