Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

conditional toc tree not discarded #1717

Closed
andreacassioli opened this issue Feb 11, 2015 · 6 comments
Closed

conditional toc tree not discarded #1717

andreacassioli opened this issue Feb 11, 2015 · 6 comments

Comments

@andreacassioli
Copy link

Hi,
I'd like to have a conditional toctree, i.e. some entries should apperars depending on whether I set an variable to a specific value. I have tried as follow:

  1. in a rest file called api-reference.rst I have the following text
API Reference
=========================


.. toctree::
   :maxdepth: 2

   Classes         <reference/class_index>
   Exceptions     <reference/exception_index>
   Enumerations <reference/enum_index>
   Parameters   <reference/parameters>

.. ifconfig:: lang == 'cpp'

   .. toctree::
      :maxdepth: 2

      N-dimensional arrays  <manual/cxx>

  1. in the main file index.rst I have
API documentation
======================================================

.. toctree::
   :maxdepth: 2
   :numbered: 3
   :includehidden:

   intro
   notation
   API Reference <api-reference>

The I run with lang=="dotnet". Curiosly the toctree in the main page is

1. Introduction
2. Notation and Terminology
3. API Reference
   3.1. Classes
   3.2. Exceptions
   3.3. Enumerations
   3.4. Parameters
   3.5. C++ N-dimensional arrays

but from api-reference I get

   3. API Reference
     3.1. Classes
     3.2. Exceptions
     3.3. Enumerations
     3.4. Parameters

It seems that the section is correctly dropped locally but it appears in the main toc. lang is correctly set.

Am I missing something?

@shimizukawa
Copy link
Member

only and ifconfig directive doesn't remove contents body itself on source reading phase. Because of this, toctree in a ifconfig cause unexpected behavior. It's a current specification. Please see also #1488.

@andreacassioli
Copy link
Author

OK,
so not even this will work:

.. ifconfig:: True

   .. toctree

      entry1

.. ifconfig:: False

   .. toctree

      entry2


but then what is the alternative? Of course I can work out some script that changes the source folder, but this is kind of annoying.

I think this is a broader issue with conditionals. There are some similar bugs open.

@annegentle
Copy link

Thanks for the notification. I think I'll have to go with something like this scope solution:

http://stackoverflow.com/questions/21515722/how-do-i-conditionally-include-a-file-in-a-sphinx-toctree

Related extension: https://gist.github.com/kakawait/9215487

@andreacassioli
Copy link
Author

Hi,
I see extension in https://gist.github.com/kakawait/9215487 could be a solution. However, it seems to me that a proper conditional operator would be much cleaner to read and more portable.

I still believe that ifconfig should be used instead and its condition evaluated from the very beginning.

@andreacassioli
Copy link
Author

What about adding an option to a toctree like :condition: so that it will be evaluate during the doctree-read or doctree-resolved event?

@andreacassioli
Copy link
Author

I understood this is expected. Issue closed.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants