Difference between revisions of "Module Namespaces"
(→Namespace Configuration: ‘\listnamespaces’ &c.) |
(→List of Module Namespaces: added TRL) |
||
Line 5: | Line 5: | ||
should adhere to the following rules: | should adhere to the following rules: | ||
− | * | + | * Namespace identifiers (their <tt>name</tt> parameter) should have more than two characters (at least yours [http://article.gmane.org/gmane.comp.tex.context/61939]), |
* the namespace should be registered here for others to know. | * the namespace should be registered here for others to know. | ||
Line 15: | Line 15: | ||
|<tt>fb</tt> | |<tt>fb</tt> | ||
| fancybreak || [http://bitbucket.org/wolfs/fancybreak t-fancybreak] || Inserting thought breaks (transitions). | | fancybreak || [http://bitbucket.org/wolfs/fancybreak t-fancybreak] || Inserting thought breaks (transitions). | ||
+ | |- | ||
+ | |<tt>TRL</tt> | ||
+ | | transliterate | ||
+ | | [https://bitbucket.org/phg/transliterator t-transliterator] | ||
+ | | Transliteration from non-Latin scripts. | ||
|+ style="font-style:italic; font-size:83.3333%;" | Reserved module namespaces. | |+ style="font-style:italic; font-size:83.3333%;" | Reserved module namespaces. | ||
|} | |} |
Revision as of 12:14, 24 December 2010
Contents
List of Module Namespaces
TODO: This list is under construction and will eventually contain all namespaces used in context modules. (See: To-Do List) |
To avoid clashes with existing and future commands, any module should adhere to the following rules:
- Namespace identifiers (their name parameter) should have more than two characters (at least yours [1]),
- the namespace should be registered here for others to know.
Namespace | Name | Main file | Description |
---|---|---|---|
fb | fancybreak | t-fancybreak | Inserting thought breaks (transitions). |
TRL | transliterate | t-transliterator | Transliteration from non-Latin scripts. |
Generating a Namespace for Your Module
Context provides the user command \definenamespace that generates a valid namespace for variables and takes care of defining a setup command as well. Suppose you have a module called My Module (preferably in a file t-mymodule.mkiv) and want to reserve the namespace mymod. The following snippet will get you a setup command \setupMyMod.
\definenamespace[mymod] [ type=module, name=MyMod, setup=list, ]
Through \setupMyMod you can now set the variables that you are planning to use in your module – it is already a mature command that conforms to the overall context style and can take a parameter list, a list of key-value pairs or both as arguments. Any parameter defined that way can now be retrieved via another command that got auto-generated, \MyModparameter.
% setting a parameter within the namespace \setupMyMod[ yamp=Yet another module parameter, ] % command sequence that does something with the parameter \def\blueparameter{\setupcolors[state=start]\colored[blue]\MyModparameter{yamp}} % deploying the new user command \starttext \blueparameter \stoptext
Wondering why your namespace, albeit defined as mymod initially, is always referred to as MyMod, i.e. the value of the parameter name as given in the definition? Internally the namespaces are represented as ordinary command sequences with a prefix. This prefix is composed from first the usual four @-signs, second the namespace identifier, and third the key id from the argument list. In the example this results in a macro \@@@@ + mymod + yamp. Thus, \MyModparameter{yamp} would be equivalent to calling:
\unprotect \@@@@mymodyamp \protect
Namespace Configuration
\definenamespace accepts a number of options that determine what commands will be available. At the time of this writing (2010-09-27), this is rather new stuff and so far not guaranteed to stay in context unmodified.
Option | Parameters and their description (NS is a namespace dummy) | ||||
---|---|---|---|---|---|
name | string: The identifier that will be used to reference setups and parameters; e. g. a value of NS causes the macros \defineNS and \setupNS to be created. | ||||
parent | string: a namespace identifier. Should be the same as the identifier of the module’s namespace. | ||||
type | module: creates the namespace prefixed with quadruple @; other values are planned to be added in the future for internal purposes. | ||||
setup | list or boolean: initiates the creation of a setup according to the name argument, e. g. \setupNS. The specified value influences the behaviour of the setup:
| ||||
command | list or boolean: creates auxiliary macros and the proper command to define further commands within the new namespace (\defineNS).
For a name parameter NS, the values of the \setupNS command will be retrievable via \NSparameter{parametername}. Additionally, access is provided by \namedNSparameter and \detokenizedNSparameter. The \defineNS[command][..,..=..,..] can be used to create instances of a generic macro with local setups. Works like ordinary Context \definesomething commands and allows for inheritance (\defineNS[command][othercommand]). Of course, if command is set to list, the first argument of \defineNS will take comma separated values. | ||||
comment | string: meta-information, see related commands below. | ||||
version | number: meta-information, see related commands. | ||||
style | boolean: enables special handling for text color and style attributes.
If set to yes, a macro \dosetNSattributes will be created. It receives the values for the style and color arguments as supplied to the \setupNS macro which itself gets created via the setup key (see above). |
Related Commands
\listnamespaces
Prints all namespaces defined in tabular form along with additional information. Example:
\definenamespace[Newns][ name=Newns, type=module, setup=list, parent=NS, style=yes, version=3.141, comment=this space has been named, ] \starttext \listnamespaces \stoptext
Further Information
- Definition of \definenamespace.
- System Macros.
- Some of the functionality was explained by Wolfgang Schuster on the Context list