Who’s your daddy?

For a new module (see github) I needed to place a Metapost graphic so that it aligns with the baseline of the text. The simplest way to do this is

\framed[location=low,frame=off]{...}

or more rigorously

\defineframed[visualcounterframed]
             [location=low,frame=off]
...
\visualcounterframed{....}

However, something like this is error prone because every framed inherits settings from \setupframed. So, if the user sets:

\setupframed[offset=10cm]

suddenly all the frames used inside the module will have a 10cm offset. I could correct this by adding offset=0mm in \defineframed. But what if the user sets foregroundstyle=bold? Now I all Metapost labels will be bold. I could again correct by setting forgroundstyle=normal in \defineframed. If I follow this path, then I will need to set all the options of \setupframed to some sane values. But what about a module like simpleslides that uses 10 frames; I need to set defaults for all of them (Thomas, are you listening).

What I really want is that one instance of \defineframed should not inherit from \setupframed. In MkIV, the inheritance model is configurable. Almost all setup commands now accept a parent key. When an option for a command is not set, the parent name space is searched for that option.

For example, deep inside the definition of \defineframed is

\getparameters[\??ol#1][\s!parent=\??ol,#2]%

This sets \??ol as the parent name space for \defineframed. The \setupframed command sets option in the \??ol name space, and hence the inheritance.

So, to make sure that my \visualcounterframed is not affected by \setupframed, I just need to change its parent name space. First, I define a new name space:

\definenamespace
       [VISUALCOUNTER]
       [type=module,
        name=visualcounter,
        setup=yes]

This defines a name space, \????VISUALCOUNTER, with the name visualcounter. I do not know what type=module does, but that was present in all the examples that I looked. The option setup=yes defines a command \setupvisualcounter that can be used to set the \????VISUALCOUNTER name space. I could have also set parent=... if I wanted this name space to inherit from another one.

And now, all I need to do is set \????VISUALCOUNTER as the parent name space for \visualcounterframed:

\unprotect
\setupframed[visualcounterframed]
             [parent=\????VISUALCOUNTER]
\protect

and voila, isolation from default options of \setupframed. I think that all module that internally use a \framed should consider choosing an isolated parent name space.

Advertisements