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

4 thoughts on “Who’s your daddy?

  1. I think that sooner or later we will need to register the name spaces, or better the prefix: lscarso, amahajan, etc so we can safely use as name spaces
    things lscarsoBOOGOOFOO, amahajanBOOGOOFOO and so on.
    Is it possible something like
    lscarso.BOOGOOFOO
    ?

    • I haven’t tested but name:FOO etc should work, but I think that using the author name is a bit extreme. My general policy is to use a name space that is the name of the main command of my module: \defineexternalfilter — name space externalfilter; \definevisualcounter — namespace VISUALCOUNTER. That way, a name space clash also means a clash of the main command … which is a bigger concern.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s