Module template

From Wiki
Jump to navigation Jump to search

The following can be used as a template when writing modules:

%D \module
%D   [     file=<filename>, % e.g. t-xxx
%D      version=<module version>, % e.g. 20xx.xx.xx
%D        title=<module title>, % e.g. \CONTEXT\ User Module
%D     subtitle=<module subtitle>, % short description
%D       author=<author>, % name(s)
%D        email=<author email>,
%D         date=<date>, % e.g. \currentdate
%D    copyright=<copyright>, % e.g. <author>
%D      license=<license>] % e.g. 'Public Domain' or 'GNU GPL 2.0'

%C copyright/license information

% begin info
%
% title   : <a short title to explain the module>
% comment : <a longer description which explains the purpose of the module>
% status  : <current status of the module>
%
% end info

\unprotect

% module code

\protect

\continueifinputfile {<filename>}

% usage examples

\endinput

Preamble

Mandatory entries

  • title
  • subtitle
  • author

Optional entries

  • file
  • version
  • copyright
  • license
  • email

Info block

In addition to the preamble it’s suggested to add an information block which gives a short description about the module and its status. It is used with context --showmodules.

Examples

Besides using the documentation mechanism and creating a separate document to explain the module, it is possible to add code at the end of the file after which is ignored when the module is loaded with \usemodule.

The argument of \continueifinputfile takes the filename of the module. Content after that is processed when you process the module itself with context.

Create docs

To create a PDF from the module with formatted output of the documentation:

 context --extra=module --result=... <file>

It is recommended to specify a filename for the resulting PDF file because the default is context-extra.pdf.

Private area

To ensure that the module can’t be changed by users and to enable the multilingual interface, ConTeXt permits special characters in command names between \unprotect and \protect.

Between these commands, you can use ?, !, @ and _ as part of command names, e.g.

 \mymodule_start
 \????mymodule
 \c!location

Sources

Wolfgang Schuster in a message on ntg-context and slides at context meeting 2024.