Difference between revisions of "Modules"

From Wiki
Jump to navigation Jump to search
m (Added link to m-database)
m (Text replacement - "</cmd>" to "}}")
(11 intermediate revisions by 4 users not shown)
Line 1: Line 1:
< [[The ConTeXt Way]]
 
 
 
Modules are extensions to ConTeXt's core functions.
 
Modules are extensions to ConTeXt's core functions.
  
 
There are not as many modules for ConTeXt as packages for LaTeX, because a lot of LaTeX package features are in ConTeXt's core.
 
There are not as many modules for ConTeXt as packages for LaTeX, because a lot of LaTeX package features are in ConTeXt's core.
  
==Installation==
+
=Installation=
  
===Basics===
+
==Basics==
  
 
The installation of extra files in TeX (called modules in ConTeXt) can be difficult
 
The installation of extra files in TeX (called modules in ConTeXt) can be difficult
Line 25: Line 23:
 
but their existence depends on the TeX distribution;  among these, texmf-local is the most common.
 
but their existence depends on the TeX distribution;  among these, texmf-local is the most common.
  
===Installation by hand===
+
==Installation by hand==
  
 
When you want to install a new module which is available as file only create
 
When you want to install a new module which is available as file only create
Line 42: Line 40:
 
   context --generate
 
   context --generate
  
===ConTeXt standalone===
+
==ConTeXt standalone==
  
 
Users of the ConTeXt standalone (formerly "minimals") distribution don't have to download the module files and unzip them in the local directory, because they can use the <tt>first-setup</tt> script for this.
 
Users of the ConTeXt standalone (formerly "minimals") distribution don't have to download the module files and unzip them in the local directory, because they can use the <tt>first-setup</tt> script for this.
Line 78: Line 76:
 
* [http://modules.contextgarden.net/t-lettrine t-lettrine] decorative paragraph starts (initials)
 
* [http://modules.contextgarden.net/t-lettrine t-lettrine] decorative paragraph starts (initials)
 
* [http://modules.contextgarden.net/t-lilypond t-lilypond] include musical scores with GNU LilyPond
 
* [http://modules.contextgarden.net/t-lilypond t-lilypond] include musical scores with GNU LilyPond
 +
* [http://ctan.org/pkg/markdown t-markdown] render markdown documents
 
* [http://modules.contextgarden.net/mathsets t-mathsets] mathematical sets, probabilities etc.
 
* [http://modules.contextgarden.net/mathsets t-mathsets] mathematical sets, probabilities etc.
 
* [http://modules.contextgarden.net/pararef t-pararef] {{cmd|startParagraph|link=no}}, for paragraphs as ‘thought blocks’ that may contain more than one 'TeX paragraph'. These paragraphs are numbered and can be referenced. See [[Paragraph Referencing]].
 
* [http://modules.contextgarden.net/pararef t-pararef] {{cmd|startParagraph|link=no}}, for paragraphs as ‘thought blocks’ that may contain more than one 'TeX paragraph'. These paragraphs are numbered and can be referenced. See [[Paragraph Referencing]].
Line 92: Line 91:
 
(some of these are obsolete...)
 
(some of these are obsolete...)
  
===TeX Live===
+
==ConTeXt LMTX==
 +
 
 +
As of 2020-06-06, the ConTeXt LMTX distribution does not provide a built-in way to install or update modules. However, (something like) the following can be used to install and update all modules together with the rest of the distribution. The snippet must be run from the toplevel directory of the ConTeXt LMTX distribution, i.e. the directory that contains <tt>install.sh</tt>.
 +
 
 +
Because the final <tt>tex/texmf-modules</tt> must contain the union of all individual module directories, the snippet creates and leaves an intermediate <tt>modules</tt> directory in the toplevel directory of the ConTeXt LMTX distribution. There may be a more clever way of using <tt>rsync</tt>, that does not need an intermediate directory. On the other hand, as of 2020-06-06, only 37MB of space are wasted.
 +
 
 +
  # Transfer all modules from the ConTeXt Garden.
 +
  #
 +
  # No -p (--perms) is given to rsync, because, as of 2020-06-06, many
 +
  # files (e.g. all files in
 +
  # modules/t-letter/tex/context/third/letter/style) would come out
 +
  # world-writeable, which may pose a significant security risk on a
 +
  # multi-user system.
 +
  #
 +
  # The --chmod=D755,F644 may not be necessary. However, as of
 +
  # 2020-06-06, without it files come out with executable bits set.
 +
  rsync -rltsv --new-compress --delete --chmod=D755,F644    \
 +
        rsync://contextgarden.net/minimals/current/modules/ \
 +
        modules
 +
 
 +
  # Recreate tex/texmf-modules as an empty directory. WARNING: This
 +
  # assumes that you have nothing but modules from ConTeXt Garden in
 +
  # tex/texmf-modules.
 +
  rm -rf tex/texmf-modules
 +
  mkdir -p tex/texmf-modules
 +
 
 +
  # Create the union of all modules in tex/texmf-modules.
 +
  for module in modules/* ; do
 +
    rsync -rlts --exclude=/VERSION ${module}/ tex/texmf-modules
 +
  done
 +
 
 +
  # Update the ConTeXt LMTX distribution. Alternatively, if you do not
 +
  # want to do that, you have to run mtxrun --generate.
 +
  sh ./install.sh
 +
 
 +
==TeX Live==
  
 
TeX Live is a large TeX distribution for most Linux and BSD based operating systems. It provides binaries and many other files necessary to run TeX and its flavors. Many ConTeXt modules are included.
 
TeX Live is a large TeX distribution for most Linux and BSD based operating systems. It provides binaries and many other files necessary to run TeX and its flavors. Many ConTeXt modules are included.
Line 116: Line 150:
 
* context-vim
 
* context-vim
  
==Usage==
+
=Usage=
  
 
When you load a module with <code>\usemodule[modulename]</code> ConTeXt looks for a file with the following names:
 
When you load a module with <code>\usemodule[modulename]</code> ConTeXt looks for a file with the following names:
Line 133: Line 167:
 
<code>\usemodule[<prefix>][modulename]</code>  
 
<code>\usemodule[<prefix>][modulename]</code>  
  
==Included Modules==
+
=Included Modules=
  
 
* {{code|bibl-bib.lua}} ({{src|bibl-bib.mkiv}}): [[Bibliography]] (maintained by Taco)
 
* {{code|bibl-bib.lua}} ({{src|bibl-bib.mkiv}}): [[Bibliography]] (maintained by Taco)
Line 141: Line 175:
 
* {{code|m-chemic}} ({{src|m-chemic.mkii}} {{src|m-chemic.mkiv}}):  [[Chemistry|PPCHTeX]] (chemical structure formulae)  
 
* {{code|m-chemic}} ({{src|m-chemic.mkii}} {{src|m-chemic.mkiv}}):  [[Chemistry|PPCHTeX]] (chemical structure formulae)  
 
* {{code|m-cweb}} ({{src|m-cweb.tex}}): [[CWEB]] pretty printing
 
* {{code|m-cweb}} ({{src|m-cweb.tex}}): [[CWEB]] pretty printing
* {{code|m-database}} ({{src|m-database.lua}} {{src|m-database.mkii}} {{src|m-database.mkiv}}): creating simple tables (or forwarding data to user-defined commands) using [[m-database|comma/space/tab-separated values]]. Wiki: [[M-database]].
+
* {{code|m-database}} ({{src|m-database.lua}} {{src|m-database.mkii}} {{src|m-database.mkiv}}): creating simple tables (or forwarding data to user-defined commands) using [[M-database|comma/space/tab-separated values]]. Wiki: [[M-database]].
 
* {{code|m-datastrc}} ({{src|m-datastrc.tex}}):
 
* {{code|m-datastrc}} ({{src|m-datastrc.tex}}):
 
* {{code|m-directives}} ({{src|m-directives.mkiv}}):
 
* {{code|m-directives}} ({{src|m-directives.mkiv}}):
Line 183: Line 217:
 
* {{code|m-translate}} ({{src|m-translate.mkiv}}):
 
* {{code|m-translate}} ({{src|m-translate.mkiv}}):
 
* {{code|m-units}} ({{src|m-units.mkii}} {{src|m-units.mkiv}}): Structured input of values with [[units]]
 
* {{code|m-units}} ({{src|m-units.mkii}} {{src|m-units.mkiv}}): Structured input of values with [[units]]
* {{code|m-visual}} ({{src|m-visual.mkii}} {{src|m-visual.mkiv}}): [[Visual Debugging]] (described in [[This Way]] no.7 [[magazine:0007|Faking Text and More]])
+
* {{code|m-visual}} ({{src|m-visual.mkii}} {{src|m-visual.mkiv}}): [[Visual Debugging]] (described in [[This_Way_-_My_Way#ThisWay|ThisWay]] no.7 [[magazine:0007|Faking Text and More]])
 
* {{code|m-zint}} ({{src|m-zint.mkiv}}): Generate barcodes using [http://www.zint.org.uk zint.exe]
 
* {{code|m-zint}} ({{src|m-zint.mkiv}}): Generate barcodes using [http://www.zint.org.uk zint.exe]
  
==Contributed Modules==
+
=Contributed Modules=
 
For a list of contributed modules see [http://tlcontrib.metatex.org/ tlcontrib] and/or [http://modules.contextgarden.net the modules section] on contextgarden.net.
 
For a list of contributed modules see [http://tlcontrib.metatex.org/ tlcontrib] and/or [http://modules.contextgarden.net the modules section] on contextgarden.net.
  
Line 200: Line 234:
 
In order to install a contributed module, copy its directory into <code>$TEXMF/tex/context/third</code> then run <code>luatools --generate</code>.
 
In order to install a contributed module, copy its directory into <code>$TEXMF/tex/context/third</code> then run <code>luatools --generate</code>.
  
==Special Purpose Modules==
+
=Special Purpose Modules=
 
The following modules implement special formatting requirement for journals or magazines. These modules are distributed with ConTeXt, so you need not download anything.
 
The following modules implement special formatting requirement for journals or magazines. These modules are distributed with ConTeXt, so you need not download anything.
  
* [[Modules/MyWay|MyWay]] User documentation on ConTeXt
+
* [[This Way - My Way#MyWay|My Way]], User documentation on ConTeXt
 
* [[Modules/Pracjourn|pracjourn]] Articles for [http://tug.org/pracjourn/ The PracTeX Journal]
 
* [[Modules/Pracjourn|pracjourn]] Articles for [http://tug.org/pracjourn/ The PracTeX Journal]
 
* [[Modules/Maps|maps]] Articles for [http://www.ntg.nl/maps.html MAPS], the publication of NTG (Nederlandstalige TeX Gebruikersgroep or Netherlands TeX Group)
 
* [[Modules/Maps|maps]] Articles for [http://www.ntg.nl/maps.html MAPS], the publication of NTG (Nederlandstalige TeX Gebruikersgroep or Netherlands TeX Group)
  
==Modules writing guidelines==
+
=Modules writing guidelines=
  
===Module requirements===
+
==Module requirements==
 
All modules should start with a block containing ''meta information'' about that module.
 
All modules should start with a block containing ''meta information'' about that module.
There is a [[module template]] available to help setting up that header correctly.
+
There is a [[Module template]] available to help setting up that header correctly.
  
 
Do not forget to specify a ''license'' as the permitted modes of distribution
 
Do not forget to specify a ''license'' as the permitted modes of distribution
Line 225: Line 259:
 
After releasing a module its namespace[s] should be registered in the [[Module_Namespaces#List_of_Module_Namespaces|list]] for other module authors to know.
 
After releasing a module its namespace[s] should be registered in the [[Module_Namespaces#List_of_Module_Namespaces|list]] for other module authors to know.
  
===XML Interface file===
+
==XML Interface file==
 
Each module should have an associated XML specification file
 
Each module should have an associated XML specification file
 
(as in [http://source.contextgarden.net/tex/context/interface/cont-en.xml /tex/context/interface/cont-en.xml]).
 
(as in [http://source.contextgarden.net/tex/context/interface/cont-en.xml /tex/context/interface/cont-en.xml]).
Line 264: Line 298:
 
the [[Mailing list|mailing list]].
 
the [[Mailing list|mailing list]].
  
===Self-documenting source code===
+
==Self-documenting source code==
 
Source files are supposed to contain explanatory comments that document
 
Source files are supposed to contain explanatory comments that document
 
implementation details and other peculiarities the reader should be
 
implementation details and other peculiarities the reader should be
Line 304: Line 338:
 
Go there for examples of the output.)
 
Go there for examples of the output.)
  
===Legacy modules disclaimer===
+
==Legacy modules disclaimer==
 
<!-- This info is obsolete, the section could be kicked out, doesn’t it? -->
 
<!-- This info is obsolete, the section could be kicked out, doesn’t it? -->
Prior to release ''2005.05.25'', ConTeXt silently truncated all file names in <cmd>usemodule</cmd> commands to 8 characters long and lowercased them to "prevent cross platform problems with filenames".  Thus, module files that are to be used with older versions of ConTeXt must have filenames that fit those restrictions, or they will (somewhat cryptically) not be found.
+
Prior to release ''2005.05.25'', ConTeXt silently truncated all file names in {{cmd|usemodule}} commands to 8 characters long and lowercased them to "prevent cross platform problems with filenames".  Thus, module files that are to be used with older versions of ConTeXt must have filenames that fit those restrictions, or they will (somewhat cryptically) not be found.

Revision as of 13:18, 9 August 2020

Modules are extensions to ConTeXt's core functions.

There are not as many modules for ConTeXt as packages for LaTeX, because a lot of LaTeX package features are in ConTeXt's core.

Installation

Basics

The installation of extra files in TeX (called modules in ConTeXt) can be difficult for people who are new to TeX or are not themselves interested in TeX programming.

According to the TDS (TeX directory structure) and the ConTeXt developers, user-written files reside under the path

 $TEXMF/tex/context/third/<modulename>/<files>

In the private TeX directory ($TEXMF), directories can have the names

  • texmf-local
  • texmf-extra
  • texmf-project

but their existence depends on the TeX distribution; among these, texmf-local is the most common.

Installation by hand

When you want to install a new module which is available as file only create the subdirectories in the way described above and place the file there, for modules which are available as zip files with precreated subdorectories you can unzip the archive in the top-level directory (e.g. texmf-local/) and all files are on the correct place.

After the files are placed at the right place you have to update TeX's database to let it know where it can find the files, this is done for MkII with

 mktexlsr (command name depends on the TeX distribution)

and for MkIV with

 context --generate

ConTeXt standalone

Users of the ConTeXt standalone (formerly "minimals") distribution don't have to download the module files and unzip them in the local directory, because they can use the first-setup script for this.

To install for example the simpleslides modules you write

 first-setup.sh --modules="t-simpleslides"

To install more modules at the same time write

 first-setup.sh --modules="t-simpleslides,t-french"

The complete list of availables modules in standalone is:

(some of these are obsolete...)

ConTeXt LMTX

As of 2020-06-06, the ConTeXt LMTX distribution does not provide a built-in way to install or update modules. However, (something like) the following can be used to install and update all modules together with the rest of the distribution. The snippet must be run from the toplevel directory of the ConTeXt LMTX distribution, i.e. the directory that contains install.sh.

Because the final tex/texmf-modules must contain the union of all individual module directories, the snippet creates and leaves an intermediate modules directory in the toplevel directory of the ConTeXt LMTX distribution. There may be a more clever way of using rsync, that does not need an intermediate directory. On the other hand, as of 2020-06-06, only 37MB of space are wasted.

 # Transfer all modules from the ConTeXt Garden.
 #
 # No -p (--perms) is given to rsync, because, as of 2020-06-06, many
 # files (e.g. all files in
 # modules/t-letter/tex/context/third/letter/style) would come out
 # world-writeable, which may pose a significant security risk on a
 # multi-user system.
 #
 # The --chmod=D755,F644 may not be necessary. However, as of
 # 2020-06-06, without it files come out with executable bits set.
 rsync -rltsv --new-compress --delete --chmod=D755,F644    \
       rsync://contextgarden.net/minimals/current/modules/ \
       modules
 
 # Recreate tex/texmf-modules as an empty directory. WARNING: This
 # assumes that you have nothing but modules from ConTeXt Garden in
 # tex/texmf-modules.
 rm -rf tex/texmf-modules
 mkdir -p tex/texmf-modules
 
 # Create the union of all modules in tex/texmf-modules.
 for module in modules/* ; do
   rsync -rlts --exclude=/VERSION ${module}/ tex/texmf-modules
 done
 
 # Update the ConTeXt LMTX distribution. Alternatively, if you do not
 # want to do that, you have to run mtxrun --generate.
 sh ./install.sh

TeX Live

TeX Live is a large TeX distribution for most Linux and BSD based operating systems. It provides binaries and many other files necessary to run TeX and its flavors. Many ConTeXt modules are included.

The following modules are available:

  • context-account
  • context-bnf
  • context-chromato
  • context-construction-plan
  • context-degrade
  • context-french
  • context-games
  • context-gantt
  • context-gnuplot
  • context-letter
  • context-lettrine
  • context-lilypond
  • context-mathsets
  • context-simpleslides
  • context-taspresent
  • context-typearea
  • context-vim

Usage

When you load a module with \usemodule[modulename] ConTeXt looks for a file with the following names:

  • m-modulaname (core module)
  • p-modulename (private module)
  • s-modulename (ConTeXt style file)
  • x-modulename (XML module)
  • t-modulename (Third party module)
  • modulename

Once a file is found ConTeXt stops the search and loads the found file (only once).

When you have two file with the same name but different prefixes you can tell ConTeXt which file it should load with

\usemodule[<prefix>][modulename]

Included Modules

Contributed Modules

For a list of contributed modules see tlcontrib and/or the modules section on contextgarden.net.


TODO: list more modules or none of them (See: To-Do List)


  • xdesc (extended description, e.g. for epigrams)
  • nath (natural math, see Math)
  • amsl (AMSmath, see Math)
  • Gnuplot: support for direct inclusion of Gnuplot graphs out of the source (the module has been removed from the main distribution and will be included into third party modules again when ready)

File names of included modules start with "m-", but third party (contributed) modules should start with "t-".

In order to install a contributed module, copy its directory into $TEXMF/tex/context/third then run luatools --generate.

Special Purpose Modules

The following modules implement special formatting requirement for journals or magazines. These modules are distributed with ConTeXt, so you need not download anything.

Modules writing guidelines

Module requirements

All modules should start with a block containing meta information about that module. There is a Module template available to help setting up that header correctly.

Do not forget to specify a license as the permitted modes of distribution depend on which one you choose. The ConTeXt sources are licensed either under GPLv2 or the LPPL, so you might want to stick to these or a more permissive license. (Choose one: [1].) Including the full text of your license in your source repo is best practice.

In order to avoid conflicting macros it is essential for a module that it adhere to the namespace convention. After releasing a module its namespace[s] should be registered in the list for other module authors to know.

XML Interface file

Each module should have an associated XML specification file (as in /tex/context/interface/cont-en.xml). Its purpose is a comprehensive listing of the optional and non-optional arguments that a macro defined in the module accepts. From the interface a good deal of documentation can be auto-generated, as are for instance the ConTeXt Quick Reference and the initial input of the Command Reference, which itself started as a wikification of the now obsolete TeXShow.

When documenting your module, you can use

\usemodule[int-load] %Allow xml parsing 
\loadsetups[m-name-of-your-module.xml] % to load the file with definitions
\setup{nameofyourcommand}

An example:

\setuppapersize[A5]
\usemodule[int-load]
\loadsetups
\setup{externalfigure}

By default, this places a frame around the setup. If you want to get gray background, as in the context documentation, add the following

 \setupframedtexts
     [setuptext]
     [background=color,
      backgroundcolor=lightgray,
      frame=off]

Apart from the existing XML files in the ConTeXt tree there is little documentation online, so feel free to relay your questions to the mailing list.

Self-documenting source code

Source files are supposed to contain explanatory comments that document implementation details and other peculiarities the reader should be aware of. In .tex files (and other files containing primarily TeX code, e.g. .mki[iv]) any line beginning with the comment leader %D will be treated as such a docstring. Formatting is done via ordinary TeX commands. In Lua files (e.g. .cld) multi-line comments start with --[[ldx-- and end with --ldx]]--. Text inside those delimiters can be formatted using basic HTML tags. Ordinary comments are still treated as part of the source and therefore they will be typeset inside the listing.

Docstrings, though they appear to the [Lua]TeX interpreter as ordinary comments, allow for pretty printing source code when used with two dedicated modules:

Thus, in order to generate the documentation for the simplefonts module you first have to chdir to the files subdirectory of your checkout. Next you run the pretty printer on its main file

context --ctx=s-mod t-simplefonts.tex

to get a t-simplefonts.pdf which contains the – sparse – annotations in serif and the actual code as colorful listing. Likewise the processing of Lua code, e.g. font-def.lua from the main ConTeXt tree:

context --ctx=x-ldx font-def.lua

Which should generate a font-def.pdf in your current directory.

(The autogenerated documentation of all ConTeXt sources has been made available by Luigi at [2]. Go there for examples of the output.)

Legacy modules disclaimer

Prior to release 2005.05.25, ConTeXt silently truncated all file names in \usemodule commands to 8 characters long and lowercased them to "prevent cross platform problems with filenames". Thus, module files that are to be used with older versions of ConTeXt must have filenames that fit those restrictions, or they will (somewhat cryptically) not be found.