Input and compilation/Setups

Unofficial ConTeXt Wiki mirror

Last modified: 2025-09-12

Introduction

Setups are a rather common variant on macros. They have two useful properties:

Commands

Examples

Here are two simple examples:

% Create two setups
\startsetups doc:print
    \setuppapersize[A4][A4]
\stopsetups

\startsetups doc:screen
    \setuppapersize[S6][S4]
\stopsetups

% Use one or another setup
\doifmodeelse {paper} {
    \setup[doc:print]
} {
    \setup[doc:screen]
}
% Set up a headertext. Whitespace is ignored
\startsetups[doc:header]
    \marking[chapter]
    \space
    --
    \space
    \pagenumber
\stopsetups

% Use the setup
\setupheadertexts[\setup{doc:header}]

You can place setups almost everywhere and environment will not be affected by their execution. It is useful to wrap overlay definitions and such in setups as in (copied from Colorful CD inlay page):

\defineoverlay [origin] [\setups{origin}]

\startsetups origin
    \vbox to \overlayheight {
        \vfill\tfxx\setstrut
        \hsize\overlaywidth
        \hfill Fiona Apple\enspace EM\enspace2005\quad\strut\endgraf
        \kern1ex
    }
\stopsetups

You can even do things like:

\starttext
\startsetups settest
    \def\command{do something with}
    
    I want to \command{} my command.
\stopsetups

\start
    \setups{settest}
\stop

\command aaa  % will give "undefined control sequence" error

\stoptext

See also an example in the tutorial for headers and footers.

\startlines in setups

Since setups ignore whitespace, \startlines\stoplines doesn’t work within a setup. You can use a buffer and call it within the setup. The following example uses the document:stop setup that is automatically placed if you use \startdocument\stopdocument.

\startbuffer[imprint]
© \currentdate[year] Publisher
…
Printshop etc.
\stopbuffer

\startsetup document:stop
\dontleavehmode\vfill
\subject{Imprint}
\startlines
\getbuffer[imprint]
\stoplines
\stopsetup

Another option is to change the catcode regime and use \startrawsetups:

\pushcatcodetable
\obeylines
\startrawsetups[document:stop]
  \startlines
  © \currentdate[year] Publisher
  foo bar baz
  blah blah
  \stoplines
\stoprawsetups
\popcatcodetable

Using setups for namespaces

Using \setups for a variable namespace allows an easier control over the containing variables. All you have to do is to define the setups namespace:set and/or namespace:reset for a given namespace. Now every time a variable of that namespace is assigned (written), ConTeXt automatically calls these setups. Reading of variables is totally unaffected by these settings. A possible use are default values, calculations and even verification.

So once you have 'setup' your variables proper, you don't have to worry about unset variables and alike any more. Also changes can be made easy, as there is only one common setup. The drawback is the slower speed in use, as every assignment to a variable calls these setups.


To give you the idea, try this example.