5.1.2 Using a Renderer from the plastex Script

In the preceding sections, the simple renderer example was called from a custom python script. In order to use it through the main plastex script (described in Chapter 2), it needs to be located in some directory plasTeX/Renderers/SimpleRenderer, where plasTeX is the directory containing the plastex script. This directory must contain a __init__.py file defining the Renderer  class (with this name). This directory can also contain a Themes directory in order to use the theme option described in Section 2.1.1. Each subdirectory in the Themes directory is considered as a theme.

Each renderer can define its own configuration options which are loaded by the plastex script. This is done in a file named Config.py in the renderer directory. This file must define a variable named config  which is a ConfigManager instance, as described in Section 6.2. Inspiration can be drawn from the file defining the global configuration which is plasTeX/Config.py.

For instance, one could add a file plasTeX/Renderers/SimpleRenderer/Config.py containing:

from plasTeX.ConfigManager import *

config = ConfigManager()

section = config.add_section('simplerenderer')

config.add_category('simplerenderer', 'Simple Renderer Options')

section['my-option'] = StringOption(
    """ My option """,
    options='--my-option',
    category='simplerenderer',
    default='',
)

Options values are attached to the document currently rendered. For instance, in the default  method implemented in Section 5.1, which takes a node argument, one could access the value of the option defined above as node.ownerDocument.config['simplerenderer']['my-option'].