Skip to content

Instantly share code, notes, and snippets.

@phi-gamma
Created June 16, 2012 13:02
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phi-gamma/2941284 to your computer and use it in GitHub Desktop.
Save phi-gamma/2941284 to your computer and use it in GitHub Desktop.
it’s not a bug, it’s a feature! -- section for the ConTeXt wiki

If ConTeXt appears to behave in a counterintuitive way, chances are that it’s actually your intuitions that lack calibration.

Table of Contents

Controlling Page Break Before Headings

If you add the option page=yes to a heading setup, this will cause ConTeXt to break the page. Ordinarily this works as expected, unless, however, the heading immediately follows a previous section with no text in between. The rationale behind this is that consecutive headings are conceived of collectively as one single structural element. For example, the following code will generate only a single page break although the unit appears twice.

<texcode> \setuphead[section][page=yes] %% toggle page breaking \starttext \chapter{foo} %% structural inhibits breaking \section{bar} \input knuth %% -> no break! \section{baz} \input dawkins %% -> break \stoptext </texcode>

In order to get the page break at the section regardless of surrounding structurals elements, you need to unset the heading parameter continue as well. http://archive.contextgarden.net/message/20080107.115201.ca26c682.en.html

<texcode> \setuphead[section][page=yes,continue=no] \starttext \chapter{foo} \section{bar} \input knuth %% -> break \section{baz} \input dawkins %% -> break \stoptext </texcode>

(For the curious, the explanation can be found in the definition of the macro in ).

Unsolicited Vertical Mode

Some commands like cause line breaks to happen if used in vertical mode, e.g. at the beginning of a line. Example:

<context source="yes"> \starttext \framed{foo} bar. \stoptext </context>

The explanation according to the corresponding FAQ item is that before the token \frame is encountered, TEX is in vertical mode. This state is preserved until after TEX finishes typesetting the \framed macro. Consequently, horizontal mode (where paragraphs are made) is entered only at the tokens bar.

To have the frame begin the paragraph instead, horizontal mode will have to be initiated explicitly. There are a couple macros for this purpose: the very basic (; inserts an empty box, same as in the Plain format) and the more familiar (). Just use the immediately before the \framed macro and everything should be fine:

<context source="yes"> \starttext \leavevmode \framed{foo} bar.\par \dontleavehmode \framed{foo} bar. \stoptext </context>

Disappearing Crop Marks

Crop marks, activated as \setuplayout[marking=on], are a useful feature that Context supports out of the box. They have a peculiarity, though, which my make them useless in specific cases: They are, by definition, located outside the page dimension. This means that they show up iff the paper size exceeds the page size.

Thus if you need auxiliary lines for cutting but have the pages fit the paper size exactly, you can instead resort to enabling the page background frame. This example sums up the solutions posted by Wolfgang and Marco on Context Mailing List. <texcode> %% the paper size will be a multiple of the page sizes \setuppapersize [A6,landscape] [A3] \setuplayout [nx=2,ny=4]%, marking=on] %% enable the page frame \setupbackgrounds [page] [frame=on] %% some further display setups \setuppagenumbering [location=] \setupbackgrounds [page] [background=color,] \setupbodyfont [sans,58pt] %% testing ... \starttext \dorecurse{4} {\null\vfill\centerline\recurselevel\vfill\null\page} \stoptext </texcode>

Left and Right

When it comes to the justification of paragraphs, do not trust your intuitions about handedness. This is a FAQ item.

Footnotes: The Difference between and

There is a bit of terminology mess concerning notes.

Instruction Goal
This command configures the note insert, i.e. the textual content that will usually be placed at the bottom (with footnotes) or the end of the text (with endnotes). (The control sequence used to be \setupnotedefinition.)
Configure the note environment where the inserts will be located. Inherits some parameters from .
\setupnote[textstyle=,textcommand=] Configure the note symbol as appears in the main text, where the note macro is called.
Plural forms , These are synonyms for their singular forms.
This is equivalent to \setupnote[footnote].

Summary: to setup a blue note, you would first need to define and configure the insert via :

<texcode> \definenote [bluenote] [footnote] \setupnotation [bluenote] [ <pre>] <pre></pre> \starttext foo\bluenote{bar} baz \stoptext </texcode>

Now adjust the container where the blue notes will reside at the bottom of the page ():

<texcode> \definenote [bluenote] [footnote] \setupnote [bluenote] [

<pre>]

\starttext foo\bluenote{bar} baz \bluenote{xyzzy} \stoptext </texcode>

Finally, direct your attention to the note indicator, most commonly a number or a symbol. For precise control over the placement define a monadic macro and hook it into textcommand.

<texcode> \setupnote [bluenote] [

<pre>] \define[1]\myfootnotecommand{\rotate[rotation=42]{#1}}

\starttext foo\bluenote{bar} baz \bluenote{xyzzy} \stoptext </texcode>

(For more definite answers concerning the notes mechanism, use the source, Luke: .)

Float Insertion Issues

Floating objects can be tricky. Deciding where they fit best is hard enough, actually getting them there may be a lot tougher. Inserting a float will force a line break where the object is referenced in the source code. Thus, very long paragraphs may not leave an opportunity to inject the float if they cover the entire page. http://archive.contextgarden.net/message/20120405.103626.a1349c1c.en.html <texcode> \starttext Cows make \placefigure[top]{A genuine Dutch cow.}{\externalfigure[cow]} great pets. \stoptext </texcode> In these cases the postponing mechanism offers a reliable way out (). It lets you specify an offset (in pages) by which the content of the postponing environment will be delayed. In order to place a floating object at the top of the nth page from the location it is encountered, its argument has needs to be &amp;amp&#59;&amp;&#35;35&#59;91&amp;&#35;59&#59;+n&amp;amp&#59;&amp;&#35;35&#59;93&amp;&#35;59&#59;. (Absolute pages can be specified as simply &amp;amp&#59;&amp;&#35;35&#59;91&amp;&#35;59&#59;n&amp;amp&#59;&amp;&#35;35&#59;93&amp;&#35;59&#59;.) E. g. to put the foat on the following page: <texcode> \starttext \startpostponing[+1] \placefigure[top]{A genuine Dutch cow.}{\externalfigure[cow.pdf]} \stoppostponing \input knuth \page Cows make great pets. \stoptext </texcode>

Another solution can be the less known hangaround environment (, cf. Hangaround). It lets the text of a given paragraph (the content of the environment) flow around a box (the first argument). In contrast to real floats it does not place a caption. This poses a problem in MkIV as the new code will not allow placing captions arbitrarily. http://repo.or.cz/w/context.git/blob/refs/heads/origin:/tex/context/base/strc-flt.mkvi#l257 (If you desparately need separate captions please send a feature request to one of the ConTeXt_Mailing_Lists#Mailing Lists).

<context source="yes" mode="mkii"> \starttext \input dawkins

\starthangaround{ \framed[align=right,frame=off,width=.3\textwidth]{ \externalfigure [cow] [width=.3\textwidth]\crlf %% NB the fake caption works *only in mkii* \placefloatcaption [figure] [ref:acow] {A smiling Dutch cow. {\italic Bos primigenius taurus}} } } \input dawkins \stophangaround

\input dawkins \stoptext </context>

Syntax

Assignments

In the most common form of key-value type arguments, ConTeXt will accept trailing commas or even empty items. For example, the following code shows this tolerance for the command .

<texcode> \definehighlight [dontmiss] [

<pre>] </texcode>

This is the syntax accepted e.g. by the majority of setups and \getparameters. (For the parser code cf. .)

There are, however, exceptions to this rule. A known case where options are processed in a less tolerant fashion is . http://www.ntg.nl/pipermail/ntg-context/2012/067585.html Thus the following snippet will not compile, forcing ConTeXt to fail with a cryptic Argument of ... error message. <texcode> \setuplabeltext [Nomen=nomen,

<pre>] %% <= fails! \setuplabeltext [Nomen=nomen,] %% <= works \starttext \labeltext{Nomen} \labeltext{Est} \labeltext{Omen} \stoptext </texcode>

(A similar exception concerning has been migrated to the standard argument model but may still show the earlier behavior in not so recent installations. http://www.ntg.nl/pipermail/ntg-context/2012/067673.html)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment