https://wiki.contextgarden.net/api.php?action=feedcontributions&user=Willi&feedformat=atomWiki - User contributions [en]2024-03-29T13:19:19ZUser contributionsMediaWiki 1.34.1https://wiki.contextgarden.net/index.php?title=Command/setupbar&diff=34460Command/setupbar2024-03-28T21:14:36Z<p>Willi: </p>
<hr />
<div><cd:commandgroup name="setupbar" xmlns:cd="http://wiki.contextgarden.net/commanddoc/20200807"><br />
<cd:shortdesc>The command <tt>\setupbar</tt> sets up parameters for rules (lines)<br />
</cd:shortdesc><br />
<cd:variants><br />
<cd:command category="rules" file="node-rul.mkiv" interfacedate="2020-07-14T09:24" interfacefile="i-bar.xml" level="style" name="setupbar" variantnumber="1"><br />
<cd:arguments><br />
<cd:keywords list="yes" optional="yes" ordinal="1"><br />
<cd:keywordsdoc>Name of the bar. See for predefined bars {{cmd|_bar}}</cd:keywordsdoc><br />
<cd:constant type="cd:name"></cd:constant><br />
</cd:keywords><br />
<cd:assignments list="yes" ordinal="2"><br />
<cd:assignmentsdoc></cd:assignmentsdoc><br />
<cd:parameter name="color"><br />
<cd:paramdoc>color of the bar itself</cd:paramdoc><br />
<cd:constant type="cd:color"></cd:constant><br />
</cd:parameter><br />
<cd:parameter name="continue"><br />
<cd:paramdoc>controls split based on words</cd:paramdoc><br />
<cd:constant type="yes">split on words</cd:constant><br />
<cd:constant default="yes" type="no">continuous bar</cd:constant><br />
<cd:constant type="all"></cd:constant><br />
</cd:parameter><br />
<cd:parameter name="empty"><br />
<cd:paramdoc></cd:paramdoc><br />
<cd:constant type="yes"></cd:constant><br />
<cd:constant default="yes" type="no"></cd:constant><br />
</cd:parameter><br />
<cd:parameter name="unit"><br />
<cd:paramdoc>unit to use for <cd:iref name="offset"/> and <cd:iref name="dy"/></cd:paramdoc><br />
<cd:constant default="yes" type="ex"></cd:constant><br />
<cd:constant type="em"></cd:constant><br />
<cd:constant type="pt"></cd:constant><br />
<cd:constant type="in"></cd:constant><br />
<cd:constant type="cm"></cd:constant><br />
<cd:constant type="mm"></cd:constant><br />
<cd:constant type="sp"></cd:constant><br />
<cd:constant type="bp"></cd:constant><br />
<cd:constant type="pc"></cd:constant><br />
<cd:constant type="dd"></cd:constant><br />
<cd:constant type="cc"></cd:constant><br />
<cd:constant type="nc"></cd:constant><br />
</cd:parameter><br />
<cd:parameter name="order"><br />
<cd:paramdoc>put the rules in front of, or behind the text.</cd:paramdoc><br />
<cd:constant default="yes" type="foreground"></cd:constant><br />
<cd:constant type="background"></cd:constant><br />
</cd:parameter><br />
<cd:parameter name="rulethickness"><br />
<cd:paramdoc></cd:paramdoc><br />
<cd:constant type="cd:dimension"></cd:constant><br />
</cd:parameter><br />
<cd:parameter name="method"><br />
<cd:paramdoc>switch between centred and baseline-based vertical aligment</cd:paramdoc><br />
<cd:constant type="cd:number">0 = centred vertically. Leave empty / omit for <cd:iref name="offset"/> to be based on the text's baseline.</cd:constant><br />
</cd:parameter><br />
<cd:parameter name="offset"><br />
<cd:paramdoc>vertical shift</cd:paramdoc><br />
<cd:constant type="cd:number"></cd:constant><br />
</cd:parameter><br />
<cd:parameter name="dy"><br />
<cd:paramdoc>vertical shift when used nested</cd:paramdoc><br />
<cd:constant type="cd:number"></cd:constant><br />
</cd:parameter><br />
<cd:parameter name="max"><br />
<cd:paramdoc>maximum nesting level</cd:paramdoc><br />
<cd:constant type="cd:number"></cd:constant><br />
</cd:parameter><br />
<cd:parameter name="foregroundstyle"><br />
<cd:paramdoc>useful if <cd:iref name="order" type="background"/><br />
</cd:paramdoc><br />
<cd:constant type="cd:style"></cd:constant><br />
<cd:constant type="cd:command"></cd:constant><br />
</cd:parameter><br />
<cd:parameter name="foregroundcolor"><br />
<cd:paramdoc>useful if <cd:iref name="order" type="background"/><br />
</cd:paramdoc><br />
<cd:constant type="cd:color"></cd:constant><br />
</cd:parameter><br />
<cd:parameter name="mp"><br />
<cd:paramdoc>Use a named {{cmd|startuseMPgraphic}} to create the bar. See the definition of e.g. <code>underdash</code> in <code>node-rul.mkiv</code> for an example.</cd:paramdoc><br />
<cd:constant type="cd:name"></cd:constant><br />
</cd:parameter><br />
<cd:parameter name="left"><br />
<cd:paramdoc></cd:paramdoc><br />
<cd:constant type="cd:text"></cd:constant><br />
</cd:parameter><br />
<cd:parameter name="right"><br />
<cd:paramdoc></cd:paramdoc><br />
<cd:constant type="cd:text"></cd:constant><br />
</cd:parameter><br />
<cd:parameter name="repeat"><br />
<cd:paramdoc>Originally used for leader-style 'bars' (dotted or dashed). Used in combination with the (undocumented) option <cd:iref name="text"/>. Replaced by the much more powerful <cd:iref name="mp"/> option.</cd:paramdoc><br />
<cd:constant type="yes"></cd:constant><br />
<cd:constant default="yes" type="no"></cd:constant><br />
</cd:parameter><br />
</cd:assignments><br />
</cd:arguments><br />
</cd:command><br />
</cd:variants><br />
<cd:description>Set up options for 'bars': rule- and dots based decorations for running text.<br />
<br />
See {{gen|bar}} for the predefined instances. You can define your own instances with {{cmd|definebar}}.<br />
<br />
</cd:description><br />
<cd:examples><cd:example title=""><context source="yes"><br />
\setupbar[overstrike][color=red]<br />
some \overstrike{stricken} text.<br />
</context></cd:example></cd:examples><br />
<cd:notes></cd:notes><br />
<cd:seealso><br />
<cd:commandref name="definebar" originator="system"></cd:commandref><br />
<cd:source file="node-rul.mkiv" originator="system"></cd:source><br />
<cd:wikipage originator="system" page="Category:Rules"></cd:wikipage><br />
<cd:commandref name="_bar"></cd:commandref></cd:seealso><br />
</cd:commandgroup></div>Willihttps://wiki.contextgarden.net/index.php?title=Command/setupbar&diff=34459Command/setupbar2024-03-28T20:57:02Z<p>Willi: </p>
<hr />
<div><cd:commandgroup name="setupbar" xmlns:cd="http://wiki.contextgarden.net/commanddoc/20200807"><br />
<cd:shortdesc>The command <tt>\setupbar</tt> sets up parameters for rules (lines)<br />
</cd:shortdesc><br />
<cd:variants><br />
<cd:command category="rules" file="node-rul.mkiv" interfacedate="2020-07-14T09:24" interfacefile="i-bar.xml" level="style" name="setupbar" variantnumber="1"><br />
<cd:arguments><br />
<cd:keywords list="yes" optional="yes" ordinal="1"><br />
<cd:keywordsdoc>Name of the bar. See [[Category:Command/_bar]]</cd:keywordsdoc><br />
<cd:constant type="cd:name"></cd:constant><br />
</cd:keywords><br />
<cd:assignments list="yes" ordinal="2"><br />
<cd:assignmentsdoc></cd:assignmentsdoc><br />
<cd:parameter name="color"><br />
<cd:paramdoc>color of the bar itself</cd:paramdoc><br />
<cd:constant type="cd:color"></cd:constant><br />
</cd:parameter><br />
<cd:parameter name="continue"><br />
<cd:paramdoc>controls split based on words</cd:paramdoc><br />
<cd:constant type="yes">split on words</cd:constant><br />
<cd:constant default="yes" type="no">continuous bar</cd:constant><br />
<cd:constant type="all"></cd:constant><br />
</cd:parameter><br />
<cd:parameter name="empty"><br />
<cd:paramdoc></cd:paramdoc><br />
<cd:constant type="yes"></cd:constant><br />
<cd:constant default="yes" type="no"></cd:constant><br />
</cd:parameter><br />
<cd:parameter name="unit"><br />
<cd:paramdoc>unit to use for <cd:iref name="offset"/> and <cd:iref name="dy"/></cd:paramdoc><br />
<cd:constant default="yes" type="ex"></cd:constant><br />
<cd:constant type="em"></cd:constant><br />
<cd:constant type="pt"></cd:constant><br />
<cd:constant type="in"></cd:constant><br />
<cd:constant type="cm"></cd:constant><br />
<cd:constant type="mm"></cd:constant><br />
<cd:constant type="sp"></cd:constant><br />
<cd:constant type="bp"></cd:constant><br />
<cd:constant type="pc"></cd:constant><br />
<cd:constant type="dd"></cd:constant><br />
<cd:constant type="cc"></cd:constant><br />
<cd:constant type="nc"></cd:constant><br />
</cd:parameter><br />
<cd:parameter name="order"><br />
<cd:paramdoc>put the rules in front of, or behind the text.</cd:paramdoc><br />
<cd:constant default="yes" type="foreground"></cd:constant><br />
<cd:constant type="background"></cd:constant><br />
</cd:parameter><br />
<cd:parameter name="rulethickness"><br />
<cd:paramdoc></cd:paramdoc><br />
<cd:constant type="cd:dimension"></cd:constant><br />
</cd:parameter><br />
<cd:parameter name="method"><br />
<cd:paramdoc>switch between centred and baseline-based vertical aligment</cd:paramdoc><br />
<cd:constant type="cd:number">0 = centred vertically. Leave empty / omit for <cd:iref name="offset"/> to be based on the text's baseline.</cd:constant><br />
</cd:parameter><br />
<cd:parameter name="offset"><br />
<cd:paramdoc>vertical shift</cd:paramdoc><br />
<cd:constant type="cd:number"></cd:constant><br />
</cd:parameter><br />
<cd:parameter name="dy"><br />
<cd:paramdoc>vertical shift when used nested</cd:paramdoc><br />
<cd:constant type="cd:number"></cd:constant><br />
</cd:parameter><br />
<cd:parameter name="max"><br />
<cd:paramdoc>maximum nesting level</cd:paramdoc><br />
<cd:constant type="cd:number"></cd:constant><br />
</cd:parameter><br />
<cd:parameter name="foregroundstyle"><br />
<cd:paramdoc>useful if <cd:iref name="order" type="background"/><br />
</cd:paramdoc><br />
<cd:constant type="cd:style"></cd:constant><br />
<cd:constant type="cd:command"></cd:constant><br />
</cd:parameter><br />
<cd:parameter name="foregroundcolor"><br />
<cd:paramdoc>useful if <cd:iref name="order" type="background"/><br />
</cd:paramdoc><br />
<cd:constant type="cd:color"></cd:constant><br />
</cd:parameter><br />
<cd:parameter name="mp"><br />
<cd:paramdoc>Use a named {{cmd|startuseMPgraphic}} to create the bar. See the definition of e.g. <code>underdash</code> in <code>node-rul.mkiv</code> for an example.</cd:paramdoc><br />
<cd:constant type="cd:name"></cd:constant><br />
</cd:parameter><br />
<cd:parameter name="left"><br />
<cd:paramdoc></cd:paramdoc><br />
<cd:constant type="cd:text"></cd:constant><br />
</cd:parameter><br />
<cd:parameter name="right"><br />
<cd:paramdoc></cd:paramdoc><br />
<cd:constant type="cd:text"></cd:constant><br />
</cd:parameter><br />
<cd:parameter name="repeat"><br />
<cd:paramdoc>Originally used for leader-style 'bars' (dotted or dashed). Used in combination with the (undocumented) option <cd:iref name="text"/>. Replaced by the much more powerful <cd:iref name="mp"/> option.</cd:paramdoc><br />
<cd:constant type="yes"></cd:constant><br />
<cd:constant default="yes" type="no"></cd:constant><br />
</cd:parameter><br />
</cd:assignments><br />
</cd:arguments><br />
</cd:command><br />
</cd:variants><br />
<cd:description>Set up options for 'bars': rule- and dots based decorations for running text.<br />
<br />
See {{gen|bar}} for the predefined instances. You can define your own instances with {{cmd|definebar}}.<br />
<br />
</cd:description><br />
<cd:examples><cd:example title=""><context source="yes"><br />
\setupbar[overstrike][color=red]<br />
some \overstrike{stricken} text.<br />
</context></cd:example></cd:examples><br />
<cd:notes></cd:notes><br />
<cd:seealso><br />
<cd:commandref name="definebar" originator="system"></cd:commandref><br />
<cd:source file="node-rul.mkiv" originator="system"></cd:source><br />
<cd:wikipage originator="system" page="Category:Rules"></cd:wikipage><br />
<cd:commandref name="_bar"></cd:commandref></cd:seealso><br />
</cd:commandgroup></div>Willihttps://wiki.contextgarden.net/index.php?title=CLD&diff=33729CLD2022-08-25T18:45:09Z<p>Willi: /* Setting up Header Texts */</p>
<hr />
<div>'''ConTeXt Lua Documents''' (CLD) are way to access TeX from inside Lua scripts; they provide means to typeset documents using little to no TeX code at all.<br />
This makes them especially helpful for automated content generation and scripting.<br />
Internally, the Lua commands are mapped onto their ConTeXt and TeX counterparts.<br />
Knowledge of the latter is, therefore, a prerequisite to writing CLDs.<br />
If you ever dreamed of proper typesetting without backslashes galore, here is where to start at.<br />
<br />
= Basic reading =<br />
* [http://www.pragma-ade.nl/general/manuals/cld-mkiv.pdf The CLD manual] by Hans Hagen.<br />
* {{src|cldf-ini.lua}}: the entry point for the '''cldf-*''' files that contain the CLD implementation.<br />
<br />
= An Example =<br />
Writing CLDs is straightforward although there are some pitfalls.<br />
Suppose we want to typeset the following minimal example:<br />
<br />
<texcode><br />
\starttext<br />
\placefigure {none} {% <br />
\framed [frame=on, align=middle] {%<br />
\input knuth<br />
}%<br />
}%<br />
\stoptext<br />
</texcode><br />
<br />
<context><br />
\starttext<br />
\placefigure {none} {% <br />
\framed [frame=on, align=middle] {%<br />
\input knuth<br />
}%<br />
}%<br />
\stoptext<br />
</context><br />
<br />
As <em>CLD</em> this will require more verbosity because nesting -- in the present example a <code>framed</code> inside a <code>placefigure</code> -- has to be expressed through functions.<br />
Optional and key-value style arguments are expressed as arrays and dictionaries respectively, which is a transparent representation of their ConTeXt ancestors.<br />
Mandatory (grouped) arguments are given either as strings or as functions.<br />
<br />
== Nesting 1: Functions ==<br />
The following example shows two ways of rewriting the above TeX code: the first one closely resembles its structure while the second calls the function <code>test</code> from inside the <code>placefigure</code> macro.<br />
<br />
<pre><br />
context.placefigure(<br />
"none",<br />
function()<br />
context.framed( {<br />
frame="on",<br />
align="middle"<br />
}, <br />
function() context.input("knuth") end <br />
) <br />
end <br />
)<br />
<br />
context.par()<br />
<br />
function text ()<br />
context.framed( {<br />
frame="on",<br />
align="middle"<br />
}, <br />
function() context.input("knuth") end <br />
) <br />
end<br />
<br />
context.placefigure(<br />
"none",<br />
function () text() end <br />
)<br />
<br />
</pre><br />
<br />
== Nesting 2: Delayed ==<br />
<br />
An alternative to the function encapsulation is provided by <br />
the <tt>context.delayed.f()</tt> method.<br />
This way execution of the <tt>\input</tt> <br />
command is prevented until <tt>\placefigure</tt> is passed to TeX,<br />
the obvious advantage being that the source code follows the<br />
original TeX code and that it eliminates the need to create<br />
a separate function.<br />
<br />
<pre><br />
context.placefigure(<br />
"none",<br />
function()<br />
context.framed( {<br />
frame="on",<br />
align="middle"<br />
}, <br />
context.delayed.input("knuth")<br />
)<br />
end <br />
)<br />
</pre><br />
<br />
= Setting up Header Texts =<br />
<br />
As already shown in the section about Nesting 1: Functions also context.setupheadertexts needs to be called with functions. On top of this we need to know, that once context.setupheadertexts is executed it is not frozen. This makes it necessary, that we need to add "return true" inside each used function() call. This makes sure that the called function stays around until the run is finished.<br />
<br />
A complete setup of header texts in a double-sided ConTeXt Lua Document could look then like this<br />
<br />
<pre><br />
context.setupheadertexts(<br />
{function()<br />
context.getmarking({"chapter"})<br />
return true<br />
end<br />
},<br />
{function()<br />
context.pagenumber()<br />
return true<br />
end<br />
},<br />
{function()<br />
context.getmarking({"section"})<br />
return true<br />
end<br />
},<br />
{function()<br />
context.pagenumber()<br />
return true<br />
end<br />
})<br />
</pre><br />
<br />
<br />
[[Category:Programming and Databases]]</div>Willihttps://wiki.contextgarden.net/index.php?title=CLD&diff=33727CLD2022-08-25T18:42:20Z<p>Willi: /* Setting up Header Texts */</p>
<hr />
<div>'''ConTeXt Lua Documents''' (CLD) are way to access TeX from inside Lua scripts; they provide means to typeset documents using little to no TeX code at all.<br />
This makes them especially helpful for automated content generation and scripting.<br />
Internally, the Lua commands are mapped onto their ConTeXt and TeX counterparts.<br />
Knowledge of the latter is, therefore, a prerequisite to writing CLDs.<br />
If you ever dreamed of proper typesetting without backslashes galore, here is where to start at.<br />
<br />
= Basic reading =<br />
* [http://www.pragma-ade.nl/general/manuals/cld-mkiv.pdf The CLD manual] by Hans Hagen.<br />
* {{src|cldf-ini.lua}}: the entry point for the '''cldf-*''' files that contain the CLD implementation.<br />
<br />
= An Example =<br />
Writing CLDs is straightforward although there are some pitfalls.<br />
Suppose we want to typeset the following minimal example:<br />
<br />
<texcode><br />
\starttext<br />
\placefigure {none} {% <br />
\framed [frame=on, align=middle] {%<br />
\input knuth<br />
}%<br />
}%<br />
\stoptext<br />
</texcode><br />
<br />
<context><br />
\starttext<br />
\placefigure {none} {% <br />
\framed [frame=on, align=middle] {%<br />
\input knuth<br />
}%<br />
}%<br />
\stoptext<br />
</context><br />
<br />
As <em>CLD</em> this will require more verbosity because nesting -- in the present example a <code>framed</code> inside a <code>placefigure</code> -- has to be expressed through functions.<br />
Optional and key-value style arguments are expressed as arrays and dictionaries respectively, which is a transparent representation of their ConTeXt ancestors.<br />
Mandatory (grouped) arguments are given either as strings or as functions.<br />
<br />
== Nesting 1: Functions ==<br />
The following example shows two ways of rewriting the above TeX code: the first one closely resembles its structure while the second calls the function <code>test</code> from inside the <code>placefigure</code> macro.<br />
<br />
<pre><br />
context.placefigure(<br />
"none",<br />
function()<br />
context.framed( {<br />
frame="on",<br />
align="middle"<br />
}, <br />
function() context.input("knuth") end <br />
) <br />
end <br />
)<br />
<br />
context.par()<br />
<br />
function text ()<br />
context.framed( {<br />
frame="on",<br />
align="middle"<br />
}, <br />
function() context.input("knuth") end <br />
) <br />
end<br />
<br />
context.placefigure(<br />
"none",<br />
function () text() end <br />
)<br />
<br />
</pre><br />
<br />
== Nesting 2: Delayed ==<br />
<br />
An alternative to the function encapsulation is provided by <br />
the <tt>context.delayed.f()</tt> method.<br />
This way execution of the <tt>\input</tt> <br />
command is prevented until <tt>\placefigure</tt> is passed to TeX,<br />
the obvious advantage being that the source code follows the<br />
original TeX code and that it eliminates the need to create<br />
a separate function.<br />
<br />
<pre><br />
context.placefigure(<br />
"none",<br />
function()<br />
context.framed( {<br />
frame="on",<br />
align="middle"<br />
}, <br />
context.delayed.input("knuth")<br />
)<br />
end <br />
)<br />
</pre><br />
<br />
= Setting up Header Texts =<br />
<br />
As already shown in the section about Nesting 1: Functions also setupheadertexts need to be called with functions. On top of this we need to know, that once setupheadertexts is executed it is not frozen. This makes it necessary, that we need to add "return true" inside each used function() call. This makes sure that the called function stays around until the run is finished<br />
<br />
A complete setup of header texts in a double-sided ConTeXt Lua Document could look then like this<br />
<br />
<pre><br />
context.setupheadertexts(<br />
{function()<br />
context.getmarking({"chapter"})<br />
return true<br />
end<br />
},<br />
{function()<br />
context.pagenumber()<br />
return true<br />
end<br />
},<br />
{function()<br />
context.getmarking({"section"})<br />
return true<br />
end<br />
},<br />
{function()<br />
context.pagenumber()<br />
return true<br />
end<br />
})<br />
</pre><br />
<br />
<br />
[[Category:Programming and Databases]]</div>Willihttps://wiki.contextgarden.net/index.php?title=CLD&diff=33724CLD2022-08-25T18:12:36Z<p>Willi: </p>
<hr />
<div>'''ConTeXt Lua Documents''' (CLD) are way to access TeX from inside Lua scripts; they provide means to typeset documents using little to no TeX code at all.<br />
This makes them especially helpful for automated content generation and scripting.<br />
Internally, the Lua commands are mapped onto their ConTeXt and TeX counterparts.<br />
Knowledge of the latter is, therefore, a prerequisite to writing CLDs.<br />
If you ever dreamed of proper typesetting without backslashes galore, here is where to start at.<br />
<br />
= Basic reading =<br />
* [http://www.pragma-ade.nl/general/manuals/cld-mkiv.pdf The CLD manual] by Hans Hagen.<br />
* {{src|cldf-ini.lua}}: the entry point for the '''cldf-*''' files that contain the CLD implementation.<br />
<br />
= An Example =<br />
Writing CLDs is straightforward although there are some pitfalls.<br />
Suppose we want to typeset the following minimal example:<br />
<br />
<texcode><br />
\starttext<br />
\placefigure {none} {% <br />
\framed [frame=on, align=middle] {%<br />
\input knuth<br />
}%<br />
}%<br />
\stoptext<br />
</texcode><br />
<br />
<context><br />
\starttext<br />
\placefigure {none} {% <br />
\framed [frame=on, align=middle] {%<br />
\input knuth<br />
}%<br />
}%<br />
\stoptext<br />
</context><br />
<br />
As <em>CLD</em> this will require more verbosity because nesting -- in the present example a <code>framed</code> inside a <code>placefigure</code> -- has to be expressed through functions.<br />
Optional and key-value style arguments are expressed as arrays and dictionaries respectively, which is a transparent representation of their ConTeXt ancestors.<br />
Mandatory (grouped) arguments are given either as strings or as functions.<br />
<br />
== Nesting 1: Functions ==<br />
The following example shows two ways of rewriting the above TeX code: the first one closely resembles its structure while the second calls the function <code>test</code> from inside the <code>placefigure</code> macro.<br />
<br />
<pre><br />
context.placefigure(<br />
"none",<br />
function()<br />
context.framed( {<br />
frame="on",<br />
align="middle"<br />
}, <br />
function() context.input("knuth") end <br />
) <br />
end <br />
)<br />
<br />
context.par()<br />
<br />
function text ()<br />
context.framed( {<br />
frame="on",<br />
align="middle"<br />
}, <br />
function() context.input("knuth") end <br />
) <br />
end<br />
<br />
context.placefigure(<br />
"none",<br />
function () text() end <br />
)<br />
<br />
</pre><br />
<br />
== Nesting 2: Delayed ==<br />
<br />
An alternative to the function encapsulation is provided by <br />
the <tt>context.delayed.f()</tt> method.<br />
This way execution of the <tt>\input</tt> <br />
command is prevented until <tt>\placefigure</tt> is passed to TeX,<br />
the obvious advantage being that the source code follows the<br />
original TeX code and that it eliminates the need to create<br />
a separate function.<br />
<br />
<pre><br />
context.placefigure(<br />
"none",<br />
function()<br />
context.framed( {<br />
frame="on",<br />
align="middle"<br />
}, <br />
context.delayed.input("knuth")<br />
)<br />
end <br />
)<br />
</pre><br />
<br />
= Setting up Header Texts =<br />
<br />
As already shown in the section about Nesting 1: Functions also setupheadertexts need to be called with functions. On top of this we need to know, that once setupheadertexts is executed it is not frozen. This makes it necessary, that we need to add "return true" inside eacht used function() call.<br />
<br />
A complete setup of header texts in a double-sided ConTeXt Lua Document looks then like this<br />
<br />
<pre><br />
context.setupheadertexts(<br />
{function()<br />
context.chapter()<br />
return true<br />
end<br />
},<br />
{function()<br />
context.pagenumber()<br />
return true<br />
end<br />
},<br />
{function()<br />
context.chpter()<br />
return true<br />
end<br />
},<br />
{function()<br />
context.pagenumber()<br />
return true<br />
end<br />
})<br />
</pre><br />
<br />
<br />
[[Category:Programming and Databases]]</div>Willihttps://wiki.contextgarden.net/index.php?title=Command/_setuplabeltext&diff=33485Command/ setuplabeltext2022-03-17T23:07:00Z<p>Willi: In German TOC is named Inhalt not Einhalt... corrected</p>
<hr />
<div><cd:commandgroup generated="yes" name="setuplabeltext" xmlns:cd="http://wiki.contextgarden.net/commanddoc/20200807"><br />
<cd:shortdesc>The instances of <tt>\setup<i>label</i>text</tt> are used to fill in a class of labels<br />
</cd:shortdesc><br />
<cd:sequence><br />
<cd:string value="setup"></cd:string><br />
<cd:instance value="label"></cd:instance><br />
<cd:string value="text"></cd:string><br />
</cd:sequence><br />
<cd:instances><br />
<cd:constant value="head">Certain sections, like the table of contents or the list of figures, have a default title head. This title can be altered with {{cmd|setupheadtext|[name=text]}}. See [[#Description]] for the list of defined section head labels.</cd:constant><br />
<cd:constant value="label">This class holds most other labels like the '''Figure''' and '''Table''' used in float captions.</cd:constant><br />
<cd:constant value="mathlabel"></cd:constant><br />
<cd:constant value="taglabel"></cd:constant><br />
<cd:constant value="unit"></cd:constant><br />
<cd:constant value="operator"></cd:constant><br />
<cd:constant value="prefix"></cd:constant><br />
<cd:constant value="suffix"></cd:constant><br />
<cd:constant value="btxlabel"></cd:constant><br />
</cd:instances><br />
<cd:variants><br />
<cd:command category="language" file="lang-lab.mkiv" generated="yes" interfacedate="2020-07-14T09:24" interfacefile="i-labeltext.xml" level="style" name="setuplabeltext" variant="instance" variantnumber="1"><br />
<cd:arguments><br />
<cd:keywords optional="yes" ordinal="1"><br />
<cd:keywordsdoc></cd:keywordsdoc><br />
<cd:constant type="cd:language"></cd:constant><br />
</cd:keywords><br />
<cd:assignments list="yes" ordinal="2"><br />
<cd:assignmentsdoc></cd:assignmentsdoc><br />
<cd:parameter name="cd:key"><br />
<cd:paramdoc></cd:paramdoc><br />
<cd:constant type="cd:value"></cd:constant><br />
</cd:parameter><br />
</cd:assignments><br />
</cd:arguments><br />
</cd:command><br />
</cd:variants><br />
<cd:description>In some cases ConTeXt generates text labels automatically; for example,<br />
the word ''Figure'' is generated automatically when a caption is placed<br />
under a figure. These kind of words are called label texts. Labels are<br />
set with the command {{cmd|setuplabeltext}}, and retrieved with the<br />
command {{cmd|labeltext}}. They follow the language set with<br />
{{cmd|mainlanguage}}, not the local bits of different language that are<br />
set with {{cmd|language}}.<br />
<br />
'''Note''' Nearly all the labels in the ConTeXt core are actually loaded from a lua table<br />
in <code>lang-txt.lua</code>, instead of via this interface.<br />
<br />
'''NB''' The ''option parser'' for the command {{gen|setuplabeltext}}<br />
is [http://www.ntg.nl/pipermail/ntg-context/2012/067585.html known] to<br />
behave somewhat differently from most setups, posing minor constraints<br />
on code formatting.<br />
For instance the trailing comma after an assignment, otherwise employed<br />
to delimit the value, will lead to an error here.<br />
The final option in the list needs thus to be terminated by the closing<br />
bracket.<br />
<br />
<texcode><br />
\setuplabeltext [<br />
Nomen=nomen,<br />
Est=est,<br />
Omen=est, %% <= fails!<br />
]<br />
\setuplabeltext [Nomen=nomen, Est=est, Omen=est] %% <= works<br />
\starttext<br />
\labeltext{Nomen}<br />
\labeltext{Est}<br />
\labeltext{Omen}<br />
\stoptext<br />
</texcode><br />
<br />
For {{cmd|setupheadtext}}, here is the list of known section heads:<br />
<br />
{| class="wikitable"<br />
! name || text<br />
|-<br />
| content || Contents<br />
|-<br />
| tables || Tables<br />
|-<br />
| figures || Figures<br />
|-<br />
| graphics || Graphics<br />
|-<br />
| intermezzi || Intermezzos<br />
|-<br />
| index || Index<br />
|-<br />
| abbreviations || Abbreviations<br />
|-<br />
| logos || Logos<br />
|-<br />
| units || Units<br />
|-<br />
| pubs || References<br />
|}<br />
</cd:description><br />
<cd:examples><cd:example title="Example for \setupheadtext"><context source="yes"><br />
\setuppapersize[A5]<br />
\mainlanguage[de]<br />
% default headtext is 'Inhalt'<br />
\setupheadtext[de][content=Inhaltsverzeichnis]<br />
<br />
\starttext<br />
<br />
\completecontent<br />
\chapter{The first chapter}<br />
<br />
\stoptext<br />
</context></cd:example><cd:example title="Example for \setuplabeltext">Here is an example of changing section and subsection heads.<br />
<context source="yes" text="results in"><br />
% English labels<br />
\setuplabeltext[en][section=My section ] % We want a space at the end of the label<br />
\setuplabeltext[en][subsection=My subsection ]<br />
<br />
% Dutch labels<br />
\setuplabeltext[nl][section=Mijn hoofdstuk ] % We want a space at the end of the label<br />
\setuplabeltext[nl][subsection=Mijn onderdeel ]<br />
<br />
\def\setheadnumber#1#2{#1. #2}<br />
<br />
\setuphead<br />
[section,subsection]<br />
[command=\setheadnumber,<br />
before={\blank[disable]},<br />
after={\blank[disable]}]<br />
<br />
\starttext<br />
<br />
\section{First Thoughts}<br />
\subsection{First Subsection}<br />
\hairline<br />
<br />
% Changing the language does not change the labels<br />
\language[nl]<br />
\section{Second Thoughts}<br />
\subsection{Second Subsection}<br />
\hairline<br />
<br />
% To change the labels, change the main language.<br />
\mainlanguage[nl]<br />
\section{Third Thoughts}<br />
\subsection{Third Subsection}<br />
\hairline<br />
<br />
% Retrieving a label explicity:<br />
This is the Dutch label for sections: \labeltext{section}.<br />
<br />
\stoptext<br />
</context></cd:example></cd:examples><br />
<cd:notes></cd:notes><br />
<cd:seealso><br />
<cd:commandref name="_copylabeltext" originator="system"></cd:commandref><br />
<cd:commandref name="_currentlabel" originator="system"></cd:commandref><br />
<cd:commandref name="_label" originator="system"></cd:commandref><br />
<cd:commandref name="_labellanguage" originator="system"></cd:commandref><br />
<cd:commandref name="_labeltext" originator="system"></cd:commandref><br />
<cd:commandref name="_labeltexts" originator="system"></cd:commandref><br />
<cd:commandref name="_leftlabeltext" originator="system"></cd:commandref><br />
<cd:commandref name="_presetlabeltext" originator="system"></cd:commandref><br />
<cd:commandref name="_rightlabeltext" originator="system"></cd:commandref><br />
<cd:commandref name="_startlabeltext" originator="system"></cd:commandref><br />
<cd:commandref name="definelabelclass" originator="system"></cd:commandref><br />
<cd:source file="lang-lab.mkiv" originator="system"></cd:source><br />
<cd:wikipage originator="system" page="Category:Language"></cd:wikipage><br />
<cd:source file="lang-txt.lua"></cd:source></cd:seealso><br />
</cd:commandgroup></div>Willihttps://wiki.contextgarden.net/index.php?title=Font_Switching&diff=32568Font Switching2021-06-08T16:45:14Z<p>Willi: Correction of typo</p>
<hr />
<div>In ConTeXt there are four ways to switch fonts:<br />
<br />
* font style/alternative commands ({{cmd|rm}}, {{cmd|ss}}, etc.),<br />
* font size commands ({{cmd|tfa}}, {{cmd|tfb}}, etc.),<br />
* mnemonic command aliases ({{cmd|bold}}, {{cmd|sans}}, etc.),<br />
* a complete font change ({{cmd|setupbodyfont}}, {{cmd|switchtobodyfont}}).<br />
<br />
== Before you start ... ==<br />
<br />
1. Placing a font switch at the begin of a paragraph can sometimes generate unexpected side-effects. This can be avoided by forcing horizontal mode before any font change:<br />
<texcode><br />
\dontleavehmode{\bf Warning!} Care must be taken when a font switch is used at the beginning of a paragraph.\par<br />
</texcode><br />
<br />
2. It is usually a bad style to use explicit font switches in the text. It is better to define a semantic command that takes care of the font switching. For example, instead of using <code>{\bf\red important text}</code><br />
<texcode><br />
\definehighlight[important][style=bold, color=red]<br />
</texcode><br />
and then use <code>\important{important text}</code> in the text.<br />
<br />
== Font styles and alternatives ==<br />
<br />
There are three main types of font styles: serif, sans serif, and teletype. To<br />
switch between these styles, use {{cmd|rm}} for serif, {{cmd|ss}} for<br />
sans serif, and {{cmd|tt}} for teletype.<br />
<br />
Each of these styles comes in different alternatives: normal, bold, italic,<br />
slanted, bold-italic, bold-slanted, and small-capped. To switch to a different<br />
alternative, use {{cmd|tf}} ("typeface") for normal, {{cmd|bf}} for bold, {{cmd|it}}<br />
for italic, {{cmd|sl}} for slanted, {{cmd|bi}} for bold-italic,<br />
{{cmd|bs}} for bold-slanted, and {{cmd|sc}} for small-capped.<br />
<br />
You can generally combine font styles with alternatives, so if you want to<br />
switch to bold sans serif, you can use either <code>\bf\ss</code> or<br />
<code>\ss\bf</code>. The various combinations look like the following.<br />
<br />
<context mode="mkiv"><br />
\setupbodyfont[8pt]<br />
\setupcolors[rgb, state=start]<br />
\definecolor[one][c=0, m=.4, y=1, k=0]<br />
\definecolor[two][c=0, m=.2, y=.5, k=0]<br />
\setupTABLE[frame=off,offset=0.5em]<br />
<br />
\setupTABLE[c][2][style=\rm]<br />
\setupTABLE[c][3][style=\ss]<br />
\setupTABLE[c][4][style=\tt]<br />
\setupTABLE[r][1][background=color, backgroundcolor=one]<br />
\setupTABLE[c][1][background=color, backgroundcolor=one]<br />
<br />
\startTABLE<br />
\NC \NC \type{\rm} serif \NC \type{\ss} sans serif \NC \type{\tt} teletype \NC \NR<br />
\NC \type{\tf} \NC Normal \NC Normal \NC Normal \NC \NR<br />
\NC \type{\bf} \NC \bf Bold \NC \bf Bold \NC \bf Bold \NC \NR<br />
\NC \type{\it} \NC \it Italic \NC \it Italic \NC \it Italic \NC \NR<br />
\NC \type{\sl} \NC \sl Slanted \NC \sl Slanted \NC \sl Slanted\NC \NR<br />
\NC \type{\bi} \NC \bi Bold Italic \NC \bi Bold Italic \NC \bi Bold Italic\NC \NR<br />
\NC \type{\bs} \NC \bs Bold Slanted \NC \bs Bold Slanted \NC \bs Bold Slanted\NC \NR<br />
\NC \type{\sc} \NC \sc Smallcaps \NC \sc Smallcaps \NC \sc Smallcaps\NC \NR<br />
\stopTABLE<br />
<br />
</context><br />
<br />
A font switch remains valid for the rest of the ''group''. So, if you want to<br />
temporarily switch to a different font, use the font style command inside a<br />
group. The easiest way to start a group is to enclose the text within braces<br />
(also called curly brackets), for example<br />
<br />
<texcode><br />
This is serif text<br />
{\ss This is sans serif}<br />
This is serif again<br />
{\tt and this is typewriter}<br />
And serif again<br />
</texcode><br />
<br />
which gives (notice the braces in the above lines)<br />
<br />
<context><br />
This is serif text \crlf<br />
{\ss This is sans serif} \crlf<br />
This is serif again \crlf<br />
{\tt and this is typewriter} \crlf<br />
And serif again<br />
</context><br />
<br />
== Emphasizing text ==<br />
There is a font switch {{cmd|em}} to ''emphasize'' text. This is somewhat<br />
special: it does automatic italic correction and changes the alternative depending<br />
on the current alternative. For example, if the current font alternative is normal (i.e. upright),<br />
{{cmd|em}} switches to slanted; and if the current font alternative is slanted,<br />
{{cmd|em}} switches to normal.<br />
<br />
<context><br />
\starttabulate[|l|f{\tf}l|f{\it}l|f{\sl}l|f{\bf}l|f{\bi}l|f{\bs}l|]<br />
\NC \NC \tttf \tex{tf} \NC \tttf \tex{it} \NC \tttf \tex{sl} \NC<br />
\tttf \tex{bf} \NC \tttf \tex{bi} \NC \tttf \tex{bs} \NC\NR<br />
\NC \NC Text \NC Text \NC Text \NC<br />
Text \NC Text \NC Text \NC\NR<br />
\NC \tex{em} \NC \em Text \NC \em Text \NC \em Text \NC<br />
\em Text \NC \em Text \NC \em Text \NC\NR<br />
\NC \tex{boldface} \NC \boldface Text \NC \boldface Text \NC \boldface Text \NC<br />
\boldface Text \NC \boldface Text \NC \boldface Text \NC\NR<br />
\NC \tex{typeface} \NC \typeface Text \NC \typeface Text \NC \typeface Text \NC<br />
\typeface Text \NC \typeface Text \NC \typeface Text \NC\NR<br />
\NC \tex{swapface} \NC \swapface Text \NC \swapface Text \NC \swapface Text \NC<br />
\swapface Text \NC \swapface Text \NC \swapface Text \NC\NR<br />
\stoptabulate<br />
</context><br />
<br />
ConTeXt uses the Latin Modern fonts by default; these fonts look<br />
similar to the original Computer Modern fonts, but have a much larger<br />
character repertoire. As it happens, in the Latin Modern (and Computer<br />
Modern) fonts, the slanted font does not stand out from the<br />
upright font enough for some tastes; so, many people prefer to use the<br />
italic font for emphasis. To do that use <br />
<texcode><br />
\definebodyfontenvironment[default][em=italic]<br />
</texcode><br />
<br />
{{note| For Opentype fonts, italic correction needs to be set using<br />
<texcode>\definefontfeature[default][default][itlc=yes]</texcode>}}<br />
<br />
== Font sizes ==<br />
<br />
Occasionally one needs to use a font size different from the bodyfont. ConTeXt provides two series<br />
of commands for that. For a larger font size, you can use {{cmd|tfa}} to scale<br />
the font size by a factor of <code>1.2</code>, {{cmd|tfb}} to scale by a factor of<br />
<code>(1.2)^2 = 1.44</code>, {{cmd|tfc}} to scale by <code>(1.2)^3 = 1.728</code> and {{cmd|tfd}} to<br />
scale by <code>(1.2)^4 = 2.074</code>. The scale is relative to the current bodyfont size.<br />
<br />
<br />
To decrease the font size, you can use {{cmd|tfx}}<br />
to scale the font by a factor of <code>0.8</code> and {{cmd|tfxx}} to scale by a factor<br />
of <code>0.6</code>.<br />
<br />
The complete set of relative font sizes are listed below:<br />
{| style="border:1px solid #ffcc00; width:100%; padding: 0.5em;" <br />
|- align="right"<br />
!size||factor ||4pt||5pt||6pt||7pt||8pt||9pt||10pt||11pt||12pt||14.4pt||17.3pt||20.7pt<br />
|- align="right"<br />
|xx ||0.6 ||4 ||5 ||5 ||5 ||5 ||5 ||6 ||7 ||8 ||10 ||12 ||14.4<br />
|- align="right"<br />
|x ||0.8 ||4 ||5 ||5 ||6 ||6 ||7 ||8 ||9 ||10 ||12 ||14.4 ||17.3<br />
|- align="right" style="background-color: #ffeebb;"<br />
|tf ||1.0 ||4 ||5 ||6 ||7 ||8 ||9 ||10 ||11 ||12 ||14.4 ||17.3 ||20.7<br />
|- align="right"<br />
|a ||1.2 ||4.8||6.0||7.2||8.4||9.6||10.8||12.0||13.2||14.4||17.3 ||20.7 ||24.8<br />
|- align="right"<br />
|b ||1.44 ||5.8||7.2||8.6||10.1||11.5||13.0||14.4||15.8||17.3||20.7||24.9 ||29.8<br />
|- align="right"<br />
|c ||1.728 ||6.9||8.6||10.4||12.1||13.8||15.6||17.3||19.0||20.7||24.9||29.9||35.8<br />
|- align="right"<br />
|d ||2.074 ||8.3||10.4||12.4||14.5||16.6||18.7||20.7||22.8||24.9||29.9||35.9||42.9<br />
|-<br />
| _<br />
|- align="right"<br />
|scriptscript|| 0.5 ||4 ||5 ||5 ||5 ||5 ||5 ||5 ||6 ||7 ||9 ||10 ||12<br />
|- align="right"<br />
|script|| 0.7 ||4 ||5 ||5 ||6 ||6 ||7 ||7 ||8 ||9 ||11 ||12 ||14.4<br />
|- align="right"<br />
|small|| 0.8 ||4 ||4 ||5 ||5 ||6 ||7 ||8 ||9 ||10 ||12 ||14.4||17.3<br />
|- align="right"<br />
|big || 1.2 ||6 ||7 ||8 ||9 ||10 ||11 ||12 ||12 ||14.4||17.3||20.7||20.7<br />
|}<br />
<br />
As defined in [[source:font-ini.mkvi|font-ini]]. All sizes in pt, except factor.<br />
<br />
<br />
The mapping of particular command suffixes (a, x, etc.) and current bodyfont size to effective font size can<br />
be changed by {{cmd|definebodyfontenvironment}}. The default values defined in [[source:font-ini.mkiv|font-ini]] are:<br />
<texcode><br />
\definebodyfontenvironment<br />
[\s!default]<br />
[ \s!text=1.0,<br />
\s!script=0.7,<br />
\s!scriptscript=0.5,<br />
\c!a=1.200,<br />
\c!b=1.440,<br />
\c!c=1.728,<br />
\c!d=2.074,<br />
*=\currentfontscale, % wildcard<br />
\c!x=0.8,<br />
\c!xx=0.6,<br />
\c!big=1.2,<br />
\c!small=0.8,<br />
\c!interlinespace=,<br />
\c!em=\v!slanted]<br />
</texcode><br />
'''N.B.''': <code>script</code> and <code>scriptsize</code> are used in math mode.<br />
<br />
It is also possible to set the scaling factors for specific font sizes. For example, if you want {{cmd|tfa}} to set the effective font size to 12pt when the bodyfont size is 10pt, and to set the effective font size to <br />
14pt when the bodyfont size is 11pt, then add<br />
<texcode><br />
\definebodyfontenvironment [10pt] [a=12pt]<br />
\definebodyfontenvironment [11pt] [a=14pt]<br />
</texcode><br />
<br />
'''Note:''' When the first parameter is <code>default</code>, the scaling factors ''must'' have numerical values. When the first parameter is a font size (e.g., <code>12pt</code>), the scaling factors can either be numerical value or a dimension. <br />
<br />
{{cmd|definebodyfontenvironment}} is described in detail in <br />
the ConTeXt manual and the [[source:font-ini.mkiv|font-ini]] source file.<br />
<br />
Font size can be combined with font styles. As a shortcut, you can use<br />
{{cmd|bfa}} to get bold font scaled by <code>1.2</code>, {{cmd|bfx}} to get a bold font<br />
scaled by <code>0.8</code> and similar commands for other font styles.<br />
<br />
These quick font switches are meant for changing the font style, alternative, or size of a few<br />
words: they do not change the bodyfont, so they don't affect interline spacing or math font sizes. So, if<br />
you want to change the font size of an entire paragraph, use<br />
{{cmd|switchtobodyfont}} described below in [[Font_Switching#Complete_font_change|Complete Font Change]]. <br />
<br />
These caveats also hold when the font switches are used as style directives for <code>[[Style_and_Color_Parameters|style=]]...</code> in any setup command that accepts <code>style</code> option. For example, if you are defining a block quote environment that uses a smaller font size, instead of <br />
<br />
<texcode><br />
\definedelimitedtext[extract][style=\tfx]<br />
</texcode><br />
<br />
you should use<br />
<br />
<texcode><br />
\definedelimitedtext[extract][style=\tfx\setupinterlinespace]<br />
</texcode><br />
<br />
Note however that <code>\setupinterlinespace</code> is added automatically for section heads, so <br />
<br />
<texcode><br />
\setuphead[section][style=\bfa]<br />
</texcode><br />
<br />
works correctly. <br />
<br />
<br />
== Mnemonic font switches ==<br />
<br />
While learning a document markup language like ConTeXt, it can be hard to<br />
remember all the commands. ConTeXt provides other, easy-to-remember font<br />
switches. So for bold you can use {{cmd|bold}}, for italic you can use<br />
{{cmd|italic}}, for slanted you can use {{cmd|slanted}}, and so on. You can<br />
probably guess what the following do:<br />
<br />
{|<br />
| {{cmd|normal}} <br />
| {{cmd|slanted}}<br />
|-<br />
| {{cmd|boldslanted}}<br />
| {{cmd|slantedbold}}<br />
|-<br />
| {{cmd|bolditalic}}<br />
| {{cmd|italicbold}}<br />
|-<br />
| {{cmd|small}}<br />
| {{cmd|smallnormal}}<br />
|-<br />
| {{cmd|smallbold}}<br />
| {{cmd|smallslanted}}<br />
|-<br />
| {{cmd|smallboldslanted}}<br />
| {{cmd|smallslantedbold}}<br />
|-<br />
| {{cmd|smallbolditalic}}<br />
| {{cmd|smallitalicbold}}<br />
|-<br />
| {{cmd|sans}}<br />
| {{cmd|sansserif}}<br />
|-<br />
| {{cmd|sansbold}}<br />
| {{cmd|smallcaps}} <br />
|}<br />
<br />
In addition, the commands {{cmd|smallbodyfont}} and<br />
{{cmd|bigbodyfont}} can be used to change the font size. The relative size depends on the value of <code>big</code> and <code>small</code> in {{cmd|definebodyfontenvironment}}.<br />
<br />
These mnemonic font switches are pretty smart. You can either use them as<br />
font style switches inside a { ''group'' }, or as a font changing command that takes an<br />
argument. For example,<br />
<br />
<context source="yes"><br />
This is {\bold bold} and so is \bold{this}. But this is not.<br />
</context><br />
<br />
These mnemonic font switches can also be used for all <code>style=...</code><br />
options, and while using them as style options, you can just give the command<br />
name without the backslash. For example:<br />
<texcode><br />
\setuphead[section][style=bold] <br />
</texcode><br />
<br />
(<code>\boldface</code> shown above is also defined to parallel the<br />
<code>\typeface</code> and <code>\swapface</code> switches.)<br />
<br />
== Capitalizing words ==<br />
<br />
* Note that {{cmd|WORD}}, {{cmd|Word}} and all following macros aren't ''switches'', but ''commands'' (brackets behind, not around): <tt>{</tt>{{cmd|em}} <tt>switch}</tt>, vs {{cmd|Word}}<tt>{macro}</tt>.<br />
<br />
== Underline, strike through, and overline ==<br />
<br />
* Underlined, struck, and overlined text can be achieved with {{cmd|overbar}} , {{cmd|overbars}}, {{cmd|overstrike}}, {{cmd|overstrikes}}, {{cmd|underbar}}, and {{cmd|underbars}}.<br />
<br />
The canonical way is <code>\overstrike{text}</code>. However, it you're using mycrotypography with <code>\setupalign[hz,hanging]</code> expect the rule to be placed over the character (with the Latin Modern fonts you should not have this problem, experienced with Linux Libertine and mkiv). This is not what is expected. The workaround is to put the overstriked text in a <code>\inframed[frame=off]{}</code>. <br />
<br />
E.g.<br />
<texcode><br />
bla bla bla \inframed[frame=off]{\overstrike{striked}} bla bla<br />
</texcode><br />
<br />
<context><br />
bla bla bla \inframed[frame=off]{\overstrike{striked}} bla bla<br />
</context><br />
<br />
Disabling mycrotypography also works, but probably not desiderable. <br />
<pre><br />
\setupalign[nothanging,nohz]<br />
\strikeout{text}<br />
\setupalign[hanging,hz]<br />
</pre><br />
<br />
== Complete font (bodyfont) change ==<br />
<br />
If you need to change to a different font size and take care of interline<br />
spacing, you can change the bodyfont by using {{cmd|switchtobodyfont}}. For example, to switch to 12pt<br />
you can use <code>\switchtobodyfont[12pt]</code>.<br />
<br />
<br />
ConTeXt provides two relative sizes, called ''big'' and ''small''. So, to increase the bodyfont size, use <code>\switchtobodyfont[big]</code> (or <code>\setbigbodyfont</code>), and to decrease the bodyfont size, use <code>\switchtobodyfont[small]</code> (or <code>\setsmallbodyfont</code>). The exact<br />
size used for big and small can be set using <br />
{{cmd|definebodyfontenvironment}}.<br />
<br />
The {{cmd|setupbodyfont}} command accepts all the same arguments as<br />
{{cmd|switchtobodyfont}}. The difference between the two is that<br />
{{cmd|setupbodyfont}} also changes the font for headers, footers and other<br />
page markings, while {{cmd|switchtobodyfont}} does not. So you should use<br />
{{cmd|setupbodyfont}} for global font definitions to apply to the whole document, and<br />
{{cmd|switchtobodyfont}} for local font changes (i.e. changes to the running text only). The effect of<br />
{{cmd|switchtobodyfont}} can be localized within a group as usual.<br />
<br />
== Switching typefaces ==<br />
<br />
So far we have discussed style and size changes within a given typeface<br />
family. If you want to use a different typeface altogether, such as Times or<br />
Palatino, use `\switchtobodyfont[times]` or `\switchtobodyfont[palatino]`. Here `times` and `palatino` refer to the name of the typescript definitions for the font. ConTeXt distribution comes with some pre-defined typescripts; if you want to switch to another font, you need to define your own typescript. For details, see [[Fonts | the page on fonts]].<br />
<br />
== From font-var.mkvi [https://source.contextgarden.net/tex/context/base/mkiv/font-var.mkvi?search=fontface#l49] ==<br />
<br />
<context source=yes><br />
% fontclass % modern dejavu<br />
% fontbody % ... 10pt 11pt 12pt ...<br />
% fontstyle % rm ss tt mm hw cg ...<br />
% fontalternative % tf bf sl it bs bi sc ...<br />
% fontsize % a b c d ...<br />
% fontface % 0=normal 1=text 2=script 3=scriptscript 4=x 5=xx (math are temporary)<br />
<br />
class: \fontclass<br />
<br />
body : \fontbody<br />
<br />
style: \fontstyle<br />
<br />
alternative: \fontalternative<br />
<br />
size: \fontsize<br />
<br />
face: \fontface<br />
<br />
</context><br />
<br />
<br />
[[Category:Fonts]]</div>Willihttps://wiki.contextgarden.net/index.php?title=Command/showinjector&diff=30831Command/showinjector2020-08-21T13:54:52Z<p>Willi: </p>
<hr />
<div><?xml version='1.0'?><br />
<!-- this file was generated on 2020-08-20T09:05 --><br />
<cd:commandgroup name="showinjector" xmlns:cd="http://wiki.contextgarden.net/commanddoc/20200807"><br />
<cd:shortdesc><br />
<!-- a short command summary goes here --><br />
The command <tt>\showinjector</tt> is used for showing the number of the entry to lists.<br />
</cd:shortdesc><br />
<cd:variants><br />
<cd:command file="typo-inj.mkiv" interfacedate="2020-06-19T13:41" interfacefile="i-injector.xml" level="document" name="showinjector" variantnumber="1"><br />
<cd:arguments><br />
<cd:keywords list="yes" optional="yes" ordinal="1"><br />
<cd:keywordsdoc></cd:keywordsdoc><br />
<cd:constant type="cd:name">list, register</cd:constant><br />
</cd:keywords><br />
</cd:arguments><br />
</cd:command><br />
</cd:variants><br />
<cd:description><br />
<!-- the long description of the command goes here --><br />
At the end of the development of a document it can happen, dat a pagebreak does occur in an unwanted moment or one needs to insert whitespace at a specific point in the typeset list. In order to know the number of the entry one can issue <tt>\showinjector</tt> and compile the document. The result will be, that for each entry in the list the respective number of the entry will be printed in the left margin.<br />
</cd:description><br />
<cd:examples><br />
<!-- command example(s)<br />
<cd:example title=""><br />
</cd:example><br />
--><br />
</cd:examples><br />
<cd:notes><br />
<!-- this is for special remarks that do not fit elsewhere, like discovered bugs in specific context versions<br />
<cd:note author="..." date="..."><br />
</cd:note><br />
--><br />
</cd:notes><br />
<cd:seealso><br />
<!-- one or more of these:--><br />
<cd:commandref name="setinjector"></cd:commandref><br />
<!--<br />
<cd:wikipage page="xx"></cd:wikipage><br />
<cd:url url="https://xx"></cd:url><br />
<cd:manual pdf="xx"></cd:manual><br />
<cd:source file="xx"></cd:source><br />
--><br />
<cd:source file="typo-inj.mkiv" originator="system"></cd:source> <br />
</cd:seealso><br />
</cd:commandgroup></div>Willihttps://wiki.contextgarden.net/index.php?title=Command/showinjector&diff=30828Command/showinjector2020-08-21T13:53:11Z<p>Willi: </p>
<hr />
<div><?xml version='1.0'?><br />
<!-- this file was generated on 2020-08-20T09:05 --><br />
<cd:commandgroup name="showinjector" xmlns:cd="http://wiki.contextgarden.net/commanddoc/20200807"><br />
<cd:shortdesc><br />
<!-- a short command summary goes here --><br />
The command <tt>\showinjector</tt> is used for showing the number of the entry to lists.<br />
</cd:shortdesc><br />
<cd:variants><br />
<cd:command file="typo-inj.mkiv" interfacedate="2020-06-19T13:41" interfacefile="i-injector.xml" level="document" name="showinjector" variantnumber="1"><br />
<cd:arguments><br />
<cd:keywords list="yes" optional="yes" ordinal="1"><br />
<cd:keywordsdoc></cd:keywordsdoc><br />
<cd:constant type="cd:name">list, register</cd:constant><br />
</cd:keywords><br />
</cd:arguments><br />
</cd:command><br />
</cd:variants><br />
<cd:description><br />
<!-- the long description of the command goes here --><br />
At the end of the development of a document it can happen, dat a pagebreak does occur in an unwanted moment or one needs to insert whitespace at a specific point in the typeset list. In order to know the number of the entry one can issue <tt>\showinjector</tt> and compile the document. The result will be, that for each entry in the list the respective number of the entry will be printed in the left margin.<br />
</cd:description><br />
<cd:examples><br />
<!-- command example(s)<br />
<cd:example title=""><br />
</cd:example><br />
--><br />
</cd:examples><br />
<cd:notes><br />
<!-- this is for special remarks that do not fit elsewhere, like discovered bugs in specific context versions<br />
<cd:note author="..." date="..."><br />
</cd:note><br />
--><br />
</cd:notes><br />
<cd:seealso><br />
<!-- one or more of these:--><br />
<cd:commandref name="showinjector"></cd:commandref><br />
<!--<br />
<cd:wikipage page="xx"></cd:wikipage><br />
<cd:url url="https://xx"></cd:url><br />
<cd:manual pdf="xx"></cd:manual><br />
<cd:source file="xx"></cd:source><br />
--><br />
<cd:source file="typo-inj.mkiv" originator="system"></cd:source> <br />
</cd:seealso><br />
</cd:commandgroup></div>Willihttps://wiki.contextgarden.net/index.php?title=Command/showinjector&diff=30825Command/showinjector2020-08-21T13:52:07Z<p>Willi: Created page with "Documentation for \showinjector"</p>
<hr />
<div><?xml version='1.0'?><br />
<!-- this file was generated on 2020-08-20T09:05 --><br />
<cd:commandgroup name="showinjector" xmlns:cd="http://wiki.contextgarden.net/commanddoc/20200807"><br />
<cd:shortdesc><br />
<!-- a short command summary goes here --><br />
The command <tt>\showinjector</tt> is used for showing the number of the entry to lists.<br />
</cd:shortdesc><br />
<cd:variants><br />
<cd:command file="typo-inj.mkiv" interfacedate="2020-06-19T13:41" interfacefile="i-injector.xml" level="document" name="showinjector" variantnumber="1"><br />
<cd:arguments><br />
<cd:keywords list="yes" optional="yes" ordinal="1"><br />
<cd:keywordsdoc></cd:keywordsdoc><br />
<cd:constant type="cd:name"></cd:constant><br />
</cd:keywords><br />
</cd:arguments><br />
</cd:command><br />
</cd:variants><br />
<cd:description><br />
<!-- the long description of the command goes here --><br />
At the end of the development of a document it can happen, dat a pagebreak does occur in an unwanted moment or one needs to insert whitespace at a specific point in the typeset list. In order to know the number of the entry one can issue <tt>\showinjector</tt> and compile the document. The result will be, that for each entry in the list the respective number of the entry will be printed in the left margin.<br />
</cd:description><br />
<cd:examples><br />
<!-- command example(s)<br />
<cd:example title=""><br />
</cd:example><br />
--><br />
</cd:examples><br />
<cd:notes><br />
<!-- this is for special remarks that do not fit elsewhere, like discovered bugs in specific context versions<br />
<cd:note author="..." date="..."><br />
</cd:note><br />
--><br />
</cd:notes><br />
<cd:seealso><br />
<!-- one or more of these:--><br />
<cd:commandref name="showinjector"></cd:commandref><br />
<!--<br />
<cd:wikipage page="xx"></cd:wikipage><br />
<cd:url url="https://xx"></cd:url><br />
<cd:manual pdf="xx"></cd:manual><br />
<cd:source file="xx"></cd:source><br />
--><br />
<cd:source file="typo-inj.mkiv" originator="system"></cd:source> <br />
</cd:seealso><br />
</cd:commandgroup></div>Willihttps://wiki.contextgarden.net/index.php?title=Command/setinjector&diff=30815Command/setinjector2020-08-21T13:44:00Z<p>Willi: </p>
<hr />
<div><?xml version='1.0'?><br />
<!-- this file was generated on 2020-08-20T09:05 --><br />
<cd:commandgroup name="setinjector" xmlns:cd="http://wiki.contextgarden.net/commanddoc/20200807"><br />
<cd:shortdesc><br />
<!-- a short command summary goes here --><br />
The command <tt>\setinjector</tt> is used for injecting actions on a TOC or register during the final stage of a document production: empty lines, page breaks etc.<br />
</cd:shortdesc><br />
<cd:variants><br />
<cd:command file="typo-inj.mkiv" interfacedate="2020-06-19T13:41" interfacefile="i-injector.xml" level="document" name="setinjector" variantnumber="1"><br />
<cd:arguments><br />
<cd:keywords ordinal="1"><br />
<cd:keywordsdoc></cd:keywordsdoc><br />
<cd:constant type="cd:name">list,register</cd:constant><br />
</cd:keywords><br />
<cd:keywords list="yes" ordinal="2"><br />
<cd:keywordsdoc></cd:keywordsdoc><br />
<cd:constant type="cd:number">entry number where the action must take place</cd:constant><br />
</cd:keywords><br />
<cd:keywords ordinal="3"><br />
<cd:keywordsdoc></cd:keywordsdoc><br />
<cd:constant type="cd:command">\blank, \page</cd:constant><br />
</cd:keywords><br />
</cd:arguments><br />
</cd:command><br />
</cd:variants><br />
<cd:description><br />
<!-- the long description of the command goes here --><br />
The command is only used in the final stage of the deocument development. It is providing a possibility to tweak the automatically assembled list.<br />
<br />
The command <tt>\setinjector</tt> has three arguments. It works on automatically generated lists e.g. TOC, registers.<br />
The first argument gives the name of the list to which the injector applies.<br />
The second argument is a number denoting the number of the section to which the third argument applies. All section numbers are sequentially numbered throughout all section levels.<br />
The third argument contains a command which is injected at the point given in the second argument.<br />
<br />
Before setting up <tt>\setinjector</tt> one needs to run the document with <tt>\showinjector</tt> enabled. This command will show the number of the different entries in the different lists in the left margin.<br />
<br />
This mechanism allows the user to tweak the list e.g. when a page break must occur after a certain entry or one needs to insert white space after an entry.<br />
One needs to be aware of the fact, that the mechanism only works when no <tt>\setuplist[name][alternative=command,command=...]</tt> is used for the respective list.<br />
</cd:description><br />
<cd:examples><br />
<!-- command example(s) --><br />
<cd:example title=""><br />
<texcode>\setinjector[list][10][\page]</texcode><br />
</cd:example><br />
<cd:example title=""><br />
<texcode>\setinjector[list][1][{\blank[6*big]}]</texcode><br />
</cd:example><br />
<cd:example title=""><br />
<texcode>\setinjector[register][3][\column]</texcode><br />
</cd:example><br />
<!--><br />
</cd:examples><br />
<cd:notes><br />
<!-- this is for special remarks that do not fit elsewhere, like discovered bugs in specific context versions<br />
<cd:note author="..." date="..."><br />
</cd:note><br />
--><br />
</cd:notes><br />
<cd:seealso><br />
<!-- one or more of these:--><br />
<cd:commandref name="showinjector"></cd:commandref><br />
<!--<br />
<cd:wikipage page="xx"></cd:wikipage><br />
<cd:url url="https://xx"></cd:url><br />
<cd:manual pdf="xx"></cd:manual><br />
<cd:source file="xx"></cd:source><br />
--><br />
<cd:source file="typo-inj.mkiv" originator="system"></cd:source> <br />
</cd:seealso><br />
</cd:commandgroup></div>Willihttps://wiki.contextgarden.net/index.php?title=Command/setinjector&diff=30749Command/setinjector2020-08-21T11:39:43Z<p>Willi: </p>
<hr />
<div><?xml version='1.0'?><br />
<!-- this file was generated on 2020-08-20T09:05 --><br />
<cd:commandgroup name="setinjector" xmlns:cd="http://wiki.contextgarden.net/commanddoc/20200807"><br />
<cd:shortdesc><br />
<!-- a short command summary goes here --><br />
The command <tt>\setinjector</tt> is used for injecting actions on a TOC or register during the final stage of a document production: empty lines, page breaks etc.<br />
</cd:shortdesc><br />
<cd:variants><br />
<cd:command file="typo-inj.mkiv" interfacedate="2020-06-19T13:41" interfacefile="i-injector.xml" level="document" name="setinjector" variantnumber="1"><br />
<cd:arguments><br />
<cd:keywords ordinal="1"><br />
<cd:keywordsdoc></cd:keywordsdoc><br />
<cd:constant type="cd:name">list,register</cd:constant><br />
</cd:keywords><br />
<cd:keywords list="yes" ordinal="2"><br />
<cd:keywordsdoc></cd:keywordsdoc><br />
<cd:constant type="cd:number">entry number where the action must take place</cd:constant><br />
</cd:keywords><br />
<cd:keywords ordinal="3"><br />
<cd:keywordsdoc></cd:keywordsdoc><br />
<cd:constant type="cd:command">\blank, \page</cd:constant><br />
</cd:keywords><br />
</cd:arguments><br />
</cd:command><br />
</cd:variants><br />
<cd:description><br />
<!-- the long description of the command goes here --><br />
The command is only used in the final stage of the deocument development. It is providing a possibility to tweak the automatically assembled list.<br />
<br />
The command <tt>\setinjector</tt> has three arguments. It works on automatically generated lists e.g. TOC, registers.<br />
The first argument gives the name of the list to which the injector applies.<br />
The second argument is a number denoting the number of the section to which the third argument applies. All section numbers are sequentially numbered throughout all section levels.<br />
The third argument contains a command which is injected at the point given in the second argument.<br />
<br />
Before setting up <tt>\setinjector</tt> one needs to run the document with <tt>\showinjector</tt> enabled. This command will show the number of the different entries in the different lists in the left margin.<br />
<br />
This mechanism allows the user to tweak the list e.g. when a page break must occur after a certain entry or one needs to insert white space after an entry.<br />
One needs to be aware of the fact, that the mechanism only works when no <tt>\setuplist[name][alternative=command,command=...]</tt> is used for the respective list.<br />
</cd:description><br />
<cd:examples><br />
<!-- command example(s) --><br />
<cd:example title="Example"><br />
\setinjector[list][10][\page]<br />
</cd:example><br />
<cd:example title="Example"><br />
\setinjector[list] [1][{\blank[6*big]}]<br />
</cd:example><br />
<cd:example title="Example"><br />
\setinjector[register][3][\column]<br />
</cd:example><br />
<!--><br />
</cd:examples><br />
<cd:notes><br />
<!-- this is for special remarks that do not fit elsewhere, like discovered bugs in specific context versions<br />
<cd:note author="..." date="..."><br />
</cd:note><br />
--><br />
</cd:notes><br />
<cd:seealso><br />
<!-- one or more of these:--><br />
<cd:commandref name="showinjector"></cd:commandref><br />
<!--<br />
<cd:wikipage page="xx"></cd:wikipage><br />
<cd:url url="https://xx"></cd:url><br />
<cd:manual pdf="xx"></cd:manual><br />
<cd:source file="xx"></cd:source><br />
--><br />
<cd:source file="typo-inj.mkiv" originator="system"></cd:source> <br />
</cd:seealso><br />
</cd:commandgroup></div>Willihttps://wiki.contextgarden.net/index.php?title=Command/setinjector&diff=30747Command/setinjector2020-08-21T11:36:34Z<p>Willi: Created page with "Documentation for \setinjector"</p>
<hr />
<div><?xml version='1.0'?><br />
<!-- this file was generated on 2020-08-20T09:05 --><br />
<cd:commandgroup name="setinjector" xmlns:cd="http://wiki.contextgarden.net/commanddoc/20200807"><br />
<cd:shortdesc><br />
<!-- a short command summary goes here --><br />
The command <tt>\setinjector</tt> is used for injecting actions on a TOC or register during the final stage of a document production: empty lines, page breaks etc.<br />
</cd:shortdesc><br />
<cd:variants><br />
<cd:command file="typo-inj.mkiv" interfacedate="2020-06-19T13:41" interfacefile="i-injector.xml" level="document" name="setinjector" variantnumber="1"><br />
<cd:arguments><br />
<cd:keywords ordinal="1"><br />
<cd:keywordsdoc></cd:keywordsdoc><br />
<cd:constant type="cd:name">list,register</cd:constant><br />
</cd:keywords><br />
<cd:keywords list="yes" ordinal="2"><br />
<cd:keywordsdoc></cd:keywordsdoc><br />
<cd:constant type="cd:number">entry number where the action must take place</cd:constant><br />
</cd:keywords><br />
<cd:keywords ordinal="3"><br />
<cd:keywordsdoc></cd:keywordsdoc><br />
<cd:constant type="cd:command">\blank, \page</cd:constant><br />
</cd:keywords><br />
</cd:arguments><br />
</cd:command><br />
</cd:variants><br />
<cd:description><br />
<!-- the long description of the command goes here --><br />
The command is only used in the final stage of the deocument development. It is providing a possibility to tweak the automatically assembled list.<br />
<br />
The command <tt>\setinjector</tt> has three arguments. It works on automatically generated lists e.g. TOC, registers.<br />
The first argument gives the name of the list to which the injector applies.<br />
The second argument is a number denoting the number of the section to which the third argument applies. All section numbers are sequentially numbered throughout all section levels.<br />
The third argument contains a command which is injected at the point given in the second argument.<br />
<br />
Before setting up <tt>\setinjector</tt> one needs to run the document with <tt>\showinjector</tt> enabled. This command will show the number of the different entries in the different lists in the left margin.<br />
<br />
This mechanism allows the user to tweak the list e.g. when a page break must occur after a certain entry or one needs to insert white space after an entry.<br />
One needs to be aware of the fact, that the mechanism only works when no <tt>\setuplist[][alternative=command,command=...]</tt> is used for the respective list.<br />
</cd:description><br />
<cd:examples><br />
<!-- command example(s) --><br />
<cd:example title="Example"><br />
\setinjector[list][10][\page]<br />
</cd:example><br />
<cd:example title="Example"><br />
\setinjector[list] [1][{\blank[6*big]}]<br />
</cd:example><br />
<cd:example title="Example"><br />
\setinjector[register][3][\column]<br />
</cd:example><br />
<!--><br />
</cd:examples><br />
<cd:notes><br />
<!-- this is for special remarks that do not fit elsewhere, like discovered bugs in specific context versions<br />
<cd:note author="..." date="..."><br />
</cd:note><br />
--><br />
</cd:notes><br />
<cd:seealso><br />
<!-- one or more of these:--><br />
<cd:commandref name="showinjector"></cd:commandref><br />
<!--<br />
<cd:wikipage page="xx"></cd:wikipage><br />
<cd:url url="https://xx"></cd:url><br />
<cd:manual pdf="xx"></cd:manual><br />
<cd:source file="xx"></cd:source><br />
--><br />
<cd:source file="typo-inj.mkiv" originator="system"></cd:source> <br />
</cd:seealso><br />
</cd:commandgroup></div>Willihttps://wiki.contextgarden.net/index.php?title=References&diff=24282References2019-08-18T21:10:36Z<p>Willi: /* References to an external file */</p>
<hr />
<div>< [[Structurals]] | [[Bibliography]] ><br />
<br />
==General Use==<br />
If you want to refer to any text element, you must first define the target's reference label. All titling commands and a lot of others take one as optional parameter, e.g.<br />
<texcode><br />
\chapter[preface]{Dear Reader}<br />
</texcode><br />
Then you can refer to this spot with<br />
<texcode><br />
As I told you in \in{chapter}[preface] on \at{page}[preface], I really like ConTeXt...<br />
</texcode><br />
That will typeset the text in braces and add the number of the refered element, e.g. "chapter 1 on page 1".<br />
<br />
To define a reference label anywhere you can also use {{cmd|pagereference|[reference]}} and {{cmd|textreference|[reference]{text}}}. Everwhere where you can define one label, you can also define more at once, if you separate them with commas. It's also possible to use "namespaces" like <code>[fig:cow]</code>.<br />
<br />
If you activated interaction, references become links automatically.<br />
<br />
Starting with ConTeXt 2012.06.22, there is a third command: {{cmd|contentreference|[reference][framedsettings]{text}}} which wraps the <code>text</code> argument inside a {{cmd|framed}}. The main difference with {{cmd|textreference}} where the <code>text</code> contains a {{cmd|framed}} itself is that, when interaction is enabled, {{cmd|contentreference}} places the top left of the target area at the top left of the framed box whereas {{cmd|textreference}} uses its baseline.<br />
<br />
===Example===<br />
<texcode><br />
\chapter[preface]{Dear Reader}<br />
<br />
\pagereference[zapfquote]\input zapf<br />
<br />
\dots<br />
<br />
As I have told you in \in{chapter}[preface] on \at{page}[preface], I really like \ConTeXt.<br />
And Mr.\,Zapf (see \at{page}[zapfquote]) at least likes \TeX\ in general.<br />
</texcode><br />
<context><br />
\chapter[preface]{Dear Reader}<br />
<br />
\pagereference[zapfquote]\input zapf<br />
<br />
\dots<br />
<br />
As I have told you in \in{chapter}[preface] on \at{page}[preface], I really like \ConTeXt. And Mr.\,Zapf (see \at{page}[zapfquote]) at least likes \TeX\ in general.<br />
</context><br />
<br />
== Different layouts for different kinds of references ==<br />
<br />
If you want less typing to get special formatting for the references to sections, equations, ... here's Aditya's recipe to do it.<br />
<br />
Suppose that you want to get<br />
:See ''equation (2.3)'' or ''section 4.2''.<br />
where the slanted content is typeset automatically. You first need to define the formatting with {{cmd|definereferenceformat}}:<br />
<texcode><br />
\definereferenceformat[insec][text=section]<br />
\definereferenceformat[ineq] [left=(,right=),text=equation]<br />
</texcode><br />
Then you can simply type<br />
<texcode><br />
See \ineq[eq:some equation] or \insec[sec:some section].<br />
</texcode><br />
<br />
A more automated solution uses the following macro:<br />
<br />
<texcode><br />
\def\myin[#1:#2]{%<br />
\expandafter\ifx\csname in#1\endcsname\relax<br />
\writestatus{warning}{referenceformat in#1 not defined}%<br />
\in[#1:#2]%<br />
\else<br />
\csname in#1\endcsname[#1:#2]%<br />
\fi}<br />
</texcode><br />
<br />
and requires you to write the following code:<br />
<br />
<texcode><br />
See \myin[eq:some equation] or \myin[sec:some section].<br />
</texcode><br />
<br />
{{todo|complete example would be better}}<br />
<br />
<br />
==Adjusting the level of referenced prefixes==<br />
<br />
When the default chapter and section prefixes are used, the chapters are<br />
prefixed by a number, so are the sections. When referring to a section using<br />
the command {{cmd|in|{section}[sec:foo]}} the chapter number is prefixed<br />
following by a dot and the according section number.<br />
<br />
However, some styles do not show the chapter prefix while displaying the<br />
sections. In this case the referencing commands, like {{cmd|in}} just output the<br />
section number, which is of course ambiguous.<br />
<br />
To fix this problem, the command {{cmd|setupreferencestructureprefix}} can be<br />
incorporated to adjust the prefixes displayed by the referencing commands.<br />
<br />
===Example===<br />
<br />
Given that {{cmd|start}}/{{cmd|stopchapter}} output <code>Romannumerals</code> prefixes (<tt>I,<br />
II, III, …</tt>) and {{cmd|start}}/{{cmd|stopsection}} output <code>Character</code> prefixes (<tt>A,B, C, …</tt>), the following commands give the results provided in the comments.<br />
<br />
<texcode><br />
\setupreferencestructureprefix [default] [prefixsegments=2:2] % nothing<br />
\setupreferencestructureprefix [default] [prefixsegments=2:3] % I<br />
\setupreferencestructureprefix [default] [prefixsegments=2:4] % I.A<br />
<br />
\setupreferencestructureprefix [default] [prefixsegments=3:4] % I.A<br />
\setupreferencestructureprefix [default] [prefixsegments=4:4] % A<br />
\setupreferencestructureprefix [default] [prefixsegments=5:4] % nothing<br />
</texcode><br />
<br />
<br />
==Adjusting the separator in between the referenced prefixes==<br />
<br />
To adjust the separator between the different structure<br />
levels in the referencing commands, like {{cmd|in}}, the command<br />
{{cmd|definestructureseparatorset}} is used.<br />
<br />
===Example===<br />
<br />
To change the separator between chapter and section from a dot to a hyphen use<br />
{{cmd|definestructureseparatorset}} as follows.<br />
<br />
<texcode><br />
\definestructureseparatorset [default] [,,-]<br />
</texcode><br />
<br />
==Putting a separator in the heading but not the reference==<br />
<br />
Sometimes you want to have a separator in the heading but not the reference. For example, you want section heading to look like "3. This is a new section" (with a dot after the section number), but references to the section should not have the dot (they should be like "In section 3 we found..."). Wolfgang Schuster gave a solution (for MkIV) [http://www.ntg.nl/pipermail/ntg-context/2013/072650.html on the list]:<br />
<br />
<texcode><br />
\defineprocessor[dostopper][right=.]<br />
\defineprocessor[nostopper][right=]<br />
<br />
\defineconversionset[stopperconversionyes][][dostopper->n]<br />
\defineconversionset[stopperconversionnop][][nostopper->n]<br />
<br />
\setuphead[chapter][sectionconversionset=stopperconversionyes]<br />
<br />
%\setupreferencestructureprefix[chapter][default][prefixconversionset=stopperconversionnop]<br />
\setupreferencestructureprefix[default][prefixconversionset=stopperconversionnop]<br />
<br />
\starttext<br />
<br />
\chapter[one]{First heading}<br />
<br />
\input knuth<br />
<br />
In \in{Chapter}[one] we learn.<br />
<br />
\stoptext<br />
<br />
</texcode><br />
<br />
==References to an external file==<br />
<br />
You can refer to referenced elements in an external file. MkIV requires for this the presence of the '''tuc-file''' of the referenced file. ConTeXt will catch the information to be included from this file.<br />
<br />
===Example===<br />
External files: hasseltbook.tex/pdf/'''tuc'''<br />
<br />
The contents of hasseltbook.tex could be:<br />
<br />
<texcode><br />
\starttext<br />
<br />
\startstandardmakeup<br />
\midaligned{\tfd Festivities in Hasselt}<br />
\stopstandardmakeup<br />
<br />
\startchapter[title=Euifeest,reference=euifeest]<br />
Something about the Euifeest.\index{Euifeest}<br />
\stopchapter<br />
<br />
\stoptext<br />
</texcode><br />
<br />
In your document you can say:<br />
<br />
<texcode><br />
\setupinteraction<br />
[state=start]<br />
<br />
\useexternaldocument<br />
[hia][hasseltbook][Festivities in Hasselt]<br />
<br />
\setupinteraction<br />
[state=start,<br />
color=green,<br />
style=bold]<br />
<br />
\starttext<br />
Most tourist attractions are described in \from[hia].\crlf<br />
A description of the \about[hia::euifeest] is found in \from[hia].\crlf<br />
The eui||feest is described on \at{page}[hia::euifeest] in \from[hia].\crlf<br />
See for more information \in{chapter}[hia::euifeest] in \from[hia].<br />
\stoptext<br />
</texcode><br />
<br />
Note how the link is established to the externalfile: <br />
<texcode>\command[symbolic-name::reference]</texcode><br />
<br />
==Related Modules==<br />
<br />
* [[Cross Referencing]]: Cross references in a (academic) text are either internal (linking to an other point inside the same document) or external (linking to a entity of the bibliography that points to a different document). <br />
* [[Paragraph Referencing]]: The pararef module understands a paragraph as a full closed block of one thought.<br />
<br />
{{todo|Describe what the arguments of the commands do and how the commands work}}<br />
<br />
{{Getting started navbox}}</div>Willihttps://wiki.contextgarden.net/index.php?title=References&diff=24281References2019-08-18T21:05:25Z<p>Willi: referring to elements in an external file</p>
<hr />
<div>< [[Structurals]] | [[Bibliography]] ><br />
<br />
==General Use==<br />
If you want to refer to any text element, you must first define the target's reference label. All titling commands and a lot of others take one as optional parameter, e.g.<br />
<texcode><br />
\chapter[preface]{Dear Reader}<br />
</texcode><br />
Then you can refer to this spot with<br />
<texcode><br />
As I told you in \in{chapter}[preface] on \at{page}[preface], I really like ConTeXt...<br />
</texcode><br />
That will typeset the text in braces and add the number of the refered element, e.g. "chapter 1 on page 1".<br />
<br />
To define a reference label anywhere you can also use {{cmd|pagereference|[reference]}} and {{cmd|textreference|[reference]{text}}}. Everwhere where you can define one label, you can also define more at once, if you separate them with commas. It's also possible to use "namespaces" like <code>[fig:cow]</code>.<br />
<br />
If you activated interaction, references become links automatically.<br />
<br />
Starting with ConTeXt 2012.06.22, there is a third command: {{cmd|contentreference|[reference][framedsettings]{text}}} which wraps the <code>text</code> argument inside a {{cmd|framed}}. The main difference with {{cmd|textreference}} where the <code>text</code> contains a {{cmd|framed}} itself is that, when interaction is enabled, {{cmd|contentreference}} places the top left of the target area at the top left of the framed box whereas {{cmd|textreference}} uses its baseline.<br />
<br />
===Example===<br />
<texcode><br />
\chapter[preface]{Dear Reader}<br />
<br />
\pagereference[zapfquote]\input zapf<br />
<br />
\dots<br />
<br />
As I have told you in \in{chapter}[preface] on \at{page}[preface], I really like \ConTeXt.<br />
And Mr.\,Zapf (see \at{page}[zapfquote]) at least likes \TeX\ in general.<br />
</texcode><br />
<context><br />
\chapter[preface]{Dear Reader}<br />
<br />
\pagereference[zapfquote]\input zapf<br />
<br />
\dots<br />
<br />
As I have told you in \in{chapter}[preface] on \at{page}[preface], I really like \ConTeXt. And Mr.\,Zapf (see \at{page}[zapfquote]) at least likes \TeX\ in general.<br />
</context><br />
<br />
== Different layouts for different kinds of references ==<br />
<br />
If you want less typing to get special formatting for the references to sections, equations, ... here's Aditya's recipe to do it.<br />
<br />
Suppose that you want to get<br />
:See ''equation (2.3)'' or ''section 4.2''.<br />
where the slanted content is typeset automatically. You first need to define the formatting with {{cmd|definereferenceformat}}:<br />
<texcode><br />
\definereferenceformat[insec][text=section]<br />
\definereferenceformat[ineq] [left=(,right=),text=equation]<br />
</texcode><br />
Then you can simply type<br />
<texcode><br />
See \ineq[eq:some equation] or \insec[sec:some section].<br />
</texcode><br />
<br />
A more automated solution uses the following macro:<br />
<br />
<texcode><br />
\def\myin[#1:#2]{%<br />
\expandafter\ifx\csname in#1\endcsname\relax<br />
\writestatus{warning}{referenceformat in#1 not defined}%<br />
\in[#1:#2]%<br />
\else<br />
\csname in#1\endcsname[#1:#2]%<br />
\fi}<br />
</texcode><br />
<br />
and requires you to write the following code:<br />
<br />
<texcode><br />
See \myin[eq:some equation] or \myin[sec:some section].<br />
</texcode><br />
<br />
{{todo|complete example would be better}}<br />
<br />
<br />
==Adjusting the level of referenced prefixes==<br />
<br />
When the default chapter and section prefixes are used, the chapters are<br />
prefixed by a number, so are the sections. When referring to a section using<br />
the command {{cmd|in|{section}[sec:foo]}} the chapter number is prefixed<br />
following by a dot and the according section number.<br />
<br />
However, some styles do not show the chapter prefix while displaying the<br />
sections. In this case the referencing commands, like {{cmd|in}} just output the<br />
section number, which is of course ambiguous.<br />
<br />
To fix this problem, the command {{cmd|setupreferencestructureprefix}} can be<br />
incorporated to adjust the prefixes displayed by the referencing commands.<br />
<br />
===Example===<br />
<br />
Given that {{cmd|start}}/{{cmd|stopchapter}} output <code>Romannumerals</code> prefixes (<tt>I,<br />
II, III, …</tt>) and {{cmd|start}}/{{cmd|stopsection}} output <code>Character</code> prefixes (<tt>A,B, C, …</tt>), the following commands give the results provided in the comments.<br />
<br />
<texcode><br />
\setupreferencestructureprefix [default] [prefixsegments=2:2] % nothing<br />
\setupreferencestructureprefix [default] [prefixsegments=2:3] % I<br />
\setupreferencestructureprefix [default] [prefixsegments=2:4] % I.A<br />
<br />
\setupreferencestructureprefix [default] [prefixsegments=3:4] % I.A<br />
\setupreferencestructureprefix [default] [prefixsegments=4:4] % A<br />
\setupreferencestructureprefix [default] [prefixsegments=5:4] % nothing<br />
</texcode><br />
<br />
<br />
==Adjusting the separator in between the referenced prefixes==<br />
<br />
To adjust the separator between the different structure<br />
levels in the referencing commands, like {{cmd|in}}, the command<br />
{{cmd|definestructureseparatorset}} is used.<br />
<br />
===Example===<br />
<br />
To change the separator between chapter and section from a dot to a hyphen use<br />
{{cmd|definestructureseparatorset}} as follows.<br />
<br />
<texcode><br />
\definestructureseparatorset [default] [,,-]<br />
</texcode><br />
<br />
==Putting a separator in the heading but not the reference==<br />
<br />
Sometimes you want to have a separator in the heading but not the reference. For example, you want section heading to look like "3. This is a new section" (with a dot after the section number), but references to the section should not have the dot (they should be like "In section 3 we found..."). Wolfgang Schuster gave a solution (for MkIV) [http://www.ntg.nl/pipermail/ntg-context/2013/072650.html on the list]:<br />
<br />
<texcode><br />
\defineprocessor[dostopper][right=.]<br />
\defineprocessor[nostopper][right=]<br />
<br />
\defineconversionset[stopperconversionyes][][dostopper->n]<br />
\defineconversionset[stopperconversionnop][][nostopper->n]<br />
<br />
\setuphead[chapter][sectionconversionset=stopperconversionyes]<br />
<br />
%\setupreferencestructureprefix[chapter][default][prefixconversionset=stopperconversionnop]<br />
\setupreferencestructureprefix[default][prefixconversionset=stopperconversionnop]<br />
<br />
\starttext<br />
<br />
\chapter[one]{First heading}<br />
<br />
\input knuth<br />
<br />
In \in{Chapter}[one] we learn.<br />
<br />
\stoptext<br />
<br />
</texcode><br />
<br />
==References to an external file==<br />
<br />
You can refer to referenced elements in an external file. MKIV requires for this the presence of the '''tuc-file''' of the referenced file. ConTeXt will catch the information to be included from this file.<br />
<br />
===Example===<br />
External files: hasseltbook.tex/pdf/'''tuc'''<br />
<br />
The contents of hasseltbook.tex could be:<br />
<br />
<texcode><br />
\starttext<br />
<br />
\startstandardmakeup<br />
\midaligned{\tfd Festivities in Hasselt}<br />
\stopstandardmakeup<br />
<br />
\startchapter[title=Euifeest,reference=euifeest]<br />
Something about the Euifeest.\index{Euifeest}<br />
\stopchapter<br />
<br />
\stoptext<br />
</texcode><br />
<br />
In your document you can say:<br />
<br />
<texcode><br />
\setupinteraction<br />
[state=start]<br />
<br />
\useexternaldocument<br />
[hia][hasseltbook][Festivities in Hasselt]<br />
<br />
\setupinteraction<br />
[state=start,<br />
color=green,<br />
style=bold]<br />
<br />
\starttext<br />
Most tourist attractions are described in \from[hia].\crlf<br />
A description of the \about[hia::euifeest] is found in \from[hia].\crlf<br />
The eui||feest is described on \at{page}[hia::euifeest] in \from[hia].\crlf<br />
See for more information \in{chapter}[hia::euifeest] in \from[hia].<br />
\stoptext<br />
</texcode><br />
<br />
Note how the link is established to the externalfile: <br />
<texcode>\command[symbolic-name::reference]</texcode><br />
<br />
==Related Modules==<br />
<br />
* [[Cross Referencing]]: Cross references in a (academic) text are either internal (linking to an other point inside the same document) or external (linking to a entity of the bibliography that points to a different document). <br />
* [[Paragraph Referencing]]: The pararef module understands a paragraph as a full closed block of one thought.<br />
<br />
{{todo|Describe what the arguments of the commands do and how the commands work}}<br />
<br />
{{Getting started navbox}}</div>Willihttps://wiki.contextgarden.net/index.php?title=MetaPost&diff=22660MetaPost2014-10-15T20:04:33Z<p>Willi: Added Hans, the provider of the solution to the problem with textext...</p>
<hr />
<div>< [[Math]], [[MetaFun]], [[Graphics]]<br />
<br />
MetaPost is a graphical programming language, based on Donald Knuth's MetaFont. Normally MP graphics are converted to PostScript and used with dvips, but ConTeXt can use it directly with PDF (see the<br />
[http://www.pragma-ade.com/general/sources/mptopdf.pdf MP to PDF] manual).<br />
<br />
MetaPost is ConTeXt's native graphics language. [[MetaFun]] is a MetaPost module by Hans Hagen that adds a lot of extra features; it is enabled by default, so one could say that MetaFun is ConTeXt's default dialect of MetaPost.<br />
<br />
== Documentation & Tutorials ==<br />
* [http://www.tug.org/docs/metapost/mpman.pdf A User's Manual for MetaPost] <!-- http://cm.bell-labs.com/who/hobby/cstr_162.pdf has its pages reversed --><br />
* [http://remote.science.uva.nl/~heck/Courses/mptut.pdf Learning METAPOST by doing] ([http://maps.aanhet.net/maps/pdf/32_14.pdf this] and [http://maps.aanhet.net/maps/pdf/32_15.pdf this link] are not working)<br />
* [http://www.tug.org/pracjourn/2006-4/henderson/henderson.pdf A Beginner's Guide to METAPOST for Creating High-Quality Graphics] by Troy Henderson<br />
* [[manual:metafun-s.pdf|MetaFun]]<br />
* [http://tex.loria.fr/prod-graph/zoonekynd/metapost/metapost.html Lots of examples]<br />
* [[Color in MetaPost]] describes how to get color mixtures, TeX colors, and transparent effects in MetaPost graphics.<br />
* [http://wiki.contextgarden.net/MetaPost_in_ConTeXt MetaPost in ConTeXt]<br />
<br />
== Using MetaPost in ConTeXt ==<br />
<br />
With {{cmd|startuseMPgraphic}}, you define a piece of graphics code that is processed anew every time the graphic is placed with {{cmd|useMPgraphic}}. Further commands are described at [[MetaPost in ConTeXt]].<br />
<br />
<context source=yes><br />
\def\mycolor{.625red}<br />
<br />
\startuseMPgraphic{name}<br />
fill fullcircle scaled 20pt withcolor \mycolor;<br />
\stopuseMPgraphic<br />
<br />
red: \useMPgraphic{name}<br />
<br />
\def\mycolor{.625blue}<br />
blue: \useMPgraphic{name}<br />
</context><br />
<br />
== Different Packages, Extensions & Applications of Metapost ==<br />
* [http://www.ctan.org/tex-archive/graphics/metaplot/ MetaPlot] - graph drawing<br />
* [http://www.ctan.org/tex-archive/graphics/metapost/contrib/macros/metaobj/ MetaObj] - object-oriented drawing, see also the page about [[MetaObj and Labels]]<br />
<br />
* [http://stud4.tuwien.ac.at/~e0225855/finomaton/finomaton.html finomaton] - drawing finite state automata<br />
* [http://www-math.univ-poitiers.fr/~phan/statsmac.html statsmac] - metapost macros for statistics graphs<br />
* [http://metauml.sourceforge.net/ MetaUML] - MetaPost library for typesetting UML diagrams<br />
* [http://vigna.dsi.unimi.it/metagraph/ METAGRAPH] - drawing (un)directed graphs<br />
<br />
=== 3D support ===<br />
* [http://matagalatlante.org/nobre/featpost/doc/featexamples.html FeatPost]<br />
* [http://www.gnu.org/software/3dldf/LDF.html 3DLDF]<br />
* [http://www-math.univ-poitiers.fr/~phan/m3Dplain.html m3D]<br />
<br />
{{todo|needs major review}}<br />
<br />
== MetaPost relatives ==<br />
=== Font Creation ===<br />
* [[MetaType1]], see [http://www.ctan.org/tex-archive/fonts/utilities/metatype1/ CTAN]<br />
<br />
=== 3D drawing ===<br />
* [http://asymptote.sourceforge.net/ Asymptote] - inspired by MetaPost & fully generalizes MetaPost path construction algorithms to three-dimensions<br />
<br />
== Testing plain MetaPost ==<br />
To test whether MetaPost is installed on your system, create a file called {{code|test.mp}}:<br />
<br />
beginfig(1)<br />
draw fullcircle scaled 3cm ;<br />
endfig ;<br />
end ;<br />
<br />
* apply MetaPost on the testfile<br />
<br />
mp test.mp<br />
or<br />
mpost test.mp<br />
<br />
* that should create a postscript file test.1<br />
* open test.1 with a postscript viewer like Ghostview, Okular, … You should see a circle.<br />
<br />
== Testing MetaPost embedded in ConTeXt ==<br />
<br />
If MetaPost is installed on your system and working correctly, you can <br />
<br />
\starttext<br />
\startMPcode<br />
draw fullcircle scaled 3cm;<br />
\stopMPcode<br />
\stoptext<br />
<br />
* for mkii you need to have write18 support enabled and run<br />
texexec --pdf test.tex<br />
<br />
* for mkiv run<br />
context test.tex<br />
<br />
* that should create a pdf file test.pdf<br />
* open test.pdf with a pdf viewer like Adobe Acrobat, Okular... You should see a circle.<br />
<br />
== Text in MetaPost ==<br />
<br />
Text that is typeset using `textext` or `btex … etex` adapts to the body font. However, when `label("Foo", pair)` or `"Foo" infont defaultfont` is used, which is not the recommended way, the text is typeset using the font `MetafunDefault`, which can be changed if desired. Example:<br />
<br />
<context mode="mkiv" source="yes" text="Gives:"><br />
\starttext<br />
\startMPcode<br />
label("Foo", origin);<br />
draw textext("Bar") yshifted -LineHeight;<br />
\stopMPcode<br />
<br />
\definefontsynonym<br />
[MetafunDefault]<br />
[Bold*default]<br />
<br />
\switchtobodyfont [pagella, 18pt]<br />
<br />
\startMPcode<br />
label("Foo", origin);<br />
draw textext("Foo") yshifted -LineHeight;<br />
\stopMPcode<br />
\stoptext<br />
</context><br />
<br />
The recommended way to typeset text is to use the `textext` macro and change the font using {{cmd |setupMPinstance}}.<br />
<br />
== Repetition of a Text Element to Fill a Bar Using textext ==<br />
<br />
Imagine you want to create a frame which consists out of one glyph or a combination of different glyphs in order to make a decorative border. For this purpose a series of such elements should be placed on the bar as pictures, evenly spaced. Probably you want to have at the end of the bar a different glyph inserted as a picture too.<br />
<br />
The following code is working but the last picture is not the expected glyph. One would expect 14 times the "?" and at the end of the bar a "*":<br />
<br />
<context mode="mkiv" source="yes" text="Gives:"><br />
\starttext<br />
\startMPpage<br />
picture PicA ; PicA := textext("*");<br />
picture PicB ; PicB := textext("?");<br />
<br />
numeric Step ; Step := 2cm div bbwidth(PicB) ;<br />
<br />
for i = 1 upto Step :<br />
draw PicB shifted (i*5mm,0) ;<br />
endfor ;<br />
draw PicA ;<br />
\stopMPpage<br />
\stoptext<br />
</context><br />
<br />
What you get is 15 "?" but no "*"!<br />
<br />
In order to get this corrected one needs to calculate the boundingbox of the "?" on beforehand. Hans Hagen provided this solution on 14-10-2014.<br />
<br />
<context mode="mkiv" source="yes" text="Gives:"><br />
\starttext<br />
\startMPcalculation<br />
path PicX ; PicX := boundingbox textext("?") ;<br />
\stopMPcalculation<br />
<br />
\startMPpage<br />
picture PicA ; PicA := textext("*");<br />
picture PicB ; PicB := textext("?");<br />
<br />
numeric Step ; Step := 2cm div bbwidth(PicX) ;<br />
% numeric Step ; Step := 2cm div bbwidth(PicB) ;<br />
<br />
for i = 1 upto Step :<br />
draw PicB shifted (i*5mm,0) ;<br />
endfor ;<br />
draw PicA ;<br />
\stopMPpage<br />
\stoptext<br />
<br />
</context><br />
<br />
Now you get 14 "?" and the "*".<br />
<br />
=== A Full Example ===<br />
<br />
<context mode="mkiv" source="yes" text="Gives:"><br />
\setupbodyfont[8pt]<br />
<br />
\defineoverlay[Myframe][\reuseMPgraphic{Frame}]<br />
<br />
\setuppapersize[A8][A8]<br />
<br />
\setuplayout<br />
[topspace=5mm,<br />
backspace=5mm,<br />
height=middle,<br />
width=middle,<br />
header=0pt,<br />
footer=0pt]<br />
<br />
\starttext<br />
<br />
% ======== Definition of the frame in Metafun ==========<br />
\startMPcalculation<br />
path PicX ; PicX := boundingbox textext("= : =") ;<br />
\stopMPcalculation <br />
<br />
\startreusableMPgraphic{Frame}<br />
numeric u,v,xshift,yshift,picwidth,remnant,nelements;<br />
<br />
u := OverlayWidth;<br />
v := OverlayHeight;<br />
<br />
path p,w;<br />
p := unitsquare xscaled u yscaled v;<br />
w := fullcircle scaled 8pt;<br />
<br />
picture Edgepic,Linepic[];<br />
<br />
color edgedotcolor,linelementcolorA;<br />
<br />
edgedotcolor := blue;<br />
linelementcolorA := red;<br />
<br />
Linepic[1] := textext("\rotate[rotation=90]{= : =}");<br />
Linepic[2] := textext("= : =");<br />
Edgepic := textext("o");<br />
<br />
%Calculations for the horizontal frame-element placement:<br />
% In order to make this work, the width of the line element needs to be calculated on beforehand.<br />
% path PicX; PicX := textext(")(");<br />
picwidth := bbwidth(PicX);<br />
nelements := u div picwidth;<br />
remnant := u mod picwidth;<br />
xshift := picwidth + remnant/nelements; <br />
<br />
Linepic[3] := Linepic[2] shifted (0.5*picwidth,0);<br />
<br />
for a = llcorner p, ulcorner p :<br />
for i = 1 upto nelements :<br />
draw Linepic[3] shifted ((xpart a + (i-1)*xshift),ypart a) withcolor linelementcolorA;<br />
endfor;<br />
endfor;<br />
<br />
%Calculations for the vertical frame-element placement:<br />
picheight := bbwidth(PicX);<br />
nelements := v div picheight;<br />
remnant := v mod picheight;<br />
yshift := picheight + remnant/nelements;<br />
<br />
Linepic[4]:= Linepic[1] shifted (0,0.5*picheight);<br />
<br />
for a = llcorner p, lrcorner p :<br />
for i = 1 upto nelements:<br />
draw Linepic[4] shifted (xpart a,ypart a + (i-1)*yshift) withcolor linelementcolorA;<br />
endfor;<br />
endfor;<br />
<br />
for i = llcorner p, lrcorner p,ulcorner p,urcorner p :<br />
fill w shifted (xpart i,ypart i) withcolor white;<br />
draw Edgepic shifted (xpart i,ypart i) withcolor edgedotcolor;<br />
endfor;<br />
<br />
% For frame-element positioning checking:<br />
% draw p;<br />
%<br />
\stopreusableMPgraphic<br />
<br />
% ==========<br />
<br />
\startframedtext<br />
[width=0.8\textwidth,height=0.8\textheight,frame=off,background=Myframe, align={middle,lohi}]<br />
The butterfly counts not months but moments, and has time enough.<br />
\blank<br />
{\tfx Rabindranath Tagore}<br />
\stopframedtext<br />
\stoptext<br />
<br />
</context><br />
<br />
There is some strange cropping going on on the Wiki-implementation. Of course the left frame is in reality equal to the right frame...<br />
<br />
There is one important remark: The MPcalculation and the drawing itself must be inside \starttext ... \stoptext.<br />
== Other Links ==<br />
<br />
* Metapost home page: http://tug.org/metapost<br />
* John Hobby's page: http://cm.bell-labs.com/who/hobby/MetaPost.html<br />
* Current development: http://foundry.supelec.fr/projects/metapost/<br />
* http://melusine.eu.org/syracuse/metapost/<br />
<br />
[[Category:Graphics]]<br />
[[Category:Metapost]]</div>Willihttps://wiki.contextgarden.net/index.php?title=MetaPost&diff=22659MetaPost2014-10-15T20:00:50Z<p>Willi: More info about using textext. Included a full example</p>
<hr />
<div>< [[Math]], [[MetaFun]], [[Graphics]]<br />
<br />
MetaPost is a graphical programming language, based on Donald Knuth's MetaFont. Normally MP graphics are converted to PostScript and used with dvips, but ConTeXt can use it directly with PDF (see the<br />
[http://www.pragma-ade.com/general/sources/mptopdf.pdf MP to PDF] manual).<br />
<br />
MetaPost is ConTeXt's native graphics language. [[MetaFun]] is a MetaPost module by Hans Hagen that adds a lot of extra features; it is enabled by default, so one could say that MetaFun is ConTeXt's default dialect of MetaPost.<br />
<br />
== Documentation & Tutorials ==<br />
* [http://www.tug.org/docs/metapost/mpman.pdf A User's Manual for MetaPost] <!-- http://cm.bell-labs.com/who/hobby/cstr_162.pdf has its pages reversed --><br />
* [http://remote.science.uva.nl/~heck/Courses/mptut.pdf Learning METAPOST by doing] ([http://maps.aanhet.net/maps/pdf/32_14.pdf this] and [http://maps.aanhet.net/maps/pdf/32_15.pdf this link] are not working)<br />
* [http://www.tug.org/pracjourn/2006-4/henderson/henderson.pdf A Beginner's Guide to METAPOST for Creating High-Quality Graphics] by Troy Henderson<br />
* [[manual:metafun-s.pdf|MetaFun]]<br />
* [http://tex.loria.fr/prod-graph/zoonekynd/metapost/metapost.html Lots of examples]<br />
* [[Color in MetaPost]] describes how to get color mixtures, TeX colors, and transparent effects in MetaPost graphics.<br />
* [http://wiki.contextgarden.net/MetaPost_in_ConTeXt MetaPost in ConTeXt]<br />
<br />
== Using MetaPost in ConTeXt ==<br />
<br />
With {{cmd|startuseMPgraphic}}, you define a piece of graphics code that is processed anew every time the graphic is placed with {{cmd|useMPgraphic}}. Further commands are described at [[MetaPost in ConTeXt]].<br />
<br />
<context source=yes><br />
\def\mycolor{.625red}<br />
<br />
\startuseMPgraphic{name}<br />
fill fullcircle scaled 20pt withcolor \mycolor;<br />
\stopuseMPgraphic<br />
<br />
red: \useMPgraphic{name}<br />
<br />
\def\mycolor{.625blue}<br />
blue: \useMPgraphic{name}<br />
</context><br />
<br />
== Different Packages, Extensions & Applications of Metapost ==<br />
* [http://www.ctan.org/tex-archive/graphics/metaplot/ MetaPlot] - graph drawing<br />
* [http://www.ctan.org/tex-archive/graphics/metapost/contrib/macros/metaobj/ MetaObj] - object-oriented drawing, see also the page about [[MetaObj and Labels]]<br />
<br />
* [http://stud4.tuwien.ac.at/~e0225855/finomaton/finomaton.html finomaton] - drawing finite state automata<br />
* [http://www-math.univ-poitiers.fr/~phan/statsmac.html statsmac] - metapost macros for statistics graphs<br />
* [http://metauml.sourceforge.net/ MetaUML] - MetaPost library for typesetting UML diagrams<br />
* [http://vigna.dsi.unimi.it/metagraph/ METAGRAPH] - drawing (un)directed graphs<br />
<br />
=== 3D support ===<br />
* [http://matagalatlante.org/nobre/featpost/doc/featexamples.html FeatPost]<br />
* [http://www.gnu.org/software/3dldf/LDF.html 3DLDF]<br />
* [http://www-math.univ-poitiers.fr/~phan/m3Dplain.html m3D]<br />
<br />
{{todo|needs major review}}<br />
<br />
== MetaPost relatives ==<br />
=== Font Creation ===<br />
* [[MetaType1]], see [http://www.ctan.org/tex-archive/fonts/utilities/metatype1/ CTAN]<br />
<br />
=== 3D drawing ===<br />
* [http://asymptote.sourceforge.net/ Asymptote] - inspired by MetaPost & fully generalizes MetaPost path construction algorithms to three-dimensions<br />
<br />
== Testing plain MetaPost ==<br />
To test whether MetaPost is installed on your system, create a file called {{code|test.mp}}:<br />
<br />
beginfig(1)<br />
draw fullcircle scaled 3cm ;<br />
endfig ;<br />
end ;<br />
<br />
* apply MetaPost on the testfile<br />
<br />
mp test.mp<br />
or<br />
mpost test.mp<br />
<br />
* that should create a postscript file test.1<br />
* open test.1 with a postscript viewer like Ghostview, Okular, … You should see a circle.<br />
<br />
== Testing MetaPost embedded in ConTeXt ==<br />
<br />
If MetaPost is installed on your system and working correctly, you can <br />
<br />
\starttext<br />
\startMPcode<br />
draw fullcircle scaled 3cm;<br />
\stopMPcode<br />
\stoptext<br />
<br />
* for mkii you need to have write18 support enabled and run<br />
texexec --pdf test.tex<br />
<br />
* for mkiv run<br />
context test.tex<br />
<br />
* that should create a pdf file test.pdf<br />
* open test.pdf with a pdf viewer like Adobe Acrobat, Okular... You should see a circle.<br />
<br />
== Text in MetaPost ==<br />
<br />
Text that is typeset using `textext` or `btex … etex` adapts to the body font. However, when `label("Foo", pair)` or `"Foo" infont defaultfont` is used, which is not the recommended way, the text is typeset using the font `MetafunDefault`, which can be changed if desired. Example:<br />
<br />
<context mode="mkiv" source="yes" text="Gives:"><br />
\starttext<br />
\startMPcode<br />
label("Foo", origin);<br />
draw textext("Bar") yshifted -LineHeight;<br />
\stopMPcode<br />
<br />
\definefontsynonym<br />
[MetafunDefault]<br />
[Bold*default]<br />
<br />
\switchtobodyfont [pagella, 18pt]<br />
<br />
\startMPcode<br />
label("Foo", origin);<br />
draw textext("Foo") yshifted -LineHeight;<br />
\stopMPcode<br />
\stoptext<br />
</context><br />
<br />
The recommended way to typeset text is to use the `textext` macro and change the font using {{cmd |setupMPinstance}}.<br />
<br />
== Repetition of a Text Element to Fill a Bar Using textext ==<br />
<br />
Imagine you want to create a frame which consists out of one glyph or a combination of different glyphs in order to make a decorative border. For this purpose a series of such elements should be placed on the bar as pictures, evenly spaced. Probably you want to have at the end of the bar a different glyph inserted as a picture too.<br />
<br />
The following code is working but the last picture is not the expected glyph. One would expect 14 times the "?" and at the end of the bar a "*":<br />
<br />
<context mode="mkiv" source="yes" text="Gives:"><br />
\starttext<br />
\startMPpage<br />
picture PicA ; PicA := textext("*");<br />
picture PicB ; PicB := textext("?");<br />
<br />
numeric Step ; Step := 2cm div bbwidth(PicB) ;<br />
<br />
for i = 1 upto Step :<br />
draw PicB shifted (i*5mm,0) ;<br />
endfor ;<br />
draw PicA ;<br />
\stopMPpage<br />
\stoptext<br />
</context><br />
<br />
What you get is 15 "?" but no "*"!<br />
<br />
In order to get this corrected one needs to calculate the boundingbox of the "?" on beforehand:<br />
<br />
<context mode="mkiv" source="yes" text="Gives:"><br />
\starttext<br />
\startMPcalculation<br />
path PicX ; PicX := boundingbox textext("?") ;<br />
\stopMPcalculation<br />
<br />
\startMPpage<br />
picture PicA ; PicA := textext("*");<br />
picture PicB ; PicB := textext("?");<br />
<br />
numeric Step ; Step := 2cm div bbwidth(PicX) ;<br />
% numeric Step ; Step := 2cm div bbwidth(PicB) ;<br />
<br />
for i = 1 upto Step :<br />
draw PicB shifted (i*5mm,0) ;<br />
endfor ;<br />
draw PicA ;<br />
\stopMPpage<br />
\stoptext<br />
<br />
</context><br />
<br />
Now you get 14 "?" and the "*".<br />
<br />
=== A Full Example ===<br />
<br />
<context mode="mkiv" source="yes" text="Gives:"><br />
\setupbodyfont[8pt]<br />
<br />
\defineoverlay[Myframe][\reuseMPgraphic{Frame}]<br />
<br />
\setuppapersize[A8][A8]<br />
<br />
\setuplayout<br />
[topspace=5mm,<br />
backspace=5mm,<br />
height=middle,<br />
width=middle,<br />
header=0pt,<br />
footer=0pt]<br />
<br />
\starttext<br />
<br />
% ======== Definition of the frame in Metafun ==========<br />
\startMPcalculation<br />
path PicX ; PicX := boundingbox textext("= : =") ;<br />
\stopMPcalculation <br />
<br />
\startreusableMPgraphic{Frame}<br />
numeric u,v,xshift,yshift,picwidth,remnant,nelements;<br />
<br />
u := OverlayWidth;<br />
v := OverlayHeight;<br />
<br />
path p,w;<br />
p := unitsquare xscaled u yscaled v;<br />
w := fullcircle scaled 8pt;<br />
<br />
picture Edgepic,Linepic[];<br />
<br />
color edgedotcolor,linelementcolorA;<br />
<br />
edgedotcolor := blue;<br />
linelementcolorA := red;<br />
<br />
Linepic[1] := textext("\rotate[rotation=90]{= : =}");<br />
Linepic[2] := textext("= : =");<br />
Edgepic := textext("o");<br />
<br />
%Calculations for the horizontal frame-element placement:<br />
% In order to make this work, the width of the line element needs to be calculated on beforehand.<br />
% path PicX; PicX := textext(")(");<br />
picwidth := bbwidth(PicX);<br />
nelements := u div picwidth;<br />
remnant := u mod picwidth;<br />
xshift := picwidth + remnant/nelements; <br />
<br />
Linepic[3] := Linepic[2] shifted (0.5*picwidth,0);<br />
<br />
for a = llcorner p, ulcorner p :<br />
for i = 1 upto nelements :<br />
draw Linepic[3] shifted ((xpart a + (i-1)*xshift),ypart a) withcolor linelementcolorA;<br />
endfor;<br />
endfor;<br />
<br />
%Calculations for the vertical frame-element placement:<br />
picheight := bbwidth(PicX);<br />
nelements := v div picheight;<br />
remnant := v mod picheight;<br />
yshift := picheight + remnant/nelements;<br />
<br />
Linepic[4]:= Linepic[1] shifted (0,0.5*picheight);<br />
<br />
for a = llcorner p, lrcorner p :<br />
for i = 1 upto nelements:<br />
draw Linepic[4] shifted (xpart a,ypart a + (i-1)*yshift) withcolor linelementcolorA;<br />
endfor;<br />
endfor;<br />
<br />
for i = llcorner p, lrcorner p,ulcorner p,urcorner p :<br />
fill w shifted (xpart i,ypart i) withcolor white;<br />
draw Edgepic shifted (xpart i,ypart i) withcolor edgedotcolor;<br />
endfor;<br />
<br />
% For frame-element positioning checking:<br />
% draw p;<br />
%<br />
\stopreusableMPgraphic<br />
<br />
% ==========<br />
<br />
\startframedtext<br />
[width=0.8\textwidth,height=0.8\textheight,frame=off,background=Myframe, align={middle,lohi}]<br />
The butterfly counts not months but moments, and has time enough.<br />
\blank<br />
{\tfx Rabindranath Tagore}<br />
\stopframedtext<br />
\stoptext<br />
<br />
</context><br />
<br />
There is some strange cropping going on on the Wiki-implementation. Of course the left frame is in reality equal to the right frame...<br />
<br />
There is one important remark: The MPcalculation and the drawing itself must be inside \starttext ... \stoptext.<br />
== Other Links ==<br />
<br />
* Metapost home page: http://tug.org/metapost<br />
* John Hobby's page: http://cm.bell-labs.com/who/hobby/MetaPost.html<br />
* Current development: http://foundry.supelec.fr/projects/metapost/<br />
* http://melusine.eu.org/syracuse/metapost/<br />
<br />
[[Category:Graphics]]<br />
[[Category:Metapost]]</div>Willihttps://wiki.contextgarden.net/index.php?title=Command/setupenumerations&diff=22653Command/setupenumerations2014-10-07T08:58:21Z<p>Willi: Added an example MKIV with using before and after keys.</p>
<hr />
<div>{{Reference<br />
|name=setupenumerations<br />
|attributes=<br />
}}<br />
<br />
== [[Help:Reference|Syntax]] ==<br />
<table cellspacing="4" cellpadding="2" class="cmd"><br />
<tr><br />
<td colspan="2" class="cmd">\setupenumerations<span class="first" style="color:red;">[...,...,...]</span><span class="second" >[...,...=...,...]</span></td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[...,...,...]</td><br />
<td>name of an enumeration (defined with {{cmd|defineenumeration}})</td><br />
</tr><br />
<tr valign="top" class="second"><br />
<td class="cmd">[...,...=...,...]</td><br />
<td>see {{cmd|setupdescriptions}} </td><br />
</tr><br />
</table><br />
<br />
<br />
== Description ==<br />
Set up the appearance and behaviour of an enumeration. Enumeration environments are actually special description environments, so the keys are described at {{cmd|setupdescriptions}}.<br />
<br />
== Example ==<br />
<context source=yes text="This gives:"><br />
\defineenumeration[Potato]<br />
<br />
\Potato <br />
One potato<br />
<br />
\setupenumerations[Potato][location=left]<br />
% In mkiv one would use `alternative=left`.<br />
<br />
\Potato <br />
Two potato<br />
<br />
</context><br />
<br />
The before and after keys control the spacing around enumerations. It you want to achieve something similar to the itemize-option "packed" then use: (MKIV example)<br />
<br />
<context source=yes text="This gives:"><br />
\defineenumeration[Packed]<br />
<br />
\setupenumerations<br />
[Packed]<br />
[text=,<br />
headstyle=normal,<br />
alternative=left,<br />
distance=0pt,<br />
width=13pt,<br />
stopper=\high{o},<br />
before=\blank[small]},<br />
after={\blank[small]},<br />
inbetween=]<br />
<br />
<br />
\Packed<br />
First issue<br />
<br />
\Packed<br />
Second issue<br />
<br />
</context><br />
== See also ==<br />
* {{cmd|defineenumeration}} for creating new kinds of numbered objects.<br />
* {{cmd|setupenumerations}} for setting up looks and behaviour.<br />
* {{cmd|enumeration}} for single-paragraph numbered objects.<br />
* {{cmd|startenumeration}} for multiple-paragraph numbered objects.<br />
<br />
== Help from ConTeXt-Mailinglist/Forum ==<br />
All issues with:<br />
{{Forum|{{SUBPAGENAME}}}}<br />
<br />
[[Category:Command/Numbered objects|setupenumerations]]</div>Willihttps://wiki.contextgarden.net/index.php?title=Titles&diff=13427Titles2011-10-17T21:23:41Z<p>Willi: Flush raw head data through setuptexttexts</p>
<hr />
<div>< [[Structurals]] | [[Visuals]] ><br />
<br />
==Default==<br />
<br />
Titles define the structure of your document. Decide yourself, how deep you want to nest them:<br />
<br />
<table><br />
<tr bgcolor="#CCCCCC"><br />
<th>numbered</th><br />
<th>unnumbered</th><br />
</tr><br />
<tr><br />
<td><cmd>part</cmd><br />
</td><td>&#151;</td><br />
</tr><br />
<tr><br />
<td><cmd>chapter</cmd></td><br />
<td><cmd>title</cmd></td><br />
</tr><br />
<tr><br />
<td><cmd>section</cmd></td><br />
<td><cmd>subject</cmd></td><br />
</tr><br />
<tr><br />
<td><cmd>subsection</cmd></td><br />
<td><cmd>subsubject</cmd></td><br />
</tr><br />
<tr><br />
<td><cmd>subsubsection</cmd></td><br />
<td><cmd>subsubsubject</cmd></td><br />
</tr><br />
<tr><br />
<td>...</td><br />
<td>...</td><br />
</tr><br />
</table><br />
<br />
The ''unnumbered'' versions don't appear in a table of contents! But you can<br />
switch off the numbering of the ''numbered'' versions with <cmd>setuphead</cmd><br />
to get unnumbered titles ''and'' a toc (confusing?).<br />
<br />
Also note that in the front matter of the document, all titles are unnumbered<br />
by default. In this case, the only difference between the "numbered" and<br />
"unnumbered" titles is that the latter don't show up in the table of contents.<br />
<br />
===Referencing Titles===<br />
<br />
Every heading command can take an optional parameter as reference:<br />
<br />
<texcode><br />
\title[hasselt-by-night]{Hasselt by night}<br />
</texcode><br />
<br />
The bracket pair is optional and used for internal [[References]]. If you want<br />
to refer to this header you type for example<br />
<br />
<texcode><br />
\at{page}[hasselt-by-night].<br />
<br />
(see <cmd>at</cmd>)<br />
</texcode><br />
<br />
Note that reference labels are limited to ASCII characters in traditional TeX.<br />
This limitation has been removed in ConTeXt mkiv.<br />
<br />
==Titling Style==<br />
<br />
see <cmd>setuphead</cmd> and some enhanced samples below.<br />
<br />
A FAQ is, how to get a line under the pageheader:<br />
<br />
<texcode><br />
\setupbackgrounds[header][text][bottomframe=on]<br />
</texcode><br />
<br />
To make the section numbers appear as characters, do<br />
<br />
<texcode><br />
\setupsection[section-3][bodypartconversion=Character]<br />
</texcode><br />
<br />
The <code>section-3</code> corresponds to <code>section</code>. Similarly,<br />
<code>section-1</code> corresponds to <code>part</code>, <code>section-2</code><br />
corresponds to <code>chapter</code> and so on.<br />
<br />
==Titling Alignment==<br />
<br />
Titles should often be left aligned without hyphenation. Try this:<br />
<br />
<texcode><br />
\setuphead[chapter][align={flushleft, nothyphenated, verytolerant}] % "flushleft" is the same as "right"<br />
</texcode><br />
<br />
==Using colors in chapters and sections==<br />
<br />
If you want you may have colors on your document's chapters or sections.<br />
To do that you should use <cmd>setuphead</cmd>. Take a look at the following<br />
example:<br />
<br />
<texcode><br />
\setupcolors[state=start] % Important. You won't have colors without it.<br />
<br />
\setuphead[chapter][header=empty] % Chapter pages won't have headers<br />
<br />
\setupheadertexts[][chapter] % The header will be the chapter's name<br />
<br />
\starttext<br />
<br />
\completecontent<br />
<br />
\chapter{Black chapter 1}<br />
<br />
\setuphead[section][color=darkcyan] % This is how you change your chapter's color.<br />
<br />
\section{Dark cyan section 1.1}<br />
<br />
\page<br />
Test.<br />
<br />
\setuphead[chapter][color=darkgreen]<br />
<br />
\chapter{Dark green chapter}<br />
<br />
\page<br />
Test.<br />
<br />
\setuphead[chapter][color=red]<br />
<br />
\chapter{Red chapter}<br />
<br />
\page<br />
Test.<br />
<br />
\stoptext <br />
</texcode><br />
<br />
==Your Own Titling Levels==<br />
<br />
Of course you can define your own titling commands and probably must adapt the default settings.<br />
<br />
<texcode><br />
\definehead[myheader][section]<br />
<br />
\setuphead<br />
[myheader]<br />
[numberstyle=bold,<br />
textstyle=cap,<br />
before=\hairline\blank,<br />
after=\nowhitespace\hairline]<br />
<br />
\myheader[hasselt-ref]{Hasselt makes headlines}<br />
</texcode><br />
<br />
A new header <cmd>myheader</cmd> is defined and it inherits the properties<br />
of <cmd>section</cmd> (title, subject, whatever). You can ''define'' several<br />
headers at once!<br />
<br />
==Formatting Titles with <cmd>setuphead</cmd>==<br />
<br />
<cmd>setuphead</cmd> accepts a number of parameters which change the style of<br />
the heading. At least the following commands are available:<br />
<br />
<table><br />
<tr bgcolor="#CCCCCC"><br />
<th>text</th><br />
<th>number</th><br />
</tr><br />
<tr><br />
<td><tt>textstyle</tt></td><br />
<td><tt>numberstyle</tt></td><br />
</tr><br />
<tr><br />
<td><tt>textcommand</tt></td><br />
<td><tt>numbercommand</tt></td><br />
</tr><br />
<tr><br />
<td><tt>deeptextcommand</tt></td><br />
<td><tt>deepnumbercommand</tt></td><br />
</tr><br />
</table><br />
<br />
Quite obviously, the number-commands work on the chapter/section/etc. number,<br />
their text counterparts change the text itself. However, there are differences<br />
between <tt>style</tt>, <tt>command</tt> and <tt>deepcommand</tt>.<br />
<br />
The <tt>style</tt> variants accept a style (<tt>bold</tt>, <tt>cap</tt>, etc.)<br />
or a font switch (<cmd>em</cmd>, <cmd>tfx</cmd>, etc). <tt>textstyle</tt> prepends<br />
the text with the associated style. <tt>textcommand</tt> is a command name which<br />
is given the text (with all markup) as a parameter. <tt>deeptextcommand</tt> is<br />
similar to <tt>textcommand</tt> but it acts only on the text (not on the markup).<br />
<br />
So, if we have <cmd>title{A story}</cmd>, the different parameters have the following results:<br />
<br />
<table><br />
<tr><br />
<td><tt>textstyle=\em</tt></td><br />
<td><tt>=></tt></td><br />
<td><tt>\em A story</tt></td><br />
</tr><br />
<tr><br />
<td><tt>textstyle=\em, textcommand=\uppercase</tt></td><br />
<td><tt>=></tt></td><br />
<td><tt>\uppercase{\em A story}</tt></td><br />
<td><tt>=></tt></td><br />
<td><tt>\em A STORY</tt></td><br />
</tr><br />
<tr><br />
<td><tt>textstyle=\em, deeptextcommand=\uppercase</tt></td><br />
<td><tt>=></tt></td><br />
<td><tt>\em\uppercase{A story}</tt></td><br />
<td><tt>=></tt><br />
</td><td><tt>\em A STORY</tt></td><br />
</tr><br />
</table><br />
<br />
What is the difference between <tt>textcommand</tt> and <tt>deeptextcommand</tt>,<br />
then? With this example there is very little difference, as <tt>uppercase</tt><br />
knows how to handle markup. Sometimes this is not the case. For example, an almost<br />
similar command <tt>WORD</tt> is not compatible with <tt>textcommand</tt>, because<br />
it wreaks havoc with markup:<br />
<br />
<table><br />
<tr><br />
<td><tt>textstyle=\em, textcommand=\WORD</tt></td><br />
<td><tt>=></tt></td><br />
<td><tt>\WORD{\em A story}</tt></td><br />
<td><tt>=></tt></td><br />
<td><tt>\EM A STORY</tt></td><br />
</tr><br />
<tr><br />
<td><tt>textstyle=\em, deeptextcommand=\WORD</tt></td><br />
<td><tt>=></tt></td><br />
<td><tt>\em\WORD{A story}</tt></td><br />
<td><tt>=></tt></td><br />
<td><tt>\em A STORY</tt></td><br />
</tr><br />
</table><br />
<br />
In this case using <tt>deeptextcommand</tt> is the correct solution for capitalizing<br />
headers. (Using <cmd>uppercase</cmd> works in this specific case, but only if you stick<br />
to Latin 1 or Anglo-Saxon characters. Other languages will suffer from lowercase accented<br />
characters, like CAFé.)<br />
<br />
Use <cmd>setuphead</cmd><tt>[part][conversion=Romannumerals]</tt>, for example, to employ an<br />
alternative numbering scheme.<br />
<br />
=== Truly empty pagebreak before chapters ===<br />
<br />
Using <cmd>setuppagenumbering[alternative=doublesided]</cmd> makes the chapters start<br />
on the right page. However, the blank page is not truely empty, it contains headers and<br />
footers. To get truely empty pages, use the following<br />
<br />
<texcode><br />
\definepagebreak<br />
[mychapterpagebreak]<br />
[yes,header,right]<br />
%[yes,header,left]<br />
%[yes,header,footer,right]<br />
<br />
\setuphead<br />
[chapter]<br />
[page=mychapterpagebreak]<br />
%[page=Mychapterpagebreak,header=empty,footer=empty]<br />
<br />
%\setupsectionblock[frontpart][page=chapter]<br />
%\setupsectionblock[bodypart][page=chapter]<br />
%\setupsectionblock[backpart][page=chapter]<br />
%\setupsectionblock[appendix][page=chapter]<br />
<br />
\setuppagenumbering[alternative=doublesided,location={header,margin}]<br />
\setupheadertexts[{My special headertext}]<br />
\setupfootertexts[This is a text in the footer]<br />
%\setupbackgrounds[header][text][bottomframe=on]<br />
<br />
\starttext<br />
\chapter{testA} \dorecurse{10}{\input tufte }<br />
\chapter{testB} \dorecurse{10}{\input tufte }<br />
\chapter{testC} \dorecurse{10}{\input tufte }<br />
\stoptext<br />
</texcode><br />
<br />
'''Explanation''' (provided by Willi Egger on the mailing list)<br />
<br />
* You define a new pagebreak rule. It has the name <code>mychapterpagebreak</code>. The options set read as: <code>pagebreak=yes</code>, placeheader, use a right page.<br />
* You set options for the header of type chapter and use for the option page the afore defined new pagebreak.<br />
* You might want to experiment with the commented lines and see what happens. For example, the <cmd>setupsectionblock</cmd> commands will give a truly blank page (if needed) after the specified <cmd>stop*part</cmd> command.<br />
<br />
== Independent Section Numbering ==<br />
<br />
If you want section numbering to be independent of chapter numbering, use<br />
<br />
<texcode><br />
\setuphead [chapter][resetnumber=no]<br />
\setupsection[section][previousnumber=no]<br />
</texcode><br />
<br />
This is handled differently in mkiv (where "resetnumber=no" is silently ignored):<br />
<br />
<texcode><br />
\definestructureresetset[default][1,1,0][1] % reset part, chapter, but not section<br />
\setuphead[sectionresetset=default]<br />
</texcode><br />
<br />
==Unnumbered titles in table of contents==<br />
<br />
Sometimes one wants an unnumbered chapter, say introduction, the following might do that trick:<br />
<br />
<texcode><br />
\definehead [intro] [chapter]<br />
\setuphead [intro] [number=no]<br />
\definecombinedlist [content][intro,chapter,section]<br />
\setuplist [intro] [headnumber=no]<br />
<br />
\starttext<br />
\completecontent<br />
\startfrontmatter<br />
\intro{No number}<br />
\stopfrontmatter<br />
<br />
\startbodymatter<br />
\chapter{Has number}<br />
\stopbodymatter<br />
\stoptext<br />
</texcode><br />
<br />
<context><br />
\definehead [intro] [chapter]<br />
\setuphead [intro] [number=no]<br />
<br />
\definecombinedlist [content][intro,chapter,section]<br />
\setuplist [intro] [headnumber=no]<br />
<br />
\starttext<br />
\completecontent<br />
\startfrontmatter<br />
\intro{No number}<br />
\stopfrontmatter<br />
<br />
\startbodymatter<br />
\chapter{Has number}<br />
\stopbodymatter<br />
\stoptext<br />
</context><br />
<br />
Note that just putting the introduction in the frontmatter already did the trick for me (on a recent MkIV).<br />
<br />
==Your Own Title Styles==<br />
<br />
Sometimes the possibilities of <cmd>setuphead</cmd> aren't enough. You can define<br />
your own styling commands, as shown in the following examples.<br />
<br />
===Start the title in the margin===<br />
<br />
This very simple example shows how to start a title within the margin, rather than at the text's edge<br />
<br />
<texcode><br />
\setuphead[chapter][alternative=margin]<br />
</texcode><br />
<br />
This looks like<br />
<br />
<context><br />
\setuphead[chapter][alternative=margin]<br />
<br />
\chapter{Sample chapter}<br />
<br />
Number is in margin, not at text edge.<br />
</context><br />
<br />
===Chapter titles in new line===<br />
To have the chapter title simply in a new line a new command needs to be defined that takes care of this. It needs to be wrapped in <cmd>framed</cmd>.<br />
<br />
<texcode><br />
\setuplabeltext [en] [chapter=Chapter~]<br />
% Does not work, not wrapped in \framed<br />
% \def\MyChapter#1#2{#1\blank#2}<br />
\define[2]\MyChapter<br />
{\framed[frame=off,width=broad,align=flushleft]{#1\\#2}}<br />
\setuphead [chapter] [command=\MyChapter]<br />
\startchapter [title=Foo Bar]<br />
\stopchapter<br />
</texcode><br />
<br />
This looks like<br />
<br />
<context><br />
\setuplabeltext [en] [chapter=Chapter~]<br />
\define[2]\MyChapter<br />
{\framed[frame=off,width=broad,align=flushleft]{#1\\#2}}<br />
\setuphead [chapter] [command=\MyChapter]<br />
\chapter{Foo Bar}<br />
</context><br />
<br />
===Expanded chapter titles===<br />
<br />
This example illustrates expanded chapter titles.<br />
<br />
<texcode><br />
\def\MyChapterCommand#1#2% #1 is number, #2 is text<br />
{\framed[frame=off,bottomframe=on,topframe=on]<br />
{\vbox{\headtext{chapter} #1\blank#2}}} % \vbox is needed for \blank to work<br />
<br />
\setuphead[chapter][command=\MyChapterCommand, style={\ss\bfa}]<br />
<br />
\setupheadtext[chapter=Chapter] % used by \headtext<br />
</texcode><br />
<br />
so <tt>\chapter{My First Chapter}</tt> looks like:<br />
<br />
<context><br />
\def\MyChapterCommand#1#2%<br />
{\framed[frame=off,bottomframe=on,topframe=on]<br />
{\vbox{\headtext{chapter} #1\blank#2}}}<br />
<br />
\setuphead[chapter][command=\MyChapterCommand, style={\ss\bfa}]<br />
\setupheadtext[chapter=Chapter]<br />
<br />
\chapter{My First Chapter}<br />
</context><br />
<br />
===Exercise numbers===<br />
<br />
For a textbook, suppose that you collect the exercises in a section at the end<br />
of each chapter, with each exercise a subsection having a short title, and the<br />
exercises should be numbered only by the subsection (not 1.6.7 for example,<br />
just 7). The usage:<br />
<br />
<texcode><br />
\section{Exercises}<br />
<br />
\exercise{Batteries}<br />
What is the cost of energy from a 9V battery? From a wall socket (the mains)?<br />
</texcode><br />
<br />
The setup code:<br />
<texcode><br />
\definehead[exercise][subsection]<br />
<br />
\setuphead<br />
[exercise]<br />
[style=italic, <br />
numbercommand={\determineheadnumber[subsection]\currentheadnumber\gobbleoneargument}]<br />
</texcode><br />
<br />
===A complex graphical element under the chapter title===<br />
<br />
<texcode><br />
\setupcolors[state=start]<br />
\startuseMPgraphic{HeaderDeco}<br />
numeric w, h, repeats;<br />
path p[];<br />
w := OverlayWidth ; h := OverlayHeight ;<br />
repeats := abs(TextWidth/BodyFontSize);<br />
p[1] := unitsquare xscaled w yscaled h ;<br />
draw p[1] withcolor white;<br />
p[2] := fullcircle scaled BodyFontSize;<br />
p[3] := fullcircle scaled .25BodyFontSize;<br />
draw p[2] shifted (.5BodyFontSize,0);<br />
for i = 1 upto repeats:<br />
if odd i :<br />
filldraw p[3] shifted (i*BodyFontSize+.5BodyFontSize,0);<br />
else :<br />
draw p[2] shifted (i*BodyFontSize+.5BodyFontSize,0);<br />
fi;<br />
endfor;<br />
\stopuseMPgraphic<br />
<br />
\setuphead[chapter][command=\Myheader]<br />
\setupheadtext[chapter=Chapitre]<br />
\defineoverlay[HeaderDeco][\uniqueMPgraphic{HeaderDeco}]<br />
<br />
\def\Myheader#1#2{%<br />
\framedtext<br />
[width= \overlaywidth,<br />
height=6\bodyfontsize,<br />
background={foreground,HeaderDeco},<br />
offset=0pt,<br />
strut=no,<br />
frame=off,<br />
align=middle]{%<br />
\headtext{chapter} #1<br />
\blank[small]<br />
#2}}<br />
<br />
\starttext<br />
\chapter{Here we go!}<br />
\stoptext<br />
</texcode><br />
<br />
It looks like:<br />
<br />
<context><br />
\setupcolors[state=start]<br />
\startuseMPgraphic{HeaderDeco}<br />
numeric w, h, repeats;<br />
path p[];<br />
w := OverlayWidth ; h := OverlayHeight ;<br />
repeats := abs(TextWidth/BodyFontSize);<br />
p[1] := unitsquare xscaled w yscaled h ;<br />
draw p[1] withcolor white;<br />
p[2] := fullcircle scaled BodyFontSize;<br />
p[3] := fullcircle scaled .25BodyFontSize;<br />
draw p[2] shifted (.5BodyFontSize,0);<br />
for i = 1 upto repeats:<br />
if odd i :<br />
filldraw p[3] shifted (i*BodyFontSize+.5BodyFontSize,0);<br />
else :<br />
draw p[2] shifted (i*BodyFontSize+.5BodyFontSize,0);<br />
fi;<br />
endfor;<br />
\stopuseMPgraphic<br />
<br />
\setuphead[chapter][command=\Myheader]<br />
\setupheadtext<br />
[chapter=Chapitre]<br />
\defineoverlay[HeaderDeco][\uniqueMPgraphic{HeaderDeco}]<br />
<br />
\def\Myheader#1#2{%<br />
\framedtext<br />
[width= \overlaywidth,<br />
height=6\bodyfontsize,<br />
background={foreground,HeaderDeco},<br />
offset=0pt,<br />
strut=no,<br />
frame=off,<br />
align=middle]{%<br />
\headtext{chapter} #1<br />
\blank[small]<br />
#2}}<br />
<br />
\starttext<br />
\chapter{Here we go!}<br />
\stoptext<br />
</context><br />
<br />
===Titles in margin===<br />
<br />
It is sometimes wanted to place the title of a section/subject etc in the margin next to the section text (instead of above it).<br />
This is achieved by the following setup:<br />
<br />
<texcode><br />
\setuphead<br />
[subject]<br />
[alternative=text,distance=0pt,command=\MyHead]<br />
<br />
\def\MyHead#1#2{\inmargin{#1 #2}}<br />
</texcode><br />
<br />
This (with 'style=\sc' added in setuphead) gives:<br />
<br />
<context><br />
\setuphead<br />
[subject]<br />
[alternative=text,distance=0pt,command=\MyHead,style=\sc]<br />
<br />
\def\MyHead#1#2{\inmargin{#1 #2}}<br />
<br />
\starttext<br />
<br />
\subject{First Subject}<br />
This is the text in the first subject. This is the text in the first subject.<br />
This is the text in the first subject. This is the text in the first subject.<br />
This is the text in the first subject. This is the text in the first subject.<br />
This is the text in the first subject. This is the text in the first subject.<br />
<br />
\subject{Second Subject}<br />
This is the text in the second subject. This is the text in the second subject.<br />
This is the text in the second subject. This is the text in the second subject. <br />
This is the text in the second subject. This is the text in the second subject. <br />
This is the text in the second subject. This is the text in the second subject. <br />
<br />
\stoptext<br />
</context><br />
<br />
See the mailing list thread [[http://www.ntg.nl/pipermail/ntg-context/2003/002053.html]] for more on this.<br />
<br />
===Headings numbered independent of chapters or other headings===<br />
<br />
If you want a heading that gets numbered without resetting at new sections or chapters (for example, for problems whose numbers increment throughout a book), here is a solution due to Hans [http://archive.contextgarden.net/message/20030415.153451.374310d8.en.html on the mailing list]:<br />
<br />
<texcode><br />
% use a lower level head<br />
<br />
\definehead<br />
[Problem]<br />
[subsubsubsection]<br />
<br />
% cleaned up<br />
<br />
\setuphead<br />
[Problem]<br />
[style=\ss\bf,<br />
color=red,<br />
before=\blank]<br />
<br />
% use a label text<br />
<br />
\setuplabeltext<br />
[Problem=Problem ]<br />
<br />
% use your own numbers<br />
<br />
\setuphead<br />
[Problem]<br />
[ownnumber=yes]<br />
<br />
% increment and feed<br />
<br />
\newcounter\ProblemNumber<br />
<br />
\def\problem#1%<br />
{\doglobal\increment\ProblemNumber<br />
\Problem{\ProblemNumber}{#1}}<br />
<br />
% nicer here<br />
<br />
\setuplist<br />
[Problem]<br />
[alternative=c,<br />
criterium=all,<br />
width=2em,<br />
interaction=all]<br />
<br />
% the test<br />
<br />
\starttext<br />
<br />
List of Problems<br />
<br />
\blank[big] \placelist[Problem] \blank[big]<br />
<br />
\section{Tufte}<br />
<br />
\input tufte<br />
<br />
\problem{First problem}<br />
<br />
The first problem description.<br />
<br />
\section{Another Tufte}<br />
<br />
\input tufte<br />
<br />
\problem{Second problem}<br />
<br />
Second problem description.<br />
<br />
\stoptext<br />
</texcode><br />
<br />
===Chapter headers===<br />
<br />
Setup of headers like chapters.<br />
<br />
While reading Pixar docs about Renderman, I've found their headers nice and wanted to copy this style.<br />
I found a premise in Metafun manual, p.187 (Hello text), and Hans email me ([http://archive.contextgarden.net/message/20041020.100630.d531bb1d.en.html 20/10/2004 ]) on the context list a more simple solution than using metapost. The minimum is to put it here, for others who are like me, wandering for source code.<br />
Feel free to adapt code below to your langage specific settings, mine is french.<br />
<br />
<texcode><br />
\useencoding[ffr]<br />
\mainlanguage[fr]<br />
\enableregime[utf] %for UTF8<br />
<br />
% \enableregime[il1] %for ISO 8859-1 8859-15<br />
<br />
\usetypescript[palatino][texnansi]<br />
\setupbodyfont[palatino,rm,12pt]<br />
<br />
\setupcolors[state=start]<br />
<br />
\definefont[BigFontOne][Regular sa 3] %RegularSlanted sa 3(ori)%Sans sa 3:don't work (pb accents)<br />
\definefont[BigFontTwo][RegularBold sa 2] %%RegularSlanted<br />
<br />
\definecolor[BigColorOne][r=.86,g=.850,b=.54]<br />
\definecolor[BigColorTwo][r=.43,g=.425,b=.27]<br />
<br />
\setuphead<br />
[chapter]<br />
[deeptextcommand=\MyChapterText,<br />
color=BigColorTwo,<br />
style=\BigFontTwo]<br />
<br />
\def\MyChapterText#1{\rlap{\BigFontOne\BigColorOne#1}\kern15pt#1}<br />
<br />
\starttext<br />
<br />
\chapter[chap:ques]{Question}<br />
\chapter[chap:answ]{Answer}<br />
\chapter[chap:answ]{Remarque}<br />
\chapter[chap:answ]{Cours}<br />
\chapter[chap:answ]{Exercice}<br />
\chapter[chap:answ]{Travail dirigé}<br />
\chapter[chap:answ]{Exposé}<br />
\stoptext<br />
</texcode><br />
<br />
I've tryed to change a bit Hans code, by putting \kern15pt, for moving backgroundtext to the left of \rlap alignment, and an unsuccess one to switch same backgroundtext in Sans font (no french accents).<br />
<br />
olivier<br />
<br />
<context><br />
\useencoding[ffr]<br />
\mainlanguage[fr]<br />
<br />
% fonts currently don't work this way,<br />
% I'll fix that soon. Patrick<br />
<br />
% \usetypescript[palatino][texnansi]<br />
% \setupbodyfont[palatino,rm,12pt]<br />
<br />
\setupcolors[state=start]<br />
<br />
\definefont[BigFontOne][Regular sa 3] %RegularSlanted sa 3(ori)%Sans sa 3:don't work (pb accents)<br />
\definefont[BigFontTwo][RegularBold sa 2] %%RegularSlanted<br />
<br />
\definecolor[BigColorOne][r=.86,g=.850,b=.54]<br />
\definecolor[BigColorTwo][r=.43,g=.425,b=.27]<br />
<br />
\setuphead<br />
[chapter]<br />
[textcommand=\MyChapterText,<br />
color=BigColorTwo,<br />
style=\BigFontTwo]<br />
<br />
\def\MyChapterText#1{\rlap{\BigFontOne\BigColorOne#1}\kern15pt#1}<br />
<br />
\starttext<br />
<br />
\chapter[chap:ques]{Question}<br />
<br />
% only one page please, since this is displayed inline. Patrick<br />
% \chapter[chap:answ]{Answer}<br />
% \chapter[chap:answ]{Remarque}<br />
% \chapter[chap:answ]{Cours}<br />
% \chapter[chap:answ]{Exercice}<br />
% \chapter[chap:answ]{Travail dirigé}<br />
% \chapter[chap:answ]{Exposé}<br />
\stoptext<br />
</context><br />
<br />
===Figures in Headings===<br />
<br />
This example shows how to completely replace the chapter text and number by an image:<br />
<br />
<context source="yes"><br />
\setupexternalfigures[location=default] % needed only for the wiki to the find the figure<br />
<br />
\useexternalfigure[chapter-1][cow.pdf]<br />
\useexternalfigure[chapter-2][hacker.jpg]<br />
<br />
\setuphead<br />
[chapter]<br />
[command=\MyChapterCommand]<br />
<br />
\def\MyChapterCommand#1#2%<br />
{\externalfigure[chapter-\currentheadnumber][height=5cm]}<br />
<br />
\starttext<br />
<br />
\chapter{One}<br />
\section{First section of Chapter One}<br />
\chapter{Two}<br />
<br />
\stoptext<br />
</context><br />
<br />
There are a few snags though. MkII "forgets" to put the chapter in the<br />
TOC. So you have to set the <tt>deeptextcommand</tt> and<br />
<tt>deepnumbercommand</tt> separately instead (thus retaining the<br />
command that puts the chapter in the TOC), rather than setting the<br />
overall <tt>command</tt>, if you need a complete TOC.<br />
<br />
<texcode><br />
\setuphead<br />
[chapter]<br />
[deeptextcommand=\MyChapterTextCommand,<br />
deepnumbercommand=\gobbleoneargument] % hide chapter number<br />
<br />
\def\MyChapterTextCommand#1%<br />
{\externalfigure[chapter-\currentheadnumber][height=5cm]}<br />
</texcode><br />
<br />
[http://archive.contextgarden.net/message/20050519.215526.df7c5cd1.html]<br />
<br />
Users of MkIV can safely rely on <tt>command</tt> and don't have to<br />
bother with the <tt>deep...command</tt> variants. However,<br />
<tt>\currentheadnumber</tt> does not seem to return anything but 0.<br />
Thus, the following code is required to define<br />
<tt>\MyChapterCommand</tt> when using MkIV:<br />
<br />
<texcode><br />
\def\MyChapterCommand#1#2%<br />
{\externalfigure[chapter-\namedheadnumber{chapter}][height=5cm]}<br />
</texcode><br />
<br />
[http://archive.contextgarden.net/message/20100817.102859.206d858e.en.html]<br />
<br />
===Chapter head with absolute positioning of following text===<br />
<br />
<texcode><br />
\setuphead[chapter][before=\vbox to 4cm\bgroup,after=\vss\egroup]<br />
\starttext<br />
\chapter{test} \input tufte<br />
\stoptext<br />
</texcode><br />
<br />
No matter how many lines the chapter head runs to, the text will always start, e.g. 4cm below the top of the heading:<br />
<br />
<context><br />
\setuppapersize[A6][A6]<br />
\setuphead[chapter][before=\vbox to 4cm\bgroup,after=\vss\egroup]<br />
\setupbodyfont[8pt]<br />
\starttext<br />
\chapter{test} \input tufte<br />
\stoptext<br />
</context><br />
<br />
====Bug and proposed workaround====<br />
<br />
I tried this sample and <cmd>getmarking[chapter]</cmd>, used in my headers,<br />
stopped to work properly. Proposed workaround below.<br />
--[[User:Sebastian.rooks|SeR]] 00:52, 27 January 2006 (CET)<br />
<br />
<texcode><br />
\def\MyChapterCommand#1#2%<br />
{\vbox to 4cm\bgroup<br />
{#1\hskip.75em #2}<br />
\vss<br />
\egroup}<br />
<br />
\setuphead[chapter][header=nomarking,command=\MyChapterCommand]<br />
\starttext<br />
\chapter{test} \input tufte<br />
\stoptext<br />
</texcode><br />
<br />
<context><br />
\setuppapersize[A6][A6]<br />
\setupbodyfont[8pt]<br />
\def\MyChapterCommand#1#2%<br />
{\vbox to 4cm\bgroup<br />
{#1\hskip.75em #2}<br />
\vss<br />
\egroup}<br />
\setuphead[chapter][header=nomarking,command=\MyChapterCommand]<br />
\starttext<br />
\chapter{test} \input tufte<br />
\stoptext<br />
</context><br />
<br />
===Section head with underlining to width of last line===<br />
<br />
A style called for section headings to be followed by a rule which extends only the width of the text. More tricky was the need to make sure that if the text ran onto another line, it was the length of the ''last'' line that was to be followed. <br />
<br />
Hans came up with this cleverness, showing two alternate ways of doing it:<br />
<br />
<context source="yes" text="produces"><br />
\def\FirstSolution#1#2%<br />
{\vbox\bgroup<br />
\setbox0\hbox{#1}<br />
\hsize.4\textwidth<br />
\beginshapebox#2\endshapebox<br />
\gdef\SetLastLineWidth{\xdef\LastLineWidth{\the\wd\scratchbox}}%<br />
\reshapebox<br />
{\setbox\scratchbox\hbox{\unhbox\shapebox}%<br />
\SetLastLineWidth<br />
\globallet\SetLastLineWidth\relax<br />
\box\scratchbox}%<br />
\scratchdimen\dimexpr\wd0+.25em+\LastLineWidth\relax<br />
% \setbox2\ruledvbox {\innerflushshapebox} <br />
% why is correction needed<br />
\setbox2\vbox {\vskip-\lineskip\innerflushshapebox}<br />
\setbox0\vbox to \ht2{\box0}<br />
\hbox{\box0\hskip.25em\box2}<br />
\offinterlineskip<br />
\vskip.25ex<br />
\blackrule[width=\scratchdimen,height=1pt]<br />
\egroup}<br />
<br />
\doglobal\newcounter\NextLinePos<br />
<br />
\def\SecondSolution#1#2%<br />
{\vbox\bgroup<br />
\hsize.4\textwidth<br />
\doglobal\increment\NextLinePos<br />
\setbox\scratchbox\hbox{#1}<br />
\hbox{\vtop{\copy\scratchbox}\hskip.25em\vtop{#2}}%<br />
\offinterlineskip<br />
\scratchdimen\dimexpr\wd\scratchbox+.25em+<br />
\MPx{e:npl:\NextLinePos}-\MPx{b:npl:\NextLinePos}\relax<br />
\vskip.25ex<br />
\blackrule[width=\scratchdimen,height=1pt]<br />
\egroup}<br />
<br />
\def\DoSecondSolution#1%<br />
{\bpos{npl:\NextLinePos}#1\epos{npl:\NextLinePos}}<br />
<br />
% \showstruts<br />
<br />
\setuphead[section][command=\FirstSolution]<br />
<br />
\starttext<br />
<br />
\section{is this nice or not}<br />
<br />
\section{is this nice or not nice, that's the question}<br />
<br />
\setuphead[section][command=\SecondSolution,deeptextcommand=\DoSecondSolution]<br />
<br />
\section{is this nice or not}<br />
<br />
\section{is this nice or not nice, that's the question}<br />
<br />
\stoptext<br />
</context><br />
<br />
As if that wasn't enough, Taco pointed out that <cmd>lastlinewidth</cmd><br />
is the easy route to finding the width of the last line. Use something like:<br />
<br />
<code><br />
\optimizedisplayspacingtrue\setlastlinewidth % core-mat macro<br />
\global\advance\lastlinewidth-\hangindent\par % adjust<br />
\blackrule[width=\lastlinewidth,height=1pt]<br />
</code><br />
<br />
=== Flushing section head data without typesetting them in the text ===<br />
<br />
The following is probably a very special case. Hoever suppose you need to place section information like the title e.g. in the topspace area. You want that the section is still displayed in the TOC, but you do not want that at the spot where <cmd>startsection[title=...,list=...]</cmd> resides there is any trace of it. The command to be used to hide the section title is:<br />
<br />
<texcode><br />
\setuphead<br />
[section]<br />
[placehead=hidden] <br />
</texcode><br />
<br />
Be aware that with this setting indeed the section title is not shown and no white space is inserted. However in this way also the list entry for the TOC is gone. What you can do in such cases is to use the following command in connection with the above mentioned setting:<br />
<br />
<texcode><br />
\setuptexttexts[{\placerawheaddata[section]} <br />
</texcode><br />
<br />
What happens is that the information in the <cmd>startsection[title=...,list=...]</cmd> command is passed to the texttexts, which are flushed at every page. In order to see when it is flushed you might place e.g. !!! in front of the <cmd>placerawheaddata[section]</cmd>.<br />
<br />
The result is a complete TOC without any trace of the section heading in the text.<br />
<br />
'''Test:'''<br />
<br />
<texcode><br />
\setuphead<br />
[section]<br />
[placehead=hidden,<br />
page=yes]<br />
<br />
\setuphead<br />
[subsection]<br />
[placehead=yes,<br />
page=yes,<br />
continue=yes,<br />
style=\it]<br />
<br />
\setuptexttexts[{\placerawheaddata[section]}]<br />
<br />
\starttext<br />
<br />
\placelist[section,subsection] \page<br />
<br />
\startsection[title=First section]<br />
<br />
\startsubsection[title=First subsection]<br />
Lorem ipsum \dots<br />
\stopsubsection<br />
<br />
\startsubsection[title=second subsection]<br />
Lorem ipsum \dots<br />
\stopsubsection<br />
<br />
\stopsection<br />
<br />
\startsection[title=Second section]<br />
<br />
\startsubsection[title=First subsection]<br />
Lorem ipsum \dots<br />
\stopsubsection<br />
<br />
\stopsection<br />
<br />
\stoptext<br />
<br />
</code> <br />
<br />
[[Category:Fonts]]<br />
[[Category:Graphics]]<br />
[[Category:Text elements]]</div>Willihttps://wiki.contextgarden.net/index.php?title=Titles&diff=13426Titles2011-10-17T21:13:55Z<p>Willi: </p>
<hr />
<div>< [[Structurals]] | [[Visuals]] ><br />
<br />
==Default==<br />
<br />
Titles define the structure of your document. Decide yourself, how deep you want to nest them:<br />
<br />
<table><br />
<tr bgcolor="#CCCCCC"><br />
<th>numbered</th><br />
<th>unnumbered</th><br />
</tr><br />
<tr><br />
<td><cmd>part</cmd><br />
</td><td>&#151;</td><br />
</tr><br />
<tr><br />
<td><cmd>chapter</cmd></td><br />
<td><cmd>title</cmd></td><br />
</tr><br />
<tr><br />
<td><cmd>section</cmd></td><br />
<td><cmd>subject</cmd></td><br />
</tr><br />
<tr><br />
<td><cmd>subsection</cmd></td><br />
<td><cmd>subsubject</cmd></td><br />
</tr><br />
<tr><br />
<td><cmd>subsubsection</cmd></td><br />
<td><cmd>subsubsubject</cmd></td><br />
</tr><br />
<tr><br />
<td>...</td><br />
<td>...</td><br />
</tr><br />
</table><br />
<br />
The ''unnumbered'' versions don't appear in a table of contents! But you can<br />
switch off the numbering of the ''numbered'' versions with <cmd>setuphead</cmd><br />
to get unnumbered titles ''and'' a toc (confusing?).<br />
<br />
Also note that in the front matter of the document, all titles are unnumbered<br />
by default. In this case, the only difference between the "numbered" and<br />
"unnumbered" titles is that the latter don't show up in the table of contents.<br />
<br />
===Referencing Titles===<br />
<br />
Every heading command can take an optional parameter as reference:<br />
<br />
<texcode><br />
\title[hasselt-by-night]{Hasselt by night}<br />
</texcode><br />
<br />
The bracket pair is optional and used for internal [[References]]. If you want<br />
to refer to this header you type for example<br />
<br />
<texcode><br />
\at{page}[hasselt-by-night].<br />
<br />
(see <cmd>at</cmd>)<br />
</texcode><br />
<br />
Note that reference labels are limited to ASCII characters in traditional TeX.<br />
This limitation has been removed in ConTeXt mkiv.<br />
<br />
==Titling Style==<br />
<br />
see <cmd>setuphead</cmd> and some enhanced samples below.<br />
<br />
A FAQ is, how to get a line under the pageheader:<br />
<br />
<texcode><br />
\setupbackgrounds[header][text][bottomframe=on]<br />
</texcode><br />
<br />
To make the section numbers appear as characters, do<br />
<br />
<texcode><br />
\setupsection[section-3][bodypartconversion=Character]<br />
</texcode><br />
<br />
The <code>section-3</code> corresponds to <code>section</code>. Similarly,<br />
<code>section-1</code> corresponds to <code>part</code>, <code>section-2</code><br />
corresponds to <code>chapter</code> and so on.<br />
<br />
==Titling Alignment==<br />
<br />
Titles should often be left aligned without hyphenation. Try this:<br />
<br />
<texcode><br />
\setuphead[chapter][align={flushleft, nothyphenated, verytolerant}] % "flushleft" is the same as "right"<br />
</texcode><br />
<br />
==Using colors in chapters and sections==<br />
<br />
If you want you may have colors on your document's chapters or sections.<br />
To do that you should use <cmd>setuphead</cmd>. Take a look at the following<br />
example:<br />
<br />
<texcode><br />
\setupcolors[state=start] % Important. You won't have colors without it.<br />
<br />
\setuphead[chapter][header=empty] % Chapter pages won't have headers<br />
<br />
\setupheadertexts[][chapter] % The header will be the chapter's name<br />
<br />
\starttext<br />
<br />
\completecontent<br />
<br />
\chapter{Black chapter 1}<br />
<br />
\setuphead[section][color=darkcyan] % This is how you change your chapter's color.<br />
<br />
\section{Dark cyan section 1.1}<br />
<br />
\page<br />
Test.<br />
<br />
\setuphead[chapter][color=darkgreen]<br />
<br />
\chapter{Dark green chapter}<br />
<br />
\page<br />
Test.<br />
<br />
\setuphead[chapter][color=red]<br />
<br />
\chapter{Red chapter}<br />
<br />
\page<br />
Test.<br />
<br />
\stoptext <br />
</texcode><br />
<br />
==Your Own Titling Levels==<br />
<br />
Of course you can define your own titling commands and probably must adapt the default settings.<br />
<br />
<texcode><br />
\definehead[myheader][section]<br />
<br />
\setuphead<br />
[myheader]<br />
[numberstyle=bold,<br />
textstyle=cap,<br />
before=\hairline\blank,<br />
after=\nowhitespace\hairline]<br />
<br />
\myheader[hasselt-ref]{Hasselt makes headlines}<br />
</texcode><br />
<br />
A new header <cmd>myheader</cmd> is defined and it inherits the properties<br />
of <cmd>section</cmd> (title, subject, whatever). You can ''define'' several<br />
headers at once!<br />
<br />
==Formatting Titles with <cmd>setuphead</cmd>==<br />
<br />
<cmd>setuphead</cmd> accepts a number of parameters which change the style of<br />
the heading. At least the following commands are available:<br />
<br />
<table><br />
<tr bgcolor="#CCCCCC"><br />
<th>text</th><br />
<th>number</th><br />
</tr><br />
<tr><br />
<td><tt>textstyle</tt></td><br />
<td><tt>numberstyle</tt></td><br />
</tr><br />
<tr><br />
<td><tt>textcommand</tt></td><br />
<td><tt>numbercommand</tt></td><br />
</tr><br />
<tr><br />
<td><tt>deeptextcommand</tt></td><br />
<td><tt>deepnumbercommand</tt></td><br />
</tr><br />
</table><br />
<br />
Quite obviously, the number-commands work on the chapter/section/etc. number,<br />
their text counterparts change the text itself. However, there are differences<br />
between <tt>style</tt>, <tt>command</tt> and <tt>deepcommand</tt>.<br />
<br />
The <tt>style</tt> variants accept a style (<tt>bold</tt>, <tt>cap</tt>, etc.)<br />
or a font switch (<cmd>em</cmd>, <cmd>tfx</cmd>, etc). <tt>textstyle</tt> prepends<br />
the text with the associated style. <tt>textcommand</tt> is a command name which<br />
is given the text (with all markup) as a parameter. <tt>deeptextcommand</tt> is<br />
similar to <tt>textcommand</tt> but it acts only on the text (not on the markup).<br />
<br />
So, if we have <cmd>title{A story}</cmd>, the different parameters have the following results:<br />
<br />
<table><br />
<tr><br />
<td><tt>textstyle=\em</tt></td><br />
<td><tt>=></tt></td><br />
<td><tt>\em A story</tt></td><br />
</tr><br />
<tr><br />
<td><tt>textstyle=\em, textcommand=\uppercase</tt></td><br />
<td><tt>=></tt></td><br />
<td><tt>\uppercase{\em A story}</tt></td><br />
<td><tt>=></tt></td><br />
<td><tt>\em A STORY</tt></td><br />
</tr><br />
<tr><br />
<td><tt>textstyle=\em, deeptextcommand=\uppercase</tt></td><br />
<td><tt>=></tt></td><br />
<td><tt>\em\uppercase{A story}</tt></td><br />
<td><tt>=></tt><br />
</td><td><tt>\em A STORY</tt></td><br />
</tr><br />
</table><br />
<br />
What is the difference between <tt>textcommand</tt> and <tt>deeptextcommand</tt>,<br />
then? With this example there is very little difference, as <tt>uppercase</tt><br />
knows how to handle markup. Sometimes this is not the case. For example, an almost<br />
similar command <tt>WORD</tt> is not compatible with <tt>textcommand</tt>, because<br />
it wreaks havoc with markup:<br />
<br />
<table><br />
<tr><br />
<td><tt>textstyle=\em, textcommand=\WORD</tt></td><br />
<td><tt>=></tt></td><br />
<td><tt>\WORD{\em A story}</tt></td><br />
<td><tt>=></tt></td><br />
<td><tt>\EM A STORY</tt></td><br />
</tr><br />
<tr><br />
<td><tt>textstyle=\em, deeptextcommand=\WORD</tt></td><br />
<td><tt>=></tt></td><br />
<td><tt>\em\WORD{A story}</tt></td><br />
<td><tt>=></tt></td><br />
<td><tt>\em A STORY</tt></td><br />
</tr><br />
</table><br />
<br />
In this case using <tt>deeptextcommand</tt> is the correct solution for capitalizing<br />
headers. (Using <cmd>uppercase</cmd> works in this specific case, but only if you stick<br />
to Latin 1 or Anglo-Saxon characters. Other languages will suffer from lowercase accented<br />
characters, like CAFé.)<br />
<br />
Use <cmd>setuphead</cmd><tt>[part][conversion=Romannumerals]</tt>, for example, to employ an<br />
alternative numbering scheme.<br />
<br />
=== Truly empty pagebreak before chapters ===<br />
<br />
Using <cmd>setuppagenumbering[alternative=doublesided]</cmd> makes the chapters start<br />
on the right page. However, the blank page is not truely empty, it contains headers and<br />
footers. To get truely empty pages, use the following<br />
<br />
<texcode><br />
\definepagebreak<br />
[mychapterpagebreak]<br />
[yes,header,right]<br />
%[yes,header,left]<br />
%[yes,header,footer,right]<br />
<br />
\setuphead<br />
[chapter]<br />
[page=mychapterpagebreak]<br />
%[page=Mychapterpagebreak,header=empty,footer=empty]<br />
<br />
%\setupsectionblock[frontpart][page=chapter]<br />
%\setupsectionblock[bodypart][page=chapter]<br />
%\setupsectionblock[backpart][page=chapter]<br />
%\setupsectionblock[appendix][page=chapter]<br />
<br />
\setuppagenumbering[alternative=doublesided,location={header,margin}]<br />
\setupheadertexts[{My special headertext}]<br />
\setupfootertexts[This is a text in the footer]<br />
%\setupbackgrounds[header][text][bottomframe=on]<br />
<br />
\starttext<br />
\chapter{testA} \dorecurse{10}{\input tufte }<br />
\chapter{testB} \dorecurse{10}{\input tufte }<br />
\chapter{testC} \dorecurse{10}{\input tufte }<br />
\stoptext<br />
</texcode><br />
<br />
'''Explanation''' (provided by Willi Egger on the mailing list)<br />
<br />
* You define a new pagebreak rule. It has the name <code>mychapterpagebreak</code>. The options set read as: <code>pagebreak=yes</code>, placeheader, use a right page.<br />
* You set options for the header of type chapter and use for the option page the afore defined new pagebreak.<br />
* You might want to experiment with the commented lines and see what happens. For example, the <cmd>setupsectionblock</cmd> commands will give a truly blank page (if needed) after the specified <cmd>stop*part</cmd> command.<br />
<br />
== Independent Section Numbering ==<br />
<br />
If you want section numbering to be independent of chapter numbering, use<br />
<br />
<texcode><br />
\setuphead [chapter][resetnumber=no]<br />
\setupsection[section][previousnumber=no]<br />
</texcode><br />
<br />
This is handled differently in mkiv (where "resetnumber=no" is silently ignored):<br />
<br />
<texcode><br />
\definestructureresetset[default][1,1,0][1] % reset part, chapter, but not section<br />
\setuphead[sectionresetset=default]<br />
</texcode><br />
<br />
==Unnumbered titles in table of contents==<br />
<br />
Sometimes one wants an unnumbered chapter, say introduction, the following might do that trick:<br />
<br />
<texcode><br />
\definehead [intro] [chapter]<br />
\setuphead [intro] [number=no]<br />
\definecombinedlist [content][intro,chapter,section]<br />
\setuplist [intro] [headnumber=no]<br />
<br />
\starttext<br />
\completecontent<br />
\startfrontmatter<br />
\intro{No number}<br />
\stopfrontmatter<br />
<br />
\startbodymatter<br />
\chapter{Has number}<br />
\stopbodymatter<br />
\stoptext<br />
</texcode><br />
<br />
<context><br />
\definehead [intro] [chapter]<br />
\setuphead [intro] [number=no]<br />
<br />
\definecombinedlist [content][intro,chapter,section]<br />
\setuplist [intro] [headnumber=no]<br />
<br />
\starttext<br />
\completecontent<br />
\startfrontmatter<br />
\intro{No number}<br />
\stopfrontmatter<br />
<br />
\startbodymatter<br />
\chapter{Has number}<br />
\stopbodymatter<br />
\stoptext<br />
</context><br />
<br />
Note that just putting the introduction in the frontmatter already did the trick for me (on a recent MkIV).<br />
<br />
==Your Own Title Styles==<br />
<br />
Sometimes the possibilities of <cmd>setuphead</cmd> aren't enough. You can define<br />
your own styling commands, as shown in the following examples.<br />
<br />
===Start the title in the margin===<br />
<br />
This very simple example shows how to start a title within the margin, rather than at the text's edge<br />
<br />
<texcode><br />
\setuphead[chapter][alternative=margin]<br />
</texcode><br />
<br />
This looks like<br />
<br />
<context><br />
\setuphead[chapter][alternative=margin]<br />
<br />
\chapter{Sample chapter}<br />
<br />
Number is in margin, not at text edge.<br />
</context><br />
<br />
===Chapter titles in new line===<br />
To have the chapter title simply in a new line a new command needs to be defined that takes care of this. It needs to be wrapped in <cmd>framed</cmd>.<br />
<br />
<texcode><br />
\setuplabeltext [en] [chapter=Chapter~]<br />
% Does not work, not wrapped in \framed<br />
% \def\MyChapter#1#2{#1\blank#2}<br />
\define[2]\MyChapter<br />
{\framed[frame=off,width=broad,align=flushleft]{#1\\#2}}<br />
\setuphead [chapter] [command=\MyChapter]<br />
\startchapter [title=Foo Bar]<br />
\stopchapter<br />
</texcode><br />
<br />
This looks like<br />
<br />
<context><br />
\setuplabeltext [en] [chapter=Chapter~]<br />
\define[2]\MyChapter<br />
{\framed[frame=off,width=broad,align=flushleft]{#1\\#2}}<br />
\setuphead [chapter] [command=\MyChapter]<br />
\chapter{Foo Bar}<br />
</context><br />
<br />
===Expanded chapter titles===<br />
<br />
This example illustrates expanded chapter titles.<br />
<br />
<texcode><br />
\def\MyChapterCommand#1#2% #1 is number, #2 is text<br />
{\framed[frame=off,bottomframe=on,topframe=on]<br />
{\vbox{\headtext{chapter} #1\blank#2}}} % \vbox is needed for \blank to work<br />
<br />
\setuphead[chapter][command=\MyChapterCommand, style={\ss\bfa}]<br />
<br />
\setupheadtext[chapter=Chapter] % used by \headtext<br />
</texcode><br />
<br />
so <tt>\chapter{My First Chapter}</tt> looks like:<br />
<br />
<context><br />
\def\MyChapterCommand#1#2%<br />
{\framed[frame=off,bottomframe=on,topframe=on]<br />
{\vbox{\headtext{chapter} #1\blank#2}}}<br />
<br />
\setuphead[chapter][command=\MyChapterCommand, style={\ss\bfa}]<br />
\setupheadtext[chapter=Chapter]<br />
<br />
\chapter{My First Chapter}<br />
</context><br />
<br />
===Exercise numbers===<br />
<br />
For a textbook, suppose that you collect the exercises in a section at the end<br />
of each chapter, with each exercise a subsection having a short title, and the<br />
exercises should be numbered only by the subsection (not 1.6.7 for example,<br />
just 7). The usage:<br />
<br />
<texcode><br />
\section{Exercises}<br />
<br />
\exercise{Batteries}<br />
What is the cost of energy from a 9V battery? From a wall socket (the mains)?<br />
</texcode><br />
<br />
The setup code:<br />
<texcode><br />
\definehead[exercise][subsection]<br />
<br />
\setuphead<br />
[exercise]<br />
[style=italic, <br />
numbercommand={\determineheadnumber[subsection]\currentheadnumber\gobbleoneargument}]<br />
</texcode><br />
<br />
===A complex graphical element under the chapter title===<br />
<br />
<texcode><br />
\setupcolors[state=start]<br />
\startuseMPgraphic{HeaderDeco}<br />
numeric w, h, repeats;<br />
path p[];<br />
w := OverlayWidth ; h := OverlayHeight ;<br />
repeats := abs(TextWidth/BodyFontSize);<br />
p[1] := unitsquare xscaled w yscaled h ;<br />
draw p[1] withcolor white;<br />
p[2] := fullcircle scaled BodyFontSize;<br />
p[3] := fullcircle scaled .25BodyFontSize;<br />
draw p[2] shifted (.5BodyFontSize,0);<br />
for i = 1 upto repeats:<br />
if odd i :<br />
filldraw p[3] shifted (i*BodyFontSize+.5BodyFontSize,0);<br />
else :<br />
draw p[2] shifted (i*BodyFontSize+.5BodyFontSize,0);<br />
fi;<br />
endfor;<br />
\stopuseMPgraphic<br />
<br />
\setuphead[chapter][command=\Myheader]<br />
\setupheadtext[chapter=Chapitre]<br />
\defineoverlay[HeaderDeco][\uniqueMPgraphic{HeaderDeco}]<br />
<br />
\def\Myheader#1#2{%<br />
\framedtext<br />
[width= \overlaywidth,<br />
height=6\bodyfontsize,<br />
background={foreground,HeaderDeco},<br />
offset=0pt,<br />
strut=no,<br />
frame=off,<br />
align=middle]{%<br />
\headtext{chapter} #1<br />
\blank[small]<br />
#2}}<br />
<br />
\starttext<br />
\chapter{Here we go!}<br />
\stoptext<br />
</texcode><br />
<br />
It looks like:<br />
<br />
<context><br />
\setupcolors[state=start]<br />
\startuseMPgraphic{HeaderDeco}<br />
numeric w, h, repeats;<br />
path p[];<br />
w := OverlayWidth ; h := OverlayHeight ;<br />
repeats := abs(TextWidth/BodyFontSize);<br />
p[1] := unitsquare xscaled w yscaled h ;<br />
draw p[1] withcolor white;<br />
p[2] := fullcircle scaled BodyFontSize;<br />
p[3] := fullcircle scaled .25BodyFontSize;<br />
draw p[2] shifted (.5BodyFontSize,0);<br />
for i = 1 upto repeats:<br />
if odd i :<br />
filldraw p[3] shifted (i*BodyFontSize+.5BodyFontSize,0);<br />
else :<br />
draw p[2] shifted (i*BodyFontSize+.5BodyFontSize,0);<br />
fi;<br />
endfor;<br />
\stopuseMPgraphic<br />
<br />
\setuphead[chapter][command=\Myheader]<br />
\setupheadtext<br />
[chapter=Chapitre]<br />
\defineoverlay[HeaderDeco][\uniqueMPgraphic{HeaderDeco}]<br />
<br />
\def\Myheader#1#2{%<br />
\framedtext<br />
[width= \overlaywidth,<br />
height=6\bodyfontsize,<br />
background={foreground,HeaderDeco},<br />
offset=0pt,<br />
strut=no,<br />
frame=off,<br />
align=middle]{%<br />
\headtext{chapter} #1<br />
\blank[small]<br />
#2}}<br />
<br />
\starttext<br />
\chapter{Here we go!}<br />
\stoptext<br />
</context><br />
<br />
===Titles in margin===<br />
<br />
It is sometimes wanted to place the title of a section/subject etc in the margin next to the section text (instead of above it).<br />
This is achieved by the following setup:<br />
<br />
<texcode><br />
\setuphead<br />
[subject]<br />
[alternative=text,distance=0pt,command=\MyHead]<br />
<br />
\def\MyHead#1#2{\inmargin{#1 #2}}<br />
</texcode><br />
<br />
This (with 'style=\sc' added in setuphead) gives:<br />
<br />
<context><br />
\setuphead<br />
[subject]<br />
[alternative=text,distance=0pt,command=\MyHead,style=\sc]<br />
<br />
\def\MyHead#1#2{\inmargin{#1 #2}}<br />
<br />
\starttext<br />
<br />
\subject{First Subject}<br />
This is the text in the first subject. This is the text in the first subject.<br />
This is the text in the first subject. This is the text in the first subject.<br />
This is the text in the first subject. This is the text in the first subject.<br />
This is the text in the first subject. This is the text in the first subject.<br />
<br />
\subject{Second Subject}<br />
This is the text in the second subject. This is the text in the second subject.<br />
This is the text in the second subject. This is the text in the second subject. <br />
This is the text in the second subject. This is the text in the second subject. <br />
This is the text in the second subject. This is the text in the second subject. <br />
<br />
\stoptext<br />
</context><br />
<br />
See the mailing list thread [[http://www.ntg.nl/pipermail/ntg-context/2003/002053.html]] for more on this.<br />
<br />
===Headings numbered independent of chapters or other headings===<br />
<br />
If you want a heading that gets numbered without resetting at new sections or chapters (for example, for problems whose numbers increment throughout a book), here is a solution due to Hans [http://archive.contextgarden.net/message/20030415.153451.374310d8.en.html on the mailing list]:<br />
<br />
<texcode><br />
% use a lower level head<br />
<br />
\definehead<br />
[Problem]<br />
[subsubsubsection]<br />
<br />
% cleaned up<br />
<br />
\setuphead<br />
[Problem]<br />
[style=\ss\bf,<br />
color=red,<br />
before=\blank]<br />
<br />
% use a label text<br />
<br />
\setuplabeltext<br />
[Problem=Problem ]<br />
<br />
% use your own numbers<br />
<br />
\setuphead<br />
[Problem]<br />
[ownnumber=yes]<br />
<br />
% increment and feed<br />
<br />
\newcounter\ProblemNumber<br />
<br />
\def\problem#1%<br />
{\doglobal\increment\ProblemNumber<br />
\Problem{\ProblemNumber}{#1}}<br />
<br />
% nicer here<br />
<br />
\setuplist<br />
[Problem]<br />
[alternative=c,<br />
criterium=all,<br />
width=2em,<br />
interaction=all]<br />
<br />
% the test<br />
<br />
\starttext<br />
<br />
List of Problems<br />
<br />
\blank[big] \placelist[Problem] \blank[big]<br />
<br />
\section{Tufte}<br />
<br />
\input tufte<br />
<br />
\problem{First problem}<br />
<br />
The first problem description.<br />
<br />
\section{Another Tufte}<br />
<br />
\input tufte<br />
<br />
\problem{Second problem}<br />
<br />
Second problem description.<br />
<br />
\stoptext<br />
</texcode><br />
<br />
===Chapter headers===<br />
<br />
Setup of headers like chapters.<br />
<br />
While reading Pixar docs about Renderman, I've found their headers nice and wanted to copy this style.<br />
I found a premise in Metafun manual, p.187 (Hello text), and Hans email me ([http://archive.contextgarden.net/message/20041020.100630.d531bb1d.en.html 20/10/2004 ]) on the context list a more simple solution than using metapost. The minimum is to put it here, for others who are like me, wandering for source code.<br />
Feel free to adapt code below to your langage specific settings, mine is french.<br />
<br />
<texcode><br />
\useencoding[ffr]<br />
\mainlanguage[fr]<br />
\enableregime[utf] %for UTF8<br />
<br />
% \enableregime[il1] %for ISO 8859-1 8859-15<br />
<br />
\usetypescript[palatino][texnansi]<br />
\setupbodyfont[palatino,rm,12pt]<br />
<br />
\setupcolors[state=start]<br />
<br />
\definefont[BigFontOne][Regular sa 3] %RegularSlanted sa 3(ori)%Sans sa 3:don't work (pb accents)<br />
\definefont[BigFontTwo][RegularBold sa 2] %%RegularSlanted<br />
<br />
\definecolor[BigColorOne][r=.86,g=.850,b=.54]<br />
\definecolor[BigColorTwo][r=.43,g=.425,b=.27]<br />
<br />
\setuphead<br />
[chapter]<br />
[deeptextcommand=\MyChapterText,<br />
color=BigColorTwo,<br />
style=\BigFontTwo]<br />
<br />
\def\MyChapterText#1{\rlap{\BigFontOne\BigColorOne#1}\kern15pt#1}<br />
<br />
\starttext<br />
<br />
\chapter[chap:ques]{Question}<br />
\chapter[chap:answ]{Answer}<br />
\chapter[chap:answ]{Remarque}<br />
\chapter[chap:answ]{Cours}<br />
\chapter[chap:answ]{Exercice}<br />
\chapter[chap:answ]{Travail dirigé}<br />
\chapter[chap:answ]{Exposé}<br />
\stoptext<br />
</texcode><br />
<br />
I've tryed to change a bit Hans code, by putting \kern15pt, for moving backgroundtext to the left of \rlap alignment, and an unsuccess one to switch same backgroundtext in Sans font (no french accents).<br />
<br />
olivier<br />
<br />
<context><br />
\useencoding[ffr]<br />
\mainlanguage[fr]<br />
<br />
% fonts currently don't work this way,<br />
% I'll fix that soon. Patrick<br />
<br />
% \usetypescript[palatino][texnansi]<br />
% \setupbodyfont[palatino,rm,12pt]<br />
<br />
\setupcolors[state=start]<br />
<br />
\definefont[BigFontOne][Regular sa 3] %RegularSlanted sa 3(ori)%Sans sa 3:don't work (pb accents)<br />
\definefont[BigFontTwo][RegularBold sa 2] %%RegularSlanted<br />
<br />
\definecolor[BigColorOne][r=.86,g=.850,b=.54]<br />
\definecolor[BigColorTwo][r=.43,g=.425,b=.27]<br />
<br />
\setuphead<br />
[chapter]<br />
[textcommand=\MyChapterText,<br />
color=BigColorTwo,<br />
style=\BigFontTwo]<br />
<br />
\def\MyChapterText#1{\rlap{\BigFontOne\BigColorOne#1}\kern15pt#1}<br />
<br />
\starttext<br />
<br />
\chapter[chap:ques]{Question}<br />
<br />
% only one page please, since this is displayed inline. Patrick<br />
% \chapter[chap:answ]{Answer}<br />
% \chapter[chap:answ]{Remarque}<br />
% \chapter[chap:answ]{Cours}<br />
% \chapter[chap:answ]{Exercice}<br />
% \chapter[chap:answ]{Travail dirigé}<br />
% \chapter[chap:answ]{Exposé}<br />
\stoptext<br />
</context><br />
<br />
===Figures in Headings===<br />
<br />
This example shows how to completely replace the chapter text and number by an image:<br />
<br />
<context source="yes"><br />
\setupexternalfigures[location=default] % needed only for the wiki to the find the figure<br />
<br />
\useexternalfigure[chapter-1][cow.pdf]<br />
\useexternalfigure[chapter-2][hacker.jpg]<br />
<br />
\setuphead<br />
[chapter]<br />
[command=\MyChapterCommand]<br />
<br />
\def\MyChapterCommand#1#2%<br />
{\externalfigure[chapter-\currentheadnumber][height=5cm]}<br />
<br />
\starttext<br />
<br />
\chapter{One}<br />
\section{First section of Chapter One}<br />
\chapter{Two}<br />
<br />
\stoptext<br />
</context><br />
<br />
There are a few snags though. MkII "forgets" to put the chapter in the<br />
TOC. So you have to set the <tt>deeptextcommand</tt> and<br />
<tt>deepnumbercommand</tt> separately instead (thus retaining the<br />
command that puts the chapter in the TOC), rather than setting the<br />
overall <tt>command</tt>, if you need a complete TOC.<br />
<br />
<texcode><br />
\setuphead<br />
[chapter]<br />
[deeptextcommand=\MyChapterTextCommand,<br />
deepnumbercommand=\gobbleoneargument] % hide chapter number<br />
<br />
\def\MyChapterTextCommand#1%<br />
{\externalfigure[chapter-\currentheadnumber][height=5cm]}<br />
</texcode><br />
<br />
[http://archive.contextgarden.net/message/20050519.215526.df7c5cd1.html]<br />
<br />
Users of MkIV can safely rely on <tt>command</tt> and don't have to<br />
bother with the <tt>deep...command</tt> variants. However,<br />
<tt>\currentheadnumber</tt> does not seem to return anything but 0.<br />
Thus, the following code is required to define<br />
<tt>\MyChapterCommand</tt> when using MkIV:<br />
<br />
<texcode><br />
\def\MyChapterCommand#1#2%<br />
{\externalfigure[chapter-\namedheadnumber{chapter}][height=5cm]}<br />
</texcode><br />
<br />
[http://archive.contextgarden.net/message/20100817.102859.206d858e.en.html]<br />
<br />
===Chapter head with absolute positioning of following text===<br />
<br />
<texcode><br />
\setuphead[chapter][before=\vbox to 4cm\bgroup,after=\vss\egroup]<br />
\starttext<br />
\chapter{test} \input tufte<br />
\stoptext<br />
</texcode><br />
<br />
No matter how many lines the chapter head runs to, the text will always start, e.g. 4cm below the top of the heading:<br />
<br />
<context><br />
\setuppapersize[A6][A6]<br />
\setuphead[chapter][before=\vbox to 4cm\bgroup,after=\vss\egroup]<br />
\setupbodyfont[8pt]<br />
\starttext<br />
\chapter{test} \input tufte<br />
\stoptext<br />
</context><br />
<br />
====Bug and proposed workaround====<br />
<br />
I tried this sample and <cmd>getmarking[chapter]</cmd>, used in my headers,<br />
stopped to work properly. Proposed workaround below.<br />
--[[User:Sebastian.rooks|SeR]] 00:52, 27 January 2006 (CET)<br />
<br />
<texcode><br />
\def\MyChapterCommand#1#2%<br />
{\vbox to 4cm\bgroup<br />
{#1\hskip.75em #2}<br />
\vss<br />
\egroup}<br />
<br />
\setuphead[chapter][header=nomarking,command=\MyChapterCommand]<br />
\starttext<br />
\chapter{test} \input tufte<br />
\stoptext<br />
</texcode><br />
<br />
<context><br />
\setuppapersize[A6][A6]<br />
\setupbodyfont[8pt]<br />
\def\MyChapterCommand#1#2%<br />
{\vbox to 4cm\bgroup<br />
{#1\hskip.75em #2}<br />
\vss<br />
\egroup}<br />
\setuphead[chapter][header=nomarking,command=\MyChapterCommand]<br />
\starttext<br />
\chapter{test} \input tufte<br />
\stoptext<br />
</context><br />
<br />
===Section head with underlining to width of last line===<br />
<br />
A style called for section headings to be followed by a rule which extends only the width of the text. More tricky was the need to make sure that if the text ran onto another line, it was the length of the ''last'' line that was to be followed. <br />
<br />
Hans came up with this cleverness, showing two alternate ways of doing it:<br />
<br />
<context source="yes" text="produces"><br />
\def\FirstSolution#1#2%<br />
{\vbox\bgroup<br />
\setbox0\hbox{#1}<br />
\hsize.4\textwidth<br />
\beginshapebox#2\endshapebox<br />
\gdef\SetLastLineWidth{\xdef\LastLineWidth{\the\wd\scratchbox}}%<br />
\reshapebox<br />
{\setbox\scratchbox\hbox{\unhbox\shapebox}%<br />
\SetLastLineWidth<br />
\globallet\SetLastLineWidth\relax<br />
\box\scratchbox}%<br />
\scratchdimen\dimexpr\wd0+.25em+\LastLineWidth\relax<br />
% \setbox2\ruledvbox {\innerflushshapebox} <br />
% why is correction needed<br />
\setbox2\vbox {\vskip-\lineskip\innerflushshapebox}<br />
\setbox0\vbox to \ht2{\box0}<br />
\hbox{\box0\hskip.25em\box2}<br />
\offinterlineskip<br />
\vskip.25ex<br />
\blackrule[width=\scratchdimen,height=1pt]<br />
\egroup}<br />
<br />
\doglobal\newcounter\NextLinePos<br />
<br />
\def\SecondSolution#1#2%<br />
{\vbox\bgroup<br />
\hsize.4\textwidth<br />
\doglobal\increment\NextLinePos<br />
\setbox\scratchbox\hbox{#1}<br />
\hbox{\vtop{\copy\scratchbox}\hskip.25em\vtop{#2}}%<br />
\offinterlineskip<br />
\scratchdimen\dimexpr\wd\scratchbox+.25em+<br />
\MPx{e:npl:\NextLinePos}-\MPx{b:npl:\NextLinePos}\relax<br />
\vskip.25ex<br />
\blackrule[width=\scratchdimen,height=1pt]<br />
\egroup}<br />
<br />
\def\DoSecondSolution#1%<br />
{\bpos{npl:\NextLinePos}#1\epos{npl:\NextLinePos}}<br />
<br />
% \showstruts<br />
<br />
\setuphead[section][command=\FirstSolution]<br />
<br />
\starttext<br />
<br />
\section{is this nice or not}<br />
<br />
\section{is this nice or not nice, that's the question}<br />
<br />
\setuphead[section][command=\SecondSolution,deeptextcommand=\DoSecondSolution]<br />
<br />
\section{is this nice or not}<br />
<br />
\section{is this nice or not nice, that's the question}<br />
<br />
\stoptext<br />
</context><br />
<br />
As if that wasn't enough, Taco pointed out that <cmd>lastlinewidth</cmd><br />
is the easy route to finding the width of the last line. Use something like:<br />
<br />
<code><br />
\optimizedisplayspacingtrue\setlastlinewidth % core-mat macro<br />
\global\advance\lastlinewidth-\hangindent\par % adjust<br />
\blackrule[width=\lastlinewidth,height=1pt]<br />
</code><br />
<br />
=== Flushing section head data without typesetting them in the text ===<br />
<br />
The following is probably a very special case. Hoever suppose you need to place section information like the title e.g. in the topspace area. You want that the section is still displayed in the TOC, but you do not want that at the spot where <cmd>\startsection[title=...,list=...]</cmd> resides there is any trace of it. The command to be used to hide the section title is:<br />
<br />
<context><br />
\setuphead<br />
[section]<br />
[placehead=hidden] <br />
</context><br />
<br />
Be aware that with this setting indeed the section title is not shown and no whit space is inserted. However in this way also the list entry for the TOC is gone. What you can do in such cases is to use the following command in connection with the above mentioned setting:<br />
<br />
<context><br />
\setuptexttexts[{\placerawheaddata[section]} <br />
</context><br />
<br />
What happens is that the information in the <cmd>\startsection[title=...,list=...]</cmd> command is passed to the texttexts, which are flushed at every page. In order to see when it is flushed you might place e.g. !!! in front of the <cmd>\placerawheaddata[section]</cmd>.<br />
<br />
The result is a complete TOC without any trace of the section heading in the text.<br />
<br />
'''Test:'''<br />
<br />
<context><br />
\setuphead<br />
[section]<br />
[placehead=hidden,<br />
page=yes]<br />
<br />
\setuphead<br />
[subsection]<br />
[placehead=yes,<br />
page=yes,<br />
continue=yes,<br />
style=\it]<br />
<br />
\setuptexttexts[{\placerawheaddata[section]}]<br />
<br />
\starttext<br />
<br />
\placelist[section,subsection] \page<br />
<br />
\startsection[title=First section]<br />
<br />
\startsubsection[title=First subsection]<br />
Lorem ipsum \dots<br />
\stopsubsection<br />
<br />
\startsubsection[title=second subsection]<br />
Lorem ipsum \dots<br />
\stopsubsection<br />
<br />
\stopsection<br />
<br />
\startsection[title=Second section]<br />
<br />
\startsubsection[title=First subsection]<br />
Lorem ipsum \dots<br />
\stopsubsection<br />
<br />
\stopsection<br />
<br />
\stoptext<br />
<br />
</context> <br />
<br />
[[Category:Fonts]]<br />
[[Category:Graphics]]<br />
[[Category:Text elements]]</div>Willihttps://wiki.contextgarden.net/index.php?title=Tabulate&diff=13289Tabulate2011-08-04T13:30:16Z<p>Willi: There is a conflict between penalties and the snapping mechanism inside tabulate. This can be solved with the command \tabulatesplitlinemode \plustwo in the preamble</p>
<hr />
<div>< [[Tables Overview]] | [[Table]] ><br />
<br />
<br />
=Summary=<br />
<br />
[[cmd:starttabulate|Tabulate]] is a versatile table environment.<br />
It supports ''paragraphs'' in cells, ''vertical rules'' (for<br />
those typographically less demanding jobs&nbsp;…), and<br />
''colorization'' of those rules, the background of fields as well<br />
as the text itself.<br />
<br />
'''Warning''': When you want to use tables with macros use \starttable and \stoptable. \starttabulate and \stoptabulate does not work correctly with macros.<br />
<br />
=Basic commands=<br />
<br />
The control sequence <tt>\starttabulate[#1]</tt> takes a layout<br />
string as optional argument.<br />
As is common with tables in TeX-based typesetting, this string<br />
(in its basic variant) consists primarily of the ''bar''<br />
character (“<tt>|</tt>”) as delimiter for columns,<br />
and of the letters <tt>c</tt>, <tt>l</tt>, as well as <tt>r</tt>,<br />
denoting the ''alignment'' within cells of this row.<br />
<br />
For instance consider a two-column table: if any text in the<br />
first column should be right aligned (''real''<br />
[[right and left|<tt>flushright</tt>]]) and the second column<br />
left aligned, the corresponding format string would be<br />
<tt>|l|r|</tt>.<br />
''NB'': those bars, as stated above, denote cell limits only<br />
&ndash; ''not'' vertical lines.<br />
<br />
<!--<br />
- wtf this listing was full of <tab> chars‽ Was this supposed<br />
- to be a bad pun on *tabulate*?<br />
--><br />
{|<br />
! width="55%"|<br />
! width="10%"|<br />
! width="35%"|<br />
|-<br />
| <texcode><br />
\starttabulate[|r|l|]<br />
\HL<br />
\NC {\bf format} \NC {\bf meaning} \NC\NR<br />
\HL<br />
\NC c \NC centered \NC\NR<br />
\NC l \NC left aligned \NC\NR<br />
\NC r \NC right aligned \NC\NR<br />
\NC w(1cm) \NC one line, fixed width \NC\NR<br />
\NC p(2cm) \NC paragraph, lines broken to fixed width \NC\NR<br />
\NC cg(.) \NC align on a character \NC\NR<br />
\HL<br />
\stoptabulate<br />
</texcode><br />
|<br />
|<context><br />
\starttabulate[|r|l|]<br />
\HL<br />
\NC {\bf format} \NC {\bf meaning} \NC\NR<br />
\HL<br />
\NC c \NC centered \NC\NR<br />
\NC l \NC left aligned \NC\NR<br />
\NC r \NC right aligned \NC\NR<br />
\NC w(1cm) \NC one line, fixed width \NC\NR<br />
\NC p(2cm) \NC paragraph, lines broken to fixed width \NC\NR<br />
\NC cg(.) \NC align on a character \NC\NR<br />
\HL<br />
\stoptabulate<br />
</context><br />
|}<br />
<br />
* <tt>HL</tt> draws a horizontal rule,<br />
* <tt>NC</tt> marks a new column (or new cell),<br />
* <tt>NR</tt> starts new row.<br />
<br />
<br />
When using fixed width, you can use values relative to the<br />
current page-width. For example: if you want the previous table<br />
take up all the width and having the second column taking three<br />
quarters of the space, change the starttabulate to:<br />
<br />
\starttabulate[|rw(.25\textwidth)|lw(.75\textwidth)|]<br />
<br />
<br />
It is generally not necessary to conclude lines with<br />
<tt>\NC\NR</tt> as <tt>\AR</tt> (for <em>a</em>uto<em>r</em>ow)<br />
will do the job as well.<br />
<br />
=Spanning Multiple Pages=<br />
<br />
Tabulate may extend to adjacient pages if needed.<br />
To achieve this the argument <tt>split</tt> must be set to<br />
''true''.<br />
''NB'': the difference between setting and unsetting this<br />
argument may not be visible on the first few pages. Rather, it<br />
seems to affect the ''end'' of the environment.<br />
<br />
<context source="yes"><br />
\setuppapersize [XY][A4]<br />
\setuppaper [nx=2,ny=2]<br />
\setuparranging [XY]<br />
\setupbodyfont[10pt]<br />
<br />
\starttext<br />
<br />
\setuptabulate[split=yes]<br />
<br />
\starttabulate<br />
\dorecurse{2}{<br />
\NC test \NC \input tufte \relax \NC \NR <br />
\NC test \NC \input dawkins \relax \NC \NR <br />
}<br />
\stoptabulate<br />
<br />
\stoptext \endinput<br />
</context><br />
<br />
==Titles==<br />
<br />
A tabulating environment can have an optional name which will be<br />
repeated above at every page break that occurs inside the table.<br />
This name needs to be specified as the argument of the<br />
<tt>title</tt> key of <tt>\setuptabulate</tt>.<br />
The <tt>header</tt> key has to be set to <em>text</em> for this<br />
to work.<br />
<br />
<texcode><br />
\setuptabulate[split=yes,header=text,title={\sc Table Titles Undisclosed!}]<br />
<br />
\starttabulate<br />
\dorecurse{2}{<br />
\NC Ed Tufte \NC \input tufte \relax \NC \NR<br />
\NC Dick Dawkins \NC \input dawkins \relax \NC \NR<br />
}<br />
</texcode><br />
<br />
<context><br />
\setuppapersize [XY][A4]<br />
\setuppaper [nx=2,ny=2]<br />
\setuparranging [XY]<br />
<br />
\starttext<br />
<br />
\setuptabulate[split=yes,header=text,title={\sc Table Titles Undisclosed!}]<br />
<br />
\starttabulate<br />
\dorecurse{2}{<br />
\NC Ed Tufte \NC \input tufte \relax \NC \NR <br />
\NC Dick Dawkins \NC \input dawkins \relax \NC \NR<br />
}<br />
\stoptabulate<br />
<br />
\stoptext \endinput<br />
</context><br />
<br />
<!--<br />
- ==Headers and Footers==<br />
- As I couldn’t get footers running I just comment this and<br />
- leave it to whoever discovers the trick to activate them.<br />
- (The <tt>footer=</tt> key seems to be implemented for<br />
- “\setuptabulate” but I couldn’t notice any effect.<br />
--><br />
==Headers==<br />
Tabulate supports header rows that can be repeated over new table<br />
pages instead of the title.<br />
There is a separate environment <tt>\starttablehead</tt> where<br />
this header row has to be specified in advance of its use in a<br />
tabulation.<br />
<br />
{|<br />
! width="55%"|<br />
! width="10%"|<br />
! width="35%"|<br />
|-<br />
| <texcode><br />
\setuptabulate[split=yes,header=repeat]<br />
<br />
\starttabulatehead<br />
\HL<br />
\NC {\bf format char} \NC {\bf meaning} \AR<br />
\HL<br />
\stoptabulatehead<br />
<br />
\starttabulate[|r|l|]<br />
\NC c \NC centered \AR<br />
\NC l \NC left aligned \AR<br />
\NC r \NC right aligned \AR<br />
\stoptabulate<br />
</texcode><br />
|<br />
| <context><br />
\setuptabulate[split=yes,header=repeat]<br />
<br />
\starttabulatehead<br />
\HL<br />
\NC {\bf format char} \NC {\bf meaning} \AR<br />
\HL<br />
\stoptabulatehead<br />
<br />
\starttabulate[|r|l|]<br />
\NC c \NC centered \AR<br />
\NC l \NC left aligned \AR<br />
\NC r \NC right aligned \AR<br />
\stoptabulate<br />
</context><br />
|}<br />
<br />
=Individualizing the Tabulate Look=<br />
<br />
Hans initially announced support for vertical lines and colors on<br />
the mailing list.[http://archive.contextgarden.net/message/20101117.123950.739657a7.en.html]<br />
<br />
==Rules==<br />
<br />
===Horizontal Rules===<br />
<br />
As already demonstrated above, the <tt>\HL</tt> statement inserts<br />
a hairline after the current line.<br />
This particularly useful when demarking header and footer rows or<br />
separated parts of a table that should not be as closely<br />
associated as the rows between the rules.<br />
<br />
{|<br />
! width="55%"|<br />
! width="10%"|<br />
! width="35%"|<br />
|-<br />
| <texcode><br />
\starttabulate[|r|c|l|] <br />
\NC test \NC test \NC test \NC\NR <br />
\HL<br />
\NC test \NC test \NC test \NC\NR <br />
\NC test \NC test \NC test \NC\NR <br />
\HL<br />
\NC test \NC test \NC test \NC\NR <br />
\HL<br />
\stoptabulate<br />
</texcode><br />
| <context><br />
\starttabulate[|r|c|l|] <br />
\NC test \NC test \NC test \NC\NR <br />
\HL<br />
\NC test \NC test \NC test \NC\NR <br />
\NC test \NC test \NC test \NC\NR <br />
\HL<br />
\NC test \NC test \NC test \NC\NR <br />
\HL<br />
\stoptabulate<br />
</context><br />
|}<br />
<br />
Context supports different categories of rules that can be<br />
configured individually in order to discern various applications.<br />
Their behaviour accounts for the designated use, e.&nbsp;g.<br />
<tt>\ML</tt> (mid rules) are intended to be deployed between<br />
ordinary rows of the table body and will prevent page breaks<br />
&ndash; no way you’d end up with a rogue hairline desecrating<br />
the bottom of your page’s text area.<br />
{|cellpadding="10" style="border:2px solid #addeff"<br />
! style="background:#addeff;" | Type !! Description<br />
|-<br />
|<tt>\HL</tt> || standard horizontal rule;<br />
|-<br />
|<tt>\FL</tt> || first rule;<br />
|-<br />
|<tt>\ML</tt> || mid rule;<br />
|-<br />
|<tt>\LL</tt> || bottom rule;<br />
|-<br />
|<tt>\LL</tt> and <tt>\TL</tt> || bottom rule;<br />
|-<br />
|<tt>\BL</tt> || last rule.<br />
|}<br />
<br />
Additionally, there is an options <tt>rulecolor</tt> for<br />
<tt>\setuptabulate</tt> that allows for those rules to be tinted.<br />
<br />
<texcode><br />
\setuptabulate[rulecolor=red]<br />
<br />
\starttabulate[|r|c|l|] <br />
\FL<br />
\NC first row \NC test \NC test \NC\NR <br />
\ML<br />
\NC rows in \NC test \NC test \NC\NR <br />
\NC between \NC test \NC test \NC\NR <br />
\LL <br />
\NC last row \NC test \NC test \NC\NR <br />
\BL<br />
\stoptabulate<br />
</texcode><br />
<br />
Other types can be discovered in the source<br />
([[source:tabl-tbl.mkiv|tabl-tbl.mkiv]]).<br />
<br />
===Vertical Rules===<br />
<br />
The <tt>\VL</tt> command serves as a replacement for <tt>\NC</tt><br />
to mark a cell border wherever a vertical rule may be desired (if<br />
they are to be desired at all from a typographical point of<br />
view).<br />
<br />
<texcode><br />
\starttabulate[||||] <br />
\NC test \VL test \VL test \VL\NR <br />
\VL test \NC test \VL test \VL\NR <br />
\VL test \VL test \NC test \VL\NR <br />
\VL test \VL test \VL test \NC\NR <br />
\stoptabulate<br />
</texcode><br />
<br />
==Coloring==<br />
<br />
The following elements can be colorized: rules, cell backgrounds,<br />
and, obviously, common text.<br />
<br />
===Colorizing Rules===<br />
<br />
For ''horizontal rules'' see above.<br />
<br />
For ''vertical rules'', <tt>\VL</tt> takes a defined color as an<br />
optional argument.<br />
<br />
<texcode><br />
\starttabulate[|r|c|l|] <br />
\VL test \VL[red] red rule \VL test \VL \NR <br />
\VL test \VL[green] green rule \VL test \VL \NR <br />
\VL test \VL[blue] blue rule \VL test \VL \NR <br />
\stoptabulate<br />
</texcode><br />
<br />
===Colorizing Backgrounds===<br />
''Backgrounds'' can be colorized either on column basis or<br />
individually by cell.<br />
<br />
There are four color-specific control sequences:<br />
{|<br />
|<tt>CR</tt> || color is applied to the background of the text and the remaining space on the right;<br />
|-<br />
|<tt>CC</tt> || color is applied to the background of the text only; <br />
|-<br />
|<tt>CM</tt> || color is applied to the background of the text and the remaining space on both sides;<br />
|-<br />
|<tt>CL</tt> || color is applied to the background of the text and the remaining space on the left.<br />
|}<br />
These are to complement the normal table layout expression (the<br />
first argument to <tt>\starttabulate</tt>.<br />
Thus, in order to colorize a four column table with the initial<br />
layout <tt>|c|c|c|c|</tt> it will have to be modified as follows:<br />
<texcode><br />
\starttabulate[|CR{red}c|CC{yellow}c|CM{green}c|CL{blue}c|] <br />
\NC test \NC test \NC test \NC test \NC \NR <br />
\NC test \NC test \NC test \NC test \NC \NR <br />
\NC test \NC test \NC test \NC test \NC \NR <br />
\NC test \NC test \NC test \NC test \NC \NR <br />
\stoptabulate<br />
</texcode><br />
<br />
Those control sequences, if applied within the table body, can<br />
replace the ordinary <tt>\NC</tt>, allowing individual cells to<br />
be colorized.<br />
<texcode><br />
\starttabulate[|c|c|c|c|c|c|]<br />
\NC g \NC l \NC i \NC d \NC e \NC r \NC \NR <br />
\NC g \NC l \NC i \CM[blue] d \NC e \NC r \NC \NR <br />
\NC g \NC l \NC i \NC d \CM[blue] e \NC r \NC \NR <br />
\NC g \NC l \CM[blue] i \CM[blue] d \CM[blue] e \NC r \NC \NR <br />
\NC g \NC l \NC i \NC d \NC e \NC r \NC \NR <br />
\stoptabulate<br />
</texcode><br />
<br />
<br />
===Colorizing Cell Text===<br />
''Normal text'' inside cells gets its color via the<br />
[[Colors|standard coloring commands]].<br />
<br />
<texcode><br />
\starttabulate[|r|c|l|] <br />
\NC test \NC {\colored[red] test} \NC test \NC\NR <br />
\NC test \NC {\colored[green] test} \NC test \NC\NR <br />
\NC test \NC {\colored[blue] test} \NC test \NC\NR <br />
\NC test \NC {\colored[cyan] test} \NC test \NC\NR <br />
\stoptabulate<br />
</texcode><br />
<br />
=Using math mode=<br />
<br />
If you want to display numerics, you can simply use <cmd>NN</cmd> for a new column instead of <cmd>NC</cmd>. This command works similar to the [http://www.pragma-ade.com/general/magazines/mag-0003.pdf digit-module]. Therefore you can also abbreviate:<br />
<br />
<texcode>\starttabulate[|l|l|]<br />
\HL<br />
\NN 10e-3 \NN 10e+3 \NR<br />
\HL<br />
\stoptabulate<br />
</texcode><br />
<br />
instead of<br />
<br />
<texcode><br />
\starttabulate[|l|l|]<br />
\HL<br />
\NC $10\cdot 10^{-3}$ \NC $10 \cdot 10^3$ \NR<br />
\HL<br />
\stoptabulate<br />
</texcode><br />
<br />
although both variants do work.<br />
<br />
<br />
=Itemization inside a tabulation=<br />
<br />
<!--(added by Willi Egger 04-08-2011)--><br />
<br />
The following issue is related to MKIV:<br />
<br />
When using an itemization inside a tabulation where one uses also the <br />
<tt>\head</tt> command there occurs a snapping problem. This is related to penalties which force a twoline split whereas the snapping mechanism prevents this. As a result two lines are typeset on top of each other. The solution is to add the following statement to the preamble:<br />
<texcode>\tabulatesplitlinemode \plustwo</texcode><br />
<br />
The following code provided by Wolfgang Schuster demonstrates the problem: Compile with and without the line <tt>\tabulatesplitlinemode\plustwo</tt><br />
<br />
<texcode><br />
\tabulatesplitlinemode \plustwo<br />
\starttabulate[|p|]<br />
\NC<br />
one \par<br />
\blank[penalty:10000]<br />
two \par<br />
\blank[penalty:10000]<br />
three<br />
\NC\NR<br />
\stoptabulate<br />
</texcode><br />
<br />
<br />
=See also=<br />
<br />
* More features are constantly added and documented only in the [[source:tabl-tbl.mkiv|source]].<br />
<br />
* [[cmd:starttabulate|Command description]]<br />
<br />
* [[TABLE|Natural Tables]]<br />
<br />
* [[cmd:starttable|Table environment]]<br />
<br />
[[Category:Tables]]</div>Willihttps://wiki.contextgarden.net/index.php?title=Tabulate&diff=13288Tabulate2011-08-04T13:21:10Z<p>Willi: </p>
<hr />
<div>< [[Tables Overview]] | [[Table]] ><br />
<br />
<br />
=Summary=<br />
<br />
[[cmd:starttabulate|Tabulate]] is a versatile table environment.<br />
It supports ''paragraphs'' in cells, ''vertical rules'' (for<br />
those typographically less demanding jobs&nbsp;…), and<br />
''colorization'' of those rules, the background of fields as well<br />
as the text itself.<br />
<br />
'''Warning''': When you want to use tables with macros use \starttable and \stoptable. \starttabulate and \stoptabulate does not work correctly with macros.<br />
<br />
=Basic commands=<br />
<br />
The control sequence <tt>\starttabulate[#1]</tt> takes a layout<br />
string as optional argument.<br />
As is common with tables in TeX-based typesetting, this string<br />
(in its basic variant) consists primarily of the ''bar''<br />
character (“<tt>|</tt>”) as delimiter for columns,<br />
and of the letters <tt>c</tt>, <tt>l</tt>, as well as <tt>r</tt>,<br />
denoting the ''alignment'' within cells of this row.<br />
<br />
For instance consider a two-column table: if any text in the<br />
first column should be right aligned (''real''<br />
[[right and left|<tt>flushright</tt>]]) and the second column<br />
left aligned, the corresponding format string would be<br />
<tt>|l|r|</tt>.<br />
''NB'': those bars, as stated above, denote cell limits only<br />
&ndash; ''not'' vertical lines.<br />
<br />
<!--<br />
- wtf this listing was full of <tab> chars‽ Was this supposed<br />
- to be a bad pun on *tabulate*?<br />
--><br />
{|<br />
! width="55%"|<br />
! width="10%"|<br />
! width="35%"|<br />
|-<br />
| <texcode><br />
\starttabulate[|r|l|]<br />
\HL<br />
\NC {\bf format} \NC {\bf meaning} \NC\NR<br />
\HL<br />
\NC c \NC centered \NC\NR<br />
\NC l \NC left aligned \NC\NR<br />
\NC r \NC right aligned \NC\NR<br />
\NC w(1cm) \NC one line, fixed width \NC\NR<br />
\NC p(2cm) \NC paragraph, lines broken to fixed width \NC\NR<br />
\NC cg(.) \NC align on a character \NC\NR<br />
\HL<br />
\stoptabulate<br />
</texcode><br />
|<br />
|<context><br />
\starttabulate[|r|l|]<br />
\HL<br />
\NC {\bf format} \NC {\bf meaning} \NC\NR<br />
\HL<br />
\NC c \NC centered \NC\NR<br />
\NC l \NC left aligned \NC\NR<br />
\NC r \NC right aligned \NC\NR<br />
\NC w(1cm) \NC one line, fixed width \NC\NR<br />
\NC p(2cm) \NC paragraph, lines broken to fixed width \NC\NR<br />
\NC cg(.) \NC align on a character \NC\NR<br />
\HL<br />
\stoptabulate<br />
</context><br />
|}<br />
<br />
* <tt>HL</tt> draws a horizontal rule,<br />
* <tt>NC</tt> marks a new column (or new cell),<br />
* <tt>NR</tt> starts new row.<br />
<br />
<br />
When using fixed width, you can use values relative to the<br />
current page-width. For example: if you want the previous table<br />
take up all the width and having the second column taking three<br />
quarters of the space, change the starttabulate to:<br />
<br />
\starttabulate[|rw(.25\textwidth)|lw(.75\textwidth)|]<br />
<br />
<br />
It is generally not necessary to conclude lines with<br />
<tt>\NC\NR</tt> as <tt>\AR</tt> (for <em>a</em>uto<em>r</em>ow)<br />
will do the job as well.<br />
<br />
=Spanning Multiple Pages=<br />
<br />
Tabulate may extend to adjacient pages if needed.<br />
To achieve this the argument <tt>split</tt> must be set to<br />
''true''.<br />
''NB'': the difference between setting and unsetting this<br />
argument may not be visible on the first few pages. Rather, it<br />
seems to affect the ''end'' of the environment.<br />
<br />
<context source="yes"><br />
\setuppapersize [XY][A4]<br />
\setuppaper [nx=2,ny=2]<br />
\setuparranging [XY]<br />
\setupbodyfont[10pt]<br />
<br />
\starttext<br />
<br />
\setuptabulate[split=yes]<br />
<br />
\starttabulate<br />
\dorecurse{2}{<br />
\NC test \NC \input tufte \relax \NC \NR <br />
\NC test \NC \input dawkins \relax \NC \NR <br />
}<br />
\stoptabulate<br />
<br />
\stoptext \endinput<br />
</context><br />
<br />
==Titles==<br />
<br />
A tabulating environment can have an optional name which will be<br />
repeated above at every page break that occurs inside the table.<br />
This name needs to be specified as the argument of the<br />
<tt>title</tt> key of <tt>\setuptabulate</tt>.<br />
The <tt>header</tt> key has to be set to <em>text</em> for this<br />
to work.<br />
<br />
<texcode><br />
\setuptabulate[split=yes,header=text,title={\sc Table Titles Undisclosed!}]<br />
<br />
\starttabulate<br />
\dorecurse{2}{<br />
\NC Ed Tufte \NC \input tufte \relax \NC \NR<br />
\NC Dick Dawkins \NC \input dawkins \relax \NC \NR<br />
}<br />
</texcode><br />
<br />
<context><br />
\setuppapersize [XY][A4]<br />
\setuppaper [nx=2,ny=2]<br />
\setuparranging [XY]<br />
<br />
\starttext<br />
<br />
\setuptabulate[split=yes,header=text,title={\sc Table Titles Undisclosed!}]<br />
<br />
\starttabulate<br />
\dorecurse{2}{<br />
\NC Ed Tufte \NC \input tufte \relax \NC \NR <br />
\NC Dick Dawkins \NC \input dawkins \relax \NC \NR<br />
}<br />
\stoptabulate<br />
<br />
\stoptext \endinput<br />
</context><br />
<br />
<!--<br />
- ==Headers and Footers==<br />
- As I couldn’t get footers running I just comment this and<br />
- leave it to whoever discovers the trick to activate them.<br />
- (The <tt>footer=</tt> key seems to be implemented for<br />
- “\setuptabulate” but I couldn’t notice any effect.<br />
--><br />
==Headers==<br />
Tabulate supports header rows that can be repeated over new table<br />
pages instead of the title.<br />
There is a separate environment <tt>\starttablehead</tt> where<br />
this header row has to be specified in advance of its use in a<br />
tabulation.<br />
<br />
{|<br />
! width="55%"|<br />
! width="10%"|<br />
! width="35%"|<br />
|-<br />
| <texcode><br />
\setuptabulate[split=yes,header=repeat]<br />
<br />
\starttabulatehead<br />
\HL<br />
\NC {\bf format char} \NC {\bf meaning} \AR<br />
\HL<br />
\stoptabulatehead<br />
<br />
\starttabulate[|r|l|]<br />
\NC c \NC centered \AR<br />
\NC l \NC left aligned \AR<br />
\NC r \NC right aligned \AR<br />
\stoptabulate<br />
</texcode><br />
|<br />
| <context><br />
\setuptabulate[split=yes,header=repeat]<br />
<br />
\starttabulatehead<br />
\HL<br />
\NC {\bf format char} \NC {\bf meaning} \AR<br />
\HL<br />
\stoptabulatehead<br />
<br />
\starttabulate[|r|l|]<br />
\NC c \NC centered \AR<br />
\NC l \NC left aligned \AR<br />
\NC r \NC right aligned \AR<br />
\stoptabulate<br />
</context><br />
|}<br />
<br />
=Individualizing the Tabulate Look=<br />
<br />
Hans initially announced support for vertical lines and colors on<br />
the mailing list.[http://archive.contextgarden.net/message/20101117.123950.739657a7.en.html]<br />
<br />
==Rules==<br />
<br />
===Horizontal Rules===<br />
<br />
As already demonstrated above, the <tt>\HL</tt> statement inserts<br />
a hairline after the current line.<br />
This particularly useful when demarking header and footer rows or<br />
separated parts of a table that should not be as closely<br />
associated as the rows between the rules.<br />
<br />
{|<br />
! width="55%"|<br />
! width="10%"|<br />
! width="35%"|<br />
|-<br />
| <texcode><br />
\starttabulate[|r|c|l|] <br />
\NC test \NC test \NC test \NC\NR <br />
\HL<br />
\NC test \NC test \NC test \NC\NR <br />
\NC test \NC test \NC test \NC\NR <br />
\HL<br />
\NC test \NC test \NC test \NC\NR <br />
\HL<br />
\stoptabulate<br />
</texcode><br />
| <context><br />
\starttabulate[|r|c|l|] <br />
\NC test \NC test \NC test \NC\NR <br />
\HL<br />
\NC test \NC test \NC test \NC\NR <br />
\NC test \NC test \NC test \NC\NR <br />
\HL<br />
\NC test \NC test \NC test \NC\NR <br />
\HL<br />
\stoptabulate<br />
</context><br />
|}<br />
<br />
Context supports different categories of rules that can be<br />
configured individually in order to discern various applications.<br />
Their behaviour accounts for the designated use, e.&nbsp;g.<br />
<tt>\ML</tt> (mid rules) are intended to be deployed between<br />
ordinary rows of the table body and will prevent page breaks<br />
&ndash; no way you’d end up with a rogue hairline desecrating<br />
the bottom of your page’s text area.<br />
{|cellpadding="10" style="border:2px solid #addeff"<br />
! style="background:#addeff;" | Type !! Description<br />
|-<br />
|<tt>\HL</tt> || standard horizontal rule;<br />
|-<br />
|<tt>\FL</tt> || first rule;<br />
|-<br />
|<tt>\ML</tt> || mid rule;<br />
|-<br />
|<tt>\LL</tt> || bottom rule;<br />
|-<br />
|<tt>\LL</tt> and <tt>\TL</tt> || bottom rule;<br />
|-<br />
|<tt>\BL</tt> || last rule.<br />
|}<br />
<br />
Additionally, there is an options <tt>rulecolor</tt> for<br />
<tt>\setuptabulate</tt> that allows for those rules to be tinted.<br />
<br />
<texcode><br />
\setuptabulate[rulecolor=red]<br />
<br />
\starttabulate[|r|c|l|] <br />
\FL<br />
\NC first row \NC test \NC test \NC\NR <br />
\ML<br />
\NC rows in \NC test \NC test \NC\NR <br />
\NC between \NC test \NC test \NC\NR <br />
\LL <br />
\NC last row \NC test \NC test \NC\NR <br />
\BL<br />
\stoptabulate<br />
</texcode><br />
<br />
Other types can be discovered in the source<br />
([[source:tabl-tbl.mkiv|tabl-tbl.mkiv]]).<br />
<br />
===Vertical Rules===<br />
<br />
The <tt>\VL</tt> command serves as a replacement for <tt>\NC</tt><br />
to mark a cell border wherever a vertical rule may be desired (if<br />
they are to be desired at all from a typographical point of<br />
view).<br />
<br />
<texcode><br />
\starttabulate[||||] <br />
\NC test \VL test \VL test \VL\NR <br />
\VL test \NC test \VL test \VL\NR <br />
\VL test \VL test \NC test \VL\NR <br />
\VL test \VL test \VL test \NC\NR <br />
\stoptabulate<br />
</texcode><br />
<br />
==Coloring==<br />
<br />
The following elements can be colorized: rules, cell backgrounds,<br />
and, obviously, common text.<br />
<br />
===Colorizing Rules===<br />
<br />
For ''horizontal rules'' see above.<br />
<br />
For ''vertical rules'', <tt>\VL</tt> takes a defined color as an<br />
optional argument.<br />
<br />
<texcode><br />
\starttabulate[|r|c|l|] <br />
\VL test \VL[red] red rule \VL test \VL \NR <br />
\VL test \VL[green] green rule \VL test \VL \NR <br />
\VL test \VL[blue] blue rule \VL test \VL \NR <br />
\stoptabulate<br />
</texcode><br />
<br />
===Colorizing Backgrounds===<br />
''Backgrounds'' can be colorized either on column basis or<br />
individually by cell.<br />
<br />
There are four color-specific control sequences:<br />
{|<br />
|<tt>CR</tt> || color is applied to the background of the text and the remaining space on the right;<br />
|-<br />
|<tt>CC</tt> || color is applied to the background of the text only; <br />
|-<br />
|<tt>CM</tt> || color is applied to the background of the text and the remaining space on both sides;<br />
|-<br />
|<tt>CL</tt> || color is applied to the background of the text and the remaining space on the left.<br />
|}<br />
These are to complement the normal table layout expression (the<br />
first argument to <tt>\starttabulate</tt>.<br />
Thus, in order to colorize a four column table with the initial<br />
layout <tt>|c|c|c|c|</tt> it will have to be modified as follows:<br />
<texcode><br />
\starttabulate[|CR{red}c|CC{yellow}c|CM{green}c|CL{blue}c|] <br />
\NC test \NC test \NC test \NC test \NC \NR <br />
\NC test \NC test \NC test \NC test \NC \NR <br />
\NC test \NC test \NC test \NC test \NC \NR <br />
\NC test \NC test \NC test \NC test \NC \NR <br />
\stoptabulate<br />
</texcode><br />
<br />
Those control sequences, if applied within the table body, can<br />
replace the ordinary <tt>\NC</tt>, allowing individual cells to<br />
be colorized.<br />
<texcode><br />
\starttabulate[|c|c|c|c|c|c|]<br />
\NC g \NC l \NC i \NC d \NC e \NC r \NC \NR <br />
\NC g \NC l \NC i \CM[blue] d \NC e \NC r \NC \NR <br />
\NC g \NC l \NC i \NC d \CM[blue] e \NC r \NC \NR <br />
\NC g \NC l \CM[blue] i \CM[blue] d \CM[blue] e \NC r \NC \NR <br />
\NC g \NC l \NC i \NC d \NC e \NC r \NC \NR <br />
\stoptabulate<br />
</texcode><br />
<br />
<br />
===Colorizing Cell Text===<br />
''Normal text'' inside cells gets its color via the<br />
[[Colors|standard coloring commands]].<br />
<br />
<texcode><br />
\starttabulate[|r|c|l|] <br />
\NC test \NC {\colored[red] test} \NC test \NC\NR <br />
\NC test \NC {\colored[green] test} \NC test \NC\NR <br />
\NC test \NC {\colored[blue] test} \NC test \NC\NR <br />
\NC test \NC {\colored[cyan] test} \NC test \NC\NR <br />
\stoptabulate<br />
</texcode><br />
<br />
=Using math mode=<br />
<br />
If you want to display numerics, you can simply use <cmd>NN</cmd> for a new column instead of <cmd>NC</cmd>. This command works similar to the [http://www.pragma-ade.com/general/magazines/mag-0003.pdf digit-module]. Therefore you can also abbreviate:<br />
<br />
<texcode>\starttabulate[|l|l|]<br />
\HL<br />
\NN 10e-3 \NN 10e+3 \NR<br />
\HL<br />
\stoptabulate<br />
</texcode><br />
<br />
instead of<br />
<br />
<texcode><br />
\starttabulate[|l|l|]<br />
\HL<br />
\NC $10\cdot 10^{-3}$ \NC $10 \cdot 10^3$ \NR<br />
\HL<br />
\stoptabulate<br />
</texcode><br />
<br />
although both variants do work.<br />
<br />
<br />
=Itemization inside a tabulation (added by Willi Egger 04-08-2011)=<br />
<br />
The following issue is related to MKIV:<br />
<br />
When using an itemization inside a tabulation where one uses also the <br />
<texcode>\head</texcode> command there occurs a snapping problem. This is related to penalties which force a twoline split whereas the snapping mechanism prevents this. As a result two lines are typeset on top of each other. The solution is to add the following statement to the preamble:<br />
<texcode>\tabulatesplitlinemode \plustwo</texcode><br />
<br />
<br />
<texcode><br />
\tabulatesplitlinemode \plustwo<br />
\starttabulate[|p|]<br />
\NC<br />
one \par<br />
\blank[penalty:10000]<br />
two \par<br />
\blank[penalty:10000]<br />
three<br />
\NC\NR<br />
\stoptabulate<br />
</texcode><br />
<br />
<br />
=See also=<br />
<br />
* More features are constantly added and documented only in the [[source:tabl-tbl.mkiv|source]].<br />
<br />
* [[cmd:starttabulate|Command description]]<br />
<br />
* [[TABLE|Natural Tables]]<br />
<br />
* [[cmd:starttable|Table environment]]<br />
<br />
[[Category:Tables]]</div>Willihttps://wiki.contextgarden.net/index.php?title=Tabulate&diff=13287Tabulate2011-08-04T13:17:08Z<p>Willi: </p>
<hr />
<div>< [[Tables Overview]] | [[Table]] ><br />
<br />
<br />
=Summary=<br />
<br />
[[cmd:starttabulate|Tabulate]] is a versatile table environment.<br />
It supports ''paragraphs'' in cells, ''vertical rules'' (for<br />
those typographically less demanding jobs&nbsp;…), and<br />
''colorization'' of those rules, the background of fields as well<br />
as the text itself.<br />
<br />
'''Warning''': When you want to use tables with macros use \starttable and \stoptable. \starttabulate and \stoptabulate does not work correctly with macros.<br />
<br />
=Basic commands=<br />
<br />
The control sequence <tt>\starttabulate[#1]</tt> takes a layout<br />
string as optional argument.<br />
As is common with tables in TeX-based typesetting, this string<br />
(in its basic variant) consists primarily of the ''bar''<br />
character (“<tt>|</tt>”) as delimiter for columns,<br />
and of the letters <tt>c</tt>, <tt>l</tt>, as well as <tt>r</tt>,<br />
denoting the ''alignment'' within cells of this row.<br />
<br />
For instance consider a two-column table: if any text in the<br />
first column should be right aligned (''real''<br />
[[right and left|<tt>flushright</tt>]]) and the second column<br />
left aligned, the corresponding format string would be<br />
<tt>|l|r|</tt>.<br />
''NB'': those bars, as stated above, denote cell limits only<br />
&ndash; ''not'' vertical lines.<br />
<br />
<!--<br />
- wtf this listing was full of <tab> chars‽ Was this supposed<br />
- to be a bad pun on *tabulate*?<br />
--><br />
{|<br />
! width="55%"|<br />
! width="10%"|<br />
! width="35%"|<br />
|-<br />
| <texcode><br />
\starttabulate[|r|l|]<br />
\HL<br />
\NC {\bf format} \NC {\bf meaning} \NC\NR<br />
\HL<br />
\NC c \NC centered \NC\NR<br />
\NC l \NC left aligned \NC\NR<br />
\NC r \NC right aligned \NC\NR<br />
\NC w(1cm) \NC one line, fixed width \NC\NR<br />
\NC p(2cm) \NC paragraph, lines broken to fixed width \NC\NR<br />
\NC cg(.) \NC align on a character \NC\NR<br />
\HL<br />
\stoptabulate<br />
</texcode><br />
|<br />
|<context><br />
\starttabulate[|r|l|]<br />
\HL<br />
\NC {\bf format} \NC {\bf meaning} \NC\NR<br />
\HL<br />
\NC c \NC centered \NC\NR<br />
\NC l \NC left aligned \NC\NR<br />
\NC r \NC right aligned \NC\NR<br />
\NC w(1cm) \NC one line, fixed width \NC\NR<br />
\NC p(2cm) \NC paragraph, lines broken to fixed width \NC\NR<br />
\NC cg(.) \NC align on a character \NC\NR<br />
\HL<br />
\stoptabulate<br />
</context><br />
|}<br />
<br />
* <tt>HL</tt> draws a horizontal rule,<br />
* <tt>NC</tt> marks a new column (or new cell),<br />
* <tt>NR</tt> starts new row.<br />
<br />
<br />
When using fixed width, you can use values relative to the<br />
current page-width. For example: if you want the previous table<br />
take up all the width and having the second column taking three<br />
quarters of the space, change the starttabulate to:<br />
<br />
\starttabulate[|rw(.25\textwidth)|lw(.75\textwidth)|]<br />
<br />
<br />
It is generally not necessary to conclude lines with<br />
<tt>\NC\NR</tt> as <tt>\AR</tt> (for <em>a</em>uto<em>r</em>ow)<br />
will do the job as well.<br />
<br />
=Spanning Multiple Pages=<br />
<br />
Tabulate may extend to adjacient pages if needed.<br />
To achieve this the argument <tt>split</tt> must be set to<br />
''true''.<br />
''NB'': the difference between setting and unsetting this<br />
argument may not be visible on the first few pages. Rather, it<br />
seems to affect the ''end'' of the environment.<br />
<br />
<context source="yes"><br />
\setuppapersize [XY][A4]<br />
\setuppaper [nx=2,ny=2]<br />
\setuparranging [XY]<br />
\setupbodyfont[10pt]<br />
<br />
\starttext<br />
<br />
\setuptabulate[split=yes]<br />
<br />
\starttabulate<br />
\dorecurse{2}{<br />
\NC test \NC \input tufte \relax \NC \NR <br />
\NC test \NC \input dawkins \relax \NC \NR <br />
}<br />
\stoptabulate<br />
<br />
\stoptext \endinput<br />
</context><br />
<br />
==Titles==<br />
<br />
A tabulating environment can have an optional name which will be<br />
repeated above at every page break that occurs inside the table.<br />
This name needs to be specified as the argument of the<br />
<tt>title</tt> key of <tt>\setuptabulate</tt>.<br />
The <tt>header</tt> key has to be set to <em>text</em> for this<br />
to work.<br />
<br />
<texcode><br />
\setuptabulate[split=yes,header=text,title={\sc Table Titles Undisclosed!}]<br />
<br />
\starttabulate<br />
\dorecurse{2}{<br />
\NC Ed Tufte \NC \input tufte \relax \NC \NR<br />
\NC Dick Dawkins \NC \input dawkins \relax \NC \NR<br />
}<br />
</texcode><br />
<br />
<context><br />
\setuppapersize [XY][A4]<br />
\setuppaper [nx=2,ny=2]<br />
\setuparranging [XY]<br />
<br />
\starttext<br />
<br />
\setuptabulate[split=yes,header=text,title={\sc Table Titles Undisclosed!}]<br />
<br />
\starttabulate<br />
\dorecurse{2}{<br />
\NC Ed Tufte \NC \input tufte \relax \NC \NR <br />
\NC Dick Dawkins \NC \input dawkins \relax \NC \NR<br />
}<br />
\stoptabulate<br />
<br />
\stoptext \endinput<br />
</context><br />
<br />
<!--<br />
- ==Headers and Footers==<br />
- As I couldn’t get footers running I just comment this and<br />
- leave it to whoever discovers the trick to activate them.<br />
- (The <tt>footer=</tt> key seems to be implemented for<br />
- “\setuptabulate” but I couldn’t notice any effect.<br />
--><br />
==Headers==<br />
Tabulate supports header rows that can be repeated over new table<br />
pages instead of the title.<br />
There is a separate environment <tt>\starttablehead</tt> where<br />
this header row has to be specified in advance of its use in a<br />
tabulation.<br />
<br />
{|<br />
! width="55%"|<br />
! width="10%"|<br />
! width="35%"|<br />
|-<br />
| <texcode><br />
\setuptabulate[split=yes,header=repeat]<br />
<br />
\starttabulatehead<br />
\HL<br />
\NC {\bf format char} \NC {\bf meaning} \AR<br />
\HL<br />
\stoptabulatehead<br />
<br />
\starttabulate[|r|l|]<br />
\NC c \NC centered \AR<br />
\NC l \NC left aligned \AR<br />
\NC r \NC right aligned \AR<br />
\stoptabulate<br />
</texcode><br />
|<br />
| <context><br />
\setuptabulate[split=yes,header=repeat]<br />
<br />
\starttabulatehead<br />
\HL<br />
\NC {\bf format char} \NC {\bf meaning} \AR<br />
\HL<br />
\stoptabulatehead<br />
<br />
\starttabulate[|r|l|]<br />
\NC c \NC centered \AR<br />
\NC l \NC left aligned \AR<br />
\NC r \NC right aligned \AR<br />
\stoptabulate<br />
</context><br />
|}<br />
<br />
=Individualizing the Tabulate Look=<br />
<br />
Hans initially announced support for vertical lines and colors on<br />
the mailing list.[http://archive.contextgarden.net/message/20101117.123950.739657a7.en.html]<br />
<br />
==Rules==<br />
<br />
===Horizontal Rules===<br />
<br />
As already demonstrated above, the <tt>\HL</tt> statement inserts<br />
a hairline after the current line.<br />
This particularly useful when demarking header and footer rows or<br />
separated parts of a table that should not be as closely<br />
associated as the rows between the rules.<br />
<br />
{|<br />
! width="55%"|<br />
! width="10%"|<br />
! width="35%"|<br />
|-<br />
| <texcode><br />
\starttabulate[|r|c|l|] <br />
\NC test \NC test \NC test \NC\NR <br />
\HL<br />
\NC test \NC test \NC test \NC\NR <br />
\NC test \NC test \NC test \NC\NR <br />
\HL<br />
\NC test \NC test \NC test \NC\NR <br />
\HL<br />
\stoptabulate<br />
</texcode><br />
| <context><br />
\starttabulate[|r|c|l|] <br />
\NC test \NC test \NC test \NC\NR <br />
\HL<br />
\NC test \NC test \NC test \NC\NR <br />
\NC test \NC test \NC test \NC\NR <br />
\HL<br />
\NC test \NC test \NC test \NC\NR <br />
\HL<br />
\stoptabulate<br />
</context><br />
|}<br />
<br />
Context supports different categories of rules that can be<br />
configured individually in order to discern various applications.<br />
Their behaviour accounts for the designated use, e.&nbsp;g.<br />
<tt>\ML</tt> (mid rules) are intended to be deployed between<br />
ordinary rows of the table body and will prevent page breaks<br />
&ndash; no way you’d end up with a rogue hairline desecrating<br />
the bottom of your page’s text area.<br />
{|cellpadding="10" style="border:2px solid #addeff"<br />
! style="background:#addeff;" | Type !! Description<br />
|-<br />
|<tt>\HL</tt> || standard horizontal rule;<br />
|-<br />
|<tt>\FL</tt> || first rule;<br />
|-<br />
|<tt>\ML</tt> || mid rule;<br />
|-<br />
|<tt>\LL</tt> || bottom rule;<br />
|-<br />
|<tt>\LL</tt> and <tt>\TL</tt> || bottom rule;<br />
|-<br />
|<tt>\BL</tt> || last rule.<br />
|}<br />
<br />
Additionally, there is an options <tt>rulecolor</tt> for<br />
<tt>\setuptabulate</tt> that allows for those rules to be tinted.<br />
<br />
<texcode><br />
\setuptabulate[rulecolor=red]<br />
<br />
\starttabulate[|r|c|l|] <br />
\FL<br />
\NC first row \NC test \NC test \NC\NR <br />
\ML<br />
\NC rows in \NC test \NC test \NC\NR <br />
\NC between \NC test \NC test \NC\NR <br />
\LL <br />
\NC last row \NC test \NC test \NC\NR <br />
\BL<br />
\stoptabulate<br />
</texcode><br />
<br />
Other types can be discovered in the source<br />
([[source:tabl-tbl.mkiv|tabl-tbl.mkiv]]).<br />
<br />
===Vertical Rules===<br />
<br />
The <tt>\VL</tt> command serves as a replacement for <tt>\NC</tt><br />
to mark a cell border wherever a vertical rule may be desired (if<br />
they are to be desired at all from a typographical point of<br />
view).<br />
<br />
<texcode><br />
\starttabulate[||||] <br />
\NC test \VL test \VL test \VL\NR <br />
\VL test \NC test \VL test \VL\NR <br />
\VL test \VL test \NC test \VL\NR <br />
\VL test \VL test \VL test \NC\NR <br />
\stoptabulate<br />
</texcode><br />
<br />
==Coloring==<br />
<br />
The following elements can be colorized: rules, cell backgrounds,<br />
and, obviously, common text.<br />
<br />
===Colorizing Rules===<br />
<br />
For ''horizontal rules'' see above.<br />
<br />
For ''vertical rules'', <tt>\VL</tt> takes a defined color as an<br />
optional argument.<br />
<br />
<texcode><br />
\starttabulate[|r|c|l|] <br />
\VL test \VL[red] red rule \VL test \VL \NR <br />
\VL test \VL[green] green rule \VL test \VL \NR <br />
\VL test \VL[blue] blue rule \VL test \VL \NR <br />
\stoptabulate<br />
</texcode><br />
<br />
===Colorizing Backgrounds===<br />
''Backgrounds'' can be colorized either on column basis or<br />
individually by cell.<br />
<br />
There are four color-specific control sequences:<br />
{|<br />
|<tt>CR</tt> || color is applied to the background of the text and the remaining space on the right;<br />
|-<br />
|<tt>CC</tt> || color is applied to the background of the text only; <br />
|-<br />
|<tt>CM</tt> || color is applied to the background of the text and the remaining space on both sides;<br />
|-<br />
|<tt>CL</tt> || color is applied to the background of the text and the remaining space on the left.<br />
|}<br />
These are to complement the normal table layout expression (the<br />
first argument to <tt>\starttabulate</tt>.<br />
Thus, in order to colorize a four column table with the initial<br />
layout <tt>|c|c|c|c|</tt> it will have to be modified as follows:<br />
<texcode><br />
\starttabulate[|CR{red}c|CC{yellow}c|CM{green}c|CL{blue}c|] <br />
\NC test \NC test \NC test \NC test \NC \NR <br />
\NC test \NC test \NC test \NC test \NC \NR <br />
\NC test \NC test \NC test \NC test \NC \NR <br />
\NC test \NC test \NC test \NC test \NC \NR <br />
\stoptabulate<br />
</texcode><br />
<br />
Those control sequences, if applied within the table body, can<br />
replace the ordinary <tt>\NC</tt>, allowing individual cells to<br />
be colorized.<br />
<texcode><br />
\starttabulate[|c|c|c|c|c|c|]<br />
\NC g \NC l \NC i \NC d \NC e \NC r \NC \NR <br />
\NC g \NC l \NC i \CM[blue] d \NC e \NC r \NC \NR <br />
\NC g \NC l \NC i \NC d \CM[blue] e \NC r \NC \NR <br />
\NC g \NC l \CM[blue] i \CM[blue] d \CM[blue] e \NC r \NC \NR <br />
\NC g \NC l \NC i \NC d \NC e \NC r \NC \NR <br />
\stoptabulate<br />
</texcode><br />
<br />
<br />
===Colorizing Cell Text===<br />
''Normal text'' inside cells gets its color via the<br />
[[Colors|standard coloring commands]].<br />
<br />
<texcode><br />
\starttabulate[|r|c|l|] <br />
\NC test \NC {\colored[red] test} \NC test \NC\NR <br />
\NC test \NC {\colored[green] test} \NC test \NC\NR <br />
\NC test \NC {\colored[blue] test} \NC test \NC\NR <br />
\NC test \NC {\colored[cyan] test} \NC test \NC\NR <br />
\stoptabulate<br />
</texcode><br />
<br />
=Using math mode=<br />
<br />
If you want to display numerics, you can simply use <cmd>NN</cmd> for a new column instead of <cmd>NC</cmd>. This command works similar to the [http://www.pragma-ade.com/general/magazines/mag-0003.pdf digit-module]. Therefore you can also abbreviate:<br />
<br />
<texcode>\starttabulate[|l|l|]<br />
\HL<br />
\NN 10e-3 \NN 10e+3 \NR<br />
\HL<br />
\stoptabulate<br />
</texcode><br />
<br />
instead of<br />
<br />
<texcode><br />
\starttabulate[|l|l|]<br />
\HL<br />
\NC $10\cdot 10^{-3}$ \NC $10 \cdot 10^3$ \NR<br />
\HL<br />
\stoptabulate<br />
</texcode><br />
<br />
although both variants do work.<br />
<br />
<br />
=Itemization inside a tabulation (added by Willi Egger 04-08-2011)<br />
<br />
When using an itemization inside a tabulation where one uses also the <br />
<texcode>\head</texcode> command there occurs a snapping problem. This is related to penalties which force a twoline split whereas the snapping mechanism prevent this. As a result two lines are typeset on top of each other. The solution is to add the following statement to the preamble:<br />
<texcode>\tabulatesplitlinemode \plustwo</texcode><br />
<br />
Example with normal tabulatesplitlinemode:<br />
<br />
<context source="yes"><br />
\starttabulate[|p|]<br />
\NC<br />
one \par<br />
\blank[penalty:10000]<br />
two \par<br />
\blank[penalty:10000]<br />
three<br />
\NC\NR<br />
\stoptabulate<br />
</context><br />
<br />
Example with <texcode>tabulatesplitlinemode</texcode> set to <texcode>\plustwo</texcode>:<br />
<br />
<context source="yes"><br />
\tabulatesplitlinemode \plustwo<br />
\starttabulate[|p|]<br />
\NC<br />
one \par<br />
\blank[penalty:10000]<br />
two \par<br />
\blank[penalty:10000]<br />
three<br />
\NC\NR<br />
\stoptabulate<br />
</context><br />
<br />
<br />
=See also=<br />
<br />
* More features are constantly added and documented only in the [[source:tabl-tbl.mkiv|source]].<br />
<br />
* [[cmd:starttabulate|Command description]]<br />
<br />
* [[TABLE|Natural Tables]]<br />
<br />
* [[cmd:starttable|Table environment]]<br />
<br />
[[Category:Tables]]</div>Willihttps://wiki.contextgarden.net/index.php?title=Last_Head_Number&diff=13095Last Head Number2011-06-15T17:12:37Z<p>Willi: Changed 'somestructureheadnumber' into somenamedheadnumber</p>
<hr />
<div>To access the last head number in a document one can use: <br />
<texcode>\someheadnumber[…][…]</texcode> <br />
The following example from the mailing list demonstrates how to use it.<br />
<br />
<texcode><br />
\dorecurse {5} {<br />
\chapter{Test \recurselevel}<br />
first: \someheadnumber[chapter][first] \par<br />
current: \someheadnumber[chapter][current] \par<br />
last: \someheadnumber[chapter][last]<br />
\dorecurse {3} {<br />
\section{Test \recurselevel}<br />
first: \someheadnumber[section][first] \par<br />
current: \someheadnumber[section][current] \par<br />
last: \someheadnumber[section][last]<br />
}<br />
}<br />
</texcode><br />
<br />
For using inside a Metapost-environment you can use the expandable version:<br />
<texcode>\somenamedheadnumber{…}{…}</texcode><br />
<br />
Willi's comment on 15-06-2011:<br />
Sinds Context 13 june 2011 the name <texcode>\somestructureheadnumber</texcode> is replaced by <texcode>\someheadnumber</texcode>. This is in line with Hans' plans to get rid of the 'structure' part inside interface-names dealing with internal counters.</div>Willihttps://wiki.contextgarden.net/index.php?title=Command/setuppaper&diff=12898Command/setuppaper2011-03-03T20:16:19Z<p>Willi: /* Example */</p>
<hr />
<div>{{Reference<br />
|name=setuppaper<br />
|attributes=<br />
}}<br />
<br />
== [[Help:Reference|Syntax]] ==<br />
<table cellspacing="4" cellpadding="2" class="cmd"><br />
<tr><br />
<td colspan="2" class="cmd">\setuppaper<span class="first" >[...,...=...,...]</span></td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Reference/en/keyword:paper|paper]]</td><br />
<td>[[Reference/en/value:name|name]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Reference/en/keyword:page|page]]</td><br />
<td>[[Reference/en/value:name|name]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Reference/en/keyword:nx|nx]]</td><br />
<td>[[Reference/en/value:number|number]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Reference/en/keyword:ny|ny]]</td><br />
<td>[[Reference/en/value:number|number]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Reference/en/keyword:width|width]]</td><br />
<td>[[Reference/en/value:dimension|dimension]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Reference/en/keyword:height|height]]</td><br />
<td>[[Reference/en/value:dimension|dimension]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Reference/en/keyword:topspace|topspace]]</td><br />
<td>[[Reference/en/value:dimension|dimension]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Reference/en/keyword:backspace|backspace]]</td><br />
<td>[[Reference/en/value:dimension|dimension]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Reference/en/keyword:option|option]]</td><br />
<td>[[Reference/en/value:max|max]] [[Reference/en/value:fit|fit]] </td><br />
</tr><br />
</table><br />
<br />
<br />
== Description ==<br />
This command is used in connection with [XY] arranging only!<br />
<br />
This command provides the means to setup the parameters needed for [XY] arrangement. Next to this it is possible to adjust the horizontal and vertical placement of the total of the arranged part.<br />
<br />
== Example ==<br />
<!-- Please fill in an example if you can --><br />
Consider an A4 sheet of labels which carries 12 labels. The topspace before the first label is 21 mm, the left and right space alongside the edges of the sheet is 8 mm.<br />
<br />
The important thing is, that the horizontal and vertical adjustments only take place, if the command<br />
<br />
<texcode><br />
\setuplayout[location=middle]<br />
</texcode><br />
<br />
is issued again as shown in the example code below or that the location=middle is added to the \stuplayout of the page. Furthermore the dx and dy parameters in the \setuppaper command, which indicate the distance betweeen adjacant pages may not be 0, because otherwise the location=middle option will cause the label-pages beeing distributed evenly over the space keeping top and bottom and left and right space equally large. <br />
<br />
<texcode><br />
\definepapersize[Label][height=42.3mm,width=97mm]<br />
\setuppapersize[Label][A4]<br />
\setuppaper<br />
[topspace=21mm, <br />
backspace=8mm,<br />
dx=0.5mm,<br />
dy=0mm,<br />
nx=2,<br />
ny=6]<br />
<br />
\setuplayout<br />
[page=Label,<br />
topspace=4mm,<br />
backspace=5mm,<br />
margin=0mm,<br />
width=87mm,<br />
height=34.3mm,<br />
header=0mm,<br />
footer=0mm]<br />
<br />
\setuplayout[location=middle]<br />
<br />
\showframe<br />
\definelayer[Label][width=\paperwidth, height=\paperheight]<br />
\setuparranging[XY]<br />
<br />
\starttext<br />
\dorecurse{12}<br />
{\setlayerframed<br />
[Label]<br />
[preset=leftbottom,y=.9cm,x=0mm]<br />
[frame=off, style=\tfx]<br />
{\CONTEXT\ is fun!}<br />
\startstandardmakeup<br />
\placelayer[Label]\page<br />
\stopstandardmakeup}<br />
\stoptext<br />
</texcode><br />
<br />
== See also ==<br />
<!-- something like [[cmd:goto|\goto]] --><br />
<br />
[[Category:Reference/en|setuppaper]]</div>Willihttps://wiki.contextgarden.net/index.php?title=Command/setuppaper&diff=12897Command/setuppaper2011-03-03T19:53:01Z<p>Willi: /* Example */</p>
<hr />
<div>{{Reference<br />
|name=setuppaper<br />
|attributes=<br />
}}<br />
<br />
== [[Help:Reference|Syntax]] ==<br />
<table cellspacing="4" cellpadding="2" class="cmd"><br />
<tr><br />
<td colspan="2" class="cmd">\setuppaper<span class="first" >[...,...=...,...]</span></td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Reference/en/keyword:paper|paper]]</td><br />
<td>[[Reference/en/value:name|name]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Reference/en/keyword:page|page]]</td><br />
<td>[[Reference/en/value:name|name]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Reference/en/keyword:nx|nx]]</td><br />
<td>[[Reference/en/value:number|number]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Reference/en/keyword:ny|ny]]</td><br />
<td>[[Reference/en/value:number|number]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Reference/en/keyword:width|width]]</td><br />
<td>[[Reference/en/value:dimension|dimension]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Reference/en/keyword:height|height]]</td><br />
<td>[[Reference/en/value:dimension|dimension]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Reference/en/keyword:topspace|topspace]]</td><br />
<td>[[Reference/en/value:dimension|dimension]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Reference/en/keyword:backspace|backspace]]</td><br />
<td>[[Reference/en/value:dimension|dimension]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Reference/en/keyword:option|option]]</td><br />
<td>[[Reference/en/value:max|max]] [[Reference/en/value:fit|fit]] </td><br />
</tr><br />
</table><br />
<br />
<br />
== Description ==<br />
This command is used in connection with [XY] arranging only!<br />
<br />
This command provides the means to setup the parameters needed for [XY] arrangement. Next to this it is possible to adjust the horizontal and vertical placement of the total of the arranged part.<br />
<br />
== Example ==<br />
<!-- Please fill in an example if you can --><br />
Consider an A4 sheet of labels which carries 12 labels. The topspace before the first label is 21 mm, the left and right space alongside the edges of the sheet is 8 mm.<br />
<br />
The important thing is, that the horizontal and vertical adjustments only take place, if the command<br />
<br />
<texcode><br />
\setuplayout[location=middle]<br />
</texcode><br />
<br />
is issued again as shown in the example code below.<br />
<br />
<texcode><br />
\definepapersize[Label][height=42.3mm,width=97mm]<br />
\setuppapersize[Label][A4]<br />
\setuppaper<br />
[topspace=21mm, <br />
backspace=8mm,<br />
dx=0.5mm,<br />
dy=0mm,<br />
nx=2,<br />
ny=6]<br />
<br />
\setuplayout<br />
[page=Label,<br />
topspace=4mm,<br />
backspace=5mm,<br />
margin=0mm,<br />
width=87mm,<br />
height=34.3mm,<br />
header=0mm,<br />
footer=0mm]<br />
<br />
\setuplayout[location=middle]<br />
<br />
\showframe<br />
\definelayer[Label][width=\paperwidth, height=\paperheight]<br />
\setuparranging[XY]<br />
<br />
\starttext<br />
\dorecurse{12}<br />
{\setlayerframed<br />
[Label]<br />
[preset=leftbottom,y=.9cm,x=0mm]<br />
[frame=off, style=\tfx]<br />
{\CONTEXT\ is fun!}<br />
\startstandardmakeup<br />
\placelayer[Label]\page<br />
\stopstandardmakeup}<br />
\stoptext<br />
</texcode><br />
<br />
== See also ==<br />
<!-- something like [[cmd:goto|\goto]] --><br />
<br />
[[Category:Reference/en|setuppaper]]</div>Willihttps://wiki.contextgarden.net/index.php?title=Command/setuppaper&diff=12896Command/setuppaper2011-03-03T19:38:45Z<p>Willi: /* Example */</p>
<hr />
<div>{{Reference<br />
|name=setuppaper<br />
|attributes=<br />
}}<br />
<br />
== [[Help:Reference|Syntax]] ==<br />
<table cellspacing="4" cellpadding="2" class="cmd"><br />
<tr><br />
<td colspan="2" class="cmd">\setuppaper<span class="first" >[...,...=...,...]</span></td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Reference/en/keyword:paper|paper]]</td><br />
<td>[[Reference/en/value:name|name]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Reference/en/keyword:page|page]]</td><br />
<td>[[Reference/en/value:name|name]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Reference/en/keyword:nx|nx]]</td><br />
<td>[[Reference/en/value:number|number]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Reference/en/keyword:ny|ny]]</td><br />
<td>[[Reference/en/value:number|number]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Reference/en/keyword:width|width]]</td><br />
<td>[[Reference/en/value:dimension|dimension]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Reference/en/keyword:height|height]]</td><br />
<td>[[Reference/en/value:dimension|dimension]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Reference/en/keyword:topspace|topspace]]</td><br />
<td>[[Reference/en/value:dimension|dimension]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Reference/en/keyword:backspace|backspace]]</td><br />
<td>[[Reference/en/value:dimension|dimension]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Reference/en/keyword:option|option]]</td><br />
<td>[[Reference/en/value:max|max]] [[Reference/en/value:fit|fit]] </td><br />
</tr><br />
</table><br />
<br />
<br />
== Description ==<br />
This command is used in connection with [XY] arranging only!<br />
<br />
This command provides the means to setup the parameters needed for [XY] arrangement. Next to this it is possible to adjust the horizontal and vertical placement of the total of the arranged part.<br />
<br />
== Example ==<br />
<!-- Please fill in an example if you can --><br />
Consider an A4 sheet of labels which carries 12 labels. The topspace before the first label is 21 mm, the left and right space alongside the edges of the sheet is 8 mm.<br />
<br />
\definepapersize[Label][height=42.3mm,width=97mm]<br />
\setuppapersize[Label][A4]<br />
\setuppaper<br />
[topspace=21mm, <br />
backspace=8mm,<br />
dx=0.5mm,<br />
dy=0mm,<br />
nx=2,<br />
ny=6]<br />
<br />
\setuplayout<br />
[page=Label,<br />
topspace=4mm,<br />
backspace=5mm,<br />
margin=0mm,<br />
width=87mm,<br />
height=34.3mm,<br />
header=0mm,<br />
footer=0mm]<br />
<br />
\setuplayout [location=middle]<br />
<br />
\showframe<br />
\definelayer[Label][width=\paperwidth, height=\paperheight]<br />
\setuparranging[XY]<br />
<br />
\starttext<br />
\dorecurse{12}<br />
{\setlayerframed<br />
[Label]<br />
[preset=leftbottom,y=.9cm,x=0mm]<br />
[frame=off, style=\tfx]<br />
{NTG-secretary}<br />
\startstandardmakeup<br />
\placelayer[Label]\page<br />
\stopstandardmakeup}<br />
\stoptext<br />
<br />
== See also ==<br />
<!-- something like [[cmd:goto|\goto]] --><br />
<br />
[[Category:Reference/en|setuppaper]]</div>Willihttps://wiki.contextgarden.net/index.php?title=Command/setuppaper&diff=12895Command/setuppaper2011-03-03T19:34:00Z<p>Willi: /* Description */</p>
<hr />
<div>{{Reference<br />
|name=setuppaper<br />
|attributes=<br />
}}<br />
<br />
== [[Help:Reference|Syntax]] ==<br />
<table cellspacing="4" cellpadding="2" class="cmd"><br />
<tr><br />
<td colspan="2" class="cmd">\setuppaper<span class="first" >[...,...=...,...]</span></td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Reference/en/keyword:paper|paper]]</td><br />
<td>[[Reference/en/value:name|name]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Reference/en/keyword:page|page]]</td><br />
<td>[[Reference/en/value:name|name]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Reference/en/keyword:nx|nx]]</td><br />
<td>[[Reference/en/value:number|number]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Reference/en/keyword:ny|ny]]</td><br />
<td>[[Reference/en/value:number|number]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Reference/en/keyword:width|width]]</td><br />
<td>[[Reference/en/value:dimension|dimension]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Reference/en/keyword:height|height]]</td><br />
<td>[[Reference/en/value:dimension|dimension]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Reference/en/keyword:topspace|topspace]]</td><br />
<td>[[Reference/en/value:dimension|dimension]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Reference/en/keyword:backspace|backspace]]</td><br />
<td>[[Reference/en/value:dimension|dimension]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Reference/en/keyword:option|option]]</td><br />
<td>[[Reference/en/value:max|max]] [[Reference/en/value:fit|fit]] </td><br />
</tr><br />
</table><br />
<br />
<br />
== Description ==<br />
This command is used in connection with [XY] arranging only!<br />
<br />
This command provides the means to setup the parameters needed for [XY] arrangement. Next to this it is possible to adjust the horizontal and vertical placement of the total of the arranged part.<br />
<br />
== Example ==<br />
<!-- Please fill in an example if you can --><br />
<br />
== See also ==<br />
<!-- something like [[cmd:goto|\goto]] --><br />
<br />
[[Category:Reference/en|setuppaper]]</div>Willihttps://wiki.contextgarden.net/index.php?title=Thumb_index&diff=12883Thumb index2011-02-28T13:55:59Z<p>Willi: The example in MKIV does not work due to the fact that in the first run the headnumbers are not there yet, so the numeric variables need to get a defined value first. Willi</p>
<hr />
<div>{{todo | this page needs to be cleaned up}}<br />
<br />
The following code is an example of how to draw a graphic on every page of a document. The graphic (a grey rectangle) appears in a different place for each chapter, and the chapter number appears in the rectangle as well. This is often called a thumb index - your thumb can flip the pages of a book while you watch the contents flash past...<br />
<br />
<texcode><br />
% by Hans Hagen, of course :-)<br />
<br />
\unprotected \def\rawsectionnumber#1{\countervalue{\??se#1}} % will be in kernel<br />
<br />
\setuppagenumbering<br />
[alternative=doublesided]<br />
<br />
\setupcolors<br />
[state=start]<br />
<br />
\setupbackgrounds<br />
[page]<br />
[background=thumbs]<br />
<br />
\defineoverlay<br />
[thumbs]<br />
[\setups{thumbs}]<br />
<br />
\def\NOfChapters{4} % i need to make this one available<br />
<br />
\startsetups thumbs<br />
<br />
\definemeasure[thumbheight][\dimexpr\paperheight/\NOfChapters\relax]<br />
<br />
\vbox to \paperheight \bgroup<br />
\vskip \rawsectionnumber{section-2} \measure{thumbheight}<br />
\vskip -1 \measure{thumbheight}<br />
\doifoddpageelse\hfill\donothing<br />
\framed<br />
[background=color,<br />
backgroundcolor=darkgray,<br />
frame=off,<br />
foregroundcolor=white,<br />
height=\measure{thumbheight},width=1cm]<br />
{\bfa \rawsectionnumber{section-2}}<br />
\doifoddpageelse\donothing\hfill<br />
\vss<br />
\egroup<br />
<br />
\stopsetups<br />
<br />
\starttext<br />
<br />
\chapter{first} \dorecurse{10}{\input tufte }<br />
\chapter{second} \dorecurse{10}{\input davis }<br />
\chapter{third} \dorecurse{10}{\input zapf }<br />
\chapter{fourth} \dorecurse{10}{\input bryson }<br />
<br />
\stoptext<br />
</texcode><br />
<br />
<br />
== Another Example ==<br />
An example (MkIV) for using Metapost to create thumb indices for chapters.<br />
<br />
<texcode><br />
\setuppapersize[A4][A4,oversized]<br />
<br />
\setuplayout<br />
[width=middle,<br />
% margin=\dimexpr\backspace-\margindistance\relax<br />
location=middle]<br />
<br />
\definecolor[chap_frame][g=1,t=1,a=12]<br />
\definecolor[sect_frame][b=1,t=1,a=12]<br />
\definecolor[textcolor] [r=1,t=1,a=12]<br />
<br />
\startuseMPgraphic{chapter thumb}<br />
path chap_frame, sect_frame ; pair pos,a,b ; picture text ;<br />
<br />
if \somenamedheadnumber{chapter}{current} > 0 :<br />
curr_chap := \somenamedheadnumber{chapter}{current} ; <br />
else :<br />
curr_chap := 1 ;<br />
fi;<br />
if \somenamedheadnumber{chapter}{last} > 0 :<br />
last_chap := \somenamedheadnumber{chapter}{last} ;<br />
else :<br />
last_chap := 1 ;<br />
fi;<br />
if \somenamedheadnumber{section}{current} > 0 : <br />
curr_sect := \somenamedheadnumber{section}{current} ; <br />
else: <br />
curr_sect := 1 ;<br />
fi;<br />
if \somenamedheadnumber{section}{last} > 0 :<br />
last_sect := \somenamedheadnumber{section}{last};<br />
else:<br />
last_sect := 1;<br />
fi; <br />
<br />
skip := TextHeight * (curr_chap-1)/last_chap ;<br />
height := TextHeight/last_chap ;<br />
sskip := height*curr_sect/last_sect ;<br />
<br />
text := textext("\ssbfb\textcolor Chapter\enspace\getmarking[chapternumber]");<br />
<br />
StartPage ;<br />
chap_frame := fullsquare xyscaled(RightMarginWidth,height) ;<br />
<br />
a := ulcorner chap_frame ;<br />
b := urcorner chap_frame ;<br />
<br />
sect_frame := a--b--(xpart b,ypart b-sskip)--(xpart a,ypart a-sskip)--cycle;<br />
<br />
pos := urcorner Field[Text][RightMarginSeparator] -<br />
ulcorner chap_frame - (0,skip);<br />
<br />
fill chap_frame shifted pos withcolor \MPcolor{chap_frame};<br />
unfill sect_frame shifted pos withcolor white ;<br />
fill sect_frame shifted pos withcolor \MPcolor{sect_frame};<br />
draw text rotated 90 shifted pos ;<br />
StopPage ;<br />
\stopuseMPgraphic<br />
<br />
<br />
\defineoverlay[chapter thumb][\useMPgraphic{chapter thumb}]<br />
<br />
\setupbackgrounds[page][background=chapter thumb]<br />
<br />
<br />
\starttext \showframe<br />
\dorecurse{6}{\chapter{Test Chapter #1}<br />
Chapter \somestructureheadnumber[chapter][current] of<br />
\somestructureheadnumber[chapter][last]<br />
\dorecurse{9}{\section{Test Section}<br />
Section \somestructureheadnumber[section][current] of<br />
\somestructureheadnumber[section][last] \blank<br />
\input tufte \par \input knuth \par<br />
}<br />
}<br />
\stoptext<br />
</texcode></div>Willihttps://wiki.contextgarden.net/index.php?title=Image_Database&diff=12822Image Database2011-02-01T22:16:41Z<p>Willi: In MKIV there is a slightly different approach to the figure-library generation and the xml-database has different labeling.</p>
<hr />
<div>< [[Graphics]] | [[XML]] | [[Figure library]] | [[Image library]] | [[Resource library]] ><br />
<br />
ConTeXt's direct XML processing allows a rather mighty management of pictures with an XML database.<br />
You can not only store images in this way, officially this technique is now named "Resource Libraries".<br />
<br />
[http://www.ntg.nl:8061/makeres.pdf Here] you can make such files online. (PDF interface!)<br />
<br />
'''XML database file: MKII'''<br />
<br />
<xmlcode><br />
<figurelibrary language="en"><br />
<description><br />
<organization>Pragma ADE</organization><br />
<project>ConTeXt Wiki</project><br />
<product>prd_pictures</product><br />
<comment>pictures for ConTeXt Wiki</comment><br />
</description><br />
<figure><br />
<file>filename</file><br />
<label>reference</label><br />
<copyright>owner</copyright><br />
<comment>comment</comment><br />
</figure><br />
<figure><br />
...<br />
</figure><br />
...<br />
</figurelibrary><br />
</xmlcode><br />
<br />
'''XML database file: MKIV'''<br />
<br />
<xmlcode><br />
<rl:library language="en"><br />
<br />
<rl:description><br />
<rl:organization>Organisation</rl:organization><br />
<rl:project>ConTeXt Wiki</rl:project><br />
<rl:product>product pictures</rl:product><br />
<rl:comment>pictures for ConTeXt Wiki</rl:comment><br />
</rl:description><br />
<br />
<rl:resource><br />
<rl:file>filename</rl:file><br />
<rl:label>reference</rl:label><br />
<rl:copyright>owner</rl:copyright><br />
<rl:comment>comment</rl:comment><br />
</rl:resource><br />
</rl:library<br />
</xmlcode><br />
<br />
'''Making a PDF list MKII'''<br />
<br />
<pre><br />
texexec --pdf --use=fig-make --mode=compact myfile<br />
</pre><br />
<br />
'''Making a PDF list MKIV'''<br />
<br />
<pre><br />
context --input=figure-lib.xml auto:x-res-01.mkiv --result=figure-lib<br />
</pre><br />
<br />
'''Use pictures from database'''<br />
<br />
<texcode><br />
\usemodule [fig-base]<br />
\usefigurebase [myfile]<br />
<br />
\externalfigure [reference] % like in &lt;label><br />
</texcode><br />
<br />
<br />
<br />
[[Category:Graphics]]<br />
[[Category:XML]]<br />
[[Category:Figure library]]<br />
[[Category:Image library]]</div>Willihttps://wiki.contextgarden.net/index.php?title=TABLE&diff=10243TABLE2010-01-05T21:24:48Z<p>Willi: /* Make a cell bold */</p>
<hr />
<div>< [[Tables Overview]] | [[XML]] ><br />
<br />
=Introduction=<br />
<br />
This table mode is called &ldquo;natural tables&rdquo; or &ldquo;automatic tables.&rdquo; I'd call it &ldquo;HTML tables,&rdquo; because it's very similar to them. They're especially suited for [[XML]] conversions.<br />
<br />
Beware: every element must use <tt>\b</tt> ... <tt>\e</tt>!<br />
<br />
You find a lot of samples in [[manual:enattab.pdf|enattab.pdf]]<br />
<br />
Willi Egger wrote a [[My Way]] how he set a typesetter's lead type case: [http://dl.contextgarden.net/myway/NaturalTables.pdf Use of natural tables]<br />
<br />
<texcode><br />
\setupTABLE[row][odd][background=color,backgroundcolor=red, width=.2\textwidth]<br />
\bTABLE[split=yes]<br />
\bTR \bTD[nr=3] 1 \eTD \bTD[nc=2] 2/3 \eTD \bTD[nr=3] 4 \eTD \eTR<br />
\bTR \bTD 2 \eTD \bTD 3 \eTD \eTR<br />
\bTR \bTD 2 \eTD \bTD 3 \eTD \eTR<br />
\bTR \bTD[nc=3] 1/2/3 \eTD \bTD 4 \eTD \eTR<br />
\bTR \bTD 1 \eTD \bTD 2 \eTD \bTD 3 \eTD \bTD 4 \eTD \eTR<br />
\eTABLE<br />
</texcode><br />
<br />
You get automatic page breaking with the option <tt>[split=yes]</tt>.<br />
<br />
The sample looks like this:<br />
<br />
<context><br />
\setupTABLE[row][odd][background=color,backgroundcolor=red, width=.2\textwidth]<br />
\bTABLE[split=yes]<br />
\bTR \bTD[nr=3] 1 \eTD \bTD[nc=2] 2/3 \eTD \bTD[nr=3] 4 \eTD \eTR<br />
\bTR \bTD 2 \eTD \bTD 3 \eTD \eTR<br />
\bTR \bTD 2 \eTD \bTD 3 \eTD \eTR<br />
\bTR \bTD[nc=3] 1/2/3 \eTD \bTD 4 \eTD \eTR<br />
\bTR \bTD 1 \eTD \bTD 2 \eTD \bTD 3 \eTD \bTD 4 \eTD \eTR<br />
\eTABLE<br />
</context><br />
<br />
= Multipage TABLEs =<br />
<br />
Try to divide your table into...<br />
* <cmd>bTABLEhead</cmd> (table header)<br />
* <cmd>bTABLEnext</cmd> (alternate table header on following pages)<br />
* <cmd>bTABLEbody</cmd> (table body)<br />
* <cmd>bTABLEfoot</cmd> (table footer)<br />
and <cmd>setupTABLE</cmd><tt>[split=yes]</tt> or <tt>[split=repeat]</tt><br />
<br />
see also [[source:core-ntb.tex|core-ntb.tex]]<br />
<br />
If you must <b>split</b> a natural table over several pages, you can<br />
simply do this by adding <tt>\setupTABLE[split=yes]</tt> to your TABLE<br />
definition. An other way is to define it right at the TABLE start<br />
by adding the parameter <tt>[split=yes]</tt> (see example).<br />
<br />
In this case the <b>table head</b><br />
(all between <cmd>bTABLEhead</cmd> and <cmd>eTABLEhead</cmd>)<br />
is printed only once at the beginning of the table. But if you use <tt>[split=repeat]</tt>,<br />
it is printed on top of every new page, that contains parts of<br />
your multipage table. Please take account of the fact, that the<br />
head cells are enclosed by <cmd>bTH</cmd> and <cmd>eTH</cmd> (and not \[be]TC).<br />
<br />
If you want to use an alternative table header for all following pages,<br />
you can do this by defining an additional header. Just add the second header<br />
between <cmd>bTABLEnext</cmd>...<cmd>eTABLEnext</cmd>,<br />
right after your normal head definition.<br />
Now every additional page of the multipage table starts with the<br />
<b>next table head</b>.<br />
<br />
The <b>table foot</b> is declared between <cmd>bTABLEfoot</cmd> and<br />
<cmd>eTABLEfoot</cmd>. It defines the concluding row of your natural table.<br />
<br />
The following standalone example deals with all the mentioned aspects of natural tables.<br />
Just <i>copy&paste</i> it as a starting point for further experiments...<br />
<br />
<texcode><br />
\starttext<br />
<br />
\setupcolors[state=start]<br />
<br />
% setup for all cells<br />
\setupTABLE[r][each][style=\tfx\it, align=center]<br />
<br />
% setup table head<br />
\setupTABLE[r][first]<br />
[background=color,<br />
backgroundcolor=yellow]<br />
% setup table footer<br />
\setupTABLE[r][last]<br />
[style=bold,<br />
background=color,<br />
backgroundcolor=green]<br />
<br />
\bTABLE[split=repeat,option=stretch]% head on every page, stretch columns<br />
%<br />
% IMPORTANT: use \bTH ... \eTH to enclose the head|next cells<br />
\bTABLEhead<br />
\bTR<br />
\bTH head1 \eTH<br />
\bTH head2 \eTH<br />
\bTH head3 \eTH<br />
\eTR<br />
\eTABLEhead<br />
% <br />
\bTABLEnext % setup for next table head<br />
\bTR [background=color,backgroundcolor=cyan]<br />
\bTH next1 \eTH<br />
\bTH next2 \eTH<br />
\bTH next3 \eTH<br />
\eTR<br />
\eTABLEnext<br />
%<br />
% the table body (main part)<br />
%<br />
\bTABLEbody<br />
%<br />
\dorecurse{100}{% 100 rows<br />
\bTR<br />
\bTC body body body body body \eTC<br />
\bTC body body body body body \eTC<br />
\bTC body body body body body \eTC<br />
\eTR<br />
}%<br />
%<br />
\eTABLEbody<br />
%<br />
% the table foot<br />
%<br />
\bTABLEfoot<br />
\bTR<br />
\bTC foot1 \eTC<br />
\bTC foot2 \eTC<br />
\bTC foot3 \eTC<br />
\eTR<br />
\eTABLEfoot<br />
%<br />
\eTABLE<br />
<br />
\stoptext<br />
</texcode><br />
<br />
= Creating tables from CSV data (Comma Separated Values) =<br />
<br />
See also [[m-database|the database module]]!<br />
<br />
and [http://dl.contextgarden.net/myway/csv.pdf Creating Tables using CSV (Comma-separated values)] by Mojca Miklavec<br />
<br />
<br />
<!-- Maybe some other place or a separate page is more appropriate for this section --><br />
<br />
An interesting example of creating a table using comma separated values was posted to the [http://archive.contextgarden.net/message/20050923.193302.f2110c93.en.html mailing list] by [[User:ChristopherCreutzig|Christopher Creutzig]]<br />
<br />
The following macros take care of processing CSV data:<br />
<texcode><br />
% Iterate over all the lines of text captured with \obeylines active<br />
% command to call is first argument, is not called for empty lines<br />
\bgroup<br />
\obeylines<br />
\gdef\ProcessLines#1#2{\doProcessLines{#1}#2^^M\doProcessLines}%<br />
\gdef\doProcessLines#1#2^^M#3\doProcessLines{%<br />
\doifnotempty{#2}{#1{#2}}%<br />
\doifnotempty{#3}{\doProcessLines{#1}#3\doProcessLines}%<br />
}%<br />
\egroup<br />
<br />
\def\startCSV{\bgroup\obeylines\dostartCSV}<br />
</texcode><br />
<br />
The next lines are an example of transforming the data into a natural table, but can be easily adapted to any type of the table or perhaps (mis)used in even more strange ways:<br />
<br />
<texcode><br />
\def\TBLentry#1{\bTD#1\eTD}<br />
\def\TBLline#1{\bTR\processcommalist[#1]\TBLentry}<br />
<br />
\def\dostartCSV#1\stopCSV{%<br />
\bTABLE<br />
\ProcessLines\TBLline{#1}%<br />
\eTABLE<br />
\egroup<br />
}<br />
</texcode><br />
<br />
The following lines will then finally result in a desired table:<br />
<br />
<texcode><br />
% some additional settings for the table may be made as well<br />
\setupTABLE[c][2][style=\tt]<br />
\setupTABLE[c][3][align=middle]<br />
\setupTABLE[r][1][style=bold] % how to override the \tt in the second column?<br />
<br />
\startCSV<br />
Name,Email,Accepted<br />
\CONTEXT,worth@trying.to,Yes<br />
Hans,main@developer.of,Yes<br />
Bug,get@rid.of,No<br />
\stopCSV<br />
</texcode><br />
<br />
<context><br />
% Iterate over all the lines of text captured with \obeylines active<br />
% command to call is first argument, is not called for empty lines<br />
\bgroup<br />
\obeylines<br />
\gdef\ProcessLines#1#2{\doProcessLines{#1}#2^^M\doProcessLines}%<br />
\gdef\doProcessLines#1#2^^M#3\doProcessLines{%<br />
\doifnotempty{#2}{#1{#2}}%<br />
\doifnotempty{#3}{\doProcessLines{#1}#3\doProcessLines}%<br />
}%<br />
\egroup<br />
<br />
\def\startCSV{\bgroup\obeylines\dostartCSV}<br />
<br />
\def\TBLentry#1{\bTD#1\eTD}<br />
\def\TBLline#1{\bTR\processcommalist[#1]\TBLentry}<br />
<br />
\def\dostartCSV#1\stopCSV{%<br />
\bTABLE<br />
\ProcessLines\TBLline{#1}%<br />
\eTABLE<br />
\egroup<br />
}<br />
<br />
\setupTABLE[c][2][style=\tt]<br />
\setupTABLE[c][3][align=middle]<br />
\setupTABLE[r][1][style={\rm\bf}]<br />
\startCSV<br />
Name,Email,Accepted<br />
\CONTEXT,worth@trying.to,Yes<br />
Hans,main@developer.of,Yes<br />
Bug,get@rid.of,No<br />
\stopCSV<br />
</context><br />
<br />
Some remarks: the (tentative) code ignores the fact that<br />
* csv data may optionally be enclosed in "" quotes that have to be removed (to be done in \TBLentry) <br />
* quoted strings may contain commas themselves (which means writing a custom version of \processcommalist instead).<br />
<br />
{{howto}}<br />
<br />
HH: there is: <br />
<br />
<texcode><br />
\processseparatedlist[list][separator]\command<br />
</texcode><br />
<br />
What about separating the values using tabs?<br />
<br />
= Designing complex TABLEs =<br />
<br />
Everything is easy when a simple grid is enough. Unfortunately, this<br />
is not the case most of the time, tables tend to have information<br />
which should flow accross cell boundaries either vertically<br />
or horizontally. One of the reasons to use TABLE instead of the<br />
table environment is that TABLE provides an easy (relatively speaking, <br />
at least) way to make merged cells to both directions.<br />
<br />
There are probably as many ways to design TABLEs as there are<br />
users, but a simple one to begin with is to start with a<br />
grid:<br />
<br />
<context><br />
\setupTABLE[r][each][height=1cm]<br />
\setupTABLE[c][each][width=1cm]<br />
\bTABLE<br />
\bTR \bTD r1c1 \eTD \bTD r1c2 \eTD \bTD r1c3 \eTD \bTD r1c4 \eTD \bTD r1c5 \eTD \bTD r1c6 \eTD \eTR<br />
\bTR \bTD r2c1 \eTD \bTD r2c2 \eTD \bTD r2c3 \eTD \bTD r2c4 \eTD \bTD r2c5 \eTD \bTD r2c6 \eTD \eTR<br />
\bTR \bTD r3c1 \eTD \bTD r3c2 \eTD \bTD r3c3 \eTD \bTD r3c4 \eTD \bTD r3c5 \eTD \bTD r3c6 \eTD \eTR<br />
\bTR \bTD r4c1 \eTD \bTD r4c2 \eTD \bTD r4c3 \eTD \bTD r4c4 \eTD \bTD r4c5 \eTD \bTD r4c6 \eTD \eTR<br />
\bTR \bTD r5c1 \eTD \bTD r5c2 \eTD \bTD r5c3 \eTD \bTD r5c4 \eTD \bTD r5c5 \eTD \bTD r5c6 \eTD \eTR<br />
\bTR \bTD r6c1 \eTD \bTD r6c2 \eTD \bTD r6c3 \eTD \bTD r6c4 \eTD \bTD r6c5 \eTD \bTD r6c6 \eTD \eTR<br />
\eTABLE<br />
</context><br />
<br />
The desired table layout is then drawn onto this grid, and the top left corner cell<br />
of each cell in the final layout identified:<br />
<br />
<context><br />
\setupTABLE[r][each][height=1cm]<br />
\setupTABLE[c][each][width=1cm]<br />
\setupTABLE[r][1][height=0cm,frame=off]<br />
\bTABLE<br />
\bTR \bTD \eTD \bTD \eTD \bTD \eTD \bTD \eTD \bTD \eTD \bTD \eTD \eTR<br />
\bTR \bTD[nc=2,nr=2] r1c1 \eTD \bTD r1c3 \eTD \bTD[nr=2] r1c4 \eTD \bTD[nc=2,nr=2] r1c5 \eTD \eTR<br />
\bTR \bTD[nr=2] r2c3 \eTD \eTR<br />
\bTR \bTD[nc=2] r3c1 \eTD \bTD[nc=2] r3c4 \eTD \bTD r3c6 \eTD \eTR<br />
\bTR \bTD r4c1 \eTD \bTD[nc=2] r4c2 \eTD \bTD[nr=2] r4c4 \eTD \bTD[nc=2] r4c5 \eTD \eTR<br />
\bTR \bTD[nr=2,nc=2] r5c1 \eTD \bTD[nr=2] r5c3 \eTD \bTD[nr=2,nc=2] r5c5 \eTD \eTR<br />
\bTR \bTD r6c4 \eTD \eTR<br />
\eTABLE<br />
</context><br />
<br />
The cells are listed from left to right and up to down. Each larger cell is then given<br />
it size by using <tt>nc=...</tt> and <tt>nr=...</tt> parameters with <tt>\bTD</tt>. The<br />
code producing the table above is:<br />
<br />
<texcode><br />
\setupTABLE[r][each][height=1cm]<br />
\setupTABLE[c][each][width=1cm]<br />
\setupTABLE[r][1][height=0cm,frame=off]<br />
\bTABLE<br />
\bTR \bTD \eTD \bTD \eTD \bTD \eTD \bTD \eTD \bTD \eTD \bTD \eTD \eTR<br />
\bTR \bTD[nc=2,nr=2] r1c1 \eTD \bTD r1c3 \eTD \bTD[nr=2] r1c4 \eTD \bTD[nr=2,nc=2] r1c5 \eTD \eTR<br />
\bTR \bTD[nr=2] r2c3 \eTD \eTR<br />
\bTR \bTD[nc=2] r3c1 \eTD \bTD[nc=2] r3c4 \eTD \bTD r3c6 \eTD \eTR<br />
\bTR \bTD r4c1 \eTD \bTD[nc=2] r4c2 \eTD \bTD[nr=2] r4c4 \eTD \bTD[nc=2] r4c5 \eTD \eTR<br />
\bTR \bTD[nr=2,nc=2] r5c1 \eTD \bTD[nr=2] r5c3 \eTD \bTD[nr=2,nc=2] r5c5 \eTD \eTR<br />
\bTR \bTD r6c4 \eTD \eTR<br />
\eTABLE<br />
</texcode><br />
<br />
N.B. There is an ugly hack in the code. An empty first row with zero height and no borders<br />
is added. If the row is omitted, then something odd happens to the number of<br />
columns. The table should have all cells, so this may be a bug. (Or then I have<br />
blundered something with this example, possibly.)<br />
<br />
Everything rectangular can be done with TABLE, as long as it can be fit in the grid. The grid<br />
does not have to be equidistant, and if its dimensions are omitted, the program<br />
will fit the data in. L-shaped or other complex cell shapes are not possible.<br />
Using them would be a bit odd, in any case, as alignment and text flow problems<br />
would be quite interesting.<br />
<br />
<br />
== Cell Addressing and Frames ==<br />
<br />
The setup commands for TABLE do not seem to be very verbosedly commented.<br />
There are, however, a few shorthands, which are useful to understand.<br />
First of all, there are several ways to address cells. This is a brief<br />
summary of some of them:<br />
<br />
<texcode><br />
\setupTABLE[r][(list of rows)][...]<br />
\setupTABLE[c][(list of columns)][...]<br />
\setupTABLE[(list of columns)][(list of rows)][...]<br />
</texcode><br />
<br />
A list contains one or more numbers separated by commas.<br />
Word "last" is equivalent to the number of the last row or<br />
column. The complete list can be replaced by the word "each"<br />
to address all cells on the row/column.<br />
<br />
Let us consider the following table:<br />
<br />
<texcode><br />
\setupTABLE[c][each][align={middle,lohi},frame=off]<br />
\setupTABLE[r][2,3,4,5,6][height=1.0cm]<br />
\setupTABLE[r][2,4][topframe=on]<br />
\setupTABLE[c][1,2,3][rightframe=on]<br />
...<br />
</texcode><br />
<br />
In plain language the rows are interpreted as follows:<br />
<br />
* Align each cell in each column (i.e. all cells) horizontally in the middle<br />
and vertically in the middle (lohi), and remove all frames (borders)<br />
* The height of rows 2 -- 6 is 1.0 cm<br />
* Draw a line on top of rows 2 and 4<br />
* Draw a line to the right side of columns 1 -- 3<br />
<br />
In this case the table is slightly complicated, there are some split cells,<br />
as shown below:<br />
<br />
<table><tr valign="top"><td><br />
<texcode><br />
\bTABLE<br />
\bTR<br />
\bTD \bf r1c1 \eTD<br />
\bTD \bf r1c2 \eTD<br />
\bTD \bf r1c3 \eTD<br />
\bTD \bf r1c4 \eTD<br />
\eTR<br />
\bTR<br />
\bTD r2c1 \eTD<br />
\bTD r2c2 \eTD<br />
\bTD[nr=2] r2c3 \eTD<br />
\bTD r2c4 \eTD<br />
\eTR<br />
\bTR<br />
\bTD r3c1 \eTD<br />
\bTD r3c2 \eTD<br />
\bTD r3c4 \eTD<br />
\eTR<br />
\bTR<br />
\bTD r4c1 \eTD<br />
\bTD r4c2 \eTD<br />
\bTD[nr=3] r4c3 \eTD<br />
\bTD[nr=3] r4c4 \eTD<br />
\eTR<br />
\bTR<br />
\bTD r5c1 \eTD<br />
\bTD r5c2 \eTD<br />
\eTR<br />
\bTR<br />
\bTD r6c1 \eTD<br />
\bTD r6c2 \eTD<br />
\eTR<br />
\eTABLE<br />
</texcode><br />
</td><td><br />
<context><br />
\setupTABLE[c][each][align={middle,lohi},frame=off]<br />
\setupTABLE[r][2,3,4,5,6][height=1.0cm]<br />
\setupTABLE[r][2,4][topframe=on]<br />
\setupTABLE[c][1,2,3][rightframe=on]<br />
\bTABLE<br />
\bTR<br />
\bTD \bf r1c1 \eTD<br />
\bTD \bf r1c2 \eTD<br />
\bTD \bf r1c3 \eTD<br />
\bTD \bf r1c4 \eTD<br />
\eTR<br />
\bTR<br />
\bTD r2c1 \eTD<br />
\bTD r2c2 \eTD<br />
\bTD[nr=2] r2c3 \eTD<br />
\bTD r2c4 \eTD<br />
\eTR<br />
\bTR<br />
\bTD r3c1 \eTD<br />
\bTD r3c2 \eTD<br />
\bTD r3c4 \eTD<br />
\eTR<br />
\bTR<br />
\bTD r4c1 \eTD<br />
\bTD r4c2 \eTD<br />
\bTD[nr=3] r4c3 \eTD<br />
\bTD[nr=3] r4c4 \eTD<br />
\eTR<br />
\bTR<br />
\bTD r5c1 \eTD<br />
\bTD r5c2 \eTD<br />
\eTR<br />
\bTR<br />
\bTD r6c1 \eTD<br />
\bTD r6c2 \eTD<br />
\eTR<br />
\eTABLE<br />
</context><br />
</td></tr></table><br />
<br />
The cell numbering is well worth noting. It is very logical (upper<br />
leftmost part of a combined cell), but sometimes the results are<br />
surprising in the beginning.<br />
<br />
The important point about cell numbering is that there is really<br />
a difference between "bottom border of row 3" and "top border of<br />
row 4". To illustrate this, let us change the frame setups:<br />
<br />
<texcode><br />
\setupTABLE[r][2,4][topframe=on]<br />
</texcode><br />
<br />
is changed to<br />
<br />
<texcode><br />
\setupTABLE[r][1,3][bottomframe=on]<br />
</texcode><br />
<br />
At first sight this is exactly the same thing. But...<br />
<br />
<context><br />
\setupTABLE[c][each][align={middle,lohi},frame=off]<br />
\setupTABLE[r][2,3,4,5,6][height=1.0cm]<br />
\setupTABLE[r][1,3][bottomframe=on]<br />
\setupTABLE[c][1,2,3][rightframe=on]<br />
\bTABLE<br />
\bTR<br />
\bTD \bf r1c1 \eTD<br />
\bTD \bf r1c2 \eTD<br />
\bTD \bf r1c3 \eTD<br />
\bTD \bf r1c4 \eTD<br />
\eTR<br />
\bTR<br />
\bTD r2c1 \eTD<br />
\bTD r2c2 \eTD<br />
\bTD[nr=2] r2c3 \eTD<br />
\bTD r2c4 \eTD<br />
\eTR<br />
\bTR<br />
\bTD r3c1 \eTD<br />
\bTD r3c2 \eTD<br />
\bTD r3c4 \eTD<br />
\eTR<br />
\bTR<br />
\bTD r4c1 \eTD<br />
\bTD r4c2 \eTD<br />
\bTD[nr=3] r4c3 \eTD<br />
\bTD[nr=3] r4c4 \eTD<br />
\eTR<br />
\bTR<br />
\bTD r5c1 \eTD<br />
\bTD r5c2 \eTD<br />
\eTR<br />
\bTR<br />
\bTD r6c1 \eTD<br />
\bTD r6c2 \eTD<br />
\eTR<br />
\eTABLE<br />
</context><br />
<br />
Where did the horizontal line in column 3 disappear? Nowhere. There is no<br />
row 3 in column 3, so there cannot be a frame under it. This problem<br />
can be overcome by using topframe and leftframe instead of bottom and<br />
right, as the cells below and to the right of a border have to exist.<br />
<br />
However, this solution leaves the problem of bottom and rightmost borders.<br />
How to draw a line in the bottom of the table? Using <br />
<tt>\setupTABLE[r][6][bottomframe=on]</tt> will leave the gap in columns 3 and 4, <br />
and <tt>\setupTABLE[r][7][topframe=on]</tt> is not possible, as there is no <br />
row 7. The clever idea of using "last" instead of the row number (6) will fail, <br />
as "last" seems to behave exactly the same way as number 6.<br />
<br />
One useful method is to switch on the borders cell by<br />
cell by adding <tt>\setupTABLE[3,4][4][bottomframe=on]</tt>, i.e.<br />
draw a border under cells r4c3 and r4c4.<br />
<br />
<context><br />
\setupTABLE[c][each][align={middle,lohi},frame=off]<br />
\setupTABLE[r][2,3,4,5,6][height=1.0cm]<br />
\setupTABLE[r][2,4][topframe=on]<br />
\setupTABLE[c][1,2,3][rightframe=on]<br />
\setupTABLE[r][6][bottomframe=on]<br />
\setupTABLE[3,4][4][bottomframe=on]<br />
\bTABLE<br />
\bTR<br />
\bTD \bf r1c1 \eTD<br />
\bTD \bf r1c2 \eTD<br />
\bTD \bf r1c3 \eTD<br />
\bTD \bf r1c4 \eTD<br />
\eTR<br />
\bTR<br />
\bTD r2c1 \eTD<br />
\bTD r2c2 \eTD<br />
\bTD[nr=2] r2c3 \eTD<br />
\bTD r2c4 \eTD<br />
\eTR<br />
\bTR<br />
\bTD r3c1 \eTD<br />
\bTD r3c2 \eTD<br />
\bTD r3c4 \eTD<br />
\eTR<br />
\bTR<br />
\bTD r4c1 \eTD<br />
\bTD r4c2 \eTD<br />
\bTD[nr=3] r4c3 \eTD<br />
\bTD[nr=3] r4c4 \eTD<br />
\eTR<br />
\bTR<br />
\bTD r5c1 \eTD<br />
\bTD r5c2 \eTD<br />
\eTR<br />
\bTR<br />
\bTD r6c1 \eTD<br />
\bTD r6c2 \eTD<br />
\eTR<br />
\eTABLE<br />
</context><br />
<br />
== Column Offset/Gap ==<br />
<br />
From the mailing list at 2005-11-09 by Vit Zyka, modified by Hans Hagen:<br />
<br />
<texcode><br />
\starttext<br />
<br />
% distance mechanism, per column (H)<br />
<br />
\start<br />
\setupTABLE[c][1][distance=2em]<br />
\setupTABLE[c][2][distance=3em]<br />
<br />
\bTABLE<br />
\bTR \bTD test \eTD \bTD test \eTD \bTD test \eTD \eTR<br />
\bTR \bTD[nx=2] test \eTD \bTD test \eTD \eTR<br />
\bTR \bTD test \eTD \bTD[nx=2] test \eTD \eTR<br />
\eTABLE<br />
<br />
\bTABLE[option=stretch]<br />
\bTR \bTD test \eTD \bTD test \eTD \bTD test \eTD \eTR<br />
\bTR \bTD[nx=2] test \eTD \bTD test \eTD \eTR<br />
\bTR \bTD test \eTD \bTD[nx=2] test \eTD \eTR<br />
\eTABLE<br />
\stop<br />
<br />
% distance mechanism, per table (V)<br />
<br />
\framed[offset=none]{%<br />
\setupTABLE[column][2][align=left]<br />
\setupTABLE[column][3][align=right]<br />
\bTABLE[columndistance=2cm,leftmargindistance=.3cm,rightmargindistance=.5cm]<br />
\bTR<br />
\bTH[nc=3] Table head\eTH<br />
\eTR<br />
\bTR\bTD[nc=2] AB\eTD\bTD C\eTD\eTR<br />
\bTR\bTD[nc=2,align=left] AB\eTD\bTD C\eTD\eTR<br />
\bTR\bTD[nc=2,align=middle] AB\eTD\bTD C\eTD\eTR<br />
\bTR\bTD A\eTD\bTD B\eTD\bTD C\eTD\eTR<br />
\bTR\bTD Aa\eTD\bTD Bb\eTD\bTD Cccc\eTD\eTR<br />
\bTR\bTD[nc=3,align=middle] ABC\eTD\eTR<br />
\eTABLE<br />
}<br />
<br />
\stoptext<br />
</texcode><br />
<br />
== Make a cell bold ==<br />
<br />
<context source="yes" text="produces"><br />
\bTABLE<br />
\bTR \bTD 1 \eTD \bTD 1 \eTD \bTD 2/3 \eTD \eTR<br />
\bTR \bTD 2 \eTD \bTD 2 \eTD \bTD 3 \eTD \eTR<br />
\bTR \bTD 2 \eTD \bTD[rulethickness=2pt] 2 \eTD \bTD 3 \eTD \eTR<br />
\bTR \bTD 1 \eTD \bTD 1 \eTD \bTD 4 \eTD \eTR<br />
\bTR \bTD 1 \eTD \bTD 1 \eTD \bTD 2 \eTD \eTR<br />
\eTABLE<br />
</context><br />
<br />
From mail december 2009 Hans Hagen en Willi Egger:<br />
<br />
The problem which I was seeking to solve is shown in the above example. The text alignment of the emphasized cell is not optimal. Hans pointed out the possible solution.<br />
<br />
<context source="yes" text="produces"><br />
\setupTABLE[row][each][rulethickness=.25pt,offset=\dimexpr1mm+2pt] <br />
\bTABLE<br />
\bTR \bTD 1 \eTD \bTD 1 \eTD \bTD 2/3 \eTD \eTR<br />
\bTR \bTD 2 \eTD \bTD 2 \eTD \bTD 3 \eTD \eTR<br />
\bTR \bTD 2 \eTD \bTD[rulethickness=2pt,offset=1mm] 2 \eTD \bTD 3 \eTD \eTR<br />
\bTR \bTD 1 \eTD \bTD 1 \eTD \bTD 4 \eTD \eTR<br />
\bTR \bTD 1 \eTD \bTD 1 \eTD \bTD 2 \eTD \eTR<br />
\eTABLE<br />
</context><br />
<br />
As soon as you want to emphasize a cell with a thicker frame, one has to adjust the offset. Basically the general offset will be enlarged by the amount of the rule thickness of the emphasized cell. In the cell with the thicker rule the offset is then diminished by the rule thickness.<br />
<br />
<br />
I place here a more realistic example. Consider you want to create an invoice with several columns. There are no vertical lines. The top frame of the table should have a thicker rule than the dividing rules between the invoice lines. The bottom frame of the list of invoice lines should have also a thicker rule like the top frame:<br />
<br />
<context source="yes" text="produces"><br />
{\bfa Invoice}<br />
\switchtobodyfont[6pt]<br />
\blank<br />
\bTABLE<br />
\setupTABLE[frame=off,offset=1mm]<br />
\setupTABLE[row][*][height=7.25mm]<br />
\setupTABLE[column][1]%<br />
[width=18mm,<br />
offset=\dimexpr1mm+2pt,<br />
align=flushleft]<br />
\setupTABLE[column][2]%<br />
[width=20mm,<br />
offset=\dimexpr1mm+2pt,<br />
align=flushleft]<br />
\setupTABLE[column][3]%<br />
[width=18mm,<br />
offset=\dimexpr1mm+2pt,<br />
align=flushright]<br />
\setupTABLE[column][4]%<br />
[width=18mm,<br />
offset=\dimexpr1mm+2pt,<br />
align=flushright]<br />
\setupTABLE[column][5]%<br />
[width=18mm,<br />
offset=\dimexpr1mm+2pt,<br />
align=left]<br />
\bTR[bottomframe=on, rulethickness=2pt,offset=1mm]<br />
\bTD\bf Date \eTD<br />
\bTD\bf Description \eTD<br />
\bTD\bf Quantity \eTD<br />
\bTD\bf Price \eTD<br />
\bTD\bf Total \eTD<br />
\eTR<br />
\bTR[bottomframe=on,rulethickness=.25pt]<br />
\bTD 05-01-2010 \eTD<br />
\bTD Element 1 \eTD<br />
\bTD 10.0 \eTD<br />
\bTD 6.00 \eTD<br />
\bTD 60.00 \eTD<br />
\eTR<br />
\bTR[bottomframe=on,rulethickness=.25pt]<br />
\bTD 05-01-2010 \eTD<br />
\bTD Element 2 \eTD<br />
\bTD 2.0 \eTD<br />
\bTD 3.00 \eTD<br />
\bTD 6.00 \eTD<br />
\eTR<br />
\bTR[topframe=on,rulethickness=2pt,offset=1mm]<br />
\bTD[nx=3] \eTD<br />
\bTD[align=flushleft] Subtotal \eTD<br />
\bTD 66.00 \eTD<br />
\eTR<br />
\bTR[offset=\dimexpr1mm+2pt]<br />
\bTD[nx=3] \eTD<br />
\bTD[align=flushleft] VAT 19\% \eTD<br />
\bTD 12.54 \eTD<br />
\eTR<br />
\bTR<br />
\bTD[nx=3] \eTD<br />
\bTD[align=flushleft] \bf Total \eTD<br />
\bTD 78.54 \eTD<br />
\eTR<br />
\eTABLE<br />
</context><br />
<br />
== Using character alignment ==<br />
<br />
ConTeXt can align columns of numbers on a character (often a decimal point to align accounting data) automatically, removing the need to add fixed spaces into your document. For any such column you need to specify the character on which to align. You use the <tt>aligncharacter=yes</tt> parameter to set up character alignment, <tt>alignmentcharacter={.}</tt> to say what the character should be (in this case a full stop) and <tt>align=middle</tt> to set the overall alignment of the column.<br />
<br />
<table><tr valign="top"><td><br />
<texcode><br />
\bTABLE<br />
\setupTABLE[column][1][align=right]<br />
\setupTABLE[column][2][alignmentcharacter={.},<br />
aligncharacter=yes,align=middle]<br />
\bTR \bTH Category \eTH \bTH Data entry \eTH \eTR<br />
\bTR \bTD First \eTD \bTD 71.3 \eTD \eTR<br />
\bTR \bTD Second \eTD \bTD 43.7 \eTD \eTR<br />
\bTR \bTD Total \eTD \bTD 115 \eTD \eTR<br />
\eTABLE<br />
</texcode><br />
</td><td><br />
<context><br />
\bTABLE<br />
\setupTABLE[column][1][align=right]<br />
\setupTABLE[column][2][alignmentcharacter={.},aligncharacter=yes,align=middle]<br />
\bTR \bTH Category \eTH \bTH Data entry \eTH \eTR<br />
\bTR \bTD First \eTD \bTD 71.3 \eTD \eTR<br />
\bTR \bTD Second \eTD \bTD 43.7 \eTD \eTR<br />
\bTR \bTD Total \eTD \bTD 115 \eTD \eTR<br />
\eTABLE<br />
</context><br />
</td></tr></table><br />
<br />
You'll note that the final line, because it has no . in the number, gets aligned under the right-hand side of the numbers. In most circumstances you would want such a number aligned with the left-hand set of digits. To so do, issue the following command in your preamble:<br />
<br />
<texcode><br />
\chardef\characteralignmentmode=2<br />
</texcode><br />
<br />
and now the table above will turn out like this:<br />
<br />
<context><br />
\chardef\characteralignmentmode=2<br />
\bTABLE<br />
\setupTABLE[column][1][align=right]<br />
\setupTABLE[column][2][alignmentcharacter={.},aligncharacter=yes,align=middle]<br />
\bTR \bTH Category \eTH \bTH Data entry \eTH \eTR<br />
\bTR \bTD First \eTD \bTD 71.3 \eTD \eTR<br />
\bTR \bTD Second \eTD \bTD 43.7 \eTD \eTR<br />
\bTR \bTD Total \eTD \bTD 115 \eTD \eTR<br />
\eTABLE<br />
</context><br />
<br />
If there's no <code>alignmentcharacter</code> in the cell, the content will be aligned in the following way depending on the value of <code>\characteralignmentmode</code>:<br />
<table style="border:1px solid #DDDDDD;"><br />
<tr style="background-color:#DDDDDD; font-weight: bold;"><td>mode</td><td width="200"></td><td>.</td><td width="200"></td></tr><br />
<tr><td style="background-color:#DDDDDD" align="center">0</td><td colspan="3" align="center">centered</td></tr><br />
<tr style="background-color:#EEEEEE;"><td style="background-color:#DDDDDD" align="center">1</td><td align="left">left in before</td><td style="background-color:#DDDDDD">.</td><td></td></tr><br />
<tr><td style="background-color:#DDDDDD" align="center">2</td><td align="right">right in before</td><td style="background-color:#DDDDDD">.</td><td></td></tr><br />
<tr style="background-color:#EEEEEE;"><td style="background-color:#DDDDDD" align="center">3</td><td></td><td style="background-color:#DDDDDD">.</td><td align="left">left in after</td></tr><br />
<tr><td style="background-color:#DDDDDD" align="center">4</td><td></td><td style="background-color:#DDDDDD">.</td><td align="right">right in after</td></tr><br />
</table><br />
<br />
== Specifying the cell column ==<br />
<br />
When writing a table you can omit empty cells and define only cells for specified columns. To have this feature fully available you need to have a beta or a quite fresh ConTeXt version.<br />
<br />
Two methods are available:<br />
<br />
* With the TD "n" option, the undefined cells are merged into a single spanned cell.<br />
* With the TD "m" option, the undefined cells appear as empty normal cells.<br />
<br />
Here is an example using the "n" option:<br />
<br />
<texcode><br />
\bTABLE[width=3em]<br />
\bTR\bTD d1 \eTD\bTD[n=2] d2 \eTD\bTD[n=5] d5 \eTD\bTD[n=7] d7 \eTD\eTR<br />
\bTR\bTD f1 \eTD\bTD[n=4] f4 \eTD\bTD[n=5] f5 \eTD\bTD[n=7] f7 \eTD\eTR<br />
\eTABLE<br />
</texcode><br />
<br />
It looks like:<br />
<br />
<context><br />
\bTABLE[width=3em]<br />
\bTR\bTD d1 \eTD\bTD[n=2] d2 \eTD\bTD[n=5] d5 \eTD\bTD[n=7] d7 \eTD\eTR<br />
\bTR\bTD f1 \eTD\bTD[n=4] f4 \eTD\bTD[n=5] f5 \eTD\bTD[n=7] f7 \eTD\eTR<br />
\eTABLE<br />
</context><br />
<br />
Here is an example using the "m" option:<br />
<br />
<texcode><br />
\bTABLE[width=3em]<br />
\bTR\bTD d1 \eTD\bTD[m=2] d2 \eTD\bTD[m=5] d5 \eTD\bTD[m=7] d7 \eTD\eTR<br />
\bTR\bTD f1 \eTD\bTD[m=4] f4 \eTD\bTD[m=5] f5 \eTD\bTD[m=7] f7 \eTD\eTR<br />
\eTABLE<br />
</texcode><br />
<br />
It looks like:<br />
<br />
<context><br />
\bTABLE[width=3em]<br />
\bTR\bTD d1 \eTD\bTD[m=2] d2 \eTD\bTD[m=5] d5 \eTD\bTD[m=7] d7 \eTD\eTR<br />
\bTR\bTD f1 \eTD\bTD[m=4] f4 \eTD\bTD[m=5] f5 \eTD\bTD[m=7] f7 \eTD\eTR<br />
\eTABLE<br />
</context><br />
<br />
== Round corners ==<br />
<br />
For a different approach for round corners and colored background follow the text after this example.<br />
<br />
It is possible to round the corners of the table if you turn off the main frame of the table and frame the table in [[cmd:framed|\framed]]. Compare two different approaches in the first and second example.<br />
<br />
You can't color the background of the table with round corners unless the frame rulethickness is not big enough to cover the rectangular corners of the background (second example). Well, you can if you frame the table twice. Once in the thick white frame and then in the thin frame with negative offset and slightly smaller corner radius (third example). Be aware of other complications -- notice that the thick white frame is still visible in the text above it.<br />
<br />
<context source="yes"><br />
\starttext<br />
\setupcolors[state=start] <br />
%\showstruts<br />
\setupTABLE[background=color,backgroundcolor=yellow]<br />
\setupframed[framecolor=darkgreen]<br />
<br />
First<br />
<br />
\def\StartTable<br />
{\setupTABLE[row] [first][topframe=off]%<br />
\setupTABLE[row] [last] [bottomframe=off]%<br />
\setupTABLE[column][first][leftframe=off]%<br />
\setupTABLE[column][last] [rightframe=off]%<br />
\framed[strut=no,corner=round,offset=.5\linewidth]<br />
\bgroup}<br />
<br />
\def\StopTable<br />
{\egroup}<br />
<br />
\StartTable<br />
\bTABLE<br />
\bTR \bTD test \eTD \bTD test \eTD \eTR<br />
\bTR \bTD test \eTD \bTD test \eTD \eTR<br />
\bTR \bTD test \eTD \bTD test \eTD \eTR<br />
\eTABLE<br />
\StopTable<br />
<br />
Second<br />
<br />
\setupTABLE[row] [first][topframe=off]<br />
\setupTABLE[row] [last] [bottomframe=off]<br />
\setupTABLE[column][first][leftframe=off]<br />
\setupTABLE[column][last] [rightframe=off]<br />
\framed[strut=no,corner=round,offset=.5\linewidth,,rulethickness=1mm]\bgroup<br />
\bTABLE<br />
\bTR \bTD test \eTD \bTD test \eTD \eTR<br />
\bTR \bTD test \eTD \bTD test \eTD \eTR<br />
\bTR \bTD test \eTD \bTD test \eTD \eTR<br />
\eTABLE<br />
\egroup<br />
<br />
Third<br />
<br />
\setupTABLE[row] [first][topframe=off]<br />
\setupTABLE[row] [last] [bottomframe=off]<br />
\setupTABLE[column][first][leftframe=off]<br />
\setupTABLE[column][last] [rightframe=off]<br />
\framed[strut=no,corner=round,radius=1.4mm,offset=-1mm,,rulethickness=.1mm]\bgroup<br />
\framed[strut=no,corner=round,radius=1.5mm,offset=0mm,,rulethickness=1mm,framecolor=white]\bgroup<br />
\bTABLE<br />
\bTR \bTD test \eTD \bTD test \eTD \eTR<br />
\bTR \bTD test \eTD \bTD test \eTD \eTR<br />
\bTR \bTD test \eTD \bTD test \eTD \eTR<br />
\eTABLE<br />
\egroup<br />
\egroup<br />
<br />
\stoptext<br />
</context><br />
<br />
From 2006-10-11 on, ConTeXt contains one more mechanism for round corners. Watch the example:<br />
<br />
<context source="yes"><br />
\starttext<br />
\setupcolors[state=start]<br />
\setupTABLE [y] [first][background=color,backgroundcolor=blue,frame=off,bottomframe=on,topframe=on,framecolor=white]<br />
\setupTABLE [first][first][backgroundcorner=2,corner=10,frame=on]<br />
\setupTABLE [last] [first][backgroundcorner=4,corner=12,frame=on]<br />
\setupTABLE [row] [each] [background=color,backgroundcolor=blue,frame=on,framecolor=white]<br />
\setupTABLE [first][2] [corner=8]<br />
\setupTABLE [last] [2] [corner=5]<br />
\setupTABLE [first][last] [corner=7]<br />
\setupTABLE [last] [last] [corner=6]<br />
<br />
\bTABLE[frame=off,align=middle]<br />
\bTR \bTD one \eTD \bTD two \eTD \bTD three \eTD \eTR<br />
\bTR \bTD first \eTD \bTD second \eTD \bTD third \eTD \eTR<br />
\bTR \bTD alpha \eTD \bTD beta \eTD \bTD gamma \eTD \eTR<br />
\eTABLE<br />
\stoptext<br />
</context><br />
<br />
=TABLEs with old table syntax=<br />
<br />
From the mailing list in March 2009, by Wolfgang Schuster and Hans Hagen:<br />
<br />
<texcode><br />
\def\startTABLE<br />
{\dosingleempty\dostartTABLE}<br />
<br />
\def\dostartTABLE[#1]%<br />
{\bgroup<br />
\bTABLE[#1]%<br />
\let\NC\doTABLENC<br />
\let\NR\doTABLENR<br />
\let\bTR\relax<br />
\let\bTD\relax<br />
\let\bTH\relax<br />
\let\bTN\relax}<br />
<br />
\def\stopTABLE<br />
{\eTABLE<br />
\egroup}<br />
<br />
\newconditional\inTABLEnc<br />
<br />
\unexpanded\def\doTABLENR<br />
{\eTR<br />
\setfalse\inTABLEnc}<br />
<br />
\unexpanded\def\doTABLENC<br />
{\futurelet\next\dodoTABLENC}<br />
<br />
\def\dodoTABLENC<br />
{\ifx\next\doTABLENR \else<br />
\expandafter\dododoTABLENC<br />
\fi}<br />
<br />
\long\def\dododoTABLENC#1\NC<br />
{\ifconditional\inTABLEnc\else\settrue\inTABLEnc\parseTR[][]\fi<br />
\dodoubleempty\parseTD#1\eTD\NC}<br />
</texcode><br />
<br />
This is now part of the core as the [[source:tabl-nte.tex|NTE module]]. Quoting its internal documentation:<br />
<br />
This module is suggested by Wolfgang Schuster who also prototyped it and came up with the rationale:<br />
<br />
This module provides an easy way to use natural in a similiar way as the older table module (based on the [[TABLE]] macros) and the newer [[tabulate]] module.<br />
<br />
You can see the advantage in the following table, once created with the new macros and once with the normal macros provided with the natural table module.<br />
<br />
Let us start with the original macros:<br />
<br />
<texcode><br />
\bTABLE<br />
\bTR<br />
\bTD Text 1 \eTD<br />
\bTD Text 2 \eTD<br />
\eTR<br />
\bTR<br />
\bTD Text 3 \eTD<br />
\bTD Text 4 \eTD<br />
\eTR<br />
\eTABLE<br />
</texcode><br />
<br />
Watch how the new macros use less code:<br />
<br />
<texcode><br />
\startTABLE<br />
\NC Text 1 \NC Text 2 \NC\NR<br />
\NC Text 3 \NC Text 4 \NC\NR<br />
\stopTABLE<br />
</texcode><br />
<br />
The actual code differs from the prototype that it does not need to collect whole rows and parse them but looks ahead instead.<br />
<br />
[[Category:Tables]]<br />
[[Category:XML]]</div>Willihttps://wiki.contextgarden.net/index.php?title=TABLE&diff=10242TABLE2010-01-05T21:04:48Z<p>Willi: /* Make a cell bold */</p>
<hr />
<div>< [[Tables Overview]] | [[XML]] ><br />
<br />
=Introduction=<br />
<br />
This table mode is called &ldquo;natural tables&rdquo; or &ldquo;automatic tables.&rdquo; I'd call it &ldquo;HTML tables,&rdquo; because it's very similar to them. They're especially suited for [[XML]] conversions.<br />
<br />
Beware: every element must use <tt>\b</tt> ... <tt>\e</tt>!<br />
<br />
You find a lot of samples in [[manual:enattab.pdf|enattab.pdf]]<br />
<br />
Willi Egger wrote a [[My Way]] how he set a typesetter's lead type case: [http://dl.contextgarden.net/myway/NaturalTables.pdf Use of natural tables]<br />
<br />
<texcode><br />
\setupTABLE[row][odd][background=color,backgroundcolor=red, width=.2\textwidth]<br />
\bTABLE[split=yes]<br />
\bTR \bTD[nr=3] 1 \eTD \bTD[nc=2] 2/3 \eTD \bTD[nr=3] 4 \eTD \eTR<br />
\bTR \bTD 2 \eTD \bTD 3 \eTD \eTR<br />
\bTR \bTD 2 \eTD \bTD 3 \eTD \eTR<br />
\bTR \bTD[nc=3] 1/2/3 \eTD \bTD 4 \eTD \eTR<br />
\bTR \bTD 1 \eTD \bTD 2 \eTD \bTD 3 \eTD \bTD 4 \eTD \eTR<br />
\eTABLE<br />
</texcode><br />
<br />
You get automatic page breaking with the option <tt>[split=yes]</tt>.<br />
<br />
The sample looks like this:<br />
<br />
<context><br />
\setupTABLE[row][odd][background=color,backgroundcolor=red, width=.2\textwidth]<br />
\bTABLE[split=yes]<br />
\bTR \bTD[nr=3] 1 \eTD \bTD[nc=2] 2/3 \eTD \bTD[nr=3] 4 \eTD \eTR<br />
\bTR \bTD 2 \eTD \bTD 3 \eTD \eTR<br />
\bTR \bTD 2 \eTD \bTD 3 \eTD \eTR<br />
\bTR \bTD[nc=3] 1/2/3 \eTD \bTD 4 \eTD \eTR<br />
\bTR \bTD 1 \eTD \bTD 2 \eTD \bTD 3 \eTD \bTD 4 \eTD \eTR<br />
\eTABLE<br />
</context><br />
<br />
= Multipage TABLEs =<br />
<br />
Try to divide your table into...<br />
* <cmd>bTABLEhead</cmd> (table header)<br />
* <cmd>bTABLEnext</cmd> (alternate table header on following pages)<br />
* <cmd>bTABLEbody</cmd> (table body)<br />
* <cmd>bTABLEfoot</cmd> (table footer)<br />
and <cmd>setupTABLE</cmd><tt>[split=yes]</tt> or <tt>[split=repeat]</tt><br />
<br />
see also [[source:core-ntb.tex|core-ntb.tex]]<br />
<br />
If you must <b>split</b> a natural table over several pages, you can<br />
simply do this by adding <tt>\setupTABLE[split=yes]</tt> to your TABLE<br />
definition. An other way is to define it right at the TABLE start<br />
by adding the parameter <tt>[split=yes]</tt> (see example).<br />
<br />
In this case the <b>table head</b><br />
(all between <cmd>bTABLEhead</cmd> and <cmd>eTABLEhead</cmd>)<br />
is printed only once at the beginning of the table. But if you use <tt>[split=repeat]</tt>,<br />
it is printed on top of every new page, that contains parts of<br />
your multipage table. Please take account of the fact, that the<br />
head cells are enclosed by <cmd>bTH</cmd> and <cmd>eTH</cmd> (and not \[be]TC).<br />
<br />
If you want to use an alternative table header for all following pages,<br />
you can do this by defining an additional header. Just add the second header<br />
between <cmd>bTABLEnext</cmd>...<cmd>eTABLEnext</cmd>,<br />
right after your normal head definition.<br />
Now every additional page of the multipage table starts with the<br />
<b>next table head</b>.<br />
<br />
The <b>table foot</b> is declared between <cmd>bTABLEfoot</cmd> and<br />
<cmd>eTABLEfoot</cmd>. It defines the concluding row of your natural table.<br />
<br />
The following standalone example deals with all the mentioned aspects of natural tables.<br />
Just <i>copy&paste</i> it as a starting point for further experiments...<br />
<br />
<texcode><br />
\starttext<br />
<br />
\setupcolors[state=start]<br />
<br />
% setup for all cells<br />
\setupTABLE[r][each][style=\tfx\it, align=center]<br />
<br />
% setup table head<br />
\setupTABLE[r][first]<br />
[background=color,<br />
backgroundcolor=yellow]<br />
% setup table footer<br />
\setupTABLE[r][last]<br />
[style=bold,<br />
background=color,<br />
backgroundcolor=green]<br />
<br />
\bTABLE[split=repeat,option=stretch]% head on every page, stretch columns<br />
%<br />
% IMPORTANT: use \bTH ... \eTH to enclose the head|next cells<br />
\bTABLEhead<br />
\bTR<br />
\bTH head1 \eTH<br />
\bTH head2 \eTH<br />
\bTH head3 \eTH<br />
\eTR<br />
\eTABLEhead<br />
% <br />
\bTABLEnext % setup for next table head<br />
\bTR [background=color,backgroundcolor=cyan]<br />
\bTH next1 \eTH<br />
\bTH next2 \eTH<br />
\bTH next3 \eTH<br />
\eTR<br />
\eTABLEnext<br />
%<br />
% the table body (main part)<br />
%<br />
\bTABLEbody<br />
%<br />
\dorecurse{100}{% 100 rows<br />
\bTR<br />
\bTC body body body body body \eTC<br />
\bTC body body body body body \eTC<br />
\bTC body body body body body \eTC<br />
\eTR<br />
}%<br />
%<br />
\eTABLEbody<br />
%<br />
% the table foot<br />
%<br />
\bTABLEfoot<br />
\bTR<br />
\bTC foot1 \eTC<br />
\bTC foot2 \eTC<br />
\bTC foot3 \eTC<br />
\eTR<br />
\eTABLEfoot<br />
%<br />
\eTABLE<br />
<br />
\stoptext<br />
</texcode><br />
<br />
= Creating tables from CSV data (Comma Separated Values) =<br />
<br />
See also [[m-database|the database module]]!<br />
<br />
and [http://dl.contextgarden.net/myway/csv.pdf Creating Tables using CSV (Comma-separated values)] by Mojca Miklavec<br />
<br />
<br />
<!-- Maybe some other place or a separate page is more appropriate for this section --><br />
<br />
An interesting example of creating a table using comma separated values was posted to the [http://archive.contextgarden.net/message/20050923.193302.f2110c93.en.html mailing list] by [[User:ChristopherCreutzig|Christopher Creutzig]]<br />
<br />
The following macros take care of processing CSV data:<br />
<texcode><br />
% Iterate over all the lines of text captured with \obeylines active<br />
% command to call is first argument, is not called for empty lines<br />
\bgroup<br />
\obeylines<br />
\gdef\ProcessLines#1#2{\doProcessLines{#1}#2^^M\doProcessLines}%<br />
\gdef\doProcessLines#1#2^^M#3\doProcessLines{%<br />
\doifnotempty{#2}{#1{#2}}%<br />
\doifnotempty{#3}{\doProcessLines{#1}#3\doProcessLines}%<br />
}%<br />
\egroup<br />
<br />
\def\startCSV{\bgroup\obeylines\dostartCSV}<br />
</texcode><br />
<br />
The next lines are an example of transforming the data into a natural table, but can be easily adapted to any type of the table or perhaps (mis)used in even more strange ways:<br />
<br />
<texcode><br />
\def\TBLentry#1{\bTD#1\eTD}<br />
\def\TBLline#1{\bTR\processcommalist[#1]\TBLentry}<br />
<br />
\def\dostartCSV#1\stopCSV{%<br />
\bTABLE<br />
\ProcessLines\TBLline{#1}%<br />
\eTABLE<br />
\egroup<br />
}<br />
</texcode><br />
<br />
The following lines will then finally result in a desired table:<br />
<br />
<texcode><br />
% some additional settings for the table may be made as well<br />
\setupTABLE[c][2][style=\tt]<br />
\setupTABLE[c][3][align=middle]<br />
\setupTABLE[r][1][style=bold] % how to override the \tt in the second column?<br />
<br />
\startCSV<br />
Name,Email,Accepted<br />
\CONTEXT,worth@trying.to,Yes<br />
Hans,main@developer.of,Yes<br />
Bug,get@rid.of,No<br />
\stopCSV<br />
</texcode><br />
<br />
<context><br />
% Iterate over all the lines of text captured with \obeylines active<br />
% command to call is first argument, is not called for empty lines<br />
\bgroup<br />
\obeylines<br />
\gdef\ProcessLines#1#2{\doProcessLines{#1}#2^^M\doProcessLines}%<br />
\gdef\doProcessLines#1#2^^M#3\doProcessLines{%<br />
\doifnotempty{#2}{#1{#2}}%<br />
\doifnotempty{#3}{\doProcessLines{#1}#3\doProcessLines}%<br />
}%<br />
\egroup<br />
<br />
\def\startCSV{\bgroup\obeylines\dostartCSV}<br />
<br />
\def\TBLentry#1{\bTD#1\eTD}<br />
\def\TBLline#1{\bTR\processcommalist[#1]\TBLentry}<br />
<br />
\def\dostartCSV#1\stopCSV{%<br />
\bTABLE<br />
\ProcessLines\TBLline{#1}%<br />
\eTABLE<br />
\egroup<br />
}<br />
<br />
\setupTABLE[c][2][style=\tt]<br />
\setupTABLE[c][3][align=middle]<br />
\setupTABLE[r][1][style={\rm\bf}]<br />
\startCSV<br />
Name,Email,Accepted<br />
\CONTEXT,worth@trying.to,Yes<br />
Hans,main@developer.of,Yes<br />
Bug,get@rid.of,No<br />
\stopCSV<br />
</context><br />
<br />
Some remarks: the (tentative) code ignores the fact that<br />
* csv data may optionally be enclosed in "" quotes that have to be removed (to be done in \TBLentry) <br />
* quoted strings may contain commas themselves (which means writing a custom version of \processcommalist instead).<br />
<br />
{{howto}}<br />
<br />
HH: there is: <br />
<br />
<texcode><br />
\processseparatedlist[list][separator]\command<br />
</texcode><br />
<br />
What about separating the values using tabs?<br />
<br />
= Designing complex TABLEs =<br />
<br />
Everything is easy when a simple grid is enough. Unfortunately, this<br />
is not the case most of the time, tables tend to have information<br />
which should flow accross cell boundaries either vertically<br />
or horizontally. One of the reasons to use TABLE instead of the<br />
table environment is that TABLE provides an easy (relatively speaking, <br />
at least) way to make merged cells to both directions.<br />
<br />
There are probably as many ways to design TABLEs as there are<br />
users, but a simple one to begin with is to start with a<br />
grid:<br />
<br />
<context><br />
\setupTABLE[r][each][height=1cm]<br />
\setupTABLE[c][each][width=1cm]<br />
\bTABLE<br />
\bTR \bTD r1c1 \eTD \bTD r1c2 \eTD \bTD r1c3 \eTD \bTD r1c4 \eTD \bTD r1c5 \eTD \bTD r1c6 \eTD \eTR<br />
\bTR \bTD r2c1 \eTD \bTD r2c2 \eTD \bTD r2c3 \eTD \bTD r2c4 \eTD \bTD r2c5 \eTD \bTD r2c6 \eTD \eTR<br />
\bTR \bTD r3c1 \eTD \bTD r3c2 \eTD \bTD r3c3 \eTD \bTD r3c4 \eTD \bTD r3c5 \eTD \bTD r3c6 \eTD \eTR<br />
\bTR \bTD r4c1 \eTD \bTD r4c2 \eTD \bTD r4c3 \eTD \bTD r4c4 \eTD \bTD r4c5 \eTD \bTD r4c6 \eTD \eTR<br />
\bTR \bTD r5c1 \eTD \bTD r5c2 \eTD \bTD r5c3 \eTD \bTD r5c4 \eTD \bTD r5c5 \eTD \bTD r5c6 \eTD \eTR<br />
\bTR \bTD r6c1 \eTD \bTD r6c2 \eTD \bTD r6c3 \eTD \bTD r6c4 \eTD \bTD r6c5 \eTD \bTD r6c6 \eTD \eTR<br />
\eTABLE<br />
</context><br />
<br />
The desired table layout is then drawn onto this grid, and the top left corner cell<br />
of each cell in the final layout identified:<br />
<br />
<context><br />
\setupTABLE[r][each][height=1cm]<br />
\setupTABLE[c][each][width=1cm]<br />
\setupTABLE[r][1][height=0cm,frame=off]<br />
\bTABLE<br />
\bTR \bTD \eTD \bTD \eTD \bTD \eTD \bTD \eTD \bTD \eTD \bTD \eTD \eTR<br />
\bTR \bTD[nc=2,nr=2] r1c1 \eTD \bTD r1c3 \eTD \bTD[nr=2] r1c4 \eTD \bTD[nc=2,nr=2] r1c5 \eTD \eTR<br />
\bTR \bTD[nr=2] r2c3 \eTD \eTR<br />
\bTR \bTD[nc=2] r3c1 \eTD \bTD[nc=2] r3c4 \eTD \bTD r3c6 \eTD \eTR<br />
\bTR \bTD r4c1 \eTD \bTD[nc=2] r4c2 \eTD \bTD[nr=2] r4c4 \eTD \bTD[nc=2] r4c5 \eTD \eTR<br />
\bTR \bTD[nr=2,nc=2] r5c1 \eTD \bTD[nr=2] r5c3 \eTD \bTD[nr=2,nc=2] r5c5 \eTD \eTR<br />
\bTR \bTD r6c4 \eTD \eTR<br />
\eTABLE<br />
</context><br />
<br />
The cells are listed from left to right and up to down. Each larger cell is then given<br />
it size by using <tt>nc=...</tt> and <tt>nr=...</tt> parameters with <tt>\bTD</tt>. The<br />
code producing the table above is:<br />
<br />
<texcode><br />
\setupTABLE[r][each][height=1cm]<br />
\setupTABLE[c][each][width=1cm]<br />
\setupTABLE[r][1][height=0cm,frame=off]<br />
\bTABLE<br />
\bTR \bTD \eTD \bTD \eTD \bTD \eTD \bTD \eTD \bTD \eTD \bTD \eTD \eTR<br />
\bTR \bTD[nc=2,nr=2] r1c1 \eTD \bTD r1c3 \eTD \bTD[nr=2] r1c4 \eTD \bTD[nr=2,nc=2] r1c5 \eTD \eTR<br />
\bTR \bTD[nr=2] r2c3 \eTD \eTR<br />
\bTR \bTD[nc=2] r3c1 \eTD \bTD[nc=2] r3c4 \eTD \bTD r3c6 \eTD \eTR<br />
\bTR \bTD r4c1 \eTD \bTD[nc=2] r4c2 \eTD \bTD[nr=2] r4c4 \eTD \bTD[nc=2] r4c5 \eTD \eTR<br />
\bTR \bTD[nr=2,nc=2] r5c1 \eTD \bTD[nr=2] r5c3 \eTD \bTD[nr=2,nc=2] r5c5 \eTD \eTR<br />
\bTR \bTD r6c4 \eTD \eTR<br />
\eTABLE<br />
</texcode><br />
<br />
N.B. There is an ugly hack in the code. An empty first row with zero height and no borders<br />
is added. If the row is omitted, then something odd happens to the number of<br />
columns. The table should have all cells, so this may be a bug. (Or then I have<br />
blundered something with this example, possibly.)<br />
<br />
Everything rectangular can be done with TABLE, as long as it can be fit in the grid. The grid<br />
does not have to be equidistant, and if its dimensions are omitted, the program<br />
will fit the data in. L-shaped or other complex cell shapes are not possible.<br />
Using them would be a bit odd, in any case, as alignment and text flow problems<br />
would be quite interesting.<br />
<br />
<br />
== Cell Addressing and Frames ==<br />
<br />
The setup commands for TABLE do not seem to be very verbosedly commented.<br />
There are, however, a few shorthands, which are useful to understand.<br />
First of all, there are several ways to address cells. This is a brief<br />
summary of some of them:<br />
<br />
<texcode><br />
\setupTABLE[r][(list of rows)][...]<br />
\setupTABLE[c][(list of columns)][...]<br />
\setupTABLE[(list of columns)][(list of rows)][...]<br />
</texcode><br />
<br />
A list contains one or more numbers separated by commas.<br />
Word "last" is equivalent to the number of the last row or<br />
column. The complete list can be replaced by the word "each"<br />
to address all cells on the row/column.<br />
<br />
Let us consider the following table:<br />
<br />
<texcode><br />
\setupTABLE[c][each][align={middle,lohi},frame=off]<br />
\setupTABLE[r][2,3,4,5,6][height=1.0cm]<br />
\setupTABLE[r][2,4][topframe=on]<br />
\setupTABLE[c][1,2,3][rightframe=on]<br />
...<br />
</texcode><br />
<br />
In plain language the rows are interpreted as follows:<br />
<br />
* Align each cell in each column (i.e. all cells) horizontally in the middle<br />
and vertically in the middle (lohi), and remove all frames (borders)<br />
* The height of rows 2 -- 6 is 1.0 cm<br />
* Draw a line on top of rows 2 and 4<br />
* Draw a line to the right side of columns 1 -- 3<br />
<br />
In this case the table is slightly complicated, there are some split cells,<br />
as shown below:<br />
<br />
<table><tr valign="top"><td><br />
<texcode><br />
\bTABLE<br />
\bTR<br />
\bTD \bf r1c1 \eTD<br />
\bTD \bf r1c2 \eTD<br />
\bTD \bf r1c3 \eTD<br />
\bTD \bf r1c4 \eTD<br />
\eTR<br />
\bTR<br />
\bTD r2c1 \eTD<br />
\bTD r2c2 \eTD<br />
\bTD[nr=2] r2c3 \eTD<br />
\bTD r2c4 \eTD<br />
\eTR<br />
\bTR<br />
\bTD r3c1 \eTD<br />
\bTD r3c2 \eTD<br />
\bTD r3c4 \eTD<br />
\eTR<br />
\bTR<br />
\bTD r4c1 \eTD<br />
\bTD r4c2 \eTD<br />
\bTD[nr=3] r4c3 \eTD<br />
\bTD[nr=3] r4c4 \eTD<br />
\eTR<br />
\bTR<br />
\bTD r5c1 \eTD<br />
\bTD r5c2 \eTD<br />
\eTR<br />
\bTR<br />
\bTD r6c1 \eTD<br />
\bTD r6c2 \eTD<br />
\eTR<br />
\eTABLE<br />
</texcode><br />
</td><td><br />
<context><br />
\setupTABLE[c][each][align={middle,lohi},frame=off]<br />
\setupTABLE[r][2,3,4,5,6][height=1.0cm]<br />
\setupTABLE[r][2,4][topframe=on]<br />
\setupTABLE[c][1,2,3][rightframe=on]<br />
\bTABLE<br />
\bTR<br />
\bTD \bf r1c1 \eTD<br />
\bTD \bf r1c2 \eTD<br />
\bTD \bf r1c3 \eTD<br />
\bTD \bf r1c4 \eTD<br />
\eTR<br />
\bTR<br />
\bTD r2c1 \eTD<br />
\bTD r2c2 \eTD<br />
\bTD[nr=2] r2c3 \eTD<br />
\bTD r2c4 \eTD<br />
\eTR<br />
\bTR<br />
\bTD r3c1 \eTD<br />
\bTD r3c2 \eTD<br />
\bTD r3c4 \eTD<br />
\eTR<br />
\bTR<br />
\bTD r4c1 \eTD<br />
\bTD r4c2 \eTD<br />
\bTD[nr=3] r4c3 \eTD<br />
\bTD[nr=3] r4c4 \eTD<br />
\eTR<br />
\bTR<br />
\bTD r5c1 \eTD<br />
\bTD r5c2 \eTD<br />
\eTR<br />
\bTR<br />
\bTD r6c1 \eTD<br />
\bTD r6c2 \eTD<br />
\eTR<br />
\eTABLE<br />
</context><br />
</td></tr></table><br />
<br />
The cell numbering is well worth noting. It is very logical (upper<br />
leftmost part of a combined cell), but sometimes the results are<br />
surprising in the beginning.<br />
<br />
The important point about cell numbering is that there is really<br />
a difference between "bottom border of row 3" and "top border of<br />
row 4". To illustrate this, let us change the frame setups:<br />
<br />
<texcode><br />
\setupTABLE[r][2,4][topframe=on]<br />
</texcode><br />
<br />
is changed to<br />
<br />
<texcode><br />
\setupTABLE[r][1,3][bottomframe=on]<br />
</texcode><br />
<br />
At first sight this is exactly the same thing. But...<br />
<br />
<context><br />
\setupTABLE[c][each][align={middle,lohi},frame=off]<br />
\setupTABLE[r][2,3,4,5,6][height=1.0cm]<br />
\setupTABLE[r][1,3][bottomframe=on]<br />
\setupTABLE[c][1,2,3][rightframe=on]<br />
\bTABLE<br />
\bTR<br />
\bTD \bf r1c1 \eTD<br />
\bTD \bf r1c2 \eTD<br />
\bTD \bf r1c3 \eTD<br />
\bTD \bf r1c4 \eTD<br />
\eTR<br />
\bTR<br />
\bTD r2c1 \eTD<br />
\bTD r2c2 \eTD<br />
\bTD[nr=2] r2c3 \eTD<br />
\bTD r2c4 \eTD<br />
\eTR<br />
\bTR<br />
\bTD r3c1 \eTD<br />
\bTD r3c2 \eTD<br />
\bTD r3c4 \eTD<br />
\eTR<br />
\bTR<br />
\bTD r4c1 \eTD<br />
\bTD r4c2 \eTD<br />
\bTD[nr=3] r4c3 \eTD<br />
\bTD[nr=3] r4c4 \eTD<br />
\eTR<br />
\bTR<br />
\bTD r5c1 \eTD<br />
\bTD r5c2 \eTD<br />
\eTR<br />
\bTR<br />
\bTD r6c1 \eTD<br />
\bTD r6c2 \eTD<br />
\eTR<br />
\eTABLE<br />
</context><br />
<br />
Where did the horizontal line in column 3 disappear? Nowhere. There is no<br />
row 3 in column 3, so there cannot be a frame under it. This problem<br />
can be overcome by using topframe and leftframe instead of bottom and<br />
right, as the cells below and to the right of a border have to exist.<br />
<br />
However, this solution leaves the problem of bottom and rightmost borders.<br />
How to draw a line in the bottom of the table? Using <br />
<tt>\setupTABLE[r][6][bottomframe=on]</tt> will leave the gap in columns 3 and 4, <br />
and <tt>\setupTABLE[r][7][topframe=on]</tt> is not possible, as there is no <br />
row 7. The clever idea of using "last" instead of the row number (6) will fail, <br />
as "last" seems to behave exactly the same way as number 6.<br />
<br />
One useful method is to switch on the borders cell by<br />
cell by adding <tt>\setupTABLE[3,4][4][bottomframe=on]</tt>, i.e.<br />
draw a border under cells r4c3 and r4c4.<br />
<br />
<context><br />
\setupTABLE[c][each][align={middle,lohi},frame=off]<br />
\setupTABLE[r][2,3,4,5,6][height=1.0cm]<br />
\setupTABLE[r][2,4][topframe=on]<br />
\setupTABLE[c][1,2,3][rightframe=on]<br />
\setupTABLE[r][6][bottomframe=on]<br />
\setupTABLE[3,4][4][bottomframe=on]<br />
\bTABLE<br />
\bTR<br />
\bTD \bf r1c1 \eTD<br />
\bTD \bf r1c2 \eTD<br />
\bTD \bf r1c3 \eTD<br />
\bTD \bf r1c4 \eTD<br />
\eTR<br />
\bTR<br />
\bTD r2c1 \eTD<br />
\bTD r2c2 \eTD<br />
\bTD[nr=2] r2c3 \eTD<br />
\bTD r2c4 \eTD<br />
\eTR<br />
\bTR<br />
\bTD r3c1 \eTD<br />
\bTD r3c2 \eTD<br />
\bTD r3c4 \eTD<br />
\eTR<br />
\bTR<br />
\bTD r4c1 \eTD<br />
\bTD r4c2 \eTD<br />
\bTD[nr=3] r4c3 \eTD<br />
\bTD[nr=3] r4c4 \eTD<br />
\eTR<br />
\bTR<br />
\bTD r5c1 \eTD<br />
\bTD r5c2 \eTD<br />
\eTR<br />
\bTR<br />
\bTD r6c1 \eTD<br />
\bTD r6c2 \eTD<br />
\eTR<br />
\eTABLE<br />
</context><br />
<br />
== Column Offset/Gap ==<br />
<br />
From the mailing list at 2005-11-09 by Vit Zyka, modified by Hans Hagen:<br />
<br />
<texcode><br />
\starttext<br />
<br />
% distance mechanism, per column (H)<br />
<br />
\start<br />
\setupTABLE[c][1][distance=2em]<br />
\setupTABLE[c][2][distance=3em]<br />
<br />
\bTABLE<br />
\bTR \bTD test \eTD \bTD test \eTD \bTD test \eTD \eTR<br />
\bTR \bTD[nx=2] test \eTD \bTD test \eTD \eTR<br />
\bTR \bTD test \eTD \bTD[nx=2] test \eTD \eTR<br />
\eTABLE<br />
<br />
\bTABLE[option=stretch]<br />
\bTR \bTD test \eTD \bTD test \eTD \bTD test \eTD \eTR<br />
\bTR \bTD[nx=2] test \eTD \bTD test \eTD \eTR<br />
\bTR \bTD test \eTD \bTD[nx=2] test \eTD \eTR<br />
\eTABLE<br />
\stop<br />
<br />
% distance mechanism, per table (V)<br />
<br />
\framed[offset=none]{%<br />
\setupTABLE[column][2][align=left]<br />
\setupTABLE[column][3][align=right]<br />
\bTABLE[columndistance=2cm,leftmargindistance=.3cm,rightmargindistance=.5cm]<br />
\bTR<br />
\bTH[nc=3] Table head\eTH<br />
\eTR<br />
\bTR\bTD[nc=2] AB\eTD\bTD C\eTD\eTR<br />
\bTR\bTD[nc=2,align=left] AB\eTD\bTD C\eTD\eTR<br />
\bTR\bTD[nc=2,align=middle] AB\eTD\bTD C\eTD\eTR<br />
\bTR\bTD A\eTD\bTD B\eTD\bTD C\eTD\eTR<br />
\bTR\bTD Aa\eTD\bTD Bb\eTD\bTD Cccc\eTD\eTR<br />
\bTR\bTD[nc=3,align=middle] ABC\eTD\eTR<br />
\eTABLE<br />
}<br />
<br />
\stoptext<br />
</texcode><br />
<br />
== Make a cell bold ==<br />
<table><tr valign="top"><td><br />
<texcode><br />
\bTABLE<br />
\bTR \bTD 1 \eTD \bTD 1 \eTD \bTD 2/3 \eTD \eTR<br />
\bTR \bTD 2 \eTD \bTD 2 \eTD \bTD 3 \eTD \eTR<br />
\bTR \bTD 2 \eTD \bTD[rulethickness=2pt] 2 \eTD \bTD 3 \eTD \eTR<br />
\bTR \bTD 1 \eTD \bTD 1 \eTD \bTD 4 \eTD \eTR<br />
\bTR \bTD 1 \eTD \bTD 1 \eTD \bTD 2 \eTD \eTR<br />
\eTABLE<br />
</texcode><br />
</td><td><br />
<context><br />
\bTABLE<br />
\bTR \bTD 1 \eTD \bTD 1 \eTD \bTD 2/3 \eTD \eTR<br />
\bTR \bTD 2 \eTD \bTD 2 \eTD \bTD 3 \eTD \eTR<br />
\bTR \bTD 2 \eTD \bTD[rulethickness=2pt] 2 \eTD \bTD 3 \eTD \eTR<br />
\bTR \bTD 1 \eTD \bTD 1 \eTD \bTD 4 \eTD \eTR<br />
\bTR \bTD 1 \eTD \bTD 1 \eTD \bTD 2 \eTD \eTR<br />
\eTABLE<br />
</context><br />
</td></tr></table><br />
<br />
In the given sample you can see, that there is a problem with the alignment. This can be improved as follows:<br />
<br />
<context source="yes" text="produces"><br />
\setupTABLE[row][each][rulethickness=.25pt,offset=\dimexpr1mm+2pt] <br />
\bTABLE<br />
\bTR \bTD 1 \eTD \bTD 1 \eTD \bTD 2/3 \eTD \eTR<br />
\bTR \bTD 2 \eTD \bTD 2 \eTD \bTD 3 \eTD \eTR<br />
\bTR \bTD 2 \eTD \bTD[rulethickness=2pt,offset=1mm] 2 \eTD \bTD 3 \eTD \eTR<br />
\bTR \bTD 1 \eTD \bTD 1 \eTD \bTD 4 \eTD \eTR<br />
\bTR \bTD 1 \eTD \bTD 1 \eTD \bTD 2 \eTD \eTR<br />
\eTABLE<br />
</context><br />
<br />
As soon as you want to emphasize a cell with a thicker frame, one has to adjust the offset. Basically the general offset will be enlarged by the amount of the rule thickness. In the cell with the thicker rule the offset is then diminished by the rulethickness.<br />
<br />
<br />
I place here a more realistic example. Consider you want to create an invoice with several columns. There are no vertical lines. The top frame of the table should have a thicker rule than the dividing rules between the invoice lines. The bottom frame of the list of invoice lines should have also a thicker rule like the top frame:<br />
<br />
<context source="yes" text="produces"><br />
{\bfa Invoice}<br />
\switchtobodyfont[6pt]<br />
\blank<br />
\bTABLE<br />
\setupTABLE[frame=off,offset=1mm]<br />
\setupTABLE[row][*][height=7.25mm]<br />
\setupTABLE[column][1]%<br />
[width=18mm,<br />
offset=\dimexpr1mm+2pt,<br />
align=flushleft]<br />
\setupTABLE[column][2]%<br />
[width=20mm,<br />
offset=\dimexpr1mm+2pt,<br />
align=flushleft]<br />
\setupTABLE[column][3]%<br />
[width=18mm,<br />
offset=\dimexpr1mm+2pt,<br />
align=flushright]<br />
\setupTABLE[column][4]%<br />
[width=18mm,<br />
offset=\dimexpr1mm+2pt,<br />
align=flushright]<br />
\setupTABLE[column][5]%<br />
[width=18mm,<br />
offset=\dimexpr1mm+2pt,<br />
align=left]<br />
\bTR[bottomframe=on, rulethickness=2pt,offset=1mm]<br />
\bTD\bf Date \eTD<br />
\bTD\bf Description \eTD<br />
\bTD\bf Quantity \eTD<br />
\bTD\bf Price \eTD<br />
\bTD\bf Total \eTD<br />
\eTR<br />
\bTR[bottomframe=on,rulethickness=.25pt]<br />
\bTD 05-01-2010 \eTD<br />
\bTD Element 1 \eTD<br />
\bTD 10.0 \eTD<br />
\bTD 6.00 \eTD<br />
\bTD 60.00 \eTD<br />
\eTR<br />
\bTR[bottomframe=on,rulethickness=.25pt]<br />
\bTD 05-01-2010 \eTD<br />
\bTD Element 2 \eTD<br />
\bTD 2.0 \eTD<br />
\bTD 3.00 \eTD<br />
\bTD 6.00 \eTD<br />
\eTR<br />
\bTR[topframe=on,rulethickness=2pt,offset=1mm]<br />
\bTD[nx=3] \eTD<br />
\bTD[align=flushleft] Subtotal \eTD<br />
\bTD 66.00 \eTD<br />
\eTR<br />
\bTR[offset=\dimexpr1mm+2pt]<br />
\bTD[nx=3] \eTD<br />
\bTD[align=flushleft] VAT 19\% \eTD<br />
\bTD 12.54 \eTD<br />
\eTR<br />
\bTR<br />
\bTD[nx=3] \eTD<br />
\bTD[align=flushleft] \bf Total \eTD<br />
\bTD 78.54 \eTD<br />
\eTR<br />
\eTABLE<br />
</context><br />
<br />
== Using character alignment ==<br />
<br />
ConTeXt can align columns of numbers on a character (often a decimal point to align accounting data) automatically, removing the need to add fixed spaces into your document. For any such column you need to specify the character on which to align. You use the <tt>aligncharacter=yes</tt> parameter to set up character alignment, <tt>alignmentcharacter={.}</tt> to say what the character should be (in this case a full stop) and <tt>align=middle</tt> to set the overall alignment of the column.<br />
<br />
<table><tr valign="top"><td><br />
<texcode><br />
\bTABLE<br />
\setupTABLE[column][1][align=right]<br />
\setupTABLE[column][2][alignmentcharacter={.},<br />
aligncharacter=yes,align=middle]<br />
\bTR \bTH Category \eTH \bTH Data entry \eTH \eTR<br />
\bTR \bTD First \eTD \bTD 71.3 \eTD \eTR<br />
\bTR \bTD Second \eTD \bTD 43.7 \eTD \eTR<br />
\bTR \bTD Total \eTD \bTD 115 \eTD \eTR<br />
\eTABLE<br />
</texcode><br />
</td><td><br />
<context><br />
\bTABLE<br />
\setupTABLE[column][1][align=right]<br />
\setupTABLE[column][2][alignmentcharacter={.},aligncharacter=yes,align=middle]<br />
\bTR \bTH Category \eTH \bTH Data entry \eTH \eTR<br />
\bTR \bTD First \eTD \bTD 71.3 \eTD \eTR<br />
\bTR \bTD Second \eTD \bTD 43.7 \eTD \eTR<br />
\bTR \bTD Total \eTD \bTD 115 \eTD \eTR<br />
\eTABLE<br />
</context><br />
</td></tr></table><br />
<br />
You'll note that the final line, because it has no . in the number, gets aligned under the right-hand side of the numbers. In most circumstances you would want such a number aligned with the left-hand set of digits. To so do, issue the following command in your preamble:<br />
<br />
<texcode><br />
\chardef\characteralignmentmode=2<br />
</texcode><br />
<br />
and now the table above will turn out like this:<br />
<br />
<context><br />
\chardef\characteralignmentmode=2<br />
\bTABLE<br />
\setupTABLE[column][1][align=right]<br />
\setupTABLE[column][2][alignmentcharacter={.},aligncharacter=yes,align=middle]<br />
\bTR \bTH Category \eTH \bTH Data entry \eTH \eTR<br />
\bTR \bTD First \eTD \bTD 71.3 \eTD \eTR<br />
\bTR \bTD Second \eTD \bTD 43.7 \eTD \eTR<br />
\bTR \bTD Total \eTD \bTD 115 \eTD \eTR<br />
\eTABLE<br />
</context><br />
<br />
If there's no <code>alignmentcharacter</code> in the cell, the content will be aligned in the following way depending on the value of <code>\characteralignmentmode</code>:<br />
<table style="border:1px solid #DDDDDD;"><br />
<tr style="background-color:#DDDDDD; font-weight: bold;"><td>mode</td><td width="200"></td><td>.</td><td width="200"></td></tr><br />
<tr><td style="background-color:#DDDDDD" align="center">0</td><td colspan="3" align="center">centered</td></tr><br />
<tr style="background-color:#EEEEEE;"><td style="background-color:#DDDDDD" align="center">1</td><td align="left">left in before</td><td style="background-color:#DDDDDD">.</td><td></td></tr><br />
<tr><td style="background-color:#DDDDDD" align="center">2</td><td align="right">right in before</td><td style="background-color:#DDDDDD">.</td><td></td></tr><br />
<tr style="background-color:#EEEEEE;"><td style="background-color:#DDDDDD" align="center">3</td><td></td><td style="background-color:#DDDDDD">.</td><td align="left">left in after</td></tr><br />
<tr><td style="background-color:#DDDDDD" align="center">4</td><td></td><td style="background-color:#DDDDDD">.</td><td align="right">right in after</td></tr><br />
</table><br />
<br />
== Specifying the cell column ==<br />
<br />
When writing a table you can omit empty cells and define only cells for specified columns. To have this feature fully available you need to have a beta or a quite fresh ConTeXt version.<br />
<br />
Two methods are available:<br />
<br />
* With the TD "n" option, the undefined cells are merged into a single spanned cell.<br />
* With the TD "m" option, the undefined cells appear as empty normal cells.<br />
<br />
Here is an example using the "n" option:<br />
<br />
<texcode><br />
\bTABLE[width=3em]<br />
\bTR\bTD d1 \eTD\bTD[n=2] d2 \eTD\bTD[n=5] d5 \eTD\bTD[n=7] d7 \eTD\eTR<br />
\bTR\bTD f1 \eTD\bTD[n=4] f4 \eTD\bTD[n=5] f5 \eTD\bTD[n=7] f7 \eTD\eTR<br />
\eTABLE<br />
</texcode><br />
<br />
It looks like:<br />
<br />
<context><br />
\bTABLE[width=3em]<br />
\bTR\bTD d1 \eTD\bTD[n=2] d2 \eTD\bTD[n=5] d5 \eTD\bTD[n=7] d7 \eTD\eTR<br />
\bTR\bTD f1 \eTD\bTD[n=4] f4 \eTD\bTD[n=5] f5 \eTD\bTD[n=7] f7 \eTD\eTR<br />
\eTABLE<br />
</context><br />
<br />
Here is an example using the "m" option:<br />
<br />
<texcode><br />
\bTABLE[width=3em]<br />
\bTR\bTD d1 \eTD\bTD[m=2] d2 \eTD\bTD[m=5] d5 \eTD\bTD[m=7] d7 \eTD\eTR<br />
\bTR\bTD f1 \eTD\bTD[m=4] f4 \eTD\bTD[m=5] f5 \eTD\bTD[m=7] f7 \eTD\eTR<br />
\eTABLE<br />
</texcode><br />
<br />
It looks like:<br />
<br />
<context><br />
\bTABLE[width=3em]<br />
\bTR\bTD d1 \eTD\bTD[m=2] d2 \eTD\bTD[m=5] d5 \eTD\bTD[m=7] d7 \eTD\eTR<br />
\bTR\bTD f1 \eTD\bTD[m=4] f4 \eTD\bTD[m=5] f5 \eTD\bTD[m=7] f7 \eTD\eTR<br />
\eTABLE<br />
</context><br />
<br />
== Round corners ==<br />
<br />
For a different approach for round corners and colored background follow the text after this example.<br />
<br />
It is possible to round the corners of the table if you turn off the main frame of the table and frame the table in [[cmd:framed|\framed]]. Compare two different approaches in the first and second example.<br />
<br />
You can't color the background of the table with round corners unless the frame rulethickness is not big enough to cover the rectangular corners of the background (second example). Well, you can if you frame the table twice. Once in the thick white frame and then in the thin frame with negative offset and slightly smaller corner radius (third example). Be aware of other complications -- notice that the thick white frame is still visible in the text above it.<br />
<br />
<context source="yes"><br />
\starttext<br />
\setupcolors[state=start] <br />
%\showstruts<br />
\setupTABLE[background=color,backgroundcolor=yellow]<br />
\setupframed[framecolor=darkgreen]<br />
<br />
First<br />
<br />
\def\StartTable<br />
{\setupTABLE[row] [first][topframe=off]%<br />
\setupTABLE[row] [last] [bottomframe=off]%<br />
\setupTABLE[column][first][leftframe=off]%<br />
\setupTABLE[column][last] [rightframe=off]%<br />
\framed[strut=no,corner=round,offset=.5\linewidth]<br />
\bgroup}<br />
<br />
\def\StopTable<br />
{\egroup}<br />
<br />
\StartTable<br />
\bTABLE<br />
\bTR \bTD test \eTD \bTD test \eTD \eTR<br />
\bTR \bTD test \eTD \bTD test \eTD \eTR<br />
\bTR \bTD test \eTD \bTD test \eTD \eTR<br />
\eTABLE<br />
\StopTable<br />
<br />
Second<br />
<br />
\setupTABLE[row] [first][topframe=off]<br />
\setupTABLE[row] [last] [bottomframe=off]<br />
\setupTABLE[column][first][leftframe=off]<br />
\setupTABLE[column][last] [rightframe=off]<br />
\framed[strut=no,corner=round,offset=.5\linewidth,,rulethickness=1mm]\bgroup<br />
\bTABLE<br />
\bTR \bTD test \eTD \bTD test \eTD \eTR<br />
\bTR \bTD test \eTD \bTD test \eTD \eTR<br />
\bTR \bTD test \eTD \bTD test \eTD \eTR<br />
\eTABLE<br />
\egroup<br />
<br />
Third<br />
<br />
\setupTABLE[row] [first][topframe=off]<br />
\setupTABLE[row] [last] [bottomframe=off]<br />
\setupTABLE[column][first][leftframe=off]<br />
\setupTABLE[column][last] [rightframe=off]<br />
\framed[strut=no,corner=round,radius=1.4mm,offset=-1mm,,rulethickness=.1mm]\bgroup<br />
\framed[strut=no,corner=round,radius=1.5mm,offset=0mm,,rulethickness=1mm,framecolor=white]\bgroup<br />
\bTABLE<br />
\bTR \bTD test \eTD \bTD test \eTD \eTR<br />
\bTR \bTD test \eTD \bTD test \eTD \eTR<br />
\bTR \bTD test \eTD \bTD test \eTD \eTR<br />
\eTABLE<br />
\egroup<br />
\egroup<br />
<br />
\stoptext<br />
</context><br />
<br />
From 2006-10-11 on, ConTeXt contains one more mechanism for round corners. Watch the example:<br />
<br />
<context source="yes"><br />
\starttext<br />
\setupcolors[state=start]<br />
\setupTABLE [y] [first][background=color,backgroundcolor=blue,frame=off,bottomframe=on,topframe=on,framecolor=white]<br />
\setupTABLE [first][first][backgroundcorner=2,corner=10,frame=on]<br />
\setupTABLE [last] [first][backgroundcorner=4,corner=12,frame=on]<br />
\setupTABLE [row] [each] [background=color,backgroundcolor=blue,frame=on,framecolor=white]<br />
\setupTABLE [first][2] [corner=8]<br />
\setupTABLE [last] [2] [corner=5]<br />
\setupTABLE [first][last] [corner=7]<br />
\setupTABLE [last] [last] [corner=6]<br />
<br />
\bTABLE[frame=off,align=middle]<br />
\bTR \bTD one \eTD \bTD two \eTD \bTD three \eTD \eTR<br />
\bTR \bTD first \eTD \bTD second \eTD \bTD third \eTD \eTR<br />
\bTR \bTD alpha \eTD \bTD beta \eTD \bTD gamma \eTD \eTR<br />
\eTABLE<br />
\stoptext<br />
</context><br />
<br />
=TABLEs with old table syntax=<br />
<br />
From the mailing list in March 2009, by Wolfgang Schuster and Hans Hagen:<br />
<br />
<texcode><br />
\def\startTABLE<br />
{\dosingleempty\dostartTABLE}<br />
<br />
\def\dostartTABLE[#1]%<br />
{\bgroup<br />
\bTABLE[#1]%<br />
\let\NC\doTABLENC<br />
\let\NR\doTABLENR<br />
\let\bTR\relax<br />
\let\bTD\relax<br />
\let\bTH\relax<br />
\let\bTN\relax}<br />
<br />
\def\stopTABLE<br />
{\eTABLE<br />
\egroup}<br />
<br />
\newconditional\inTABLEnc<br />
<br />
\unexpanded\def\doTABLENR<br />
{\eTR<br />
\setfalse\inTABLEnc}<br />
<br />
\unexpanded\def\doTABLENC<br />
{\futurelet\next\dodoTABLENC}<br />
<br />
\def\dodoTABLENC<br />
{\ifx\next\doTABLENR \else<br />
\expandafter\dododoTABLENC<br />
\fi}<br />
<br />
\long\def\dododoTABLENC#1\NC<br />
{\ifconditional\inTABLEnc\else\settrue\inTABLEnc\parseTR[][]\fi<br />
\dodoubleempty\parseTD#1\eTD\NC}<br />
</texcode><br />
<br />
This is now part of the core as the [[source:tabl-nte.tex|NTE module]]. Quoting its internal documentation:<br />
<br />
This module is suggested by Wolfgang Schuster who also prototyped it and came up with the rationale:<br />
<br />
This module provides an easy way to use natural in a similiar way as the older table module (based on the [[TABLE]] macros) and the newer [[tabulate]] module.<br />
<br />
You can see the advantage in the following table, once created with the new macros and once with the normal macros provided with the natural table module.<br />
<br />
Let us start with the original macros:<br />
<br />
<texcode><br />
\bTABLE<br />
\bTR<br />
\bTD Text 1 \eTD<br />
\bTD Text 2 \eTD<br />
\eTR<br />
\bTR<br />
\bTD Text 3 \eTD<br />
\bTD Text 4 \eTD<br />
\eTR<br />
\eTABLE<br />
</texcode><br />
<br />
Watch how the new macros use less code:<br />
<br />
<texcode><br />
\startTABLE<br />
\NC Text 1 \NC Text 2 \NC\NR<br />
\NC Text 3 \NC Text 4 \NC\NR<br />
\stopTABLE<br />
</texcode><br />
<br />
The actual code differs from the prototype that it does not need to collect whole rows and parse them but looks ahead instead.<br />
<br />
[[Category:Tables]]<br />
[[Category:XML]]</div>Willi