How to setup a new environment variable in a EnvironmentCollector?

12 views
Skip to first unread message

Yves Chevallier

unread,
Aug 2, 2019, 4:20:19 AM8/2/19
to sphinx-users
I would like to write an extension similar to the fig-numbering, but for teaching exercises. I am writing a book and I would like to define an `.. exercise::` and a `.. solution:: ` (nested into it) directives. 

At some point I would like to list all the exercices so I need an EnvironmentCollector that I setup in my application with `app.add_env_collector(ExercisesCollector)`. 

In Sphinx, the fignum environment variable is (and this is very very ugly) defined globally in the BuildEnvironment class which should NOT be aware that a feature fig numbering exists somewhere. 

Anyway. I am surprised that the EnvironmentCollector has no __init__ wheer I can say:


class ExercisesCollector(EnvironmentCollector):
    def __init__(self, app: Sphinx, env: BuildEnvironment):
        env.exercises = {}

What would be the proper way to do this in my extension?

Komiya Takeshi

unread,
Aug 2, 2019, 9:51:18 AM8/2/19
to sphinx...@googlegroups.com
Hi,

The EnvironmentCollector is a collection of event handlers for
environment object. It should not have a status locally. The
environment object is given from outside when event emitted. So you
don't need to give arguments to EnvironmentCollector.

Thanks,
Takeshi KOMIYA

2019年8月2日(金) 17:20 Yves Chevallier <cana...@gmail.com>:
> --
> You received this message because you are subscribed to the Google Groups "sphinx-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sphinx-users...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sphinx-users/0dbd4dde-9f0a-4747-ae0d-85145b4dde61%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages