https://wiki.contextgarden.net/api.php?action=feedcontributions&user=M%C3%A6stro&feedformat=atomWiki - User contributions [en]2024-03-29T01:46:34ZUser contributionsMediaWiki 1.34.1https://wiki.contextgarden.net/index.php?title=Color_in_MetaPost&diff=33734Color in MetaPost2022-08-27T16:36:48Z<p>Mæstro: /* The basics */ - another typo</p>
<hr />
<div>{{Color_navigation_Trial}}<br />
<br />
[[MetaPost]] only supports the RGB color space, although with the help of [[MetaFun - MetaPost in ConTeXt|MetaFun]] you can face transparency and CMYK colors. This article describes the use of colors in MetaPost and MetaFun.<br />
<br />
== The basics ==<br />
<br />
Colors are defined as vectors with three components: a red, green and blue one. Like pens, colors have a {{code|with...}} command:<br />
<br />
withcolor (.4,.5,.6)<br />
<br />
You can define color variables like so:<br />
<br />
color darkred ; darkred := (.625,0,0) ;<br />
% use the color<br />
withcolor darkred<br />
% actually, red is already defined, so this works:<br />
withcolor .625red<br />
<br />
Because for MetaPost colors are just vectors, you can manipulate them like you would manipulate points. This is a color halfway between red and green:<br />
<br />
withcolor .5[red,green]<br />
<br />
== Using colors defined in TeX ==<br />
<br />
In ConTeXt you define colors with {{cmd|definecolor}}. Instead of defining a color a second time in MetaPost, you can use the {{code|\MPcolor{colorname}|}} command.<br />
<br />
<context source=yes><br />
\definecolor[darkred] [r=.625] % a RGB color<br />
\definecolor[darkgray][s=.625] % a gray scale<br />
\startuseMPgraphic{color demo}<br />
pickup pencircle scaled 1mm ;<br />
path p ; p := fullcircle xscaled 5cm yscaled 0.5cm ;<br />
fill p withcolor \MPcolor{darkgray} ;<br />
draw p withcolor \MPcolor{darkred} ;<br />
\stopuseMPgraphic<br />
<br />
\bold{\color[darkgray]{This} is an \color[darkred]{ellipse}:}<br />
\useMPgraphic{color demo}<br />
</context><br />
<br />
== Transparent colors ==<br />
<br />
You can use transparent colors with the {{code|transparent(method, factor, color)}} function. For example:<br />
<br />
<context source=yes><br />
% MKII<br />
% \runMPgraphicstrue<br />
\setupcolors[state=start]<br />
\starttext<br />
\startreusableMPgraphic{a}<br />
fill unitsquare scaled 1cm withcolor yellow;<br />
fill unitsquare shifted (0.5,0.5)<br />
% method 1 = normal<br />
scaled 1cm withcolor transparent(1,0.5,red);<br />
\stopreusableMPgraphic<br />
<br />
\placefigure[force,none]{}{\reuseMPgraphic{a}}<br />
\stoptext<br />
</context><br />
<br />
The available transparency methods are the twelve methods supported by PDF specification:<br />
<br />
* 1. normal <br />
* 2. multiply <br />
* 3. screen <br />
* 4. overlay<br />
* 5. softlight <br />
* 6. hardlight <br />
* 7. colordodge <br />
* 8. colorburn<br />
* 9. darken <br />
* 10. lighten <br />
* 11. difference <br />
* 12. exclusion<br />
<br />
=== Troubleshooting transparency ===<br />
<br />
If you see black colors rather than transparent ones, then you probably hit the 'missing specials' problem. This problem was around in 2006; people may not encounter it anymore, but the solution is mentioned here anyway. From the mailing list:<br />
<br />
<pre><br />
This all sounds like the 'missing specials' problem that is caused<br />
by conflicting -progname= arguments when using the web2c version<br />
of MetaPost.<br />
<br />
Make sure you do not have conflicting memory settings for both<br />
main_memory.mpost<br />
as well as<br />
main_memory.metafun<br />
<br />
The best is to remove all trace of '.mpost' and '.metafun' memory<br />
settings from your texmf.cnf, but at least make sure all the<br />
'.mpost' and 'metafun' values are the same .<br />
<br />
Then regenerate metafun using texexec --make, and all should be<br />
well again.<br />
</pre><br />
<br />
The settings will be in {{code|tex/texmf/web2c/texmf.cnf}} or {{code|tex/texmf-context/web2c/context.cnf}} inside your ConTeXt tree. If you are using ConTeXt from the Debian/Ubuntu distribution of TeX, instead of via the recommended [[ConTeXt Standalone]], you need to edit <br />
''/etc/texmf/texmf.d/95NonPath.cnf'', instead. The part you need to edit will look something like this.<br />
<br />
<pre><br />
main_memory = 1000000 % words of inimemory available; also applies to inimf&mp<br />
main_memory.context = 1500000<br />
main_memory.mpost = 1500000<br />
</pre><br />
<br />
* Comment out the .mpost line (MetaFun uses the main_memory value of 1000000; the difference in values is the cause of the problem). <br />
* (If you are not using the standalone, regenerate your TeX with {{code|sudo update-texmf}})<br />
* Lastly, regenerate the MetaFun format with {{code|texexec --make}}. Transparency should work now.<br />
<br />
[[Category:Color]]<br />
[[Category:Graphics]]</div>Mæstrohttps://wiki.contextgarden.net/index.php?title=Color_in_MetaPost&diff=33733Color in MetaPost2022-08-27T16:36:25Z<p>Mæstro: /* The basics */ - typo</p>
<hr />
<div>{{Color_navigation_Trial}}<br />
<br />
[[MetaPost]] only supports the RGB color space, although with the help of [[MetaFun - MetaPost in ConTeXt|MetaFun]] you can face transparency and CMYK colors. This article describes the use of colors in MetaPost and MetaFun.<br />
<br />
== The basics ==<br />
<br />
Colors are defined as vectors with three components: a red, green and blue one. Like pens, colors have a {{code|with...}} command:<br />
<br />
withcolor (.4,.5,.6)<br />
<br />
You can define color variables like so:<br />
<br />
color darkred ; darkred := (.625,0.0) ;<br />
% use the color<br />
withcolor darkred<br />
% actually, red is already defined, so this works:<br />
withcolor .625red<br />
<br />
Because for MetaPost colors are just vectors, you can manipulate them like you would manipulate points. This is a color halfway between red and green:<br />
<br />
withcolor .5[red,green]<br />
<br />
== Using colors defined in TeX ==<br />
<br />
In ConTeXt you define colors with {{cmd|definecolor}}. Instead of defining a color a second time in MetaPost, you can use the {{code|\MPcolor{colorname}|}} command.<br />
<br />
<context source=yes><br />
\definecolor[darkred] [r=.625] % a RGB color<br />
\definecolor[darkgray][s=.625] % a gray scale<br />
\startuseMPgraphic{color demo}<br />
pickup pencircle scaled 1mm ;<br />
path p ; p := fullcircle xscaled 5cm yscaled 0.5cm ;<br />
fill p withcolor \MPcolor{darkgray} ;<br />
draw p withcolor \MPcolor{darkred} ;<br />
\stopuseMPgraphic<br />
<br />
\bold{\color[darkgray]{This} is an \color[darkred]{ellipse}:}<br />
\useMPgraphic{color demo}<br />
</context><br />
<br />
== Transparent colors ==<br />
<br />
You can use transparent colors with the {{code|transparent(method, factor, color)}} function. For example:<br />
<br />
<context source=yes><br />
% MKII<br />
% \runMPgraphicstrue<br />
\setupcolors[state=start]<br />
\starttext<br />
\startreusableMPgraphic{a}<br />
fill unitsquare scaled 1cm withcolor yellow;<br />
fill unitsquare shifted (0.5,0.5)<br />
% method 1 = normal<br />
scaled 1cm withcolor transparent(1,0.5,red);<br />
\stopreusableMPgraphic<br />
<br />
\placefigure[force,none]{}{\reuseMPgraphic{a}}<br />
\stoptext<br />
</context><br />
<br />
The available transparency methods are the twelve methods supported by PDF specification:<br />
<br />
* 1. normal <br />
* 2. multiply <br />
* 3. screen <br />
* 4. overlay<br />
* 5. softlight <br />
* 6. hardlight <br />
* 7. colordodge <br />
* 8. colorburn<br />
* 9. darken <br />
* 10. lighten <br />
* 11. difference <br />
* 12. exclusion<br />
<br />
=== Troubleshooting transparency ===<br />
<br />
If you see black colors rather than transparent ones, then you probably hit the 'missing specials' problem. This problem was around in 2006; people may not encounter it anymore, but the solution is mentioned here anyway. From the mailing list:<br />
<br />
<pre><br />
This all sounds like the 'missing specials' problem that is caused<br />
by conflicting -progname= arguments when using the web2c version<br />
of MetaPost.<br />
<br />
Make sure you do not have conflicting memory settings for both<br />
main_memory.mpost<br />
as well as<br />
main_memory.metafun<br />
<br />
The best is to remove all trace of '.mpost' and '.metafun' memory<br />
settings from your texmf.cnf, but at least make sure all the<br />
'.mpost' and 'metafun' values are the same .<br />
<br />
Then regenerate metafun using texexec --make, and all should be<br />
well again.<br />
</pre><br />
<br />
The settings will be in {{code|tex/texmf/web2c/texmf.cnf}} or {{code|tex/texmf-context/web2c/context.cnf}} inside your ConTeXt tree. If you are using ConTeXt from the Debian/Ubuntu distribution of TeX, instead of via the recommended [[ConTeXt Standalone]], you need to edit <br />
''/etc/texmf/texmf.d/95NonPath.cnf'', instead. The part you need to edit will look something like this.<br />
<br />
<pre><br />
main_memory = 1000000 % words of inimemory available; also applies to inimf&mp<br />
main_memory.context = 1500000<br />
main_memory.mpost = 1500000<br />
</pre><br />
<br />
* Comment out the .mpost line (MetaFun uses the main_memory value of 1000000; the difference in values is the cause of the problem). <br />
* (If you are not using the standalone, regenerate your TeX with {{code|sudo update-texmf}})<br />
* Lastly, regenerate the MetaFun format with {{code|texexec --make}}. Transparency should work now.<br />
<br />
[[Category:Color]]<br />
[[Category:Graphics]]</div>Mæstrohttps://wiki.contextgarden.net/index.php?title=Cropping_text&diff=33720Cropping text2022-08-20T14:26:14Z<p>Mæstro: /* A direct comparison */ - Fix context code</p>
<hr />
<div>== Cropping text ==<br />
There are some rare cases in which it is useful to truncate a line of text and discard some of it.<br />
<br />
=== <tt>\doboundtext</tt> ===<br />
Sometimes there is not enough room to show the complete<br />
(line of) text. In such a situation we can strip of some<br />
'''characters''' by using<br />
<br />
<texcode><br />
\doboundtext {text} {width} {sentinel}<br />
</texcode><br />
<br />
When the <tt>text</tt> is wider than the given <tt>width</tt>, it's split and the third<br />
argument (<tt>sentinel</tt>) is appended. As much text as possible is printed.<br />
<br />
An example<br />
<br />
<texcode><br />
\doboundtext{My entire inheritance goes to my beloved cat Pussy!}{60mm}{...}<br />
</texcode><br />
<br />
and it's result<br />
<br />
<context><br />
\ss\doboundtext{My entire inheritance goes to my beloved cat Pussy!}{60mm}{...}<br />
</context><br />
<br />
=== <tt>\limitatetext</tt> ===<br />
A bit more beautiful alternative for the previous command is {{cmd|limitatetext}}.<br />
This command takes care of '''word''' boundaries, so that only complete words will<br />
appear in the final (cropped) text.<br />
<br />
<texcode><br />
\limitatetext {text} {width} {sentinel}<br />
\limitatetext {text} {-width} {prelude}<br />
\limitatetext {text} {width1 , width2} {symbol}<br />
</texcode><br />
<br />
When no <tt>width</tt> is given, the whole <tt>text</tt> becomes available.<br />
A negative value crops the beginning and the text starts with<br />
the <tt>prelude</tt>. Sentinel and prelude are both optional.<br />
Just look at the example, to see what happens, if you call the macro with<br />
two positive dimensions...<br />
<br />
Example:<br />
<br />
<texcode><br />
\limitatetext {Pussy is the name of the cat!}{38mm}{...}\par<br />
\limitatetext {Pussy is the name of the cat!}{-38mm}{...}\par<br />
\limitatetext {Pussy is the name of the cat!}{12mm, 12mm}{...}<br />
</texcode><br />
<br />
leads to<br />
<br />
<context><br />
\limitatetext {\ss Pussy is the name of the cat!}{38mm}{...}\par<br />
\limitatetext {\ss Pussy is the name of the cat!}{-38mm}{...}\par<br />
\limitatetext {\ss Pussy is the name of the cat!}{10mm, 10mm}{...}<br />
</context><br />
<br />
<br />
Both commands have their range of application.<br />
{{cmd|limitatetext}} is more robust (using grouping tokens like<br />
{{cmd|underbar}} is possible), while {{cmd|doboundtext}} works better<br />
on text that cannot be hyphenated.<br />
<br />
=== <tt>\limitatefirstline</tt> ===<br />
In ConTeXt versions newer than 07.09.2005 there is also a command<br />
called {{cmd|limitatefirstline}}, which acts nearly like {{cmd|doboundtext}},<br />
but at a more robust level. This macro first tries to break the given text<br />
at character level. It uses nearly the same breaking mechanism as {{cmd|limitatetext}},<br />
so it shares the problem with nonbreakable text.<br />
But in contrast to {{cmd|limitatetext}} it has a second mechanism, that is only used,<br />
if the prior one fails or if the result of breaking is wasting too much space.<br />
This fail safe mechanism "simply" clips (no breaking at all) the text to the desired<br />
measures. This is done without any consideration to character boundaries.<br />
So you must live with the fact, that the last character can be cut off at any possible<br />
place.<br />
<br />
<texcode><br />
\limitatefirstline {text} {width} {sentinel}<br />
</texcode><br />
<br />
Example:<br />
<br />
<texcode><br />
\limitatefirstline {\underbar{Mr.~Drofnats was happiest when he was at work%<br />
typesetting beautiful documents.}{109mm}{\unknown}<br />
</texcode><br />
<br />
<br />
<context><br />
\unprotect<br />
<br />
<br />
\def\limitatefirstline#1#2#3%<br />
{\hbox\bgroup\strut\dontcomplain<br />
\setbox\scratchbox\hbox{\begstrut#1\endstrut}%<br />
\ifdim\wd\scratchbox>#2\relax<br />
\setbox\scratchbox\hbox{#3}%<br />
\hsize#2\relax<br />
\advance\hsize-\wd\scratchbox<br />
\setbox\scratchbox\vbox{\forgetall\veryraggedright#1}%<br />
\setbox\scratchbox\vsplit\scratchbox to \lineheight<br />
\vbox<br />
{\unvbox\scratchbox<br />
\global\setbox\plusone\lastbox<br />
\global\setbox\plusone\hbox{\strut\unhbox\plusone}%<br />
\hbox % to #2<br />
{\ifx\clip\undefined<br />
\box\plusone<br />
\else\ifdim\wd\plusone>\hsize<br />
\lower\strutdepth\hbox{\clip[\c!width=\hsize,\c!height=\lineheight]{\hbox{\raise\strutdepth\box\plusone}}}%<br />
\else\ifdim\wd\plusone<\dimexpr\hsize-6ex\relax% tolerance for "successful" breaking<br />
\lower\strutdepth\hbox{\clip[\c!width=\hsize,\c!height=\lineheight]{\hbox{\raise\strutdepth\hbox{\begstrut#1\endstrut}}}}%<br />
\else<br />
\box\plusone<br />
\fi\fi\fi<br />
\removeunwantedspaces#3}}% \removeunwantedspaces\hss#3}}%<br />
\else<br />
#1%<br />
\fi<br />
\egroup}<br />
<br />
\protect<br />
<br />
<br />
\limitatefirstline {\ss\underbar{Mr.~Drofnats was happiest when he was at work typesetting beautiful documents.}}{107mm}{\unknown}<br />
</context><br />
<br />
<br />
In this example breaking is successful (right after the word typesetting),<br />
but the gap between the breaking point and the given width is too big.<br />
So clipping is used here.<br />
<br />
=== A direct comparison ===<br />
<br />
{| border="0" cellpadding="5" cellspacing="0"<br />
|<br />
|It's all in the garden.<br />
|0123456789<br />
|\underbar{In a bar, under the sea}<br />
|-<br />
|<tt>'''\doboundtext'''</tt><br />
|<context>\ss\doboundtext{It's all in the garden.}{30mm}{...}</context><br />
|<context>\ss\doboundtext{0123456789}{15mm}{...}</context><br />
|align=center|not possible<br />
|-<br />
|<tt>'''\limitatetext'''</tt><br />
|<context>\ss\limitatetext{It's all in the garden.}{30mm}{...}</context><br />
|<context>\ss\limitatetext{0123456789}{15mm}{...}</context><br />
|<context>\ss\limitatetext{\underbar{In a bar, under the sea}}{31mm}{...}</context><br />
|-<br />
|<tt>'''\limitatefirstline'''</tt><br />
|<context>\ss\limitatefirstline{It's all in the garden.}{30mm}{\red...}</context><br />
|<context>\ss\limitatefirstline{0123456789}{15mm}{...}</context><br />
|<context>\ss\limitatefirstline{\underbar{In a bar, under the sea}}{31mm}{...}</context><br />
|}<br />
<br />
== Fitting text ==<br />
You can fit text into a box by:<br />
<br />
<texcode><br />
\def\HowStrange#1{#1\ifx#1\blankspace\else\allowbreak\fi}<br />
<br />
\framed<br />
[width=2cm,align={normal,verytolerant,stretch}]<br />
{\handletokens There are some rather long titles that needs to be typeset.\with\HowStrange}<br />
</texcode><br />
<br />
<context><br />
\def\HowStrange#1{#1\ifx#1\blankspace\else\allowbreak\fi}<br />
<br />
\framed<br />
[width=2cm,align={normal,verytolerant,stretch}]<br />
{\handletokens There are some rather long titles that needs to be typeset.\with\HowStrange}<br />
</context><br />
<br />
There is also similar facility for verbatim text in [[Verbatim_with_line_breaks]] and [[Wrapping]] section.<br />
<br />
== See also ==<br />
<br />
* If you meant to crop a page ''to'' some text, see {{cmd|startTEXpage}}<br />
<br />
[[Category:Basics]]<br />
[[Category:Graphics]]</div>Mæstrohttps://wiki.contextgarden.net/index.php?title=Cropping_text&diff=33719Cropping text2022-08-20T14:25:16Z<p>Mæstro: /* \limitatefirstline */ - Fix context code</p>
<hr />
<div>== Cropping text ==<br />
There are some rare cases in which it is useful to truncate a line of text and discard some of it.<br />
<br />
=== <tt>\doboundtext</tt> ===<br />
Sometimes there is not enough room to show the complete<br />
(line of) text. In such a situation we can strip of some<br />
'''characters''' by using<br />
<br />
<texcode><br />
\doboundtext {text} {width} {sentinel}<br />
</texcode><br />
<br />
When the <tt>text</tt> is wider than the given <tt>width</tt>, it's split and the third<br />
argument (<tt>sentinel</tt>) is appended. As much text as possible is printed.<br />
<br />
An example<br />
<br />
<texcode><br />
\doboundtext{My entire inheritance goes to my beloved cat Pussy!}{60mm}{...}<br />
</texcode><br />
<br />
and it's result<br />
<br />
<context><br />
\ss\doboundtext{My entire inheritance goes to my beloved cat Pussy!}{60mm}{...}<br />
</context><br />
<br />
=== <tt>\limitatetext</tt> ===<br />
A bit more beautiful alternative for the previous command is {{cmd|limitatetext}}.<br />
This command takes care of '''word''' boundaries, so that only complete words will<br />
appear in the final (cropped) text.<br />
<br />
<texcode><br />
\limitatetext {text} {width} {sentinel}<br />
\limitatetext {text} {-width} {prelude}<br />
\limitatetext {text} {width1 , width2} {symbol}<br />
</texcode><br />
<br />
When no <tt>width</tt> is given, the whole <tt>text</tt> becomes available.<br />
A negative value crops the beginning and the text starts with<br />
the <tt>prelude</tt>. Sentinel and prelude are both optional.<br />
Just look at the example, to see what happens, if you call the macro with<br />
two positive dimensions...<br />
<br />
Example:<br />
<br />
<texcode><br />
\limitatetext {Pussy is the name of the cat!}{38mm}{...}\par<br />
\limitatetext {Pussy is the name of the cat!}{-38mm}{...}\par<br />
\limitatetext {Pussy is the name of the cat!}{12mm, 12mm}{...}<br />
</texcode><br />
<br />
leads to<br />
<br />
<context><br />
\limitatetext {\ss Pussy is the name of the cat!}{38mm}{...}\par<br />
\limitatetext {\ss Pussy is the name of the cat!}{-38mm}{...}\par<br />
\limitatetext {\ss Pussy is the name of the cat!}{10mm, 10mm}{...}<br />
</context><br />
<br />
<br />
Both commands have their range of application.<br />
{{cmd|limitatetext}} is more robust (using grouping tokens like<br />
{{cmd|underbar}} is possible), while {{cmd|doboundtext}} works better<br />
on text that cannot be hyphenated.<br />
<br />
=== <tt>\limitatefirstline</tt> ===<br />
In ConTeXt versions newer than 07.09.2005 there is also a command<br />
called {{cmd|limitatefirstline}}, which acts nearly like {{cmd|doboundtext}},<br />
but at a more robust level. This macro first tries to break the given text<br />
at character level. It uses nearly the same breaking mechanism as {{cmd|limitatetext}},<br />
so it shares the problem with nonbreakable text.<br />
But in contrast to {{cmd|limitatetext}} it has a second mechanism, that is only used,<br />
if the prior one fails or if the result of breaking is wasting too much space.<br />
This fail safe mechanism "simply" clips (no breaking at all) the text to the desired<br />
measures. This is done without any consideration to character boundaries.<br />
So you must live with the fact, that the last character can be cut off at any possible<br />
place.<br />
<br />
<texcode><br />
\limitatefirstline {text} {width} {sentinel}<br />
</texcode><br />
<br />
Example:<br />
<br />
<texcode><br />
\limitatefirstline {\underbar{Mr.~Drofnats was happiest when he was at work%<br />
typesetting beautiful documents.}{109mm}{\unknown}<br />
</texcode><br />
<br />
<br />
<context><br />
\unprotect<br />
<br />
<br />
\def\limitatefirstline#1#2#3%<br />
{\hbox\bgroup\strut\dontcomplain<br />
\setbox\scratchbox\hbox{\begstrut#1\endstrut}%<br />
\ifdim\wd\scratchbox>#2\relax<br />
\setbox\scratchbox\hbox{#3}%<br />
\hsize#2\relax<br />
\advance\hsize-\wd\scratchbox<br />
\setbox\scratchbox\vbox{\forgetall\veryraggedright#1}%<br />
\setbox\scratchbox\vsplit\scratchbox to \lineheight<br />
\vbox<br />
{\unvbox\scratchbox<br />
\global\setbox\plusone\lastbox<br />
\global\setbox\plusone\hbox{\strut\unhbox\plusone}%<br />
\hbox % to #2<br />
{\ifx\clip\undefined<br />
\box\plusone<br />
\else\ifdim\wd\plusone>\hsize<br />
\lower\strutdepth\hbox{\clip[\c!width=\hsize,\c!height=\lineheight]{\hbox{\raise\strutdepth\box\plusone}}}%<br />
\else\ifdim\wd\plusone<\dimexpr\hsize-6ex\relax% tolerance for "successful" breaking<br />
\lower\strutdepth\hbox{\clip[\c!width=\hsize,\c!height=\lineheight]{\hbox{\raise\strutdepth\hbox{\begstrut#1\endstrut}}}}%<br />
\else<br />
\box\plusone<br />
\fi\fi\fi<br />
\removeunwantedspaces#3}}% \removeunwantedspaces\hss#3}}%<br />
\else<br />
#1%<br />
\fi<br />
\egroup}<br />
<br />
\protect<br />
<br />
<br />
\limitatefirstline {\ss\underbar{Mr.~Drofnats was happiest when he was at work typesetting beautiful documents.}}{107mm}{\unknown}<br />
</context><br />
<br />
<br />
In this example breaking is successful (right after the word typesetting),<br />
but the gap between the breaking point and the given width is too big.<br />
So clipping is used here.<br />
<br />
=== A direct comparison ===<br />
<br />
{| border="0" cellpadding="5" cellspacing="0"<br />
|<br />
|It's all in the garden.<br />
|0123456789<br />
|\underbar{In a bar, under the sea}<br />
|-<br />
|<tt>'''\doboundtext'''</tt><br />
|<context>\ss\x\doboundtext{It's all in the garden.}{30mm}{...}</context><br />
|<context>\ss\x\doboundtext{0123456789}{15mm}{...}</context><br />
|align=center|not possible<br />
|-<br />
|<tt>'''\limitatetext'''</tt><br />
|<context>\ss\x\limitatetext{It's all in the garden.}{30mm}{...}</context><br />
|<context>\ss\x\limitatetext{0123456789}{15mm}{...}</context><br />
|<context>\ss\x\limitatetext{\underbar{In a bar, under the sea}}{31mm}{...}</context><br />
|-<br />
|<tt>'''\limitatefirstline'''</tt><br />
|<context>\ss\x\limitatefirstline{It's all in the garden.}{30mm}{\red...}</context><br />
|<context>\ss\x\limitatefirstline{0123456789}{15mm}{...}</context><br />
|<context>\ss\x\limitatefirstline{\underbar{In a bar, under the sea}}{31mm}{...}</context><br />
|}<br />
<br />
== Fitting text ==<br />
You can fit text into a box by:<br />
<br />
<texcode><br />
\def\HowStrange#1{#1\ifx#1\blankspace\else\allowbreak\fi}<br />
<br />
\framed<br />
[width=2cm,align={normal,verytolerant,stretch}]<br />
{\handletokens There are some rather long titles that needs to be typeset.\with\HowStrange}<br />
</texcode><br />
<br />
<context><br />
\def\HowStrange#1{#1\ifx#1\blankspace\else\allowbreak\fi}<br />
<br />
\framed<br />
[width=2cm,align={normal,verytolerant,stretch}]<br />
{\handletokens There are some rather long titles that needs to be typeset.\with\HowStrange}<br />
</context><br />
<br />
There is also similar facility for verbatim text in [[Verbatim_with_line_breaks]] and [[Wrapping]] section.<br />
<br />
== See also ==<br />
<br />
* If you meant to crop a page ''to'' some text, see {{cmd|startTEXpage}}<br />
<br />
[[Category:Basics]]<br />
[[Category:Graphics]]</div>Mæstrohttps://wiki.contextgarden.net/index.php?title=Cropping_text&diff=33718Cropping text2022-08-20T14:24:46Z<p>Mæstro: /* \limitatetext */ - Fix context code</p>
<hr />
<div>== Cropping text ==<br />
There are some rare cases in which it is useful to truncate a line of text and discard some of it.<br />
<br />
=== <tt>\doboundtext</tt> ===<br />
Sometimes there is not enough room to show the complete<br />
(line of) text. In such a situation we can strip of some<br />
'''characters''' by using<br />
<br />
<texcode><br />
\doboundtext {text} {width} {sentinel}<br />
</texcode><br />
<br />
When the <tt>text</tt> is wider than the given <tt>width</tt>, it's split and the third<br />
argument (<tt>sentinel</tt>) is appended. As much text as possible is printed.<br />
<br />
An example<br />
<br />
<texcode><br />
\doboundtext{My entire inheritance goes to my beloved cat Pussy!}{60mm}{...}<br />
</texcode><br />
<br />
and it's result<br />
<br />
<context><br />
\ss\doboundtext{My entire inheritance goes to my beloved cat Pussy!}{60mm}{...}<br />
</context><br />
<br />
=== <tt>\limitatetext</tt> ===<br />
A bit more beautiful alternative for the previous command is {{cmd|limitatetext}}.<br />
This command takes care of '''word''' boundaries, so that only complete words will<br />
appear in the final (cropped) text.<br />
<br />
<texcode><br />
\limitatetext {text} {width} {sentinel}<br />
\limitatetext {text} {-width} {prelude}<br />
\limitatetext {text} {width1 , width2} {symbol}<br />
</texcode><br />
<br />
When no <tt>width</tt> is given, the whole <tt>text</tt> becomes available.<br />
A negative value crops the beginning and the text starts with<br />
the <tt>prelude</tt>. Sentinel and prelude are both optional.<br />
Just look at the example, to see what happens, if you call the macro with<br />
two positive dimensions...<br />
<br />
Example:<br />
<br />
<texcode><br />
\limitatetext {Pussy is the name of the cat!}{38mm}{...}\par<br />
\limitatetext {Pussy is the name of the cat!}{-38mm}{...}\par<br />
\limitatetext {Pussy is the name of the cat!}{12mm, 12mm}{...}<br />
</texcode><br />
<br />
leads to<br />
<br />
<context><br />
\limitatetext {\ss Pussy is the name of the cat!}{38mm}{...}\par<br />
\limitatetext {\ss Pussy is the name of the cat!}{-38mm}{...}\par<br />
\limitatetext {\ss Pussy is the name of the cat!}{10mm, 10mm}{...}<br />
</context><br />
<br />
<br />
Both commands have their range of application.<br />
{{cmd|limitatetext}} is more robust (using grouping tokens like<br />
{{cmd|underbar}} is possible), while {{cmd|doboundtext}} works better<br />
on text that cannot be hyphenated.<br />
<br />
=== <tt>\limitatefirstline</tt> ===<br />
In ConTeXt versions newer than 07.09.2005 there is also a command<br />
called {{cmd|limitatefirstline}}, which acts nearly like {{cmd|doboundtext}},<br />
but at a more robust level. This macro first tries to break the given text<br />
at character level. It uses nearly the same breaking mechanism as {{cmd|limitatetext}},<br />
so it shares the problem with nonbreakable text.<br />
But in contrast to {{cmd|limitatetext}} it has a second mechanism, that is only used,<br />
if the prior one fails or if the result of breaking is wasting too much space.<br />
This fail safe mechanism "simply" clips (no breaking at all) the text to the desired<br />
measures. This is done without any consideration to character boundaries.<br />
So you must live with the fact, that the last character can be cut off at any possible<br />
place.<br />
<br />
<texcode><br />
\limitatefirstline {text} {width} {sentinel}<br />
</texcode><br />
<br />
Example:<br />
<br />
<texcode><br />
\limitatefirstline {\underbar{Mr.~Drofnats was happiest when he was at work%<br />
typesetting beautiful documents.}{109mm}{\unknown}<br />
</texcode><br />
<br />
<br />
<context><br />
\unprotect<br />
<br />
<br />
\def\limitatefirstline#1#2#3%<br />
{\hbox\bgroup\strut\dontcomplain<br />
\setbox\scratchbox\hbox{\begstrut#1\endstrut}%<br />
\ifdim\wd\scratchbox>#2\relax<br />
\setbox\scratchbox\hbox{#3}%<br />
\hsize#2\relax<br />
\advance\hsize-\wd\scratchbox<br />
\setbox\scratchbox\vbox{\forgetall\veryraggedright#1}%<br />
\setbox\scratchbox\vsplit\scratchbox to \lineheight<br />
\vbox<br />
{\unvbox\scratchbox<br />
\global\setbox\plusone\lastbox<br />
\global\setbox\plusone\hbox{\strut\unhbox\plusone}%<br />
\hbox % to #2<br />
{\ifx\clip\undefined<br />
\box\plusone<br />
\else\ifdim\wd\plusone>\hsize<br />
\lower\strutdepth\hbox{\clip[\c!width=\hsize,\c!height=\lineheight]{\hbox{\raise\strutdepth\box\plusone}}}%<br />
\else\ifdim\wd\plusone<\dimexpr\hsize-6ex\relax% tolerance for "successful" breaking<br />
\lower\strutdepth\hbox{\clip[\c!width=\hsize,\c!height=\lineheight]{\hbox{\raise\strutdepth\hbox{\begstrut#1\endstrut}}}}%<br />
\else<br />
\box\plusone<br />
\fi\fi\fi<br />
\removeunwantedspaces#3}}% \removeunwantedspaces\hss#3}}%<br />
\else<br />
#1%<br />
\fi<br />
\egroup}<br />
<br />
\protect<br />
<br />
<br />
\limitatefirstline {\ss\x\underbar{Mr.~Drofnats was happiest when he was at work typesetting beautiful documents.}}{107mm}{\unknown}<br />
</context><br />
<br />
<br />
In this example breaking is successful (right after the word typesetting),<br />
but the gap between the breaking point and the given width is too big.<br />
So clipping is used here.<br />
<br />
=== A direct comparison ===<br />
<br />
{| border="0" cellpadding="5" cellspacing="0"<br />
|<br />
|It's all in the garden.<br />
|0123456789<br />
|\underbar{In a bar, under the sea}<br />
|-<br />
|<tt>'''\doboundtext'''</tt><br />
|<context>\ss\x\doboundtext{It's all in the garden.}{30mm}{...}</context><br />
|<context>\ss\x\doboundtext{0123456789}{15mm}{...}</context><br />
|align=center|not possible<br />
|-<br />
|<tt>'''\limitatetext'''</tt><br />
|<context>\ss\x\limitatetext{It's all in the garden.}{30mm}{...}</context><br />
|<context>\ss\x\limitatetext{0123456789}{15mm}{...}</context><br />
|<context>\ss\x\limitatetext{\underbar{In a bar, under the sea}}{31mm}{...}</context><br />
|-<br />
|<tt>'''\limitatefirstline'''</tt><br />
|<context>\ss\x\limitatefirstline{It's all in the garden.}{30mm}{\red...}</context><br />
|<context>\ss\x\limitatefirstline{0123456789}{15mm}{...}</context><br />
|<context>\ss\x\limitatefirstline{\underbar{In a bar, under the sea}}{31mm}{...}</context><br />
|}<br />
<br />
== Fitting text ==<br />
You can fit text into a box by:<br />
<br />
<texcode><br />
\def\HowStrange#1{#1\ifx#1\blankspace\else\allowbreak\fi}<br />
<br />
\framed<br />
[width=2cm,align={normal,verytolerant,stretch}]<br />
{\handletokens There are some rather long titles that needs to be typeset.\with\HowStrange}<br />
</texcode><br />
<br />
<context><br />
\def\HowStrange#1{#1\ifx#1\blankspace\else\allowbreak\fi}<br />
<br />
\framed<br />
[width=2cm,align={normal,verytolerant,stretch}]<br />
{\handletokens There are some rather long titles that needs to be typeset.\with\HowStrange}<br />
</context><br />
<br />
There is also similar facility for verbatim text in [[Verbatim_with_line_breaks]] and [[Wrapping]] section.<br />
<br />
== See also ==<br />
<br />
* If you meant to crop a page ''to'' some text, see {{cmd|startTEXpage}}<br />
<br />
[[Category:Basics]]<br />
[[Category:Graphics]]</div>Mæstrohttps://wiki.contextgarden.net/index.php?title=Cropping_text&diff=33717Cropping text2022-08-20T14:24:11Z<p>Mæstro: /* \doboundtext */ fix context code</p>
<hr />
<div>== Cropping text ==<br />
There are some rare cases in which it is useful to truncate a line of text and discard some of it.<br />
<br />
=== <tt>\doboundtext</tt> ===<br />
Sometimes there is not enough room to show the complete<br />
(line of) text. In such a situation we can strip of some<br />
'''characters''' by using<br />
<br />
<texcode><br />
\doboundtext {text} {width} {sentinel}<br />
</texcode><br />
<br />
When the <tt>text</tt> is wider than the given <tt>width</tt>, it's split and the third<br />
argument (<tt>sentinel</tt>) is appended. As much text as possible is printed.<br />
<br />
An example<br />
<br />
<texcode><br />
\doboundtext{My entire inheritance goes to my beloved cat Pussy!}{60mm}{...}<br />
</texcode><br />
<br />
and it's result<br />
<br />
<context><br />
\ss\doboundtext{My entire inheritance goes to my beloved cat Pussy!}{60mm}{...}<br />
</context><br />
<br />
=== <tt>\limitatetext</tt> ===<br />
A bit more beautiful alternative for the previous command is {{cmd|limitatetext}}.<br />
This command takes care of '''word''' boundaries, so that only complete words will<br />
appear in the final (cropped) text.<br />
<br />
<texcode><br />
\limitatetext {text} {width} {sentinel}<br />
\limitatetext {text} {-width} {prelude}<br />
\limitatetext {text} {width1 , width2} {symbol}<br />
</texcode><br />
<br />
When no <tt>width</tt> is given, the whole <tt>text</tt> becomes available.<br />
A negative value crops the beginning and the text starts with<br />
the <tt>prelude</tt>. Sentinel and prelude are both optional.<br />
Just look at the example, to see what happens, if you call the macro with<br />
two positive dimensions...<br />
<br />
Example:<br />
<br />
<texcode><br />
\limitatetext {Pussy is the name of the cat!}{38mm}{...}\par<br />
\limitatetext {Pussy is the name of the cat!}{-38mm}{...}\par<br />
\limitatetext {Pussy is the name of the cat!}{12mm, 12mm}{...}<br />
</texcode><br />
<br />
leads to<br />
<br />
<context><br />
\limitatetext {\ss\x Pussy is the name of the cat!}{38mm}{...}\par<br />
\limitatetext {\ss\x Pussy is the name of the cat!}{-38mm}{...}\par<br />
\limitatetext {\ss\x Pussy is the name of the cat!}{10mm, 10mm}{...}<br />
</context><br />
<br />
<br />
Both commands have their range of application.<br />
{{cmd|limitatetext}} is more robust (using grouping tokens like<br />
{{cmd|underbar}} is possible), while {{cmd|doboundtext}} works better<br />
on text that cannot be hyphenated.<br />
<br />
=== <tt>\limitatefirstline</tt> ===<br />
In ConTeXt versions newer than 07.09.2005 there is also a command<br />
called {{cmd|limitatefirstline}}, which acts nearly like {{cmd|doboundtext}},<br />
but at a more robust level. This macro first tries to break the given text<br />
at character level. It uses nearly the same breaking mechanism as {{cmd|limitatetext}},<br />
so it shares the problem with nonbreakable text.<br />
But in contrast to {{cmd|limitatetext}} it has a second mechanism, that is only used,<br />
if the prior one fails or if the result of breaking is wasting too much space.<br />
This fail safe mechanism "simply" clips (no breaking at all) the text to the desired<br />
measures. This is done without any consideration to character boundaries.<br />
So you must live with the fact, that the last character can be cut off at any possible<br />
place.<br />
<br />
<texcode><br />
\limitatefirstline {text} {width} {sentinel}<br />
</texcode><br />
<br />
Example:<br />
<br />
<texcode><br />
\limitatefirstline {\underbar{Mr.~Drofnats was happiest when he was at work%<br />
typesetting beautiful documents.}{109mm}{\unknown}<br />
</texcode><br />
<br />
<br />
<context><br />
\unprotect<br />
<br />
<br />
\def\limitatefirstline#1#2#3%<br />
{\hbox\bgroup\strut\dontcomplain<br />
\setbox\scratchbox\hbox{\begstrut#1\endstrut}%<br />
\ifdim\wd\scratchbox>#2\relax<br />
\setbox\scratchbox\hbox{#3}%<br />
\hsize#2\relax<br />
\advance\hsize-\wd\scratchbox<br />
\setbox\scratchbox\vbox{\forgetall\veryraggedright#1}%<br />
\setbox\scratchbox\vsplit\scratchbox to \lineheight<br />
\vbox<br />
{\unvbox\scratchbox<br />
\global\setbox\plusone\lastbox<br />
\global\setbox\plusone\hbox{\strut\unhbox\plusone}%<br />
\hbox % to #2<br />
{\ifx\clip\undefined<br />
\box\plusone<br />
\else\ifdim\wd\plusone>\hsize<br />
\lower\strutdepth\hbox{\clip[\c!width=\hsize,\c!height=\lineheight]{\hbox{\raise\strutdepth\box\plusone}}}%<br />
\else\ifdim\wd\plusone<\dimexpr\hsize-6ex\relax% tolerance for "successful" breaking<br />
\lower\strutdepth\hbox{\clip[\c!width=\hsize,\c!height=\lineheight]{\hbox{\raise\strutdepth\hbox{\begstrut#1\endstrut}}}}%<br />
\else<br />
\box\plusone<br />
\fi\fi\fi<br />
\removeunwantedspaces#3}}% \removeunwantedspaces\hss#3}}%<br />
\else<br />
#1%<br />
\fi<br />
\egroup}<br />
<br />
\protect<br />
<br />
<br />
\limitatefirstline {\ss\x\underbar{Mr.~Drofnats was happiest when he was at work typesetting beautiful documents.}}{107mm}{\unknown}<br />
</context><br />
<br />
<br />
In this example breaking is successful (right after the word typesetting),<br />
but the gap between the breaking point and the given width is too big.<br />
So clipping is used here.<br />
<br />
=== A direct comparison ===<br />
<br />
{| border="0" cellpadding="5" cellspacing="0"<br />
|<br />
|It's all in the garden.<br />
|0123456789<br />
|\underbar{In a bar, under the sea}<br />
|-<br />
|<tt>'''\doboundtext'''</tt><br />
|<context>\ss\x\doboundtext{It's all in the garden.}{30mm}{...}</context><br />
|<context>\ss\x\doboundtext{0123456789}{15mm}{...}</context><br />
|align=center|not possible<br />
|-<br />
|<tt>'''\limitatetext'''</tt><br />
|<context>\ss\x\limitatetext{It's all in the garden.}{30mm}{...}</context><br />
|<context>\ss\x\limitatetext{0123456789}{15mm}{...}</context><br />
|<context>\ss\x\limitatetext{\underbar{In a bar, under the sea}}{31mm}{...}</context><br />
|-<br />
|<tt>'''\limitatefirstline'''</tt><br />
|<context>\ss\x\limitatefirstline{It's all in the garden.}{30mm}{\red...}</context><br />
|<context>\ss\x\limitatefirstline{0123456789}{15mm}{...}</context><br />
|<context>\ss\x\limitatefirstline{\underbar{In a bar, under the sea}}{31mm}{...}</context><br />
|}<br />
<br />
== Fitting text ==<br />
You can fit text into a box by:<br />
<br />
<texcode><br />
\def\HowStrange#1{#1\ifx#1\blankspace\else\allowbreak\fi}<br />
<br />
\framed<br />
[width=2cm,align={normal,verytolerant,stretch}]<br />
{\handletokens There are some rather long titles that needs to be typeset.\with\HowStrange}<br />
</texcode><br />
<br />
<context><br />
\def\HowStrange#1{#1\ifx#1\blankspace\else\allowbreak\fi}<br />
<br />
\framed<br />
[width=2cm,align={normal,verytolerant,stretch}]<br />
{\handletokens There are some rather long titles that needs to be typeset.\with\HowStrange}<br />
</context><br />
<br />
There is also similar facility for verbatim text in [[Verbatim_with_line_breaks]] and [[Wrapping]] section.<br />
<br />
== See also ==<br />
<br />
* If you meant to crop a page ''to'' some text, see {{cmd|startTEXpage}}<br />
<br />
[[Category:Basics]]<br />
[[Category:Graphics]]</div>Mæstrohttps://wiki.contextgarden.net/index.php?title=Color_in_MetaPost&diff=33432Color in MetaPost2022-02-23T04:33:55Z<p>Mæstro: /* Transparent colors */ - comment runMPgraphicstrue</p>
<hr />
<div>{{Color_navigation_Trial}}<br />
<br />
[[MetaPost]] only supports the RGB color space, although with the help of [[MetaFun - MetaPost in ConTeXt|MetaFun]] you can face transparency and CMYK colors. This article describes the use of colors in MetaPost and MetaFun.<br />
<br />
== The basics ==<br />
<br />
Colors are defined as vectors with three components: a red, green and blue one. Like pens, colors have a {{code|with...}} command:<br />
<br />
withcolor (.4,.5.,6)<br />
<br />
You can define color variables like so:<br />
<br />
color darkred ; darkred := (.625,0.0) ;<br />
% use the color<br />
withcolor darkred<br />
% actually, red is already defined, so this works:<br />
withcolor .625red<br />
<br />
Because for MetaPost colors are just vectors, you can manipulate them like you would manipulate points. This is a color halfway between red and green:<br />
<br />
withcolor .5[red,green]<br />
<br />
== Using colors defined in TeX ==<br />
<br />
In ConTeXt you define colors with {{cmd|definecolor}}. Instead of defining a color a second time in MetaPost, you can use the {{code|\MPcolor{colorname}|}} command.<br />
<br />
<context source=yes><br />
\definecolor[darkred] [r=.625] % a RGB color<br />
\definecolor[darkgray][s=.625] % a gray scale<br />
\startuseMPgraphic{color demo}<br />
pickup pencircle scaled 1mm ;<br />
path p ; p := fullcircle xscaled 5cm yscaled 0.5cm ;<br />
fill p withcolor \MPcolor{darkgray} ;<br />
draw p withcolor \MPcolor{darkred} ;<br />
\stopuseMPgraphic<br />
<br />
\bold{\color[darkgray]{This} is an \color[darkred]{ellipse}:}<br />
\useMPgraphic{color demo}<br />
</context><br />
<br />
== Transparent colors ==<br />
<br />
You can use transparent colors with the {{code|transparent(method, factor, color)}} function. For example:<br />
<br />
<context source=yes><br />
% MKII<br />
% \runMPgraphicstrue<br />
\setupcolors[state=start]<br />
\starttext<br />
\startreusableMPgraphic{a}<br />
fill unitsquare scaled 1cm withcolor yellow;<br />
fill unitsquare shifted (0.5,0.5)<br />
% method 1 = normal<br />
scaled 1cm withcolor transparent(1,0.5,red);<br />
\stopreusableMPgraphic<br />
<br />
\placefigure[force,none]{}{\reuseMPgraphic{a}}<br />
\stoptext<br />
</context><br />
<br />
The available transparency methods are the twelve methods supported by PDF specification:<br />
<br />
* 1. normal <br />
* 2. multiply <br />
* 3. screen <br />
* 4. overlay<br />
* 5. softlight <br />
* 6. hardlight <br />
* 7. colordodge <br />
* 8. colorburn<br />
* 9. darken <br />
* 10. lighten <br />
* 11. difference <br />
* 12. exclusion<br />
<br />
=== Troubleshooting transparency ===<br />
<br />
If you see black colors rather than transparent ones, then you probably hit the 'missing specials' problem. This problem was around in 2006; people may not encounter it anymore, but the solution is mentioned here anyway. From the mailing list:<br />
<br />
<pre><br />
This all sounds like the 'missing specials' problem that is caused<br />
by conflicting -progname= arguments when using the web2c version<br />
of MetaPost.<br />
<br />
Make sure you do not have conflicting memory settings for both<br />
main_memory.mpost<br />
as well as<br />
main_memory.metafun<br />
<br />
The best is to remove all trace of '.mpost' and '.metafun' memory<br />
settings from your texmf.cnf, but at least make sure all the<br />
'.mpost' and 'metafun' values are the same .<br />
<br />
Then regenerate metafun using texexec --make, and all should be<br />
well again.<br />
</pre><br />
<br />
The settings will be in {{code|tex/texmf/web2c/texmf.cnf}} or {{code|tex/texmf-context/web2c/context.cnf}} inside your ConTeXt tree. If you are using ConTeXt from the Debian/Ubuntu distribution of TeX, instead of via the recommended [[ConTeXt Standalone]], you need to edit <br />
''/etc/texmf/texmf.d/95NonPath.cnf'', instead. The part you need to edit will look something like this.<br />
<br />
<pre><br />
main_memory = 1000000 % words of inimemory available; also applies to inimf&mp<br />
main_memory.context = 1500000<br />
main_memory.mpost = 1500000<br />
</pre><br />
<br />
* Comment out the .mpost line (MetaFun uses the main_memory value of 1000000; the difference in values is the cause of the problem). <br />
* (If you are not using the standalone, regenerate your TeX with {{code|sudo update-texmf}})<br />
* Lastly, regenerate the MetaFun format with {{code|texexec --make}}. Transparency should work now.<br />
<br />
[[Category:Color]]<br />
[[Category:Graphics]]</div>Mæstrohttps://wiki.contextgarden.net/index.php?title=Barcodes&diff=33430Barcodes2022-02-20T13:58:24Z<p>Mæstro: /* Zint module */ - update zint names, see manual: https://www.zint.org.uk/manual/chapter/4</p>
<hr />
<div>< [[Graphics]]<br />
<br />
How to create barcodes from within ConTeXt (MkIV/LMTX)?<br />
<br />
== Zint module ==<br />
<br />
* Download `zint` from https://www.zint.org.uk (Windows, Linux) or install it with [https://brew.sh Homebrew] or [https://www.macports.org/install.php MacPorts] (MacOS).<br />
* '''MkIV''': The `zint` executable must be in your `PATH`.<br />
* '''LMTX''': LuaMetaTeX uses the library. On Windows, that’s `libzint.dll`, on Linux and MacOS `libzint.so` (on MacOS the actual file name is `libzint.dylib`, but LuaMetaTeX expects `.so`).<br />
** Find that file, it should be in `/usr/local/lib` (Linux, Homebrew) or `/opt/local/lib` (MacPorts).<br />
** Create the path `$TEXROOT/tex/texmf-$ARCH/bin/lib/luametatex/zint`.<br />
** Copy or symlink the library into it (on MacOS remember naming it `libzint.so`).<br />
** Run `mtxrun --generate` to update the file database.<br />
<br />
<texcode><br />
\usemodule[zint]<br />
\barcode[alternative=isbnx, text=9783865419026, width=4cm]<br />
\barcode[alternative=qrcode, text={https://wiki.contextgarden.net}, width=3cm]<br />
</texcode><br />
<br />
Zint can produce about 40 different code types (“alternatives“). Try the [https://www.zint.org.uk/manual/chapter/4 name] (but lowercase with spaces) or look into the {{src|libs-imp-zint.lua|source}}<br />
<br />
== Barcodes module ==<br />
<br />
The old module uses PStricks and is deprecated. ({{src|m-barcodes.mkiv|Source}})<br />
<br />
<br />
== barcode.lua ==<br />
<br />
In 2012, [[User:Patrick_Gundlach|Patrick]] published a small LuaTeX library on [https://tex.stackexchange.com/questions/50707/how-to-generate-ean-barcodes-with-tikz-or-metapost#50751 Stack Exchange]. It can only create EAN codes, but it has no dependencies and doesn’t even use MetaPost.<br />
<br />
<texcode><br />
\loadluafile[barcode]<br />
\define[1]\luabarcode{\directlua{generate_barcode_lua("#1")}}<br />
<br />
\luabarcode{9783865419026}<br />
</texcode><br />
<br />
[[Category:Graphics]]</div>Mæstrohttps://wiki.contextgarden.net/index.php?title=Footnotes&diff=33420Footnotes2022-02-19T21:18:23Z<p>Mæstro: /* Footnotes in Floats */ - comment align key</p>
<hr />
<div>{{todo|This page needs to be reorganized: progression from simple to more complex use is a bit circular..}}<br />
<br />
==First View==<br />
<br />
<texcode><br />
\section{First}<br />
<br />
Way to \ConTeXt\footnote{First footnote.} is painful.<br />
<br />
\section{Second}<br />
<br />
But \ConTeXt\ is amazing.\footnote{Second footnote}<br />
<br />
\placetable<br />
{Complex Table\footnote{A table head footnote.}}<br />
{\startlocalfootnotes<br />
\placelegend<br />
{\starttable[|l|l|]<br />
\HL<br />
\NC First Column \NC Second Column \NC \FR<br />
\HL<br />
\NC East\footnote{Footnote inside graphic.} \NC North \NC \FR<br />
\NC West \NC South \NC \LR<br />
\HL<br />
\stoptable}<br />
{\placelocalfootnotes}<br />
\stoplocalfootnotes}<br />
</texcode><br />
<br />
<context><br />
\starttext<br />
\strut\vfill\<br />
\section{First}<br />
<br />
Way to \ConTeXt\footnote{First footnote.} is painful.<br />
<br />
\section{Second}<br />
<br />
But \ConTeXt\ is amazing.\footnote{Second footnote}<br />
<br />
\placetable<br />
{Complex Table\footnote{A table head footnote.}}<br />
{\startlocalfootnotes<br />
\placelegend<br />
{\starttable[|l|l|]<br />
\HL<br />
\NC First Column \NC Second Column \NC \FR<br />
\HL<br />
\NC East\footnote{Footnote inside graphic.} \NC North \NC \FR<br />
\NC West \NC South \NC \LR<br />
\HL<br />
\stoptable}<br />
{\placelocalfootnotes}<br />
\stoplocalfootnotes}<br />
\stoptext<br />
</context><br />
<br />
Here we have footnotes of two outer ones, a local one (in the table) and a postponed one (in the graphic).<br />
<br />
==Basic Footnotes==<br />
<br />
For basic footnotes, simply use {{cmd|footnote|[reference]{footnote text}}}.<br />
The reference is optional, and can be used to refer to the same footnote again. Footnotes can be referenced with the usual {{cmd|in}} and {{cmd|at}} macros (see [[References]]), or the note itself can be reproduced with {{cmd|note|[reference]}}. For example:<br />
<br />
<texcode><br />
This\footnote[footA]{Or that, if you prefer.} is a sentence with a footnote\footnote{Actually,<br />
two footnotes; this one and \in{footnote}[footA] on \at{page}[footA], denoted by \note[footA].}. <br />
</texcode><br />
<br />
<context><br />
\starttext<br />
\strut\vfill % A hack to shorten the page.<br />
This\footnote[footA]{Or that, if you prefer.} is a sentence with a footnote\footnote{Actually,<br />
two footnotes; this one and \in{footnote}[footA] on \at{page}[footA], denoted by \note[footA].}. <br />
\stoptext<br />
</context><br />
<br />
<br />
Thanks to Oblomov, it's also possible to use footnotes in footnotes, as in this example.<br />
<br />
<texcode><br />
This\footnote{Or that\footnote{Or possibly even the other.}, if you prefer.} is a sentence<br />
with a footnote. <br />
</texcode><br />
<br />
<context><br />
\starttext<br />
\strut\vfill % A hack to shorten the page.<br />
This\footnote{Or that\footnote{Or possibly even the other.}, if you prefer.} is a sentence<br />
with a footnote. <br />
\stoptext<br />
</context><br />
<br />
==Footnote Numbering==<br />
<br />
You can setup the exact behaviour of footnotes with {{cmd|setupnotation|[footnote]}} (MkII: {{cmd|setupfootnotes}}).<br />
(The command page for the MkIV version is still missing, refer to the old version; translate location to alternative and conversion to numberconversion.)<br />
<br />
For example, to use footnotes with standard footnote symbols (which ConTeXt has defined as the conversion "set 2"), with the footnote counter resetting on each page, one would use the following:<br />
<br />
<texcode><br />
\setupnotation[footnote][way=bypage,numberconversion=set 2]<br />
</texcode><br />
<br />
In MkII this was:<br />
<br />
<texcode><br />
\setupfootnotes[way=bypage, conversion=set 2]<br />
</texcode><br />
<br />
This produces the following footnotes, using the text of the previous example.<br />
<br />
<context><br />
\setupnotation[footnote][way=bypage,numberconversion=set 2]<br />
\starttext<br />
\strut\vfill % A hack to shorten the page.<br />
This\footnote[footA]{Or that, if you prefer.} is a sentence with a footnote\footnote{Actually,<br />
two footnotes; this one and \in{footnote}[footA] on \at{page}[footA], denoted by \note[footA].}. <br />
\stoptext<br />
</context><br />
<br />
==Alternate Footnote Locations==<br />
<br />
The {{cmd|setupfootnotes}} (MkII) command offers some options for the placement of footnotes; for instance, the <code>location=columns</code> option places the footnotes in a single column (of a multicolumn page) rather than across the whole page. The <code>location=text</code> option places the footnotes in text at a location specified by {{cmd|placefootnotes}}; this can be easily used to create endnotes, or even to place footnotes after each paragraph or subsection.<br />
<br />
<texcode><br />
\setupfootnotes[location=text] % MkII<br />
This\footnote[footA]{Or that, if you prefer.} is a sentence with a footnote\footnote{Actually,<br />
two footnotes; this one and footnote \note[footA].}. <br />
\placefootnotes<br />
This is some more text, with more footnotes\footnote{Specifically, this one.}.<br />
\placefootnotes<br />
</texcode><br />
<br />
<context><br />
\starttext<br />
\setupfootnotes[location=text]<br />
This\footnote[footA]{Or that, if you prefer.} is a sentence with a footnote\footnote{Actually,<br />
two footnotes; this one and footnote \note[footA].}. <br />
\placefootnotes<br />
This is some more text, with more footnotes\footnote{Specifically, this one.}.<br />
\placefootnotes<br />
\stoptext<br />
</context><br />
<br />
=== Footnotes at the end of each chapter ===<br />
<br />
Another elegant (MkIV) example places all footnotes in a subject (unnumbered section) at the end of each chapter. It is intelligent and will not create an empty subject when there are no footnotes to be placed. At no extra cost, the subject title "Footnote" will be singular or plural depending if there is only one or several footnotes to be placed:<br />
<br />
<texcode><br />
\startsetups[chapter:after]<br />
\ifcase\rawcountervalue[footnote]\relax<br />
\or<br />
\startsubject[title=Footnote]<br />
\placefootnotes<br />
\stopsubject<br />
\else<br />
\startsubject[title=Footnotes]<br />
\placefootnotes<br />
\stopsubject<br />
\fi<br />
\stopsetups<br />
<br />
\setupnotes[location=none]<br />
\setupnotation[way=bychapter]<br />
<br />
\setuphead[chapter][aftersection=\setups{chapter:after}]<br />
<br />
\starttext<br />
<br />
\startchapter[title={Chapter One}]<br />
<br />
This one\footnote{is placed}. And\footnote{this one is too}.<br />
<br />
\stopchapter<br />
<br />
\chapter[title={Chapter Two}]<br />
<br />
But this one\footnote{is not flushed}.<br />
<br />
\startchapter[title={Chapter Three}]<br />
<br />
Unless \type{\stopchapter} was invoked.<br />
<br />
\stopchapter<br />
<br />
\startchapter[title={Chapter Three}]<br />
<br />
On a chapter with\footnote{footnote}.<br />
<br />
\stopchapter<br />
<br />
\stoptext<br />
</texcode><br />
<br />
===Footnotes in the margin===<br />
<br />
First we switch off footnote placement, then we place them manually into the margin.<br />
<br />
<texcode><br />
\setupnote[footnote][location=none]<br />
\setupnotation[footnote][<br />
align=flushleft,<br />
location=serried,<br />
width=broad,<br />
]<br />
\setuptexttexts[margin][]<br />
[{\framed[%<br />
align={right,bottom},<br />
frame=off,<br />
height=\textheight,<br />
width=\rightmarginwidth<br />
]{\placenotes[footnote]}}]<br />
</texcode><br />
<br />
===... but not at the bottom===<br />
<br />
Hraban wanted numbered margin notes, starting in on the same line as the referenced text (like a combination of {{cmd|inmargin}} and {{cmd|footnote}}). Wolfgang answered:<br />
<br />
The only way I found to achieve this is by flushing the notes at the end of each footnote<br />
entry which can be done with the next key. The positioning of each margin text is tricky<br />
because {{cmd|placenotes}} adds skips at the begin of the block (which can be reduced with<br />
{{cmd|placelocalnotes}}) but a inline version of the command (e.g. <tt>\placeinlinenotes</tt>) which<br />
flushes the notes without vertical skips and a rule at the begin would help.<br />
<br />
<texcode><br />
\define\PlaceFootnote<br />
{\inrightmargin{\vtop{\placelocalnotes[footnote][before=,after=]}}}<br />
<br />
\setupnote<br />
[footnote]<br />
[location=text,<br />
bodyfont=,<br />
next=\PlaceFootnote]<br />
<br />
\setupnotation<br />
[footnote]<br />
[alternative=serried]<br />
<br />
\setuplayout<br />
[width=12cm,<br />
rightmargindistance=0.5cm,<br />
rightmargin=5cm]<br />
<br />
\starttext<br />
\dorecurse{6}{\input ward\expanded{\footnote{This is a footnote \recurselevel}} }<br />
\stoptext<br />
</texcode><br />
<br />
==Footnote Formatting==<br />
<br />
You can change the font used in the footnotes with<br />
{{cmd|setupfootnotedefinition|[before=\MyFontCommand]}}.<br />
<br />
Footnotes can be placed in multiple columns, using the <code>n=<i>number</i></code> option of {{cmd|setupnotes}} or {{cmd|setupnote}} (MkII: {{cmd|setupfootnotes}}).<br />
<br />
<texcode><br />
\setupfootnotes[n=3] % MkII<br />
This\footnote[footA](Or that\footnote{Or the other.}, if you prefer.} is a sentence<br />
with a footnote\footnote{Actually, two footnotes; this one and \in{footnote}[footA]<br />
on \at{page}[footA], denoted by \note[footA].}. <br />
</texcode><br />
<br />
<context><br />
\setupfootnotes[n=3]<br />
\starttext<br />
\strut\vfill % A hack to shorten the page.<br />
This\footnote[footA]{Or that\footnote{Or the other.}, if you prefer.} is a sentence<br />
with a footnote\footnote{Actually, two footnotes; this one and \in{footnote}[footA]<br />
on \at{page}[footA], denoted by \note[footA].}. <br />
\stoptext<br />
</context><br />
<br />
{{todo|This is ugly, and points up some ConTeXt bugs that need to be fixed.}}<br />
<br />
===Footnotes in pagraph form===<br />
<br />
When enabling footnotes (actually notes and linenotes) in pagraph form, there is some risk in having no right separation between body and the notes. This can be partially avoided using <code>width=broad</code> ([http://www.ntg.nl/pipermail/ntg-context/2013/073650.html Hans dixit]).<br />
<br />
<texcode><br />
\setupnote<br />
[footnote]<br />
[paragraph=yes]<br />
<br />
\setupnotation<br />
[footnote]<br />
[alternative=serried,<br />
width=broad,<br />
distance=.5em,<br />
display=no]<br />
<br />
\starttext<br />
\dorecurse{500}{text text text\footnote{note} }<br />
\stoptext<br />
</texcode><br />
<br />
==Footnotes in Floats==<br />
<br />
[[Floating Objects|Floats]] cannot include normal footnotes, because they are likely to float to another page from the page on which they were defined, thus getting the footnotes out of order. Thus, to include footnotes in a float, one must use local footnotes. This table, which uses the {{cmd|placelegend}} command to create a place for the footnotes, illustrates the process:<br />
<br />
<texcode><br />
\startlocalfootnotes[n=2]<br />
\placetable{A table with footnotes.}<br />
\placelegend<br />
{\starttable[|l|r|]<br />
\HL<br />
\VL One\footnote{First} \VL Two\footnote{Second} \VL\FR<br />
\VL Three\footnote{Third} \VL Four\footnote{Fourth} \VL\LR<br />
\HL<br />
\stoptable}<br />
{\placelocalfootnotes}<br />
\stoplocalfootnotes<br />
</texcode><br />
<br />
<context><br />
\startlocalfootnotes[n=2]<br />
\placetable{A table with footnotes.}<br />
\placelegend<br />
{\strut\starttable[|l|r|]<br />
\HL<br />
\VL One\footnote{First} \VL Two\footnote{Second} \VL\FR<br />
\VL Three\footnote{Third} \VL Four\footnote{Fourth} \VL\LR<br />
\HL<br />
\stoptable}<br />
{\placelocalfootnotes}<br />
\stoplocalfootnotes<br />
</context><br />
<br />
When using natural tables, the above leads to alignment problems. An alternative is to use:<br />
<br />
<texcode><br />
\defineframed[noteframed]<br />
\setupframed[noteframed]<br />
[width=\hsize,<br />
frame=off,<br />
align=right,<br />
%height=fit,<br />
top=\hbox\bgroup,<br />
bottom=\egroup]<br />
<br />
\starttext<br />
<br />
\startlocalfootnotes[n=0]<br />
\placetable<br />
{Caption}<br />
{\placelegend<br />
{\bTABLE<br />
\bTR\bTD One\footnote{First} \eTD\bTD Two\footnote{Second} \eTD\eTR<br />
\bTR\bTD Three\footnote{Third} \eTD\bTD Four\footnote{Fourth} \eTD\eTR<br />
\eTABLE}<br />
{\noteframed{\placelocalfootnotes}}}<br />
\stoplocalfootnotes<br />
<br />
\stoptext<br />
</texcode><br />
<br />
<context><br />
\defineframed[noteframed]<br />
\setupframed[noteframed]<br />
[width=\hsize,<br />
frame=off,<br />
%align=right,<br />
%height=fit,<br />
top=\hbox\bgroup,<br />
bottom=\egroup]<br />
<br />
\starttext<br />
<br />
\startlocalfootnotes%[n=0]<br />
\placetable<br />
{Caption}<br />
{\placelegend<br />
{\bTABLE<br />
\bTR\bTD One\footnote{First} \eTD\bTD Two\footnote{Second} \eTD\eTR<br />
\bTR\bTD Three\footnote{Third} \eTD\bTD Four\footnote{Fourth} \eTD\eTR<br />
\eTABLE}<br />
{\noteframed{\placelocalfootnotes}}}<br />
\stoplocalfootnotes<br />
<br />
\stoptext<br />
</context><br />
<br />
==Footnotes in a box==<br />
<br />
Note that it is necessary to add the command {{cmd|automigrateinserts}} (for example before {{cmd|link=no|starttext}})<br />
in order to correctly handle the placement of footnotes within a box such as {{cmd|framed}} or {{cmd|placeongrid}}...<br />
<br />
==Placing Footnotes Manually==<br />
<br />
In some cases, ConTeXt's footnoting system may not be able to do exactly what you want. For instance, you may want to place a footnote in a table so that the footnote appears with the rest of the footnotes on the page, or you may want to create a footnote to a footnote to a footnote. Many of these cases can be handled by using the {{cmd|footnotetext}} command (which creates a footnote without placing the corresponding symbol in the text) and the {{cmd|note}} command (which places the footnote symbol in the text, but does not create a footnote).<br />
<br />
For example, to create a footnote to a footnote to a footnote, all but the first footnotes are created with {{cmd|footnotetext}} commands, which are placed in the main text – thereby ensuring that the footnotes are numbered and appear in the correct order. Then, these footnotes are referenced by {{cmd|note}} commands within the relevant footnotes. In this example, the lines are broken for clarity; note the <code>%</code> at the end of each line to prevent spurious spaces in the text.<br />
<br />
<texcode><br />
This%<br />
\footnote{Or that\note[footB], if you prefer.}%<br />
\footnotetext[footB]{Or possibly even the other\note[footC].}%<br />
\footnotetext[footC]{It could be something entirely different.}<br />
is a sentence with nested footnotes.<br />
</texcode><br />
<br />
<context><br />
\starttext<br />
\strut\vfill<br />
This%<br />
\footnote{Or that\note[footB], if you prefer.}%<br />
\footnotetext[footB]{Or possibly even the other\note[footC].}%<br />
\footnotetext[footC]{It could be something entirely different.}<br />
is a sentence with nested footnotes.<br />
\stoptext<br />
</context><br />
<br />
== Suppressing Footnotes Entirely ==<br />
<br />
The boolean {{cmd|link=no|notesenabled}} controls whether footnotes are processed at all.<br />
If set to ''false'', invocations of {{cmd|footnote}} will be ignored.<br />
After it is set to ''true'' again ConTeXt will pick up the footnote counters at their<br />
previous state, so numbering will continuous.<br />
<br />
<context source="yes" mode="mkiv"><br />
\setuppapersize [A7]<br />
\starttext<br />
<br />
\dorecurse {2} { foo \footnote {bar} baz \par }<br />
<br />
\notesenabledfalse<br />
<br />
\dorecurse {3} { foo \footnote {bar} baz \par }<br />
<br />
\notesenabledtrue<br />
<br />
\dorecurse {2} { foo \footnote {bar} baz \par }<br />
<br />
\stoptext<br />
</context><br />
<br />
== Color of Footnote Links that Refer to the Same Page ==<br />
<br />
If you have set footnotes to be interactive and have noticed that your footnote links become red, it is because they are linked to content on the same page on which they appear. This means they are governed by {{cmd|setupinteraction}}’s attribute <code>contrastcolor</code>, rather than <code>color</code>.<br />
<br />
To fix the redness (or change it to a different color), try:<br />
<br />
<texcode><br />
\setupinteraction[state=start,color=black,contrastcolor=black]<br />
</texcode><br />
<br />
== Changing footnote interlinespace ==<br />
<br />
If you want to change the interlinespace of footnotes without impacting the rest of the document, try:<br />
<texcode><br />
\startsetups[footnote:interlinespace]<br />
\setupinterlinespace[line=2.8ex]<br />
\stopsetups<br />
<br />
\setupnote[footnote][setups=footnote:interlinespace]<br />
</texcode><br />
<br />
<br />
<br />
<br />
== Special Needs ==<br />
There are numerous ways to display and format footnotes. The following section gathers solutions to some special tasks asked on the mailing list.<br />
<br />
=== Hyphenation ===<br />
* Is there a way to turn off hyphenation for the main body of my text, but enable it for the footnotes?<br />
<br />
<texcode><br />
\starttext<br />
<br />
\setupnote[footnote][align={normal,hyphenated}]<br />
<br />
\setupalign[hyphenated] \input tufte \footnote{\input tufte \relax} \par<br />
<br />
\setupalign[nothyphenated,stretch,tolerant] \input tufte<br />
\footnote{\input tufte \relax} \par<br />
<br />
\stoptext<br />
</texcode><br />
<br />
===Mark Placement===<br />
* How can I change the placement of the footnote mark?<br />
<br />
Currently, footnotes are set so that the left end of the text of the footnote is aligned with the left edge of the text, and the footnote number hangs out into the margin. Is it possible to change this? (For instance, suppose I would like the number aligned to the text-edge, and then a fixed-width space, and then the text?)<br />
<br />
This behavior is controlled by the <code>location</code> key of {{cmd|setupnotation}}. Here are some examples:<br />
<br />
Note number is typeset in an area with a width of 1 cm, aligned at the left of the text area:<br />
<br />
<context source="yes" text="produces"><br />
\definepapersize[wiki][width=8cm,height=8cm]<br />
<br />
\setuppapersize[wiki][wiki]<br />
<br />
\starttext<br />
<br />
\showframe<br />
<br />
\setupnotation[footnote][location=left,width=1cm]<br />
\setupnote[footnote][location=page,numbercommand=]<br />
<br />
test \footnote{test}<br />
<br />
\stoptext <br />
</context><br />
<br />
<br />
Suppose that one wants a width of 1.5 em. Then<br />
<br />
<texcode><br />
\setupnote[footnote][margindistance=0em,command=\myfootnotecommand]<br />
\setupnotation[footnote][location=left,hang=1]<br />
<br />
\def\myfootnotecommand#1{\hbox to 1.5em{#1.}}<br />
</texcode><br />
<br />
===Line Spacing===<br />
* Can I change the line spacing of a footnote independently of that of the main text?<br />
<br />
The way to do this is not obvious, but this is the code you need to use:<br />
<br />
<texcode><br />
\def\setnotebodyfont<br />
{\switchtobodyfont[your desired font size]\setupinterlinespace[your desired spacing]} <br />
</texcode><br />
<br />
===Placement in Bidirectional Documents===<br />
* Can the footnote rule be placed on the right-hand side?<br />
<br />
This is possible via setting the <code>rule</code> key of {{cmd|setupnote}} and {{cmd|definenote}}. In right-to-left documents it is usually desirable to have right-to-left footnotes, where right-aligned footnote rules make more sense aesthetically. Set <code>rule=right</code> to achieve this. Prior to 01-04-2016 Beta, this would have turned off the footnote rule completely: one needed to use <code>rule={on,right}</code>.<br />
<br />
In a BiDi document the direction of the surrounding text where the {{cmd|footnote}} is invoked determines the direction of the footnote block to come later. Therefore, some footnotes may be right-to-left whereas others can be left-to-right. Note that the text of the footnote does not play a role here. The style designer decides whether left or right footnote rules make more sense. However, there is a third option: setting <code>rule=paragraph</code> looks at the first paragraph in the footnote block and let that determine the position of the footnote rule. In other words, if the footnote block of the page starts with an RTL text we end up with a right-aligned footnote rule and a left-aligned rule is typeset otherwise. (The first line/paragraph of the footnote block on a page need not correspond to the start of a footnote; it can rather be the leftover from a long footnote that started on some previous page.)<br />
<br />
For more fancy footnote rules, you can use <code>rulecommand=\MyRuleCommand</code>. Look at the definition of <code>\normalnoterule</code> in strc-not.mkvi for a starting point.<br />
<br />
[[Category:Basics]]</div>Mæstrohttps://wiki.contextgarden.net/index.php?title=Footnotes&diff=33419Footnotes2022-02-19T21:10:27Z<p>Mæstro: /* Placing Footnotes Manually */ - use starttext stoptext for example</p>
<hr />
<div>{{todo|This page needs to be reorganized: progression from simple to more complex use is a bit circular..}}<br />
<br />
==First View==<br />
<br />
<texcode><br />
\section{First}<br />
<br />
Way to \ConTeXt\footnote{First footnote.} is painful.<br />
<br />
\section{Second}<br />
<br />
But \ConTeXt\ is amazing.\footnote{Second footnote}<br />
<br />
\placetable<br />
{Complex Table\footnote{A table head footnote.}}<br />
{\startlocalfootnotes<br />
\placelegend<br />
{\starttable[|l|l|]<br />
\HL<br />
\NC First Column \NC Second Column \NC \FR<br />
\HL<br />
\NC East\footnote{Footnote inside graphic.} \NC North \NC \FR<br />
\NC West \NC South \NC \LR<br />
\HL<br />
\stoptable}<br />
{\placelocalfootnotes}<br />
\stoplocalfootnotes}<br />
</texcode><br />
<br />
<context><br />
\starttext<br />
\strut\vfill\<br />
\section{First}<br />
<br />
Way to \ConTeXt\footnote{First footnote.} is painful.<br />
<br />
\section{Second}<br />
<br />
But \ConTeXt\ is amazing.\footnote{Second footnote}<br />
<br />
\placetable<br />
{Complex Table\footnote{A table head footnote.}}<br />
{\startlocalfootnotes<br />
\placelegend<br />
{\starttable[|l|l|]<br />
\HL<br />
\NC First Column \NC Second Column \NC \FR<br />
\HL<br />
\NC East\footnote{Footnote inside graphic.} \NC North \NC \FR<br />
\NC West \NC South \NC \LR<br />
\HL<br />
\stoptable}<br />
{\placelocalfootnotes}<br />
\stoplocalfootnotes}<br />
\stoptext<br />
</context><br />
<br />
Here we have footnotes of two outer ones, a local one (in the table) and a postponed one (in the graphic).<br />
<br />
==Basic Footnotes==<br />
<br />
For basic footnotes, simply use {{cmd|footnote|[reference]{footnote text}}}.<br />
The reference is optional, and can be used to refer to the same footnote again. Footnotes can be referenced with the usual {{cmd|in}} and {{cmd|at}} macros (see [[References]]), or the note itself can be reproduced with {{cmd|note|[reference]}}. For example:<br />
<br />
<texcode><br />
This\footnote[footA]{Or that, if you prefer.} is a sentence with a footnote\footnote{Actually,<br />
two footnotes; this one and \in{footnote}[footA] on \at{page}[footA], denoted by \note[footA].}. <br />
</texcode><br />
<br />
<context><br />
\starttext<br />
\strut\vfill % A hack to shorten the page.<br />
This\footnote[footA]{Or that, if you prefer.} is a sentence with a footnote\footnote{Actually,<br />
two footnotes; this one and \in{footnote}[footA] on \at{page}[footA], denoted by \note[footA].}. <br />
\stoptext<br />
</context><br />
<br />
<br />
Thanks to Oblomov, it's also possible to use footnotes in footnotes, as in this example.<br />
<br />
<texcode><br />
This\footnote{Or that\footnote{Or possibly even the other.}, if you prefer.} is a sentence<br />
with a footnote. <br />
</texcode><br />
<br />
<context><br />
\starttext<br />
\strut\vfill % A hack to shorten the page.<br />
This\footnote{Or that\footnote{Or possibly even the other.}, if you prefer.} is a sentence<br />
with a footnote. <br />
\stoptext<br />
</context><br />
<br />
==Footnote Numbering==<br />
<br />
You can setup the exact behaviour of footnotes with {{cmd|setupnotation|[footnote]}} (MkII: {{cmd|setupfootnotes}}).<br />
(The command page for the MkIV version is still missing, refer to the old version; translate location to alternative and conversion to numberconversion.)<br />
<br />
For example, to use footnotes with standard footnote symbols (which ConTeXt has defined as the conversion "set 2"), with the footnote counter resetting on each page, one would use the following:<br />
<br />
<texcode><br />
\setupnotation[footnote][way=bypage,numberconversion=set 2]<br />
</texcode><br />
<br />
In MkII this was:<br />
<br />
<texcode><br />
\setupfootnotes[way=bypage, conversion=set 2]<br />
</texcode><br />
<br />
This produces the following footnotes, using the text of the previous example.<br />
<br />
<context><br />
\setupnotation[footnote][way=bypage,numberconversion=set 2]<br />
\starttext<br />
\strut\vfill % A hack to shorten the page.<br />
This\footnote[footA]{Or that, if you prefer.} is a sentence with a footnote\footnote{Actually,<br />
two footnotes; this one and \in{footnote}[footA] on \at{page}[footA], denoted by \note[footA].}. <br />
\stoptext<br />
</context><br />
<br />
==Alternate Footnote Locations==<br />
<br />
The {{cmd|setupfootnotes}} (MkII) command offers some options for the placement of footnotes; for instance, the <code>location=columns</code> option places the footnotes in a single column (of a multicolumn page) rather than across the whole page. The <code>location=text</code> option places the footnotes in text at a location specified by {{cmd|placefootnotes}}; this can be easily used to create endnotes, or even to place footnotes after each paragraph or subsection.<br />
<br />
<texcode><br />
\setupfootnotes[location=text] % MkII<br />
This\footnote[footA]{Or that, if you prefer.} is a sentence with a footnote\footnote{Actually,<br />
two footnotes; this one and footnote \note[footA].}. <br />
\placefootnotes<br />
This is some more text, with more footnotes\footnote{Specifically, this one.}.<br />
\placefootnotes<br />
</texcode><br />
<br />
<context><br />
\starttext<br />
\setupfootnotes[location=text]<br />
This\footnote[footA]{Or that, if you prefer.} is a sentence with a footnote\footnote{Actually,<br />
two footnotes; this one and footnote \note[footA].}. <br />
\placefootnotes<br />
This is some more text, with more footnotes\footnote{Specifically, this one.}.<br />
\placefootnotes<br />
\stoptext<br />
</context><br />
<br />
=== Footnotes at the end of each chapter ===<br />
<br />
Another elegant (MkIV) example places all footnotes in a subject (unnumbered section) at the end of each chapter. It is intelligent and will not create an empty subject when there are no footnotes to be placed. At no extra cost, the subject title "Footnote" will be singular or plural depending if there is only one or several footnotes to be placed:<br />
<br />
<texcode><br />
\startsetups[chapter:after]<br />
\ifcase\rawcountervalue[footnote]\relax<br />
\or<br />
\startsubject[title=Footnote]<br />
\placefootnotes<br />
\stopsubject<br />
\else<br />
\startsubject[title=Footnotes]<br />
\placefootnotes<br />
\stopsubject<br />
\fi<br />
\stopsetups<br />
<br />
\setupnotes[location=none]<br />
\setupnotation[way=bychapter]<br />
<br />
\setuphead[chapter][aftersection=\setups{chapter:after}]<br />
<br />
\starttext<br />
<br />
\startchapter[title={Chapter One}]<br />
<br />
This one\footnote{is placed}. And\footnote{this one is too}.<br />
<br />
\stopchapter<br />
<br />
\chapter[title={Chapter Two}]<br />
<br />
But this one\footnote{is not flushed}.<br />
<br />
\startchapter[title={Chapter Three}]<br />
<br />
Unless \type{\stopchapter} was invoked.<br />
<br />
\stopchapter<br />
<br />
\startchapter[title={Chapter Three}]<br />
<br />
On a chapter with\footnote{footnote}.<br />
<br />
\stopchapter<br />
<br />
\stoptext<br />
</texcode><br />
<br />
===Footnotes in the margin===<br />
<br />
First we switch off footnote placement, then we place them manually into the margin.<br />
<br />
<texcode><br />
\setupnote[footnote][location=none]<br />
\setupnotation[footnote][<br />
align=flushleft,<br />
location=serried,<br />
width=broad,<br />
]<br />
\setuptexttexts[margin][]<br />
[{\framed[%<br />
align={right,bottom},<br />
frame=off,<br />
height=\textheight,<br />
width=\rightmarginwidth<br />
]{\placenotes[footnote]}}]<br />
</texcode><br />
<br />
===... but not at the bottom===<br />
<br />
Hraban wanted numbered margin notes, starting in on the same line as the referenced text (like a combination of {{cmd|inmargin}} and {{cmd|footnote}}). Wolfgang answered:<br />
<br />
The only way I found to achieve this is by flushing the notes at the end of each footnote<br />
entry which can be done with the next key. The positioning of each margin text is tricky<br />
because {{cmd|placenotes}} adds skips at the begin of the block (which can be reduced with<br />
{{cmd|placelocalnotes}}) but a inline version of the command (e.g. <tt>\placeinlinenotes</tt>) which<br />
flushes the notes without vertical skips and a rule at the begin would help.<br />
<br />
<texcode><br />
\define\PlaceFootnote<br />
{\inrightmargin{\vtop{\placelocalnotes[footnote][before=,after=]}}}<br />
<br />
\setupnote<br />
[footnote]<br />
[location=text,<br />
bodyfont=,<br />
next=\PlaceFootnote]<br />
<br />
\setupnotation<br />
[footnote]<br />
[alternative=serried]<br />
<br />
\setuplayout<br />
[width=12cm,<br />
rightmargindistance=0.5cm,<br />
rightmargin=5cm]<br />
<br />
\starttext<br />
\dorecurse{6}{\input ward\expanded{\footnote{This is a footnote \recurselevel}} }<br />
\stoptext<br />
</texcode><br />
<br />
==Footnote Formatting==<br />
<br />
You can change the font used in the footnotes with<br />
{{cmd|setupfootnotedefinition|[before=\MyFontCommand]}}.<br />
<br />
Footnotes can be placed in multiple columns, using the <code>n=<i>number</i></code> option of {{cmd|setupnotes}} or {{cmd|setupnote}} (MkII: {{cmd|setupfootnotes}}).<br />
<br />
<texcode><br />
\setupfootnotes[n=3] % MkII<br />
This\footnote[footA](Or that\footnote{Or the other.}, if you prefer.} is a sentence<br />
with a footnote\footnote{Actually, two footnotes; this one and \in{footnote}[footA]<br />
on \at{page}[footA], denoted by \note[footA].}. <br />
</texcode><br />
<br />
<context><br />
\setupfootnotes[n=3]<br />
\starttext<br />
\strut\vfill % A hack to shorten the page.<br />
This\footnote[footA]{Or that\footnote{Or the other.}, if you prefer.} is a sentence<br />
with a footnote\footnote{Actually, two footnotes; this one and \in{footnote}[footA]<br />
on \at{page}[footA], denoted by \note[footA].}. <br />
\stoptext<br />
</context><br />
<br />
{{todo|This is ugly, and points up some ConTeXt bugs that need to be fixed.}}<br />
<br />
===Footnotes in pagraph form===<br />
<br />
When enabling footnotes (actually notes and linenotes) in pagraph form, there is some risk in having no right separation between body and the notes. This can be partially avoided using <code>width=broad</code> ([http://www.ntg.nl/pipermail/ntg-context/2013/073650.html Hans dixit]).<br />
<br />
<texcode><br />
\setupnote<br />
[footnote]<br />
[paragraph=yes]<br />
<br />
\setupnotation<br />
[footnote]<br />
[alternative=serried,<br />
width=broad,<br />
distance=.5em,<br />
display=no]<br />
<br />
\starttext<br />
\dorecurse{500}{text text text\footnote{note} }<br />
\stoptext<br />
</texcode><br />
<br />
==Footnotes in Floats==<br />
<br />
[[Floating Objects|Floats]] cannot include normal footnotes, because they are likely to float to another page from the page on which they were defined, thus getting the footnotes out of order. Thus, to include footnotes in a float, one must use local footnotes. This table, which uses the {{cmd|placelegend}} command to create a place for the footnotes, illustrates the process:<br />
<br />
<texcode><br />
\startlocalfootnotes[n=2]<br />
\placetable{A table with footnotes.}<br />
\placelegend<br />
{\starttable[|l|r|]<br />
\HL<br />
\VL One\footnote{First} \VL Two\footnote{Second} \VL\FR<br />
\VL Three\footnote{Third} \VL Four\footnote{Fourth} \VL\LR<br />
\HL<br />
\stoptable}<br />
{\placelocalfootnotes}<br />
\stoplocalfootnotes<br />
</texcode><br />
<br />
<context><br />
\startlocalfootnotes[n=2]<br />
\placetable{A table with footnotes.}<br />
\placelegend<br />
{\strut\starttable[|l|r|]<br />
\HL<br />
\VL One\footnote{First} \VL Two\footnote{Second} \VL\FR<br />
\VL Three\footnote{Third} \VL Four\footnote{Fourth} \VL\LR<br />
\HL<br />
\stoptable}<br />
{\placelocalfootnotes}<br />
\stoplocalfootnotes<br />
</context><br />
<br />
When using natural tables, the above leads to alignment problems. An alternative is to use:<br />
<br />
<texcode><br />
\defineframed[noteframed]<br />
\setupframed[noteframed]<br />
[width=\hsize,<br />
frame=off,<br />
align=right,<br />
%height=fit,<br />
top=\hbox\bgroup,<br />
bottom=\egroup]<br />
<br />
\starttext<br />
<br />
\startlocalfootnotes[n=0]<br />
\placetable<br />
{Caption}<br />
{\placelegend<br />
{\bTABLE<br />
\bTR\bTD One\footnote{First} \eTD\bTD Two\footnote{Second} \eTD\eTR<br />
\bTR\bTD Three\footnote{Third} \eTD\bTD Four\footnote{Fourth} \eTD\eTR<br />
\eTABLE}<br />
{\noteframed{\placelocalfootnotes}}}<br />
\stoplocalfootnotes<br />
<br />
\stoptext<br />
</texcode><br />
<br />
<context><br />
\defineframed[noteframed]<br />
\setupframed[noteframed]<br />
[width=\hsize,<br />
frame=off,<br />
align=right,<br />
%height=fit,<br />
top=\hbox\bgroup,<br />
bottom=\egroup]<br />
<br />
\starttext<br />
<br />
\startlocalfootnotes[n=0]<br />
\placetable<br />
{Caption}<br />
{\placelegend<br />
{\bTABLE<br />
\bTR\bTD One\footnote{First} \eTD\bTD Two\footnote{Second} \eTD\eTR<br />
\bTR\bTD Three\footnote{Third} \eTD\bTD Four\footnote{Fourth} \eTD\eTR<br />
\eTABLE}<br />
{\noteframed{\placelocalfootnotes}}}<br />
\stoplocalfootnotes<br />
<br />
\stoptext<br />
</context><br />
<br />
==Footnotes in a box==<br />
<br />
Note that it is necessary to add the command {{cmd|automigrateinserts}} (for example before {{cmd|link=no|starttext}})<br />
in order to correctly handle the placement of footnotes within a box such as {{cmd|framed}} or {{cmd|placeongrid}}...<br />
<br />
==Placing Footnotes Manually==<br />
<br />
In some cases, ConTeXt's footnoting system may not be able to do exactly what you want. For instance, you may want to place a footnote in a table so that the footnote appears with the rest of the footnotes on the page, or you may want to create a footnote to a footnote to a footnote. Many of these cases can be handled by using the {{cmd|footnotetext}} command (which creates a footnote without placing the corresponding symbol in the text) and the {{cmd|note}} command (which places the footnote symbol in the text, but does not create a footnote).<br />
<br />
For example, to create a footnote to a footnote to a footnote, all but the first footnotes are created with {{cmd|footnotetext}} commands, which are placed in the main text – thereby ensuring that the footnotes are numbered and appear in the correct order. Then, these footnotes are referenced by {{cmd|note}} commands within the relevant footnotes. In this example, the lines are broken for clarity; note the <code>%</code> at the end of each line to prevent spurious spaces in the text.<br />
<br />
<texcode><br />
This%<br />
\footnote{Or that\note[footB], if you prefer.}%<br />
\footnotetext[footB]{Or possibly even the other\note[footC].}%<br />
\footnotetext[footC]{It could be something entirely different.}<br />
is a sentence with nested footnotes.<br />
</texcode><br />
<br />
<context><br />
\starttext<br />
\strut\vfill<br />
This%<br />
\footnote{Or that\note[footB], if you prefer.}%<br />
\footnotetext[footB]{Or possibly even the other\note[footC].}%<br />
\footnotetext[footC]{It could be something entirely different.}<br />
is a sentence with nested footnotes.<br />
\stoptext<br />
</context><br />
<br />
== Suppressing Footnotes Entirely ==<br />
<br />
The boolean {{cmd|link=no|notesenabled}} controls whether footnotes are processed at all.<br />
If set to ''false'', invocations of {{cmd|footnote}} will be ignored.<br />
After it is set to ''true'' again ConTeXt will pick up the footnote counters at their<br />
previous state, so numbering will continuous.<br />
<br />
<context source="yes" mode="mkiv"><br />
\setuppapersize [A7]<br />
\starttext<br />
<br />
\dorecurse {2} { foo \footnote {bar} baz \par }<br />
<br />
\notesenabledfalse<br />
<br />
\dorecurse {3} { foo \footnote {bar} baz \par }<br />
<br />
\notesenabledtrue<br />
<br />
\dorecurse {2} { foo \footnote {bar} baz \par }<br />
<br />
\stoptext<br />
</context><br />
<br />
== Color of Footnote Links that Refer to the Same Page ==<br />
<br />
If you have set footnotes to be interactive and have noticed that your footnote links become red, it is because they are linked to content on the same page on which they appear. This means they are governed by {{cmd|setupinteraction}}’s attribute <code>contrastcolor</code>, rather than <code>color</code>.<br />
<br />
To fix the redness (or change it to a different color), try:<br />
<br />
<texcode><br />
\setupinteraction[state=start,color=black,contrastcolor=black]<br />
</texcode><br />
<br />
== Changing footnote interlinespace ==<br />
<br />
If you want to change the interlinespace of footnotes without impacting the rest of the document, try:<br />
<texcode><br />
\startsetups[footnote:interlinespace]<br />
\setupinterlinespace[line=2.8ex]<br />
\stopsetups<br />
<br />
\setupnote[footnote][setups=footnote:interlinespace]<br />
</texcode><br />
<br />
<br />
<br />
<br />
== Special Needs ==<br />
There are numerous ways to display and format footnotes. The following section gathers solutions to some special tasks asked on the mailing list.<br />
<br />
=== Hyphenation ===<br />
* Is there a way to turn off hyphenation for the main body of my text, but enable it for the footnotes?<br />
<br />
<texcode><br />
\starttext<br />
<br />
\setupnote[footnote][align={normal,hyphenated}]<br />
<br />
\setupalign[hyphenated] \input tufte \footnote{\input tufte \relax} \par<br />
<br />
\setupalign[nothyphenated,stretch,tolerant] \input tufte<br />
\footnote{\input tufte \relax} \par<br />
<br />
\stoptext<br />
</texcode><br />
<br />
===Mark Placement===<br />
* How can I change the placement of the footnote mark?<br />
<br />
Currently, footnotes are set so that the left end of the text of the footnote is aligned with the left edge of the text, and the footnote number hangs out into the margin. Is it possible to change this? (For instance, suppose I would like the number aligned to the text-edge, and then a fixed-width space, and then the text?)<br />
<br />
This behavior is controlled by the <code>location</code> key of {{cmd|setupnotation}}. Here are some examples:<br />
<br />
Note number is typeset in an area with a width of 1 cm, aligned at the left of the text area:<br />
<br />
<context source="yes" text="produces"><br />
\definepapersize[wiki][width=8cm,height=8cm]<br />
<br />
\setuppapersize[wiki][wiki]<br />
<br />
\starttext<br />
<br />
\showframe<br />
<br />
\setupnotation[footnote][location=left,width=1cm]<br />
\setupnote[footnote][location=page,numbercommand=]<br />
<br />
test \footnote{test}<br />
<br />
\stoptext <br />
</context><br />
<br />
<br />
Suppose that one wants a width of 1.5 em. Then<br />
<br />
<texcode><br />
\setupnote[footnote][margindistance=0em,command=\myfootnotecommand]<br />
\setupnotation[footnote][location=left,hang=1]<br />
<br />
\def\myfootnotecommand#1{\hbox to 1.5em{#1.}}<br />
</texcode><br />
<br />
===Line Spacing===<br />
* Can I change the line spacing of a footnote independently of that of the main text?<br />
<br />
The way to do this is not obvious, but this is the code you need to use:<br />
<br />
<texcode><br />
\def\setnotebodyfont<br />
{\switchtobodyfont[your desired font size]\setupinterlinespace[your desired spacing]} <br />
</texcode><br />
<br />
===Placement in Bidirectional Documents===<br />
* Can the footnote rule be placed on the right-hand side?<br />
<br />
This is possible via setting the <code>rule</code> key of {{cmd|setupnote}} and {{cmd|definenote}}. In right-to-left documents it is usually desirable to have right-to-left footnotes, where right-aligned footnote rules make more sense aesthetically. Set <code>rule=right</code> to achieve this. Prior to 01-04-2016 Beta, this would have turned off the footnote rule completely: one needed to use <code>rule={on,right}</code>.<br />
<br />
In a BiDi document the direction of the surrounding text where the {{cmd|footnote}} is invoked determines the direction of the footnote block to come later. Therefore, some footnotes may be right-to-left whereas others can be left-to-right. Note that the text of the footnote does not play a role here. The style designer decides whether left or right footnote rules make more sense. However, there is a third option: setting <code>rule=paragraph</code> looks at the first paragraph in the footnote block and let that determine the position of the footnote rule. In other words, if the footnote block of the page starts with an RTL text we end up with a right-aligned footnote rule and a left-aligned rule is typeset otherwise. (The first line/paragraph of the footnote block on a page need not correspond to the start of a footnote; it can rather be the leftover from a long footnote that started on some previous page.)<br />
<br />
For more fancy footnote rules, you can use <code>rulecommand=\MyRuleCommand</code>. Look at the definition of <code>\normalnoterule</code> in strc-not.mkvi for a starting point.<br />
<br />
[[Category:Basics]]</div>Mæstrohttps://wiki.contextgarden.net/index.php?title=Footnotes&diff=33418Footnotes2022-02-19T21:09:19Z<p>Mæstro: /* Footnote Formatting */ - footnote command typo</p>
<hr />
<div>{{todo|This page needs to be reorganized: progression from simple to more complex use is a bit circular..}}<br />
<br />
==First View==<br />
<br />
<texcode><br />
\section{First}<br />
<br />
Way to \ConTeXt\footnote{First footnote.} is painful.<br />
<br />
\section{Second}<br />
<br />
But \ConTeXt\ is amazing.\footnote{Second footnote}<br />
<br />
\placetable<br />
{Complex Table\footnote{A table head footnote.}}<br />
{\startlocalfootnotes<br />
\placelegend<br />
{\starttable[|l|l|]<br />
\HL<br />
\NC First Column \NC Second Column \NC \FR<br />
\HL<br />
\NC East\footnote{Footnote inside graphic.} \NC North \NC \FR<br />
\NC West \NC South \NC \LR<br />
\HL<br />
\stoptable}<br />
{\placelocalfootnotes}<br />
\stoplocalfootnotes}<br />
</texcode><br />
<br />
<context><br />
\starttext<br />
\strut\vfill\<br />
\section{First}<br />
<br />
Way to \ConTeXt\footnote{First footnote.} is painful.<br />
<br />
\section{Second}<br />
<br />
But \ConTeXt\ is amazing.\footnote{Second footnote}<br />
<br />
\placetable<br />
{Complex Table\footnote{A table head footnote.}}<br />
{\startlocalfootnotes<br />
\placelegend<br />
{\starttable[|l|l|]<br />
\HL<br />
\NC First Column \NC Second Column \NC \FR<br />
\HL<br />
\NC East\footnote{Footnote inside graphic.} \NC North \NC \FR<br />
\NC West \NC South \NC \LR<br />
\HL<br />
\stoptable}<br />
{\placelocalfootnotes}<br />
\stoplocalfootnotes}<br />
\stoptext<br />
</context><br />
<br />
Here we have footnotes of two outer ones, a local one (in the table) and a postponed one (in the graphic).<br />
<br />
==Basic Footnotes==<br />
<br />
For basic footnotes, simply use {{cmd|footnote|[reference]{footnote text}}}.<br />
The reference is optional, and can be used to refer to the same footnote again. Footnotes can be referenced with the usual {{cmd|in}} and {{cmd|at}} macros (see [[References]]), or the note itself can be reproduced with {{cmd|note|[reference]}}. For example:<br />
<br />
<texcode><br />
This\footnote[footA]{Or that, if you prefer.} is a sentence with a footnote\footnote{Actually,<br />
two footnotes; this one and \in{footnote}[footA] on \at{page}[footA], denoted by \note[footA].}. <br />
</texcode><br />
<br />
<context><br />
\starttext<br />
\strut\vfill % A hack to shorten the page.<br />
This\footnote[footA]{Or that, if you prefer.} is a sentence with a footnote\footnote{Actually,<br />
two footnotes; this one and \in{footnote}[footA] on \at{page}[footA], denoted by \note[footA].}. <br />
\stoptext<br />
</context><br />
<br />
<br />
Thanks to Oblomov, it's also possible to use footnotes in footnotes, as in this example.<br />
<br />
<texcode><br />
This\footnote{Or that\footnote{Or possibly even the other.}, if you prefer.} is a sentence<br />
with a footnote. <br />
</texcode><br />
<br />
<context><br />
\starttext<br />
\strut\vfill % A hack to shorten the page.<br />
This\footnote{Or that\footnote{Or possibly even the other.}, if you prefer.} is a sentence<br />
with a footnote. <br />
\stoptext<br />
</context><br />
<br />
==Footnote Numbering==<br />
<br />
You can setup the exact behaviour of footnotes with {{cmd|setupnotation|[footnote]}} (MkII: {{cmd|setupfootnotes}}).<br />
(The command page for the MkIV version is still missing, refer to the old version; translate location to alternative and conversion to numberconversion.)<br />
<br />
For example, to use footnotes with standard footnote symbols (which ConTeXt has defined as the conversion "set 2"), with the footnote counter resetting on each page, one would use the following:<br />
<br />
<texcode><br />
\setupnotation[footnote][way=bypage,numberconversion=set 2]<br />
</texcode><br />
<br />
In MkII this was:<br />
<br />
<texcode><br />
\setupfootnotes[way=bypage, conversion=set 2]<br />
</texcode><br />
<br />
This produces the following footnotes, using the text of the previous example.<br />
<br />
<context><br />
\setupnotation[footnote][way=bypage,numberconversion=set 2]<br />
\starttext<br />
\strut\vfill % A hack to shorten the page.<br />
This\footnote[footA]{Or that, if you prefer.} is a sentence with a footnote\footnote{Actually,<br />
two footnotes; this one and \in{footnote}[footA] on \at{page}[footA], denoted by \note[footA].}. <br />
\stoptext<br />
</context><br />
<br />
==Alternate Footnote Locations==<br />
<br />
The {{cmd|setupfootnotes}} (MkII) command offers some options for the placement of footnotes; for instance, the <code>location=columns</code> option places the footnotes in a single column (of a multicolumn page) rather than across the whole page. The <code>location=text</code> option places the footnotes in text at a location specified by {{cmd|placefootnotes}}; this can be easily used to create endnotes, or even to place footnotes after each paragraph or subsection.<br />
<br />
<texcode><br />
\setupfootnotes[location=text] % MkII<br />
This\footnote[footA]{Or that, if you prefer.} is a sentence with a footnote\footnote{Actually,<br />
two footnotes; this one and footnote \note[footA].}. <br />
\placefootnotes<br />
This is some more text, with more footnotes\footnote{Specifically, this one.}.<br />
\placefootnotes<br />
</texcode><br />
<br />
<context><br />
\starttext<br />
\setupfootnotes[location=text]<br />
This\footnote[footA]{Or that, if you prefer.} is a sentence with a footnote\footnote{Actually,<br />
two footnotes; this one and footnote \note[footA].}. <br />
\placefootnotes<br />
This is some more text, with more footnotes\footnote{Specifically, this one.}.<br />
\placefootnotes<br />
\stoptext<br />
</context><br />
<br />
=== Footnotes at the end of each chapter ===<br />
<br />
Another elegant (MkIV) example places all footnotes in a subject (unnumbered section) at the end of each chapter. It is intelligent and will not create an empty subject when there are no footnotes to be placed. At no extra cost, the subject title "Footnote" will be singular or plural depending if there is only one or several footnotes to be placed:<br />
<br />
<texcode><br />
\startsetups[chapter:after]<br />
\ifcase\rawcountervalue[footnote]\relax<br />
\or<br />
\startsubject[title=Footnote]<br />
\placefootnotes<br />
\stopsubject<br />
\else<br />
\startsubject[title=Footnotes]<br />
\placefootnotes<br />
\stopsubject<br />
\fi<br />
\stopsetups<br />
<br />
\setupnotes[location=none]<br />
\setupnotation[way=bychapter]<br />
<br />
\setuphead[chapter][aftersection=\setups{chapter:after}]<br />
<br />
\starttext<br />
<br />
\startchapter[title={Chapter One}]<br />
<br />
This one\footnote{is placed}. And\footnote{this one is too}.<br />
<br />
\stopchapter<br />
<br />
\chapter[title={Chapter Two}]<br />
<br />
But this one\footnote{is not flushed}.<br />
<br />
\startchapter[title={Chapter Three}]<br />
<br />
Unless \type{\stopchapter} was invoked.<br />
<br />
\stopchapter<br />
<br />
\startchapter[title={Chapter Three}]<br />
<br />
On a chapter with\footnote{footnote}.<br />
<br />
\stopchapter<br />
<br />
\stoptext<br />
</texcode><br />
<br />
===Footnotes in the margin===<br />
<br />
First we switch off footnote placement, then we place them manually into the margin.<br />
<br />
<texcode><br />
\setupnote[footnote][location=none]<br />
\setupnotation[footnote][<br />
align=flushleft,<br />
location=serried,<br />
width=broad,<br />
]<br />
\setuptexttexts[margin][]<br />
[{\framed[%<br />
align={right,bottom},<br />
frame=off,<br />
height=\textheight,<br />
width=\rightmarginwidth<br />
]{\placenotes[footnote]}}]<br />
</texcode><br />
<br />
===... but not at the bottom===<br />
<br />
Hraban wanted numbered margin notes, starting in on the same line as the referenced text (like a combination of {{cmd|inmargin}} and {{cmd|footnote}}). Wolfgang answered:<br />
<br />
The only way I found to achieve this is by flushing the notes at the end of each footnote<br />
entry which can be done with the next key. The positioning of each margin text is tricky<br />
because {{cmd|placenotes}} adds skips at the begin of the block (which can be reduced with<br />
{{cmd|placelocalnotes}}) but a inline version of the command (e.g. <tt>\placeinlinenotes</tt>) which<br />
flushes the notes without vertical skips and a rule at the begin would help.<br />
<br />
<texcode><br />
\define\PlaceFootnote<br />
{\inrightmargin{\vtop{\placelocalnotes[footnote][before=,after=]}}}<br />
<br />
\setupnote<br />
[footnote]<br />
[location=text,<br />
bodyfont=,<br />
next=\PlaceFootnote]<br />
<br />
\setupnotation<br />
[footnote]<br />
[alternative=serried]<br />
<br />
\setuplayout<br />
[width=12cm,<br />
rightmargindistance=0.5cm,<br />
rightmargin=5cm]<br />
<br />
\starttext<br />
\dorecurse{6}{\input ward\expanded{\footnote{This is a footnote \recurselevel}} }<br />
\stoptext<br />
</texcode><br />
<br />
==Footnote Formatting==<br />
<br />
You can change the font used in the footnotes with<br />
{{cmd|setupfootnotedefinition|[before=\MyFontCommand]}}.<br />
<br />
Footnotes can be placed in multiple columns, using the <code>n=<i>number</i></code> option of {{cmd|setupnotes}} or {{cmd|setupnote}} (MkII: {{cmd|setupfootnotes}}).<br />
<br />
<texcode><br />
\setupfootnotes[n=3] % MkII<br />
This\footnote[footA](Or that\footnote{Or the other.}, if you prefer.} is a sentence<br />
with a footnote\footnote{Actually, two footnotes; this one and \in{footnote}[footA]<br />
on \at{page}[footA], denoted by \note[footA].}. <br />
</texcode><br />
<br />
<context><br />
\setupfootnotes[n=3]<br />
\starttext<br />
\strut\vfill % A hack to shorten the page.<br />
This\footnote[footA]{Or that\footnote{Or the other.}, if you prefer.} is a sentence<br />
with a footnote\footnote{Actually, two footnotes; this one and \in{footnote}[footA]<br />
on \at{page}[footA], denoted by \note[footA].}. <br />
\stoptext<br />
</context><br />
<br />
{{todo|This is ugly, and points up some ConTeXt bugs that need to be fixed.}}<br />
<br />
===Footnotes in pagraph form===<br />
<br />
When enabling footnotes (actually notes and linenotes) in pagraph form, there is some risk in having no right separation between body and the notes. This can be partially avoided using <code>width=broad</code> ([http://www.ntg.nl/pipermail/ntg-context/2013/073650.html Hans dixit]).<br />
<br />
<texcode><br />
\setupnote<br />
[footnote]<br />
[paragraph=yes]<br />
<br />
\setupnotation<br />
[footnote]<br />
[alternative=serried,<br />
width=broad,<br />
distance=.5em,<br />
display=no]<br />
<br />
\starttext<br />
\dorecurse{500}{text text text\footnote{note} }<br />
\stoptext<br />
</texcode><br />
<br />
==Footnotes in Floats==<br />
<br />
[[Floating Objects|Floats]] cannot include normal footnotes, because they are likely to float to another page from the page on which they were defined, thus getting the footnotes out of order. Thus, to include footnotes in a float, one must use local footnotes. This table, which uses the {{cmd|placelegend}} command to create a place for the footnotes, illustrates the process:<br />
<br />
<texcode><br />
\startlocalfootnotes[n=2]<br />
\placetable{A table with footnotes.}<br />
\placelegend<br />
{\starttable[|l|r|]<br />
\HL<br />
\VL One\footnote{First} \VL Two\footnote{Second} \VL\FR<br />
\VL Three\footnote{Third} \VL Four\footnote{Fourth} \VL\LR<br />
\HL<br />
\stoptable}<br />
{\placelocalfootnotes}<br />
\stoplocalfootnotes<br />
</texcode><br />
<br />
<context><br />
\startlocalfootnotes[n=2]<br />
\placetable{A table with footnotes.}<br />
\placelegend<br />
{\strut\starttable[|l|r|]<br />
\HL<br />
\VL One\footnote{First} \VL Two\footnote{Second} \VL\FR<br />
\VL Three\footnote{Third} \VL Four\footnote{Fourth} \VL\LR<br />
\HL<br />
\stoptable}<br />
{\placelocalfootnotes}<br />
\stoplocalfootnotes<br />
</context><br />
<br />
When using natural tables, the above leads to alignment problems. An alternative is to use:<br />
<br />
<texcode><br />
\defineframed[noteframed]<br />
\setupframed[noteframed]<br />
[width=\hsize,<br />
frame=off,<br />
align=right,<br />
%height=fit,<br />
top=\hbox\bgroup,<br />
bottom=\egroup]<br />
<br />
\starttext<br />
<br />
\startlocalfootnotes[n=0]<br />
\placetable<br />
{Caption}<br />
{\placelegend<br />
{\bTABLE<br />
\bTR\bTD One\footnote{First} \eTD\bTD Two\footnote{Second} \eTD\eTR<br />
\bTR\bTD Three\footnote{Third} \eTD\bTD Four\footnote{Fourth} \eTD\eTR<br />
\eTABLE}<br />
{\noteframed{\placelocalfootnotes}}}<br />
\stoplocalfootnotes<br />
<br />
\stoptext<br />
</texcode><br />
<br />
<context><br />
\defineframed[noteframed]<br />
\setupframed[noteframed]<br />
[width=\hsize,<br />
frame=off,<br />
align=right,<br />
%height=fit,<br />
top=\hbox\bgroup,<br />
bottom=\egroup]<br />
<br />
\starttext<br />
<br />
\startlocalfootnotes[n=0]<br />
\placetable<br />
{Caption}<br />
{\placelegend<br />
{\bTABLE<br />
\bTR\bTD One\footnote{First} \eTD\bTD Two\footnote{Second} \eTD\eTR<br />
\bTR\bTD Three\footnote{Third} \eTD\bTD Four\footnote{Fourth} \eTD\eTR<br />
\eTABLE}<br />
{\noteframed{\placelocalfootnotes}}}<br />
\stoplocalfootnotes<br />
<br />
\stoptext<br />
</context><br />
<br />
==Footnotes in a box==<br />
<br />
Note that it is necessary to add the command {{cmd|automigrateinserts}} (for example before {{cmd|link=no|starttext}})<br />
in order to correctly handle the placement of footnotes within a box such as {{cmd|framed}} or {{cmd|placeongrid}}...<br />
<br />
==Placing Footnotes Manually==<br />
<br />
In some cases, ConTeXt's footnoting system may not be able to do exactly what you want. For instance, you may want to place a footnote in a table so that the footnote appears with the rest of the footnotes on the page, or you may want to create a footnote to a footnote to a footnote. Many of these cases can be handled by using the {{cmd|footnotetext}} command (which creates a footnote without placing the corresponding symbol in the text) and the {{cmd|note}} command (which places the footnote symbol in the text, but does not create a footnote).<br />
<br />
For example, to create a footnote to a footnote to a footnote, all but the first footnotes are created with {{cmd|footnotetext}} commands, which are placed in the main text – thereby ensuring that the footnotes are numbered and appear in the correct order. Then, these footnotes are referenced by {{cmd|note}} commands within the relevant footnotes. In this example, the lines are broken for clarity; note the <code>%</code> at the end of each line to prevent spurious spaces in the text.<br />
<br />
<texcode><br />
This%<br />
\footnote{Or that\note[footB], if you prefer.}%<br />
\footnotetext[footB]{Or possibly even the other\note[footC].}%<br />
\footnotetext[footC]{It could be something entirely different.}<br />
is a sentence with nested footnotes.<br />
</texcode><br />
<br />
<context><br />
\strut\vfill<br />
This%<br />
\footnote{Or that\note[footB], if you prefer.}%<br />
\footnotetext[footB]{Or possibly even the other\note[footC].}%<br />
\footnotetext[footC]{It could be something entirely different.}<br />
is a sentence with nested footnotes.<br />
</context><br />
<br />
== Suppressing Footnotes Entirely ==<br />
<br />
The boolean {{cmd|link=no|notesenabled}} controls whether footnotes are processed at all.<br />
If set to ''false'', invocations of {{cmd|footnote}} will be ignored.<br />
After it is set to ''true'' again ConTeXt will pick up the footnote counters at their<br />
previous state, so numbering will continuous.<br />
<br />
<context source="yes" mode="mkiv"><br />
\setuppapersize [A7]<br />
\starttext<br />
<br />
\dorecurse {2} { foo \footnote {bar} baz \par }<br />
<br />
\notesenabledfalse<br />
<br />
\dorecurse {3} { foo \footnote {bar} baz \par }<br />
<br />
\notesenabledtrue<br />
<br />
\dorecurse {2} { foo \footnote {bar} baz \par }<br />
<br />
\stoptext<br />
</context><br />
<br />
== Color of Footnote Links that Refer to the Same Page ==<br />
<br />
If you have set footnotes to be interactive and have noticed that your footnote links become red, it is because they are linked to content on the same page on which they appear. This means they are governed by {{cmd|setupinteraction}}’s attribute <code>contrastcolor</code>, rather than <code>color</code>.<br />
<br />
To fix the redness (or change it to a different color), try:<br />
<br />
<texcode><br />
\setupinteraction[state=start,color=black,contrastcolor=black]<br />
</texcode><br />
<br />
== Changing footnote interlinespace ==<br />
<br />
If you want to change the interlinespace of footnotes without impacting the rest of the document, try:<br />
<texcode><br />
\startsetups[footnote:interlinespace]<br />
\setupinterlinespace[line=2.8ex]<br />
\stopsetups<br />
<br />
\setupnote[footnote][setups=footnote:interlinespace]<br />
</texcode><br />
<br />
<br />
<br />
<br />
== Special Needs ==<br />
There are numerous ways to display and format footnotes. The following section gathers solutions to some special tasks asked on the mailing list.<br />
<br />
=== Hyphenation ===<br />
* Is there a way to turn off hyphenation for the main body of my text, but enable it for the footnotes?<br />
<br />
<texcode><br />
\starttext<br />
<br />
\setupnote[footnote][align={normal,hyphenated}]<br />
<br />
\setupalign[hyphenated] \input tufte \footnote{\input tufte \relax} \par<br />
<br />
\setupalign[nothyphenated,stretch,tolerant] \input tufte<br />
\footnote{\input tufte \relax} \par<br />
<br />
\stoptext<br />
</texcode><br />
<br />
===Mark Placement===<br />
* How can I change the placement of the footnote mark?<br />
<br />
Currently, footnotes are set so that the left end of the text of the footnote is aligned with the left edge of the text, and the footnote number hangs out into the margin. Is it possible to change this? (For instance, suppose I would like the number aligned to the text-edge, and then a fixed-width space, and then the text?)<br />
<br />
This behavior is controlled by the <code>location</code> key of {{cmd|setupnotation}}. Here are some examples:<br />
<br />
Note number is typeset in an area with a width of 1 cm, aligned at the left of the text area:<br />
<br />
<context source="yes" text="produces"><br />
\definepapersize[wiki][width=8cm,height=8cm]<br />
<br />
\setuppapersize[wiki][wiki]<br />
<br />
\starttext<br />
<br />
\showframe<br />
<br />
\setupnotation[footnote][location=left,width=1cm]<br />
\setupnote[footnote][location=page,numbercommand=]<br />
<br />
test \footnote{test}<br />
<br />
\stoptext <br />
</context><br />
<br />
<br />
Suppose that one wants a width of 1.5 em. Then<br />
<br />
<texcode><br />
\setupnote[footnote][margindistance=0em,command=\myfootnotecommand]<br />
\setupnotation[footnote][location=left,hang=1]<br />
<br />
\def\myfootnotecommand#1{\hbox to 1.5em{#1.}}<br />
</texcode><br />
<br />
===Line Spacing===<br />
* Can I change the line spacing of a footnote independently of that of the main text?<br />
<br />
The way to do this is not obvious, but this is the code you need to use:<br />
<br />
<texcode><br />
\def\setnotebodyfont<br />
{\switchtobodyfont[your desired font size]\setupinterlinespace[your desired spacing]} <br />
</texcode><br />
<br />
===Placement in Bidirectional Documents===<br />
* Can the footnote rule be placed on the right-hand side?<br />
<br />
This is possible via setting the <code>rule</code> key of {{cmd|setupnote}} and {{cmd|definenote}}. In right-to-left documents it is usually desirable to have right-to-left footnotes, where right-aligned footnote rules make more sense aesthetically. Set <code>rule=right</code> to achieve this. Prior to 01-04-2016 Beta, this would have turned off the footnote rule completely: one needed to use <code>rule={on,right}</code>.<br />
<br />
In a BiDi document the direction of the surrounding text where the {{cmd|footnote}} is invoked determines the direction of the footnote block to come later. Therefore, some footnotes may be right-to-left whereas others can be left-to-right. Note that the text of the footnote does not play a role here. The style designer decides whether left or right footnote rules make more sense. However, there is a third option: setting <code>rule=paragraph</code> looks at the first paragraph in the footnote block and let that determine the position of the footnote rule. In other words, if the footnote block of the page starts with an RTL text we end up with a right-aligned footnote rule and a left-aligned rule is typeset otherwise. (The first line/paragraph of the footnote block on a page need not correspond to the start of a footnote; it can rather be the leftover from a long footnote that started on some previous page.)<br />
<br />
For more fancy footnote rules, you can use <code>rulecommand=\MyRuleCommand</code>. Look at the definition of <code>\normalnoterule</code> in strc-not.mkvi for a starting point.<br />
<br />
[[Category:Basics]]</div>Mæstrohttps://wiki.contextgarden.net/index.php?title=Footnotes&diff=33417Footnotes2022-02-19T21:08:38Z<p>Mæstro: /* Footnote Numbering */ - footnote command typo</p>
<hr />
<div>{{todo|This page needs to be reorganized: progression from simple to more complex use is a bit circular..}}<br />
<br />
==First View==<br />
<br />
<texcode><br />
\section{First}<br />
<br />
Way to \ConTeXt\footnote{First footnote.} is painful.<br />
<br />
\section{Second}<br />
<br />
But \ConTeXt\ is amazing.\footnote{Second footnote}<br />
<br />
\placetable<br />
{Complex Table\footnote{A table head footnote.}}<br />
{\startlocalfootnotes<br />
\placelegend<br />
{\starttable[|l|l|]<br />
\HL<br />
\NC First Column \NC Second Column \NC \FR<br />
\HL<br />
\NC East\footnote{Footnote inside graphic.} \NC North \NC \FR<br />
\NC West \NC South \NC \LR<br />
\HL<br />
\stoptable}<br />
{\placelocalfootnotes}<br />
\stoplocalfootnotes}<br />
</texcode><br />
<br />
<context><br />
\starttext<br />
\strut\vfill\<br />
\section{First}<br />
<br />
Way to \ConTeXt\footnote{First footnote.} is painful.<br />
<br />
\section{Second}<br />
<br />
But \ConTeXt\ is amazing.\footnote{Second footnote}<br />
<br />
\placetable<br />
{Complex Table\footnote{A table head footnote.}}<br />
{\startlocalfootnotes<br />
\placelegend<br />
{\starttable[|l|l|]<br />
\HL<br />
\NC First Column \NC Second Column \NC \FR<br />
\HL<br />
\NC East\footnote{Footnote inside graphic.} \NC North \NC \FR<br />
\NC West \NC South \NC \LR<br />
\HL<br />
\stoptable}<br />
{\placelocalfootnotes}<br />
\stoplocalfootnotes}<br />
\stoptext<br />
</context><br />
<br />
Here we have footnotes of two outer ones, a local one (in the table) and a postponed one (in the graphic).<br />
<br />
==Basic Footnotes==<br />
<br />
For basic footnotes, simply use {{cmd|footnote|[reference]{footnote text}}}.<br />
The reference is optional, and can be used to refer to the same footnote again. Footnotes can be referenced with the usual {{cmd|in}} and {{cmd|at}} macros (see [[References]]), or the note itself can be reproduced with {{cmd|note|[reference]}}. For example:<br />
<br />
<texcode><br />
This\footnote[footA]{Or that, if you prefer.} is a sentence with a footnote\footnote{Actually,<br />
two footnotes; this one and \in{footnote}[footA] on \at{page}[footA], denoted by \note[footA].}. <br />
</texcode><br />
<br />
<context><br />
\starttext<br />
\strut\vfill % A hack to shorten the page.<br />
This\footnote[footA]{Or that, if you prefer.} is a sentence with a footnote\footnote{Actually,<br />
two footnotes; this one and \in{footnote}[footA] on \at{page}[footA], denoted by \note[footA].}. <br />
\stoptext<br />
</context><br />
<br />
<br />
Thanks to Oblomov, it's also possible to use footnotes in footnotes, as in this example.<br />
<br />
<texcode><br />
This\footnote{Or that\footnote{Or possibly even the other.}, if you prefer.} is a sentence<br />
with a footnote. <br />
</texcode><br />
<br />
<context><br />
\starttext<br />
\strut\vfill % A hack to shorten the page.<br />
This\footnote{Or that\footnote{Or possibly even the other.}, if you prefer.} is a sentence<br />
with a footnote. <br />
\stoptext<br />
</context><br />
<br />
==Footnote Numbering==<br />
<br />
You can setup the exact behaviour of footnotes with {{cmd|setupnotation|[footnote]}} (MkII: {{cmd|setupfootnotes}}).<br />
(The command page for the MkIV version is still missing, refer to the old version; translate location to alternative and conversion to numberconversion.)<br />
<br />
For example, to use footnotes with standard footnote symbols (which ConTeXt has defined as the conversion "set 2"), with the footnote counter resetting on each page, one would use the following:<br />
<br />
<texcode><br />
\setupnotation[footnote][way=bypage,numberconversion=set 2]<br />
</texcode><br />
<br />
In MkII this was:<br />
<br />
<texcode><br />
\setupfootnotes[way=bypage, conversion=set 2]<br />
</texcode><br />
<br />
This produces the following footnotes, using the text of the previous example.<br />
<br />
<context><br />
\setupnotation[footnote][way=bypage,numberconversion=set 2]<br />
\starttext<br />
\strut\vfill % A hack to shorten the page.<br />
This\footnote[footA]{Or that, if you prefer.} is a sentence with a footnote\footnote{Actually,<br />
two footnotes; this one and \in{footnote}[footA] on \at{page}[footA], denoted by \note[footA].}. <br />
\stoptext<br />
</context><br />
<br />
==Alternate Footnote Locations==<br />
<br />
The {{cmd|setupfootnotes}} (MkII) command offers some options for the placement of footnotes; for instance, the <code>location=columns</code> option places the footnotes in a single column (of a multicolumn page) rather than across the whole page. The <code>location=text</code> option places the footnotes in text at a location specified by {{cmd|placefootnotes}}; this can be easily used to create endnotes, or even to place footnotes after each paragraph or subsection.<br />
<br />
<texcode><br />
\setupfootnotes[location=text] % MkII<br />
This\footnote[footA]{Or that, if you prefer.} is a sentence with a footnote\footnote{Actually,<br />
two footnotes; this one and footnote \note[footA].}. <br />
\placefootnotes<br />
This is some more text, with more footnotes\footnote{Specifically, this one.}.<br />
\placefootnotes<br />
</texcode><br />
<br />
<context><br />
\starttext<br />
\setupfootnotes[location=text]<br />
This\footnote[footA]{Or that, if you prefer.} is a sentence with a footnote\footnote{Actually,<br />
two footnotes; this one and footnote \note[footA].}. <br />
\placefootnotes<br />
This is some more text, with more footnotes\footnote{Specifically, this one.}.<br />
\placefootnotes<br />
\stoptext<br />
</context><br />
<br />
=== Footnotes at the end of each chapter ===<br />
<br />
Another elegant (MkIV) example places all footnotes in a subject (unnumbered section) at the end of each chapter. It is intelligent and will not create an empty subject when there are no footnotes to be placed. At no extra cost, the subject title "Footnote" will be singular or plural depending if there is only one or several footnotes to be placed:<br />
<br />
<texcode><br />
\startsetups[chapter:after]<br />
\ifcase\rawcountervalue[footnote]\relax<br />
\or<br />
\startsubject[title=Footnote]<br />
\placefootnotes<br />
\stopsubject<br />
\else<br />
\startsubject[title=Footnotes]<br />
\placefootnotes<br />
\stopsubject<br />
\fi<br />
\stopsetups<br />
<br />
\setupnotes[location=none]<br />
\setupnotation[way=bychapter]<br />
<br />
\setuphead[chapter][aftersection=\setups{chapter:after}]<br />
<br />
\starttext<br />
<br />
\startchapter[title={Chapter One}]<br />
<br />
This one\footnote{is placed}. And\footnote{this one is too}.<br />
<br />
\stopchapter<br />
<br />
\chapter[title={Chapter Two}]<br />
<br />
But this one\footnote{is not flushed}.<br />
<br />
\startchapter[title={Chapter Three}]<br />
<br />
Unless \type{\stopchapter} was invoked.<br />
<br />
\stopchapter<br />
<br />
\startchapter[title={Chapter Three}]<br />
<br />
On a chapter with\footnote{footnote}.<br />
<br />
\stopchapter<br />
<br />
\stoptext<br />
</texcode><br />
<br />
===Footnotes in the margin===<br />
<br />
First we switch off footnote placement, then we place them manually into the margin.<br />
<br />
<texcode><br />
\setupnote[footnote][location=none]<br />
\setupnotation[footnote][<br />
align=flushleft,<br />
location=serried,<br />
width=broad,<br />
]<br />
\setuptexttexts[margin][]<br />
[{\framed[%<br />
align={right,bottom},<br />
frame=off,<br />
height=\textheight,<br />
width=\rightmarginwidth<br />
]{\placenotes[footnote]}}]<br />
</texcode><br />
<br />
===... but not at the bottom===<br />
<br />
Hraban wanted numbered margin notes, starting in on the same line as the referenced text (like a combination of {{cmd|inmargin}} and {{cmd|footnote}}). Wolfgang answered:<br />
<br />
The only way I found to achieve this is by flushing the notes at the end of each footnote<br />
entry which can be done with the next key. The positioning of each margin text is tricky<br />
because {{cmd|placenotes}} adds skips at the begin of the block (which can be reduced with<br />
{{cmd|placelocalnotes}}) but a inline version of the command (e.g. <tt>\placeinlinenotes</tt>) which<br />
flushes the notes without vertical skips and a rule at the begin would help.<br />
<br />
<texcode><br />
\define\PlaceFootnote<br />
{\inrightmargin{\vtop{\placelocalnotes[footnote][before=,after=]}}}<br />
<br />
\setupnote<br />
[footnote]<br />
[location=text,<br />
bodyfont=,<br />
next=\PlaceFootnote]<br />
<br />
\setupnotation<br />
[footnote]<br />
[alternative=serried]<br />
<br />
\setuplayout<br />
[width=12cm,<br />
rightmargindistance=0.5cm,<br />
rightmargin=5cm]<br />
<br />
\starttext<br />
\dorecurse{6}{\input ward\expanded{\footnote{This is a footnote \recurselevel}} }<br />
\stoptext<br />
</texcode><br />
<br />
==Footnote Formatting==<br />
<br />
You can change the font used in the footnotes with<br />
{{cmd|setupfootnotedefinition|[before=\MyFontCommand]}}.<br />
<br />
Footnotes can be placed in multiple columns, using the <code>n=<i>number</i></code> option of {{cmd|setupnotes}} or {{cmd|setupnote}} (MkII: {{cmd|setupfootnotes}}).<br />
<br />
<texcode><br />
\setupfootnotes[n=3] % MkII<br />
This\footnote[footA](Or that\footnote{Or the other.}, if you prefer.} is a sentence<br />
with a footnote\footnote{Actually, two footnotes; this one and \in{footnote}[footA]<br />
on \at{page}[footA], denoted by \note[footA].}. <br />
</texcode><br />
<br />
<context><br />
\setupfootnotes[n=3]<br />
\starttext<br />
\strut\vfill % A hack to shorten the page.<br />
This\footnote[footA](Or that\footnote{Or the other.}, if you prefer.} is a sentence<br />
with a footnote\footnote{Actually, two footnotes; this one and \in{footnote}[footA]<br />
on \at{page}[footA], denoted by \note[footA].}. <br />
\stoptext<br />
</context><br />
<br />
{{todo|This is ugly, and points up some ConTeXt bugs that need to be fixed.}}<br />
<br />
===Footnotes in pagraph form===<br />
<br />
When enabling footnotes (actually notes and linenotes) in pagraph form, there is some risk in having no right separation between body and the notes. This can be partially avoided using <code>width=broad</code> ([http://www.ntg.nl/pipermail/ntg-context/2013/073650.html Hans dixit]).<br />
<br />
<texcode><br />
\setupnote<br />
[footnote]<br />
[paragraph=yes]<br />
<br />
\setupnotation<br />
[footnote]<br />
[alternative=serried,<br />
width=broad,<br />
distance=.5em,<br />
display=no]<br />
<br />
\starttext<br />
\dorecurse{500}{text text text\footnote{note} }<br />
\stoptext<br />
</texcode><br />
<br />
==Footnotes in Floats==<br />
<br />
[[Floating Objects|Floats]] cannot include normal footnotes, because they are likely to float to another page from the page on which they were defined, thus getting the footnotes out of order. Thus, to include footnotes in a float, one must use local footnotes. This table, which uses the {{cmd|placelegend}} command to create a place for the footnotes, illustrates the process:<br />
<br />
<texcode><br />
\startlocalfootnotes[n=2]<br />
\placetable{A table with footnotes.}<br />
\placelegend<br />
{\starttable[|l|r|]<br />
\HL<br />
\VL One\footnote{First} \VL Two\footnote{Second} \VL\FR<br />
\VL Three\footnote{Third} \VL Four\footnote{Fourth} \VL\LR<br />
\HL<br />
\stoptable}<br />
{\placelocalfootnotes}<br />
\stoplocalfootnotes<br />
</texcode><br />
<br />
<context><br />
\startlocalfootnotes[n=2]<br />
\placetable{A table with footnotes.}<br />
\placelegend<br />
{\strut\starttable[|l|r|]<br />
\HL<br />
\VL One\footnote{First} \VL Two\footnote{Second} \VL\FR<br />
\VL Three\footnote{Third} \VL Four\footnote{Fourth} \VL\LR<br />
\HL<br />
\stoptable}<br />
{\placelocalfootnotes}<br />
\stoplocalfootnotes<br />
</context><br />
<br />
When using natural tables, the above leads to alignment problems. An alternative is to use:<br />
<br />
<texcode><br />
\defineframed[noteframed]<br />
\setupframed[noteframed]<br />
[width=\hsize,<br />
frame=off,<br />
align=right,<br />
%height=fit,<br />
top=\hbox\bgroup,<br />
bottom=\egroup]<br />
<br />
\starttext<br />
<br />
\startlocalfootnotes[n=0]<br />
\placetable<br />
{Caption}<br />
{\placelegend<br />
{\bTABLE<br />
\bTR\bTD One\footnote{First} \eTD\bTD Two\footnote{Second} \eTD\eTR<br />
\bTR\bTD Three\footnote{Third} \eTD\bTD Four\footnote{Fourth} \eTD\eTR<br />
\eTABLE}<br />
{\noteframed{\placelocalfootnotes}}}<br />
\stoplocalfootnotes<br />
<br />
\stoptext<br />
</texcode><br />
<br />
<context><br />
\defineframed[noteframed]<br />
\setupframed[noteframed]<br />
[width=\hsize,<br />
frame=off,<br />
align=right,<br />
%height=fit,<br />
top=\hbox\bgroup,<br />
bottom=\egroup]<br />
<br />
\starttext<br />
<br />
\startlocalfootnotes[n=0]<br />
\placetable<br />
{Caption}<br />
{\placelegend<br />
{\bTABLE<br />
\bTR\bTD One\footnote{First} \eTD\bTD Two\footnote{Second} \eTD\eTR<br />
\bTR\bTD Three\footnote{Third} \eTD\bTD Four\footnote{Fourth} \eTD\eTR<br />
\eTABLE}<br />
{\noteframed{\placelocalfootnotes}}}<br />
\stoplocalfootnotes<br />
<br />
\stoptext<br />
</context><br />
<br />
==Footnotes in a box==<br />
<br />
Note that it is necessary to add the command {{cmd|automigrateinserts}} (for example before {{cmd|link=no|starttext}})<br />
in order to correctly handle the placement of footnotes within a box such as {{cmd|framed}} or {{cmd|placeongrid}}...<br />
<br />
==Placing Footnotes Manually==<br />
<br />
In some cases, ConTeXt's footnoting system may not be able to do exactly what you want. For instance, you may want to place a footnote in a table so that the footnote appears with the rest of the footnotes on the page, or you may want to create a footnote to a footnote to a footnote. Many of these cases can be handled by using the {{cmd|footnotetext}} command (which creates a footnote without placing the corresponding symbol in the text) and the {{cmd|note}} command (which places the footnote symbol in the text, but does not create a footnote).<br />
<br />
For example, to create a footnote to a footnote to a footnote, all but the first footnotes are created with {{cmd|footnotetext}} commands, which are placed in the main text – thereby ensuring that the footnotes are numbered and appear in the correct order. Then, these footnotes are referenced by {{cmd|note}} commands within the relevant footnotes. In this example, the lines are broken for clarity; note the <code>%</code> at the end of each line to prevent spurious spaces in the text.<br />
<br />
<texcode><br />
This%<br />
\footnote{Or that\note[footB], if you prefer.}%<br />
\footnotetext[footB]{Or possibly even the other\note[footC].}%<br />
\footnotetext[footC]{It could be something entirely different.}<br />
is a sentence with nested footnotes.<br />
</texcode><br />
<br />
<context><br />
\strut\vfill<br />
This%<br />
\footnote{Or that\note[footB], if you prefer.}%<br />
\footnotetext[footB]{Or possibly even the other\note[footC].}%<br />
\footnotetext[footC]{It could be something entirely different.}<br />
is a sentence with nested footnotes.<br />
</context><br />
<br />
== Suppressing Footnotes Entirely ==<br />
<br />
The boolean {{cmd|link=no|notesenabled}} controls whether footnotes are processed at all.<br />
If set to ''false'', invocations of {{cmd|footnote}} will be ignored.<br />
After it is set to ''true'' again ConTeXt will pick up the footnote counters at their<br />
previous state, so numbering will continuous.<br />
<br />
<context source="yes" mode="mkiv"><br />
\setuppapersize [A7]<br />
\starttext<br />
<br />
\dorecurse {2} { foo \footnote {bar} baz \par }<br />
<br />
\notesenabledfalse<br />
<br />
\dorecurse {3} { foo \footnote {bar} baz \par }<br />
<br />
\notesenabledtrue<br />
<br />
\dorecurse {2} { foo \footnote {bar} baz \par }<br />
<br />
\stoptext<br />
</context><br />
<br />
== Color of Footnote Links that Refer to the Same Page ==<br />
<br />
If you have set footnotes to be interactive and have noticed that your footnote links become red, it is because they are linked to content on the same page on which they appear. This means they are governed by {{cmd|setupinteraction}}’s attribute <code>contrastcolor</code>, rather than <code>color</code>.<br />
<br />
To fix the redness (or change it to a different color), try:<br />
<br />
<texcode><br />
\setupinteraction[state=start,color=black,contrastcolor=black]<br />
</texcode><br />
<br />
== Changing footnote interlinespace ==<br />
<br />
If you want to change the interlinespace of footnotes without impacting the rest of the document, try:<br />
<texcode><br />
\startsetups[footnote:interlinespace]<br />
\setupinterlinespace[line=2.8ex]<br />
\stopsetups<br />
<br />
\setupnote[footnote][setups=footnote:interlinespace]<br />
</texcode><br />
<br />
<br />
<br />
<br />
== Special Needs ==<br />
There are numerous ways to display and format footnotes. The following section gathers solutions to some special tasks asked on the mailing list.<br />
<br />
=== Hyphenation ===<br />
* Is there a way to turn off hyphenation for the main body of my text, but enable it for the footnotes?<br />
<br />
<texcode><br />
\starttext<br />
<br />
\setupnote[footnote][align={normal,hyphenated}]<br />
<br />
\setupalign[hyphenated] \input tufte \footnote{\input tufte \relax} \par<br />
<br />
\setupalign[nothyphenated,stretch,tolerant] \input tufte<br />
\footnote{\input tufte \relax} \par<br />
<br />
\stoptext<br />
</texcode><br />
<br />
===Mark Placement===<br />
* How can I change the placement of the footnote mark?<br />
<br />
Currently, footnotes are set so that the left end of the text of the footnote is aligned with the left edge of the text, and the footnote number hangs out into the margin. Is it possible to change this? (For instance, suppose I would like the number aligned to the text-edge, and then a fixed-width space, and then the text?)<br />
<br />
This behavior is controlled by the <code>location</code> key of {{cmd|setupnotation}}. Here are some examples:<br />
<br />
Note number is typeset in an area with a width of 1 cm, aligned at the left of the text area:<br />
<br />
<context source="yes" text="produces"><br />
\definepapersize[wiki][width=8cm,height=8cm]<br />
<br />
\setuppapersize[wiki][wiki]<br />
<br />
\starttext<br />
<br />
\showframe<br />
<br />
\setupnotation[footnote][location=left,width=1cm]<br />
\setupnote[footnote][location=page,numbercommand=]<br />
<br />
test \footnote{test}<br />
<br />
\stoptext <br />
</context><br />
<br />
<br />
Suppose that one wants a width of 1.5 em. Then<br />
<br />
<texcode><br />
\setupnote[footnote][margindistance=0em,command=\myfootnotecommand]<br />
\setupnotation[footnote][location=left,hang=1]<br />
<br />
\def\myfootnotecommand#1{\hbox to 1.5em{#1.}}<br />
</texcode><br />
<br />
===Line Spacing===<br />
* Can I change the line spacing of a footnote independently of that of the main text?<br />
<br />
The way to do this is not obvious, but this is the code you need to use:<br />
<br />
<texcode><br />
\def\setnotebodyfont<br />
{\switchtobodyfont[your desired font size]\setupinterlinespace[your desired spacing]} <br />
</texcode><br />
<br />
===Placement in Bidirectional Documents===<br />
* Can the footnote rule be placed on the right-hand side?<br />
<br />
This is possible via setting the <code>rule</code> key of {{cmd|setupnote}} and {{cmd|definenote}}. In right-to-left documents it is usually desirable to have right-to-left footnotes, where right-aligned footnote rules make more sense aesthetically. Set <code>rule=right</code> to achieve this. Prior to 01-04-2016 Beta, this would have turned off the footnote rule completely: one needed to use <code>rule={on,right}</code>.<br />
<br />
In a BiDi document the direction of the surrounding text where the {{cmd|footnote}} is invoked determines the direction of the footnote block to come later. Therefore, some footnotes may be right-to-left whereas others can be left-to-right. Note that the text of the footnote does not play a role here. The style designer decides whether left or right footnote rules make more sense. However, there is a third option: setting <code>rule=paragraph</code> looks at the first paragraph in the footnote block and let that determine the position of the footnote rule. In other words, if the footnote block of the page starts with an RTL text we end up with a right-aligned footnote rule and a left-aligned rule is typeset otherwise. (The first line/paragraph of the footnote block on a page need not correspond to the start of a footnote; it can rather be the leftover from a long footnote that started on some previous page.)<br />
<br />
For more fancy footnote rules, you can use <code>rulecommand=\MyRuleCommand</code>. Look at the definition of <code>\normalnoterule</code> in strc-not.mkvi for a starting point.<br />
<br />
[[Category:Basics]]</div>Mæstrohttps://wiki.contextgarden.net/index.php?title=Footnotes&diff=33416Footnotes2022-02-19T21:02:39Z<p>Mæstro: /* Basic Footnotes */ - footnote command typo</p>
<hr />
<div>{{todo|This page needs to be reorganized: progression from simple to more complex use is a bit circular..}}<br />
<br />
==First View==<br />
<br />
<texcode><br />
\section{First}<br />
<br />
Way to \ConTeXt\footnote{First footnote.} is painful.<br />
<br />
\section{Second}<br />
<br />
But \ConTeXt\ is amazing.\footnote{Second footnote}<br />
<br />
\placetable<br />
{Complex Table\footnote{A table head footnote.}}<br />
{\startlocalfootnotes<br />
\placelegend<br />
{\starttable[|l|l|]<br />
\HL<br />
\NC First Column \NC Second Column \NC \FR<br />
\HL<br />
\NC East\footnote{Footnote inside graphic.} \NC North \NC \FR<br />
\NC West \NC South \NC \LR<br />
\HL<br />
\stoptable}<br />
{\placelocalfootnotes}<br />
\stoplocalfootnotes}<br />
</texcode><br />
<br />
<context><br />
\starttext<br />
\strut\vfill\<br />
\section{First}<br />
<br />
Way to \ConTeXt\footnote{First footnote.} is painful.<br />
<br />
\section{Second}<br />
<br />
But \ConTeXt\ is amazing.\footnote{Second footnote}<br />
<br />
\placetable<br />
{Complex Table\footnote{A table head footnote.}}<br />
{\startlocalfootnotes<br />
\placelegend<br />
{\starttable[|l|l|]<br />
\HL<br />
\NC First Column \NC Second Column \NC \FR<br />
\HL<br />
\NC East\footnote{Footnote inside graphic.} \NC North \NC \FR<br />
\NC West \NC South \NC \LR<br />
\HL<br />
\stoptable}<br />
{\placelocalfootnotes}<br />
\stoplocalfootnotes}<br />
\stoptext<br />
</context><br />
<br />
Here we have footnotes of two outer ones, a local one (in the table) and a postponed one (in the graphic).<br />
<br />
==Basic Footnotes==<br />
<br />
For basic footnotes, simply use {{cmd|footnote|[reference]{footnote text}}}.<br />
The reference is optional, and can be used to refer to the same footnote again. Footnotes can be referenced with the usual {{cmd|in}} and {{cmd|at}} macros (see [[References]]), or the note itself can be reproduced with {{cmd|note|[reference]}}. For example:<br />
<br />
<texcode><br />
This\footnote[footA]{Or that, if you prefer.} is a sentence with a footnote\footnote{Actually,<br />
two footnotes; this one and \in{footnote}[footA] on \at{page}[footA], denoted by \note[footA].}. <br />
</texcode><br />
<br />
<context><br />
\starttext<br />
\strut\vfill % A hack to shorten the page.<br />
This\footnote[footA]{Or that, if you prefer.} is a sentence with a footnote\footnote{Actually,<br />
two footnotes; this one and \in{footnote}[footA] on \at{page}[footA], denoted by \note[footA].}. <br />
\stoptext<br />
</context><br />
<br />
<br />
Thanks to Oblomov, it's also possible to use footnotes in footnotes, as in this example.<br />
<br />
<texcode><br />
This\footnote{Or that\footnote{Or possibly even the other.}, if you prefer.} is a sentence<br />
with a footnote. <br />
</texcode><br />
<br />
<context><br />
\starttext<br />
\strut\vfill % A hack to shorten the page.<br />
This\footnote{Or that\footnote{Or possibly even the other.}, if you prefer.} is a sentence<br />
with a footnote. <br />
\stoptext<br />
</context><br />
<br />
==Footnote Numbering==<br />
<br />
You can setup the exact behaviour of footnotes with {{cmd|setupnotation|[footnote]}} (MkII: {{cmd|setupfootnotes}}).<br />
(The command page for the MkIV version is still missing, refer to the old version; translate location to alternative and conversion to numberconversion.)<br />
<br />
For example, to use footnotes with standard footnote symbols (which ConTeXt has defined as the conversion "set 2"), with the footnote counter resetting on each page, one would use the following:<br />
<br />
<texcode><br />
\setupnotation[footnote][way=bypage,numberconversion=set 2]<br />
</texcode><br />
<br />
In MkII this was:<br />
<br />
<texcode><br />
\setupfootnotes[way=bypage, conversion=set 2]<br />
</texcode><br />
<br />
This produces the following footnotes, using the text of the previous example.<br />
<br />
<context><br />
\setupfootnotes[way=bypage, conversion=set 2]<br />
\starttext<br />
\strut\vfill % A hack to shorten the page.<br />
This\footnote[footA](Or that, if you prefer.} is a sentence with a footnote\footnote{Actually,<br />
two footnotes; this one and \in{footnote}[footA] on \at{page}[footA], denoted by \note[footA].}. <br />
\stoptext<br />
</context><br />
<br />
==Alternate Footnote Locations==<br />
<br />
The {{cmd|setupfootnotes}} (MkII) command offers some options for the placement of footnotes; for instance, the <code>location=columns</code> option places the footnotes in a single column (of a multicolumn page) rather than across the whole page. The <code>location=text</code> option places the footnotes in text at a location specified by {{cmd|placefootnotes}}; this can be easily used to create endnotes, or even to place footnotes after each paragraph or subsection.<br />
<br />
<texcode><br />
\setupfootnotes[location=text] % MkII<br />
This\footnote[footA]{Or that, if you prefer.} is a sentence with a footnote\footnote{Actually,<br />
two footnotes; this one and footnote \note[footA].}. <br />
\placefootnotes<br />
This is some more text, with more footnotes\footnote{Specifically, this one.}.<br />
\placefootnotes<br />
</texcode><br />
<br />
<context><br />
\starttext<br />
\setupfootnotes[location=text]<br />
This\footnote[footA]{Or that, if you prefer.} is a sentence with a footnote\footnote{Actually,<br />
two footnotes; this one and footnote \note[footA].}. <br />
\placefootnotes<br />
This is some more text, with more footnotes\footnote{Specifically, this one.}.<br />
\placefootnotes<br />
\stoptext<br />
</context><br />
<br />
=== Footnotes at the end of each chapter ===<br />
<br />
Another elegant (MkIV) example places all footnotes in a subject (unnumbered section) at the end of each chapter. It is intelligent and will not create an empty subject when there are no footnotes to be placed. At no extra cost, the subject title "Footnote" will be singular or plural depending if there is only one or several footnotes to be placed:<br />
<br />
<texcode><br />
\startsetups[chapter:after]<br />
\ifcase\rawcountervalue[footnote]\relax<br />
\or<br />
\startsubject[title=Footnote]<br />
\placefootnotes<br />
\stopsubject<br />
\else<br />
\startsubject[title=Footnotes]<br />
\placefootnotes<br />
\stopsubject<br />
\fi<br />
\stopsetups<br />
<br />
\setupnotes[location=none]<br />
\setupnotation[way=bychapter]<br />
<br />
\setuphead[chapter][aftersection=\setups{chapter:after}]<br />
<br />
\starttext<br />
<br />
\startchapter[title={Chapter One}]<br />
<br />
This one\footnote{is placed}. And\footnote{this one is too}.<br />
<br />
\stopchapter<br />
<br />
\chapter[title={Chapter Two}]<br />
<br />
But this one\footnote{is not flushed}.<br />
<br />
\startchapter[title={Chapter Three}]<br />
<br />
Unless \type{\stopchapter} was invoked.<br />
<br />
\stopchapter<br />
<br />
\startchapter[title={Chapter Three}]<br />
<br />
On a chapter with\footnote{footnote}.<br />
<br />
\stopchapter<br />
<br />
\stoptext<br />
</texcode><br />
<br />
===Footnotes in the margin===<br />
<br />
First we switch off footnote placement, then we place them manually into the margin.<br />
<br />
<texcode><br />
\setupnote[footnote][location=none]<br />
\setupnotation[footnote][<br />
align=flushleft,<br />
location=serried,<br />
width=broad,<br />
]<br />
\setuptexttexts[margin][]<br />
[{\framed[%<br />
align={right,bottom},<br />
frame=off,<br />
height=\textheight,<br />
width=\rightmarginwidth<br />
]{\placenotes[footnote]}}]<br />
</texcode><br />
<br />
===... but not at the bottom===<br />
<br />
Hraban wanted numbered margin notes, starting in on the same line as the referenced text (like a combination of {{cmd|inmargin}} and {{cmd|footnote}}). Wolfgang answered:<br />
<br />
The only way I found to achieve this is by flushing the notes at the end of each footnote<br />
entry which can be done with the next key. The positioning of each margin text is tricky<br />
because {{cmd|placenotes}} adds skips at the begin of the block (which can be reduced with<br />
{{cmd|placelocalnotes}}) but a inline version of the command (e.g. <tt>\placeinlinenotes</tt>) which<br />
flushes the notes without vertical skips and a rule at the begin would help.<br />
<br />
<texcode><br />
\define\PlaceFootnote<br />
{\inrightmargin{\vtop{\placelocalnotes[footnote][before=,after=]}}}<br />
<br />
\setupnote<br />
[footnote]<br />
[location=text,<br />
bodyfont=,<br />
next=\PlaceFootnote]<br />
<br />
\setupnotation<br />
[footnote]<br />
[alternative=serried]<br />
<br />
\setuplayout<br />
[width=12cm,<br />
rightmargindistance=0.5cm,<br />
rightmargin=5cm]<br />
<br />
\starttext<br />
\dorecurse{6}{\input ward\expanded{\footnote{This is a footnote \recurselevel}} }<br />
\stoptext<br />
</texcode><br />
<br />
==Footnote Formatting==<br />
<br />
You can change the font used in the footnotes with<br />
{{cmd|setupfootnotedefinition|[before=\MyFontCommand]}}.<br />
<br />
Footnotes can be placed in multiple columns, using the <code>n=<i>number</i></code> option of {{cmd|setupnotes}} or {{cmd|setupnote}} (MkII: {{cmd|setupfootnotes}}).<br />
<br />
<texcode><br />
\setupfootnotes[n=3] % MkII<br />
This\footnote[footA](Or that\footnote{Or the other.}, if you prefer.} is a sentence<br />
with a footnote\footnote{Actually, two footnotes; this one and \in{footnote}[footA]<br />
on \at{page}[footA], denoted by \note[footA].}. <br />
</texcode><br />
<br />
<context><br />
\setupfootnotes[n=3]<br />
\starttext<br />
\strut\vfill % A hack to shorten the page.<br />
This\footnote[footA](Or that\footnote{Or the other.}, if you prefer.} is a sentence<br />
with a footnote\footnote{Actually, two footnotes; this one and \in{footnote}[footA]<br />
on \at{page}[footA], denoted by \note[footA].}. <br />
\stoptext<br />
</context><br />
<br />
{{todo|This is ugly, and points up some ConTeXt bugs that need to be fixed.}}<br />
<br />
===Footnotes in pagraph form===<br />
<br />
When enabling footnotes (actually notes and linenotes) in pagraph form, there is some risk in having no right separation between body and the notes. This can be partially avoided using <code>width=broad</code> ([http://www.ntg.nl/pipermail/ntg-context/2013/073650.html Hans dixit]).<br />
<br />
<texcode><br />
\setupnote<br />
[footnote]<br />
[paragraph=yes]<br />
<br />
\setupnotation<br />
[footnote]<br />
[alternative=serried,<br />
width=broad,<br />
distance=.5em,<br />
display=no]<br />
<br />
\starttext<br />
\dorecurse{500}{text text text\footnote{note} }<br />
\stoptext<br />
</texcode><br />
<br />
==Footnotes in Floats==<br />
<br />
[[Floating Objects|Floats]] cannot include normal footnotes, because they are likely to float to another page from the page on which they were defined, thus getting the footnotes out of order. Thus, to include footnotes in a float, one must use local footnotes. This table, which uses the {{cmd|placelegend}} command to create a place for the footnotes, illustrates the process:<br />
<br />
<texcode><br />
\startlocalfootnotes[n=2]<br />
\placetable{A table with footnotes.}<br />
\placelegend<br />
{\starttable[|l|r|]<br />
\HL<br />
\VL One\footnote{First} \VL Two\footnote{Second} \VL\FR<br />
\VL Three\footnote{Third} \VL Four\footnote{Fourth} \VL\LR<br />
\HL<br />
\stoptable}<br />
{\placelocalfootnotes}<br />
\stoplocalfootnotes<br />
</texcode><br />
<br />
<context><br />
\startlocalfootnotes[n=2]<br />
\placetable{A table with footnotes.}<br />
\placelegend<br />
{\strut\starttable[|l|r|]<br />
\HL<br />
\VL One\footnote{First} \VL Two\footnote{Second} \VL\FR<br />
\VL Three\footnote{Third} \VL Four\footnote{Fourth} \VL\LR<br />
\HL<br />
\stoptable}<br />
{\placelocalfootnotes}<br />
\stoplocalfootnotes<br />
</context><br />
<br />
When using natural tables, the above leads to alignment problems. An alternative is to use:<br />
<br />
<texcode><br />
\defineframed[noteframed]<br />
\setupframed[noteframed]<br />
[width=\hsize,<br />
frame=off,<br />
align=right,<br />
%height=fit,<br />
top=\hbox\bgroup,<br />
bottom=\egroup]<br />
<br />
\starttext<br />
<br />
\startlocalfootnotes[n=0]<br />
\placetable<br />
{Caption}<br />
{\placelegend<br />
{\bTABLE<br />
\bTR\bTD One\footnote{First} \eTD\bTD Two\footnote{Second} \eTD\eTR<br />
\bTR\bTD Three\footnote{Third} \eTD\bTD Four\footnote{Fourth} \eTD\eTR<br />
\eTABLE}<br />
{\noteframed{\placelocalfootnotes}}}<br />
\stoplocalfootnotes<br />
<br />
\stoptext<br />
</texcode><br />
<br />
<context><br />
\defineframed[noteframed]<br />
\setupframed[noteframed]<br />
[width=\hsize,<br />
frame=off,<br />
align=right,<br />
%height=fit,<br />
top=\hbox\bgroup,<br />
bottom=\egroup]<br />
<br />
\starttext<br />
<br />
\startlocalfootnotes[n=0]<br />
\placetable<br />
{Caption}<br />
{\placelegend<br />
{\bTABLE<br />
\bTR\bTD One\footnote{First} \eTD\bTD Two\footnote{Second} \eTD\eTR<br />
\bTR\bTD Three\footnote{Third} \eTD\bTD Four\footnote{Fourth} \eTD\eTR<br />
\eTABLE}<br />
{\noteframed{\placelocalfootnotes}}}<br />
\stoplocalfootnotes<br />
<br />
\stoptext<br />
</context><br />
<br />
==Footnotes in a box==<br />
<br />
Note that it is necessary to add the command {{cmd|automigrateinserts}} (for example before {{cmd|link=no|starttext}})<br />
in order to correctly handle the placement of footnotes within a box such as {{cmd|framed}} or {{cmd|placeongrid}}...<br />
<br />
==Placing Footnotes Manually==<br />
<br />
In some cases, ConTeXt's footnoting system may not be able to do exactly what you want. For instance, you may want to place a footnote in a table so that the footnote appears with the rest of the footnotes on the page, or you may want to create a footnote to a footnote to a footnote. Many of these cases can be handled by using the {{cmd|footnotetext}} command (which creates a footnote without placing the corresponding symbol in the text) and the {{cmd|note}} command (which places the footnote symbol in the text, but does not create a footnote).<br />
<br />
For example, to create a footnote to a footnote to a footnote, all but the first footnotes are created with {{cmd|footnotetext}} commands, which are placed in the main text – thereby ensuring that the footnotes are numbered and appear in the correct order. Then, these footnotes are referenced by {{cmd|note}} commands within the relevant footnotes. In this example, the lines are broken for clarity; note the <code>%</code> at the end of each line to prevent spurious spaces in the text.<br />
<br />
<texcode><br />
This%<br />
\footnote{Or that\note[footB], if you prefer.}%<br />
\footnotetext[footB]{Or possibly even the other\note[footC].}%<br />
\footnotetext[footC]{It could be something entirely different.}<br />
is a sentence with nested footnotes.<br />
</texcode><br />
<br />
<context><br />
\strut\vfill<br />
This%<br />
\footnote{Or that\note[footB], if you prefer.}%<br />
\footnotetext[footB]{Or possibly even the other\note[footC].}%<br />
\footnotetext[footC]{It could be something entirely different.}<br />
is a sentence with nested footnotes.<br />
</context><br />
<br />
== Suppressing Footnotes Entirely ==<br />
<br />
The boolean {{cmd|link=no|notesenabled}} controls whether footnotes are processed at all.<br />
If set to ''false'', invocations of {{cmd|footnote}} will be ignored.<br />
After it is set to ''true'' again ConTeXt will pick up the footnote counters at their<br />
previous state, so numbering will continuous.<br />
<br />
<context source="yes" mode="mkiv"><br />
\setuppapersize [A7]<br />
\starttext<br />
<br />
\dorecurse {2} { foo \footnote {bar} baz \par }<br />
<br />
\notesenabledfalse<br />
<br />
\dorecurse {3} { foo \footnote {bar} baz \par }<br />
<br />
\notesenabledtrue<br />
<br />
\dorecurse {2} { foo \footnote {bar} baz \par }<br />
<br />
\stoptext<br />
</context><br />
<br />
== Color of Footnote Links that Refer to the Same Page ==<br />
<br />
If you have set footnotes to be interactive and have noticed that your footnote links become red, it is because they are linked to content on the same page on which they appear. This means they are governed by {{cmd|setupinteraction}}’s attribute <code>contrastcolor</code>, rather than <code>color</code>.<br />
<br />
To fix the redness (or change it to a different color), try:<br />
<br />
<texcode><br />
\setupinteraction[state=start,color=black,contrastcolor=black]<br />
</texcode><br />
<br />
== Changing footnote interlinespace ==<br />
<br />
If you want to change the interlinespace of footnotes without impacting the rest of the document, try:<br />
<texcode><br />
\startsetups[footnote:interlinespace]<br />
\setupinterlinespace[line=2.8ex]<br />
\stopsetups<br />
<br />
\setupnote[footnote][setups=footnote:interlinespace]<br />
</texcode><br />
<br />
<br />
<br />
<br />
== Special Needs ==<br />
There are numerous ways to display and format footnotes. The following section gathers solutions to some special tasks asked on the mailing list.<br />
<br />
=== Hyphenation ===<br />
* Is there a way to turn off hyphenation for the main body of my text, but enable it for the footnotes?<br />
<br />
<texcode><br />
\starttext<br />
<br />
\setupnote[footnote][align={normal,hyphenated}]<br />
<br />
\setupalign[hyphenated] \input tufte \footnote{\input tufte \relax} \par<br />
<br />
\setupalign[nothyphenated,stretch,tolerant] \input tufte<br />
\footnote{\input tufte \relax} \par<br />
<br />
\stoptext<br />
</texcode><br />
<br />
===Mark Placement===<br />
* How can I change the placement of the footnote mark?<br />
<br />
Currently, footnotes are set so that the left end of the text of the footnote is aligned with the left edge of the text, and the footnote number hangs out into the margin. Is it possible to change this? (For instance, suppose I would like the number aligned to the text-edge, and then a fixed-width space, and then the text?)<br />
<br />
This behavior is controlled by the <code>location</code> key of {{cmd|setupnotation}}. Here are some examples:<br />
<br />
Note number is typeset in an area with a width of 1 cm, aligned at the left of the text area:<br />
<br />
<context source="yes" text="produces"><br />
\definepapersize[wiki][width=8cm,height=8cm]<br />
<br />
\setuppapersize[wiki][wiki]<br />
<br />
\starttext<br />
<br />
\showframe<br />
<br />
\setupnotation[footnote][location=left,width=1cm]<br />
\setupnote[footnote][location=page,numbercommand=]<br />
<br />
test \footnote{test}<br />
<br />
\stoptext <br />
</context><br />
<br />
<br />
Suppose that one wants a width of 1.5 em. Then<br />
<br />
<texcode><br />
\setupnote[footnote][margindistance=0em,command=\myfootnotecommand]<br />
\setupnotation[footnote][location=left,hang=1]<br />
<br />
\def\myfootnotecommand#1{\hbox to 1.5em{#1.}}<br />
</texcode><br />
<br />
===Line Spacing===<br />
* Can I change the line spacing of a footnote independently of that of the main text?<br />
<br />
The way to do this is not obvious, but this is the code you need to use:<br />
<br />
<texcode><br />
\def\setnotebodyfont<br />
{\switchtobodyfont[your desired font size]\setupinterlinespace[your desired spacing]} <br />
</texcode><br />
<br />
===Placement in Bidirectional Documents===<br />
* Can the footnote rule be placed on the right-hand side?<br />
<br />
This is possible via setting the <code>rule</code> key of {{cmd|setupnote}} and {{cmd|definenote}}. In right-to-left documents it is usually desirable to have right-to-left footnotes, where right-aligned footnote rules make more sense aesthetically. Set <code>rule=right</code> to achieve this. Prior to 01-04-2016 Beta, this would have turned off the footnote rule completely: one needed to use <code>rule={on,right}</code>.<br />
<br />
In a BiDi document the direction of the surrounding text where the {{cmd|footnote}} is invoked determines the direction of the footnote block to come later. Therefore, some footnotes may be right-to-left whereas others can be left-to-right. Note that the text of the footnote does not play a role here. The style designer decides whether left or right footnote rules make more sense. However, there is a third option: setting <code>rule=paragraph</code> looks at the first paragraph in the footnote block and let that determine the position of the footnote rule. In other words, if the footnote block of the page starts with an RTL text we end up with a right-aligned footnote rule and a left-aligned rule is typeset otherwise. (The first line/paragraph of the footnote block on a page need not correspond to the start of a footnote; it can rather be the leftover from a long footnote that started on some previous page.)<br />
<br />
For more fancy footnote rules, you can use <code>rulecommand=\MyRuleCommand</code>. Look at the definition of <code>\normalnoterule</code> in strc-not.mkvi for a starting point.<br />
<br />
[[Category:Basics]]</div>Mæstrohttps://wiki.contextgarden.net/index.php?title=Color&diff=33415Color2022-02-17T03:02:51Z<p>Mæstro: /* X11 colors */ - fix typos for nbsp</p>
<hr />
<div>{{Color_navigation_Trial}}<br />
<br />
__TOC__ <br />
<br />
<br />
= Before you start ... = <br />
<br />
1. It’s usually bad style to use explicit color switches in the text. It’s better to define a semantic command that takes care of the color switching. For example, instead of using <code>\color[red]{important text}</code>, define<br />
<texcode><br />
\definehighlight[important][color=red]<br />
</texcode><br />
and then use <code>\important{important text}</code> in the text.<br />
<br />
2. Colors are not enabled by default in MkII. To enable colors in MkII, use<br />
<texcode>\setupcolors[state=start]</texcode><br />
<br />
3. To disable colors in a document, use<br />
<texcode>\setupcolors[state=stop]</texcode><br />
<br />
Last [[Documentation|manual dedicated to color]] was issued in 2016<br />
<br />
= Basic Usage =<br />
<br />
<br />
To color text, use<br />
<br />
<texcode>\color[defined-color]{ ... text ... }</texcode><br />
<br />
or <br />
<br />
<texcode>\startcolor[defined-color] <br />
... text ... <br />
\stopcolor</texcode><br />
<br />
where <code>defined-color</code> is a color defined using {{cmd|definecolor}}. For example, <code>red</code> is one of the predefined colors. So, we can use:<br />
<br />
{|<br />
! width="45%"|<br />
! width="10%"|<br />
! width="45%"|<br />
|-<br />
| <texcode><br />
Three \color[red]{cool} cats<br />
</texcode><br />
|<br />
|<context mode=mkiv><br />
\starttext<br />
Three \color[red]{cool} cats<br />
\stoptext<br />
</context><br />
|}<br />
<br />
or<br />
<br />
<context source=yes><br />
\startcolor[red]<br />
\input tufte<br />
\stopcolor<br />
</context><br />
<br />
<br />
It is also possible to use RGB or CMYK or hex values to color text. The syntax for these is<br />
<texcode>\colored[settings]{... text ...}</texcode><br />
where <code>settings</code> are the same settings as used by {{cmd|definecolor}}. For example:<br />
<br />
<br />
{|<br />
! width="45%"|<br />
! width="10%"|<br />
! width="45%"|<br />
|-<br />
| <texcode><br />
Three \colored[r=0.1, g=0.8, b=0.8]{colorful} cats<br />
</texcode><br />
|<br />
|<context mode=mkiv><br />
\starttext<br />
Three \colored[r=0.1, g=0.8, b=0.8]{colorful} cats<br />
\stoptext<br />
</context><br />
|}<br />
<br />
<br />
'''Note'''. There is no need to use the color commands directly. Almost all ConTeXt commands accept a <code>color</code> key, and you can use <code>color=defined-color</code>. For example, <br />
<br />
* To color the section titles red, use<br />
<texcode>\setuphead[color=red]</texcode><br />
<br />
* To color the footnotes red, use<br />
<texcode>\setupfootnotes[color=red]</texcode><br />
<br />
etc.<br />
<br />
== Changing color of entire document ==<br />
<br />
To change the main text color of the document use<br />
<br />
<texcode>\setupcolors[textcolor=defined-color]</texcode><br />
<br />
For example,<br />
<br />
{|<br />
! width="45%"|<br />
! width="10%"|<br />
! width="45%"|<br />
|-<br />
|<texcode>\setupcolors[textcolor=blue]<br />
\starttext<br />
\input tufte <br />
\stoptext<br />
</texcode><br />
|<br />
|<context mode=mkiv><br />
\setupcolors[textcolor=blue]<br />
\startTEXpage<br />
\input tufte<br />
\stopTEXpage<br />
</context><br />
|}<br />
<br />
== Changing background color of page ==<br />
<br />
The background color of the page can be changed using<br />
<texcode>\setupbackgrounds[page][background=color,backgroundcolor=defined-color]</texcode><br />
<br />
<br />
For example,<br />
{|<br />
! width="45%"|<br />
! width="10%"|<br />
! width="45%"|<br />
|-<br />
| <texcode><br />
\setuppapersize[A8, landscape]<br />
\setupbackgrounds[page][background=color,backgroundcolor=blue]<br />
\setupcolors[textcolor=white]<br />
<br />
\starttext<br />
\input ward<br />
\stoptext<br />
</texcode><br />
|<br />
|<context><br />
\setuppapersize[A8, landscape]<br />
\setupbackgrounds[page][background=color,backgroundcolor=blue]<br />
\setupcolors[textcolor=white]<br />
<br />
\starttext<br />
\input ward<br />
\stoptext<br />
</context><br />
|}<br />
<br />
= Defining New Colors =<br />
<br />
ConTeXt Defining New Colors|supports several color models:<br />
* [https://en.wikipedia.org/wiki/CMYK_color_model CMYK], typically used for printing<br />
* [https://en.wikipedia.org/wiki/RGB_color_model RGB], [https://en.wikipedia.org/wiki/HSL_and_HSV HSV/HSL] and [https://en.wikipedia.org/wiki/HWB_color_model HWB], typically used for screen display,<br />
* [[Transparency]] ([https://en.wikipedia.org/wiki/Transparency_(graphic) Transparency] on wikipedia).<br />
* [[Spot Colors]] typically used for offset printing ([https://en.wikipedia.org/wiki/Spot_color Spot colors] on wikipedia). <br />
<br />
New colors may be defined in the following ways<br />
<br />
{| class="wikitable"<br />
! Name !! Syntax (and Example) !! Explanation<br />
|-<br />
| style="width:20%;" | RGB color model<br />
| style="width:40%;" | <texcode>\definecolor[...][r=..., g=..., b=...]</texcode> <br />
For example,<br />
<texcode>\definecolor[lime][r=0.75, g=1, b=0] <br />
This is \color[lime]{a new color}<br />
that we defined</texcode><br />
| The values for <code>r</code>, <code>g</code>, and <code>b</code> are floating point number between <code>0</code> and <code>1</code>. <br />
|-<br />
| CMYK color model<br />
| <texcode>\definecolor[...][c=.., m=.., y=.., k=..]</texcode> <br />
For example,<br />
<texcode>\definecolor[lime][c=0.25, m=0, y=1, k=0] <br />
This is \color[lime]{a new color}<br />
that we defined</texcode><br />
| The values for <code>c</code>, <code>m</code>, <code>y</code> and <code>k</code> are floating point number between <code>0</code> and <code>1</code>. <br />
|-<br />
| HSV/HSL color model<br />
|<texcode>\definecolor[...][h=.., s=.., v=..]</texcode> <br />
For example,<br />
<texcode>\definecolor[lime][h=75, s=1, v=1] <br />
This is \color[lime]{a new color}<br />
that we defined</texcode><br />
| The value for <code>h</code> (hue) is between <code>0</code> and <code>360</code>; the values for <code>s</code> (saturation), <code>v</code> (value/brightness) are floating point numbers between <code>0</code> and <code>1</code>. <br />
|-<br />
| HWB color model<br />
|<texcode>\definecolor[...][h=.., w=.., b=..]</texcode> <br />
For example,<br />
<texcode>\definecolor[something][h=75, w=0.5, b=.1] <br />
This is \color[something]{a new color}<br />
that we defined</texcode><br />
| The value for <code>h</code> (hue) is between <code>0</code> and <code>360</code>; the values for <code>w</code> (whiteness), <code>b</code> (blackness) are floating point numbers between <code>0</code> and <code>1</code>. This mostly unknown color model is also used in CSS3/SVG.<br />
|-<br />
| Hex<br />
| <texcode>\definecolor[...][x=...]</texcode> <br />
For example,<br />
<texcode>\definecolor[lime][x=BFFF00] <br />
This is \color[lime]{a new color}<br />
that we defined</texcode><br />
| The value for <code>x</code> is a three-byte hexadecimal number where the bytes represent the red, green, and blue values. This follows the HTML and CSS style of defining colors.<br />
|-<br />
|Gray scale<br />
|<texcode>\definecolor[...][s=...]</texcode> <br />
For example,<br />
<texcode>\definecolor[screen][s=0.5] <br />
This is \color[screen]{a new color}<br />
that we defined</texcode><br />
| The value for <code>s</code> is a floating point number between <code>0</code> and <code>1</code>, representing the grayness value (1 represents white, 0 represents black).<br />
|}<br />
<br />
== Cloning existing colors ==<br />
<br />
You can ''clone'' an existing color using<br />
<texcode>\definecolor[new-color][old-color]</texcode><br />
<br />
For example<br />
{|<br />
| width="45%"| <texcode>\usecolors[xwi]<br />
\definecolor[highlight][yellow]<br />
\defineframed<br />
[important]<br />
[location=low, frame=off, <br />
background=color, backgroundcolor=highlight]<br />
<br />
This is a \important{important}word.<br />
<br />
\definecolor[highlight][lavenderblush]<br />
This is a \important{important}word.<br />
</texcode><br />
| width="10%"|<br />
| width="45%"| <context mode=mkiv>\usecolors[xwi]<br />
\definecolor[highlight][yellow]<br />
\defineframed[important][location=low, frame=off, <br />
background=color, backgroundcolor=highlight]<br />
<br />
This is a \important{important}word.<br />
<br />
\definecolor[highlight][lavenderblush]<br />
This is a \important{important}word.<br />
</context><br />
|}<br />
<br />
== Adapting existing colors ==<br />
<br />
{{todo | add details about this}}<br />
<br />
= Pre-defined colors =<br />
<br />
<br />
The following colors are pre-defined in ConTeXt (see {{src|colo-imp-rgb.mkiv}}).<br />
<br />
{| style="text-align: right; padding-right: 20px;"<br />
!| Name !! Color <br />
!style="width: 80px;"| Name !! Color <br />
!style="width: 100px;"| Name !! Color <br />
!style="width: 100px;"| Name !! Color<br />
|-<br />
|black||bgcolor="#000"| &nbsp;<br />
|white||bgcolor="#FFF"| &nbsp; <br />
|-<br />
|gray||bgcolor="#E6E6E6"| &nbsp;<br />
|lightgray||bgcolor="#D6D6D6"| &nbsp; <br />
|middlegray||bgcolor="#B9B9B9"| &nbsp; <br />
|darkgray||bgcolor="#999999"| &nbsp; <br />
|- <br />
|red||bgcolor="#FF0000"| &nbsp;<br />
|lightred||bgcolor="#FF0000"| &nbsp; <br />
|middlered||bgcolor="#CC0000"| &nbsp; <br />
|darkred||bgcolor="#990000"| &nbsp; <br />
|-<br />
|green||bgcolor="#00FF00"| &nbsp;<br />
|lightgreen||bgcolor="#00FF00"| &nbsp; <br />
|middlegreen||bgcolor="#00CC00"| &nbsp; <br />
|darkgreen||bgcolor="#009900"| &nbsp; <br />
|-<br />
|blue||bgcolor="#0000FF"| &nbsp;<br />
|lightblue||bgcolor="#0000FF"| &nbsp; <br />
|middleblue||bgcolor="#0000CC"| &nbsp; <br />
|darkblue||bgcolor="#000099"| &nbsp; <br />
|-<br />
|cyan||bgcolor="#00FFFF" | &nbsp;<br />
| &nbsp; ||bgcolor=| &nbsp; <br />
|middlecyan||bgcolor="#00CCCC" | &nbsp;<br />
|darkcyan||bgcolor="#006666" | &nbsp;<br />
|-<br />
|magenta||bgcolor="#FF00FF" | &nbsp;<br />
| &nbsp; ||bgcolor=| &nbsp; <br />
|middlemagenta||bgcolor="CC00CC" | &nbsp;<br />
|darkmagenta||bgcolor="660066" | &nbsp;<br />
|-<br />
|yellow||bgcolor="#FFFF00" | &nbsp;<br />
| &nbsp; ||bgcolor=| &nbsp; <br />
|middleyellow||bgcolor="CCCC00" | &nbsp;<br />
|darkyellow||bgcolor="666600" | &nbsp;<br />
<br />
|}<br />
<br />
In addition to thees, many color collections are defined, which are not loaded by default. These can be loaded using<br />
<br />
<texcode>\usecolors[NAME]</texcode><br />
<br />
where <code>NAME</code> is the name of the collection. The details of colors defined in these collections is shown below. You can also include such a detailed description of the colors defined in a color collection using<br />
<br />
<texcode>\showcolor[NAME]</texcode><br />
<br />
For example, the truncated output of <code>\showcolor[crayola]</code> is shown below.<br />
<br />
{| <br />
|-<br />
|<texcode>\showcolor[crayola]</texcode><br />
|<context mode=mkiv>\startTEXpage[height=5cm]\showcolor[crayola]\stopTEXpage</context><br />
|}<br />
<br />
<br />
== Crayola crayon colors == <br />
<br />
The following colors are defined in {{src|colo-imp-crayola.mkiv}}. These can<br />
be loaded using<br />
<br />
<texcode>\usecolors[crayola]</texcode><br />
<br />
<br />
{| style="text-align: right; padding-right: 20px;"<br />
!| Name !! Color <br />
!style="width: 100px;"| Name !! Color <br />
!style="width: 100px;"| Name !! Color <br />
!style="width: 100px;"| Name !! Color<br />
|-<br />
|Red||bgcolor="ED0A3F" | &nbsp; <br />
|Maroon||bgcolor="C32148" | &nbsp; <br />
|Scarlet||bgcolor="FD0E35" | &nbsp; <br />
|BrickRed||bgcolor="C62D42" | &nbsp; <br />
|-<br />
|EnglishVermilion||bgcolor="CC474B" | &nbsp; <br />
|MadderLake||bgcolor="CC3336" | &nbsp; <br />
|PermanentGeraniumLake||bgcolor="E12C2C" | &nbsp; <br />
|MaximumRed||bgcolor="D92121" | &nbsp; <br />
|-<br />
|IndianRed||bgcolor="B94E48" | &nbsp; <br />
|OrangeRed||bgcolor="FF5349" | &nbsp; <br />
|SunsetOrange||bgcolor="FE4C40" | &nbsp; <br />
|Bittersweet||bgcolor="FE6F5E" | &nbsp; <br />
|-<br />
|DarkVenetianRed||bgcolor="B33B24" | &nbsp; <br />
|VenetianRed||bgcolor="CC553D" | &nbsp; <br />
|LightVenetianRed||bgcolor="E6735C" | &nbsp; <br />
|VividTangerine||bgcolor="FF9980" | &nbsp; <br />
|-<br />
|MiddleRed||bgcolor="E58E73" | &nbsp; <br />
|BurntOrange||bgcolor="FF7F49" | &nbsp; <br />
|RedOrange||bgcolor="FF681F" | &nbsp; <br />
|Orange||bgcolor="FF8833" | &nbsp; <br />
|-<br />
|MacaroniandCheese||bgcolor="FFB97B" | &nbsp; <br />
|MiddleYellowRed||bgcolor="ECB176" | &nbsp; <br />
|MangoTango||bgcolor="E77200" | &nbsp; <br />
|YellowOrange||bgcolor="FFAE42" | &nbsp; <br />
|-<br />
|MaximumYellowRed||bgcolor="F2BA49" | &nbsp; <br />
|BananaMania||bgcolor="FBE7B2" | &nbsp; <br />
|Maize||bgcolor="F2C649" | &nbsp; <br />
|OrangeYellow||bgcolor="F8D568" | &nbsp; <br />
|-<br />
|Goldenrod||bgcolor="FCD667" | &nbsp; <br />
|Dandelion||bgcolor="FED85D" | &nbsp; <br />
|Yellow||bgcolor="FBE870" | &nbsp; <br />
|GreenYellow||bgcolor="F1E788" | &nbsp; <br />
|-<br />
|MiddleYellow||bgcolor="FFEB00" | &nbsp; <br />
|OliveGreen||bgcolor="B5B35C" | &nbsp; <br />
|SpringGreen||bgcolor="ECEBBD" | &nbsp; <br />
|MaximumYellow||bgcolor="FAFA37" | &nbsp; <br />
|-<br />
|Canary||bgcolor="FFFF99" | &nbsp; <br />
|LemonYellow||bgcolor="FFFF9F" | &nbsp; <br />
|MaximumGreenYellow||bgcolor="D9E650" | &nbsp; <br />
|MiddleGreenYellow||bgcolor="ACBF60" | &nbsp; <br />
|-<br />
|Inchworm||bgcolor="AFE313" | &nbsp; <br />
|LightChromeGreen||bgcolor="BEE64B" | &nbsp; <br />
|YellowGreen||bgcolor="C5E17A" | &nbsp; <br />
|MaximumGreen||bgcolor="5E8C31" | &nbsp; <br />
|-<br />
|Asparagus||bgcolor="7BA05B" | &nbsp; <br />
|GrannySmithApple||bgcolor="9DE093" | &nbsp; <br />
|Fern||bgcolor="63B76C" | &nbsp; <br />
|MiddleGreen||bgcolor="4D8C57" | &nbsp; <br />
|-<br />
|Green||bgcolor="3AA655" | &nbsp; <br />
|MediumChromeGreen||bgcolor="6CA67C" | &nbsp; <br />
|ForestGreen||bgcolor="5FA777" | &nbsp; <br />
|SeaGreen||bgcolor="93DFB8" | &nbsp; <br />
|-<br />
|Shamrock||bgcolor="33CC99" | &nbsp; <br />
|MountainMeadow||bgcolor="1AB385" | &nbsp; <br />
|JungleGreen||bgcolor="29AB87" | &nbsp; <br />
|CaribbeanGreen||bgcolor="00CC99" | &nbsp; <br />
|-<br />
|TropicalRainForest||bgcolor="00755E" | &nbsp; <br />
|MiddleBlueGreen||bgcolor="8DD9CC" | &nbsp; <br />
|PineGreen||bgcolor="01786F" | &nbsp; <br />
|MaximumBlueGreen||bgcolor="30BFBF" | &nbsp; <br />
|-<br />
|RobinsEggBlue||bgcolor="00CCCC" | &nbsp; <br />
|TealBlue||bgcolor="008080" | &nbsp; <br />
|LightBlue||bgcolor="8FD8D8" | &nbsp; <br />
|Aquamarine||bgcolor="95E0E8" | &nbsp; <br />
|-<br />
|TurquoiseBlue||bgcolor="6CDAE7" | &nbsp; <br />
|OuterSpace||bgcolor="2D383A" | &nbsp; <br />
|SkyBlue||bgcolor="76D7EA" | &nbsp; <br />
|MiddleBlue||bgcolor="7ED4E6" | &nbsp; <br />
|-<br />
|BlueGreen||bgcolor="0095B7" | &nbsp; <br />
|PacificBlue||bgcolor="009DC4" | &nbsp; <br />
|Cerulean||bgcolor="02A4D3" | &nbsp; <br />
|MaximumBlue||bgcolor="47ABCC" | &nbsp; <br />
|-<br />
|BlueI||bgcolor="4997D0" | &nbsp; <br />
|CeruleanBlue||bgcolor="339ACC" | &nbsp; <br />
|Cornflower||bgcolor="93CCEA" | &nbsp; <br />
|GreenBlue||bgcolor="2887C8" | &nbsp; <br />
|-<br />
|MidnightBlue||bgcolor="00468C" | &nbsp; <br />
|NavyBlue||bgcolor="0066CC" | &nbsp; <br />
|Denim||bgcolor="1560BD" | &nbsp; <br />
|BlueIII||bgcolor="0066FF" | &nbsp; <br />
|-<br />
|CadetBlue||bgcolor="A9B2C3" | &nbsp; <br />
|Periwinkle||bgcolor="C3CDE6" | &nbsp; <br />
|BlueII||bgcolor="4570E6" | &nbsp; <br />
|WildBlueYonder||bgcolor="7A89B8" | &nbsp; <br />
|-<br />
|Indigo||bgcolor="4F69C6" | &nbsp; <br />
|Manatee||bgcolor="8D90A1" | &nbsp; <br />
|CobaltBlue||bgcolor="8C90C8" | &nbsp; <br />
|CelestialBlue||bgcolor="7070CC" | &nbsp; <br />
|-<br />
|BlueBell||bgcolor="9999CC" | &nbsp; <br />
|MaximumBluePurple||bgcolor="ACACE6" | &nbsp; <br />
|VioletBlue||bgcolor="766EC8" | &nbsp; <br />
|BlueViolet||bgcolor="6456B7" | &nbsp; <br />
|-<br />
|UltramarineBlue||bgcolor="3F26BF" | &nbsp; <br />
|MiddleBluePurple||bgcolor="8B72BE" | &nbsp; <br />
|PurpleHeart||bgcolor="652DC1" | &nbsp; <br />
|RoyalPurple||bgcolor="6B3FA0" | &nbsp; <br />
|-<br />
|VioletII||bgcolor="8359A3" | &nbsp; <br />
|MediumViolet||bgcolor="8F47B3" | &nbsp; <br />
|Wisteria||bgcolor="C9A0DC" | &nbsp; <br />
|LavenderI||bgcolor="BF8FCC" | &nbsp; <br />
|-<br />
|VividViolet||bgcolor="803790" | &nbsp; <br />
|MaximumPurple||bgcolor="733380" | &nbsp; <br />
|PurpleMountainsMajesty||bgcolor="D6AEDD" | &nbsp; <br />
|Fuchsia||bgcolor="C154C1" | &nbsp; <br />
|-<br />
|PinkFlamingo||bgcolor="FC74FD" | &nbsp; <br />
|VioletI||bgcolor="732E6C" | &nbsp; <br />
|BrilliantRose||bgcolor="E667CE" | &nbsp; <br />
|Orchid||bgcolor="E29CD2" | &nbsp; <br />
|-<br />
|Plum||bgcolor="8E3179" | &nbsp; <br />
|MediumRose||bgcolor="D96CBE" | &nbsp; <br />
|Thistle||bgcolor="EBB0D7" | &nbsp; <br />
|Mulberry||bgcolor="C8509B" | &nbsp; <br />
|-<br />
|RedViolet||bgcolor="BB3385" | &nbsp; <br />
|MiddlePurple||bgcolor="D982B5" | &nbsp; <br />
|MaximumRedPurple||bgcolor="A63A79" | &nbsp; <br />
|JazzberryJam||bgcolor="A50B5E" | &nbsp; <br />
|-<br />
|Eggplant||bgcolor="614051" | &nbsp; <br />
|Magenta||bgcolor="F653A6" | &nbsp; <br />
|Cerise||bgcolor="DA3287" | &nbsp; <br />
|WildStrawberry||bgcolor="FF3399" | &nbsp; <br />
|-<br />
|LavenderII||bgcolor="FBAED2" | &nbsp; <br />
|CottonCandy||bgcolor="FFB7D5" | &nbsp; <br />
|CarnationPink||bgcolor="FFA6C9" | &nbsp; <br />
|VioletRed||bgcolor="F7468A" | &nbsp; <br />
|-<br />
|Razzmatazz||bgcolor="E30B5C" | &nbsp; <br />
|PigPink||bgcolor="FDD7E4" | &nbsp; <br />
|Carmine||bgcolor="E62E6B" | &nbsp; <br />
|Blush||bgcolor="DB5079" | &nbsp; <br />
|-<br />
|TickleMePink||bgcolor="FC80A5" | &nbsp; <br />
|Mauvelous||bgcolor="F091A9" | &nbsp; <br />
|Salmon||bgcolor="FF91A4" | &nbsp; <br />
|MiddleRedPurple||bgcolor="A55353" | &nbsp; <br />
|-<br />
|Mahogany||bgcolor="CA3435" | &nbsp; <br />
|Melon||bgcolor="FEBAAD" | &nbsp; <br />
|PinkSherbert||bgcolor="F7A38E" | &nbsp; <br />
|BurntSienna||bgcolor="E97451" | &nbsp; <br />
|-<br />
|Brown||bgcolor="AF593E" | &nbsp; <br />
|Sepia||bgcolor="9E5B40" | &nbsp; <br />
|FuzzyWuzzy||bgcolor="87421F" | &nbsp; <br />
|Beaver||bgcolor="926F5B" | &nbsp; <br />
|-<br />
|Tumbleweed||bgcolor="DEA681" | &nbsp; <br />
|RawSienna||bgcolor="D27D46" | &nbsp; <br />
|VanDykeBrown||bgcolor="664228" | &nbsp; <br />
|Tan||bgcolor="D99A6C" | &nbsp; <br />
|-<br />
|DesertSand||bgcolor="EDC9AF" | &nbsp; <br />
|Peach||bgcolor="FFCBA4" | &nbsp; <br />
|BurntUmber||bgcolor="805533" | &nbsp; <br />
|Apricot||bgcolor="FDD5B1" | &nbsp; <br />
|-<br />
|Almond||bgcolor="EED9C4" | &nbsp; <br />
|RawUmber||bgcolor="665233" | &nbsp; <br />
|Shadow||bgcolor="837050" | &nbsp; <br />
|RawSiennaI||bgcolor="E6BC5C" | &nbsp; <br />
|-<br />
|Timberwolf||bgcolor="D9D6CF" | &nbsp; <br />
|GoldI||bgcolor="92926E" | &nbsp; <br />
|GoldII||bgcolor="E6BE8A" | &nbsp; <br />
|Silver||bgcolor="C9C0BB" | &nbsp; <br />
|-<br />
|Copper||bgcolor="DA8A67" | &nbsp; <br />
|AntiqueBrass||bgcolor="C88A65" | &nbsp; <br />
|Black||bgcolor="000000" | &nbsp; <br />
|CharcoalGray||bgcolor="736A62" | &nbsp; <br />
|-<br />
|Gray||bgcolor="8B8680" | &nbsp; <br />
|BlueGray||bgcolor="C8C8CD" | &nbsp; <br />
|White||bgcolor="FFFFFF" | &nbsp; <br />
|RadicalRed||bgcolor="FF355E" | &nbsp; <br />
|-<br />
|WildWatermelon||bgcolor="FD5B78" | &nbsp; <br />
|OutrageousOrange||bgcolor="FF6037" | &nbsp; <br />
|AtomicTangerine||bgcolor="FF9966" | &nbsp; <br />
|NeonCarrot||bgcolor="FF9933" | &nbsp; <br />
|-<br />
|Sunglow||bgcolor="FFCC33" | &nbsp; <br />
|LaserLemon||bgcolor="FFFF66" | &nbsp; <br />
|UnmellowYellow||bgcolor="FFFF66" | &nbsp; <br />
|ElectricLime||bgcolor="CCFF00" | &nbsp; <br />
|-<br />
|ScreaminGreen||bgcolor="66FF66" | &nbsp; <br />
|MagicMint||bgcolor="AAF0D1" | &nbsp; <br />
|BlizzardBlue||bgcolor="50BFE6" | &nbsp; <br />
|ShockingPink||bgcolor="FF6EFF" | &nbsp; <br />
|-<br />
|RazzleDazzleRose||bgcolor="EE34D2" | &nbsp; <br />
|HotMagenta||bgcolor="FF00CC" | &nbsp; <br />
|PurplePizzazz||bgcolor="FF00CC" | &nbsp; <br />
|AztecGold||bgcolor="C39953" | &nbsp;<br />
|-<br />
|BurnishedBrown||bgcolor="A17A74" | &nbsp;<br />
|CeruleanFrost||bgcolor="6D9BC3" | &nbsp;<br />
|CinnamonSatin||bgcolor="CD607E" | &nbsp;<br />
|CopperPenny||bgcolor="AD6F69" | &nbsp;<br />
|-<br />
|CosmicCobalt||bgcolor="2E2D88" | &nbsp;<br />
|GlossyGrape||bgcolor="AB92B3" | &nbsp;<br />
|GraniteGray||bgcolor="676767" | &nbsp;<br />
|GreenSheen||bgcolor="6EAEA1" | &nbsp;<br />
|-<br />
|LilacLuster||bgcolor="AE98AA" | &nbsp;<br />
|MistyMoss||bgcolor="BBB477" | &nbsp;<br />
|MysticMaroon||bgcolor="AD4379" | &nbsp;<br />
|PearlyPurple||bgcolor="B768A2" | &nbsp;<br />
|-<br />
|PewterBlue||bgcolor="8BA8B7" | &nbsp;<br />
|PolishedPine||bgcolor="5DA493" | &nbsp;<br />
|QuickSilver||bgcolor="A6A6A6" | &nbsp;<br />
|RoseDust||bgcolor="9E5E6F" | &nbsp;<br />
|-<br />
|RustyRed||bgcolor="DA2C43" | &nbsp;<br />
|ShadowBlue||bgcolor="778BA5" | &nbsp;<br />
|ShinyShamrock||bgcolor="5FA778" | &nbsp;<br />
|SteelTeal||bgcolor="5F8A8B" | &nbsp;<br />
|-<br />
|SugarPlum||bgcolor="914E75" | &nbsp;<br />
|TwilightLavender||bgcolor="8A496B" | &nbsp;<br />
|WintergreenDream||bgcolor="56887D" | &nbsp;<br />
|Amethyst||bgcolor="64609A" | &nbsp;<br />
|-<br />
|Citrine||bgcolor="933709" | &nbsp;<br />
|Emerald||bgcolor="14A989" | &nbsp;<br />
|Jade||bgcolor="469A84" | &nbsp;<br />
|Jasper||bgcolor="D05340" | &nbsp;<br />
|-<br />
|LapisLazuli||bgcolor="436CB9" | &nbsp;<br />
|Malachite||bgcolor="469496" | &nbsp;<br />
|Moonstone||bgcolor="3AA8C1" | &nbsp;<br />
|Onyx||bgcolor="353839" | &nbsp;<br />
|-<br />
|Peridot||bgcolor="ABAD48" | &nbsp;<br />
|PinkPearl||bgcolor="B07080" | &nbsp;<br />
|RoseQuartz||bgcolor="BD559C" | &nbsp;<br />
|Ruby||bgcolor="AA4069" | &nbsp;<br />
|-<br />
|Sapphire||bgcolor="2D5DA1" | &nbsp;<br />
|SmokeyTopaz||bgcolor="832A0D" | &nbsp;<br />
|TigersEye||bgcolor="B56917" | &nbsp;<br />
|AquaPearl||bgcolor="5FBED7" | &nbsp;<br />
|-<br />
|BlackCoralPearl||bgcolor="54626F" | &nbsp;<br />
|CaribbeanGreenPearl||bgcolor="6ADA8E" | &nbsp;<br />
|CulturedPearl||bgcolor="F5F5F5" | &nbsp;<br />
|KeyLimePearl||bgcolor="E8F48C" | &nbsp;<br />
|-<br />
|MandarinPearl||bgcolor="F37A48" | &nbsp;<br />
|MidnightPearl||bgcolor="702670" | &nbsp;<br />
|MysticPearl||bgcolor="D65282" | &nbsp;<br />
|OceanBluePearl||bgcolor="4F42B5" | &nbsp;<br />
|-<br />
|OceanGreenPearl||bgcolor="48BF91" | &nbsp;<br />
|OrchidPearl||bgcolor="7B4259" | &nbsp;<br />
|RosePearl||bgcolor="F03865" | &nbsp;<br />
|SalmonPearl||bgcolor="F1444A" | &nbsp;<br />
|-<br />
|SunnyPearl||bgcolor="F2F27A" | &nbsp;<br />
|SunsetPearl||bgcolor="F1CC79" | &nbsp;<br />
|}<br />
<br />
== RAL colors == <br />
<br />
RAL color system (Deutsches Institut für Gütesicherung und Kennzeichnung)<br />
approximate RGB colors (from [http://www.ralcolor.com www.ralcolor.com]). These are defined in {{src|colo-imp-ral.mkiv}} and can be loaded using<br />
<br />
<texcode>\usecolors[ral]</texcode><br />
<br />
{| style="text-align: right; padding-right: 20px;"<br />
!| Name !! Color <br />
!style="width: 100px;"| Name !! Color <br />
!style="width: 100px;"| Name !! Color <br />
!style="width: 100px;"| Name !! Color<br />
!style="width: 100px;"| Name !! Color <br />
!style="width: 100px;"| Name !! Color<br />
|-<br />
|RAL1000||bgcolor="BEBD7F" | &nbsp; <br />
|RAL1001||bgcolor="C2B078" | &nbsp; <br />
|RAL1002||bgcolor="C6A664" | &nbsp; <br />
|RAL1003||bgcolor="E5BE01" | &nbsp; <br />
|RAL1004||bgcolor="CDA434" | &nbsp; <br />
|RAL1005||bgcolor="A98307" | &nbsp; <br />
|-<br />
|RAL1006||bgcolor="E4A010" | &nbsp; <br />
|RAL1007||bgcolor="DC9D00" | &nbsp; <br />
|RAL1011||bgcolor="8A6642" | &nbsp; <br />
|RAL1012||bgcolor="C7B446" | &nbsp; <br />
|RAL1013||bgcolor="EAE6CA" | &nbsp; <br />
|RAL1014||bgcolor="E1CC4F" | &nbsp; <br />
|-<br />
|RAL1015||bgcolor="E6D690" | &nbsp; <br />
|RAL1016||bgcolor="EDFF21" | &nbsp; <br />
|RAL1017||bgcolor="F5D033" | &nbsp; <br />
|RAL1018||bgcolor="F8F32B" | &nbsp; <br />
|RAL1019||bgcolor="9E9764" | &nbsp; <br />
|RAL1020||bgcolor="999950" | &nbsp; <br />
|-<br />
|RAL1021||bgcolor="F3DA0B" | &nbsp; <br />
|RAL1023||bgcolor="FAD201" | &nbsp; <br />
|RAL1024||bgcolor="AEA04B" | &nbsp; <br />
|RAL1026||bgcolor="FFFF00" | &nbsp; <br />
|RAL1027||bgcolor="9D9101" | &nbsp; <br />
|RAL1028||bgcolor="F4A900" | &nbsp; <br />
|-<br />
|RAL1032||bgcolor="D6AE01" | &nbsp; <br />
|RAL1033||bgcolor="F3A505" | &nbsp; <br />
|RAL1034||bgcolor="EFA94A" | &nbsp; <br />
|RAL1035||bgcolor="6A5D4D" | &nbsp; <br />
|RAL1036||bgcolor="705335" | &nbsp; <br />
|RAL1037||bgcolor="F39F18" | &nbsp; <br />
|-<br />
|RAL2000||bgcolor="ED760E" | &nbsp; <br />
|RAL2001||bgcolor="C93C20" | &nbsp; <br />
|RAL2002||bgcolor="CB2821" | &nbsp; <br />
|RAL2003||bgcolor="FF7514" | &nbsp; <br />
|RAL2004||bgcolor="F44611" | &nbsp; <br />
|RAL2005||bgcolor="FF2301" | &nbsp; <br />
|-<br />
|RAL2007||bgcolor="FFA420" | &nbsp; <br />
|RAL2008||bgcolor="F75E25" | &nbsp; <br />
|RAL2009||bgcolor="F54021" | &nbsp; <br />
|RAL2010||bgcolor="D84B20" | &nbsp; <br />
|RAL2011||bgcolor="EC7C26" | &nbsp; <br />
|RAL2012||bgcolor="E55137" | &nbsp; <br />
|-<br />
|RAL2013||bgcolor="C35831" | &nbsp; <br />
|RAL3000||bgcolor="AF2B1E" | &nbsp; <br />
|RAL3001||bgcolor="A52019" | &nbsp; <br />
|RAL3002||bgcolor="A2231D" | &nbsp; <br />
|RAL3003||bgcolor="9B111E" | &nbsp; <br />
|RAL3004||bgcolor="75151E" | &nbsp; <br />
|-<br />
|RAL3005||bgcolor="5E2129" | &nbsp; <br />
|RAL3007||bgcolor="412227" | &nbsp; <br />
|RAL3009||bgcolor="642424" | &nbsp; <br />
|RAL3011||bgcolor="781F19" | &nbsp; <br />
|RAL3012||bgcolor="C1876B" | &nbsp; <br />
|RAL3013||bgcolor="A12312" | &nbsp; <br />
|-<br />
|RAL3014||bgcolor="D36E70" | &nbsp; <br />
|RAL3015||bgcolor="EA899A" | &nbsp; <br />
|RAL3016||bgcolor="B32821" | &nbsp; <br />
|RAL3017||bgcolor="E63244" | &nbsp; <br />
|RAL3018||bgcolor="D53032" | &nbsp; <br />
|RAL3020||bgcolor="CC0605" | &nbsp; <br />
|-<br />
|RAL3022||bgcolor="D95030" | &nbsp; <br />
|RAL3024||bgcolor="F80000" | &nbsp; <br />
|RAL3026||bgcolor="FE0000" | &nbsp; <br />
|RAL3027||bgcolor="C51D34" | &nbsp; <br />
|RAL3028||bgcolor="CB3234" | &nbsp; <br />
|RAL3031||bgcolor="B32428" | &nbsp; <br />
|-<br />
|RAL3032||bgcolor="721422" | &nbsp; <br />
|RAL3033||bgcolor="B44C43" | &nbsp; <br />
|RAL4001||bgcolor="6D3F5B" | &nbsp; <br />
|RAL4002||bgcolor="922B3E" | &nbsp; <br />
|RAL4003||bgcolor="DE4C8A" | &nbsp; <br />
|RAL4004||bgcolor="641C34" | &nbsp; <br />
|-<br />
|RAL4005||bgcolor="6C4675" | &nbsp; <br />
|RAL4006||bgcolor="A03472" | &nbsp; <br />
|RAL4007||bgcolor="4A192C" | &nbsp; <br />
|RAL4008||bgcolor="924E7D" | &nbsp; <br />
|RAL4009||bgcolor="A18594" | &nbsp; <br />
|RAL4010||bgcolor="CF3476" | &nbsp; <br />
|-<br />
|RAL4011||bgcolor="8673A1" | &nbsp; <br />
|RAL4012||bgcolor="6C6874" | &nbsp; <br />
|RAL5000||bgcolor="354D73" | &nbsp; <br />
|RAL5001||bgcolor="1F3438" | &nbsp; <br />
|RAL5002||bgcolor="20214F" | &nbsp; <br />
|RAL5003||bgcolor="1D1E33" | &nbsp; <br />
|-<br />
|RAL5004||bgcolor="18171C" | &nbsp; <br />
|RAL5005||bgcolor="1E2460" | &nbsp; <br />
|RAL5007||bgcolor="3E5F8A" | &nbsp; <br />
|RAL5008||bgcolor="26252D" | &nbsp; <br />
|RAL5009||bgcolor="025669" | &nbsp; <br />
|RAL5010||bgcolor="0E294B" | &nbsp; <br />
|-<br />
|RAL5011||bgcolor="231A24" | &nbsp; <br />
|RAL5012||bgcolor="3B83BD" | &nbsp; <br />
|RAL5013||bgcolor="1E213D" | &nbsp; <br />
|RAL5014||bgcolor="606E8C" | &nbsp; <br />
|RAL5015||bgcolor="2271B3" | &nbsp; <br />
|RAL5017||bgcolor="063971" | &nbsp; <br />
|-<br />
|RAL5018||bgcolor="3F888F" | &nbsp; <br />
|RAL5019||bgcolor="1B5583" | &nbsp; <br />
|RAL5020||bgcolor="1D334A" | &nbsp; <br />
|RAL5021||bgcolor="256D7B" | &nbsp; <br />
|RAL5022||bgcolor="252850" | &nbsp; <br />
|RAL5023||bgcolor="49678D" | &nbsp; <br />
|-<br />
|RAL5024||bgcolor="5D9B9B" | &nbsp; <br />
|RAL5025||bgcolor="2A6478" | &nbsp; <br />
|RAL5026||bgcolor="102C54" | &nbsp; <br />
|RAL6000||bgcolor="316650" | &nbsp; <br />
|RAL6001||bgcolor="287233" | &nbsp; <br />
|RAL6002||bgcolor="2D572C" | &nbsp; <br />
|-<br />
|RAL6003||bgcolor="424632" | &nbsp; <br />
|RAL6004||bgcolor="1F3A3D" | &nbsp; <br />
|RAL6005||bgcolor="2F4538" | &nbsp; <br />
|RAL6006||bgcolor="3E3B32" | &nbsp; <br />
|RAL6007||bgcolor="343B29" | &nbsp; <br />
|RAL6008||bgcolor="39352A" | &nbsp; <br />
|-<br />
|RAL6009||bgcolor="31372B" | &nbsp; <br />
|RAL6010||bgcolor="35682D" | &nbsp; <br />
|RAL6011||bgcolor="587246" | &nbsp; <br />
|RAL6012||bgcolor="343E40" | &nbsp; <br />
|RAL6013||bgcolor="6C7156" | &nbsp; <br />
|RAL6014||bgcolor="47402E" | &nbsp; <br />
|-<br />
|RAL6015||bgcolor="3B3C36" | &nbsp; <br />
|RAL6016||bgcolor="1E5945" | &nbsp; <br />
|RAL6017||bgcolor="4C9141" | &nbsp; <br />
|RAL6018||bgcolor="57A639" | &nbsp; <br />
|RAL6019||bgcolor="BDECB6" | &nbsp; <br />
|RAL6020||bgcolor="2E3A23" | &nbsp; <br />
|-<br />
|RAL6021||bgcolor="89AC76" | &nbsp; <br />
|RAL6022||bgcolor="25221B" | &nbsp; <br />
|RAL6024||bgcolor="308446" | &nbsp; <br />
|RAL6025||bgcolor="3D642D" | &nbsp; <br />
|RAL6026||bgcolor="015D52" | &nbsp; <br />
|RAL6027||bgcolor="84C3BE" | &nbsp; <br />
|-<br />
|RAL6028||bgcolor="2C5545" | &nbsp; <br />
|RAL6029||bgcolor="20603D" | &nbsp; <br />
|RAL6032||bgcolor="317F43" | &nbsp; <br />
|RAL6033||bgcolor="497E76" | &nbsp; <br />
|RAL6034||bgcolor="7FB5B5" | &nbsp; <br />
|RAL6035||bgcolor="1C542D" | &nbsp; <br />
|-<br />
|RAL6036||bgcolor="193737" | &nbsp; <br />
|RAL6037||bgcolor="008F39" | &nbsp; <br />
|RAL6038||bgcolor="00BB2D" | &nbsp; <br />
|RAL7000||bgcolor="78858B" | &nbsp; <br />
|RAL7001||bgcolor="8A9597" | &nbsp; <br />
|RAL7002||bgcolor="7E7B52" | &nbsp; <br />
|-<br />
|RAL7003||bgcolor="6C7059" | &nbsp; <br />
|RAL7004||bgcolor="969992" | &nbsp; <br />
|RAL7005||bgcolor="646B63" | &nbsp; <br />
|RAL7006||bgcolor="6D6552" | &nbsp; <br />
|RAL7008||bgcolor="6A5F31" | &nbsp; <br />
|RAL7009||bgcolor="4D5645" | &nbsp; <br />
|-<br />
|RAL7010||bgcolor="4C514A" | &nbsp; <br />
|RAL7011||bgcolor="434B4D" | &nbsp; <br />
|RAL7012||bgcolor="4E5754" | &nbsp; <br />
|RAL7013||bgcolor="464531" | &nbsp; <br />
|RAL7015||bgcolor="434750" | &nbsp; <br />
|RAL7016||bgcolor="293133" | &nbsp; <br />
|-<br />
|RAL7021||bgcolor="23282B" | &nbsp; <br />
|RAL7022||bgcolor="332F2C" | &nbsp; <br />
|RAL7023||bgcolor="686C5E" | &nbsp; <br />
|RAL7024||bgcolor="474A51" | &nbsp; <br />
|RAL7026||bgcolor="2F353B" | &nbsp; <br />
|RAL7030||bgcolor="8B8C7A" | &nbsp; <br />
|-<br />
|RAL7031||bgcolor="474B4E" | &nbsp; <br />
|RAL7032||bgcolor="B8B799" | &nbsp; <br />
|RAL7033||bgcolor="7D8471" | &nbsp; <br />
|RAL7034||bgcolor="8F8B66" | &nbsp; <br />
|RAL7035||bgcolor="D7D7D7" | &nbsp; <br />
|RAL7036||bgcolor="7F7679" | &nbsp; <br />
|-<br />
|RAL7037||bgcolor="7D7F7D" | &nbsp; <br />
|RAL7038||bgcolor="B5B8B1" | &nbsp; <br />
|RAL7039||bgcolor="6C6960" | &nbsp; <br />
|RAL7040||bgcolor="9DA1AA" | &nbsp; <br />
|RAL7042||bgcolor="8D948D" | &nbsp; <br />
|RAL7043||bgcolor="4E5452" | &nbsp; <br />
|-<br />
|RAL7044||bgcolor="CAC4B0" | &nbsp; <br />
|RAL7045||bgcolor="909090" | &nbsp; <br />
|RAL7046||bgcolor="82898F" | &nbsp; <br />
|RAL7047||bgcolor="D0D0D0" | &nbsp; <br />
|RAL7048||bgcolor="898176" | &nbsp; <br />
|RAL8000||bgcolor="826C34" | &nbsp; <br />
|-<br />
|RAL8001||bgcolor="955F20" | &nbsp; <br />
|RAL8002||bgcolor="6C3B2A" | &nbsp; <br />
|RAL8003||bgcolor="734222" | &nbsp; <br />
|RAL8004||bgcolor="8E402A" | &nbsp; <br />
|RAL8007||bgcolor="59351F" | &nbsp; <br />
|RAL8008||bgcolor="6F4F28" | &nbsp; <br />
|-<br />
|RAL8011||bgcolor="5B3A29" | &nbsp; <br />
|RAL8012||bgcolor="592321" | &nbsp; <br />
|RAL8014||bgcolor="382C1E" | &nbsp; <br />
|RAL8015||bgcolor="633A34" | &nbsp; <br />
|RAL8016||bgcolor="4C2F27" | &nbsp; <br />
|RAL8017||bgcolor="45322E" | &nbsp; <br />
|-<br />
|RAL8019||bgcolor="403A3A" | &nbsp; <br />
|RAL8022||bgcolor="212121" | &nbsp; <br />
|RAL8023||bgcolor="A65E2E" | &nbsp; <br />
|RAL8024||bgcolor="79553D" | &nbsp; <br />
|RAL8025||bgcolor="755C48" | &nbsp; <br />
|RAL8028||bgcolor="4E3B31" | &nbsp; <br />
|-<br />
|RAL8029||bgcolor="763C28" | &nbsp; <br />
|RAL9001||bgcolor="FDF4E3" | &nbsp; <br />
|RAL9002||bgcolor="E7EBDA" | &nbsp; <br />
|RAL9003||bgcolor="F4F4F4" | &nbsp; <br />
|RAL9004||bgcolor="282828" | &nbsp; <br />
|RAL9005||bgcolor="0A0A0A" | &nbsp; <br />
|-<br />
|RAL9006||bgcolor="A5A5A5" | &nbsp; <br />
|RAL9007||bgcolor="8F8F8F" | &nbsp; <br />
|RAL9010||bgcolor="FFFFFF" | &nbsp; <br />
|RAL9011||bgcolor="1C1C1C" | &nbsp; <br />
|RAL9016||bgcolor="F6F6F6" | &nbsp; <br />
|RAL9017||bgcolor="1E1E1E" | &nbsp; <br />
|-<br />
|RAL9018||bgcolor="D7D7D7" | &nbsp; <br />
|RAL9022||bgcolor="9C9C9C" | &nbsp; <br />
|RAL9023||bgcolor="828282" | &nbsp; <br />
|}<br />
<br />
== Solarized colors == <br />
<br />
Colors based on the [http://ethanschoonover.com/solarized Solarized] color scheme.<br />
These are defined in {{src|colo-imp-solarized.mkiv}} and can be loaded using<br />
<br />
<texcode>\usecolors[solarized]</texcode><br />
<br />
{| style="text-align: right; padding-right: 20px;"<br />
!| Name !! Color <br />
!style="width: 100px;"| Name !! Color <br />
!style="width: 100px;"| Name !! Color <br />
!style="width: 100px;"| Name !! Color<br />
|-<br />
|base03||bgcolor="002b36" | &nbsp;<br />
|base02||bgcolor="073642" | &nbsp;<br />
|base01||bgcolor="586e75" | &nbsp;<br />
|base00||bgcolor="657b83" | &nbsp;<br />
|-<br />
|base0||bgcolor="839496" | &nbsp;<br />
|base1||bgcolor="93a1a1" | &nbsp;<br />
|base2||bgcolor="eee8d5" | &nbsp;<br />
|base3||bgcolor="fdf6e3" | &nbsp;<br />
|-<br />
|yellow||bgcolor="b58900" | &nbsp;<br />
|orange||bgcolor="cb4b16" | &nbsp;<br />
|red||bgcolor="dc322f" | &nbsp;<br />
|magenta||bgcolor="d33682" | &nbsp;<br />
|-<br />
|violet||bgcolor="6c71c4" | &nbsp;<br />
|blue||bgcolor="268bd2" | &nbsp;<br />
|cyan||bgcolor="2aa198" | &nbsp;<br />
|green||bgcolor="859900" | &nbsp;<br />
|}<br />
<br />
== SVG colors == <br />
<br />
Colors based on the [http://www.december.com/html/spec/colorsvghex.html SVG]<br />
spec. These are defined in {{src|colo-imp-svg.mkiv}} and can be loaded using<br />
<br />
<texcode>\usecolors[svg]</texcode><br />
<br />
{| style="text-align: right; padding-right: 20px;"<br />
!| Name !! Color <br />
!style="width: 100px;"| Name !! Color <br />
!style="width: 100px;"| Name !! Color <br />
!style="width: 100px;"| Name !! Color<br />
|-<br />
|black||bgcolor="000000" | &nbsp;<br />
|navy||bgcolor="000080" | &nbsp;<br />
|darkblue||bgcolor="00008B" | &nbsp;<br />
|mediumblue||bgcolor="0000CD" | &nbsp;<br />
|-<br />
|blue||bgcolor="0000FF" | &nbsp;<br />
|darkgreen||bgcolor="006400" | &nbsp;<br />
|green||bgcolor="008000" | &nbsp;<br />
|teal||bgcolor="008080" | &nbsp;<br />
|-<br />
|darkcyan||bgcolor="008B8B" | &nbsp;<br />
|deepskyblue||bgcolor="00BFFF" | &nbsp;<br />
|darkturquoise||bgcolor="00CED1" | &nbsp;<br />
|mediumspringgreen||bgcolor="00FA9A" | &nbsp;<br />
|-<br />
|lime||bgcolor="00FF00" | &nbsp;<br />
|springgreen||bgcolor="00FF7F" | &nbsp;<br />
|cyan||bgcolor="00FFFF" | &nbsp;<br />
|aqua||bgcolor="00FFFF" | &nbsp;<br />
|-<br />
|midnightblue||bgcolor="191970" | &nbsp;<br />
|dodgerblue||bgcolor="1E90FF" | &nbsp;<br />
|lightseagreen||bgcolor="20B2AA" | &nbsp;<br />
|forestgreen||bgcolor="228B22" | &nbsp;<br />
|-<br />
|seagreen||bgcolor="2E8B57" | &nbsp;<br />
|darkslategray||bgcolor="2F4F4F" | &nbsp;<br />
|darkslategrey||bgcolor="2F4F4F" | &nbsp;<br />
|limegreen||bgcolor="32CD32" | &nbsp;<br />
|-<br />
|mediumseagreen||bgcolor="3CB371" | &nbsp;<br />
|turquoise||bgcolor="40E0D0" | &nbsp;<br />
|royalblue||bgcolor="4169E1" | &nbsp;<br />
|steelblue||bgcolor="4682B4" | &nbsp;<br />
|-<br />
|darkslateblue||bgcolor="483D8B" | &nbsp;<br />
|mediumturquoise||bgcolor="48D1CC" | &nbsp;<br />
|indigo||bgcolor="4B0082" | &nbsp;<br />
|darkolivegreen||bgcolor="556B2F" | &nbsp;<br />
|-<br />
|cadetblue||bgcolor="5F9EA0" | &nbsp;<br />
|cornflowerblue||bgcolor="6495ED" | &nbsp;<br />
|mediumaquamarine||bgcolor="66CDAA" | &nbsp;<br />
|dimgrey||bgcolor="696969" | &nbsp;<br />
|-<br />
|dimgray||bgcolor="696969" | &nbsp;<br />
|slateblue||bgcolor="6A5ACD" | &nbsp;<br />
|olivedrab||bgcolor="6B8E23" | &nbsp;<br />
|slategrey||bgcolor="708090" | &nbsp;<br />
|-<br />
|slategray||bgcolor="708090" | &nbsp;<br />
|lightslategray||bgcolor="778899" | &nbsp;<br />
|lightslategrey||bgcolor="778899" | &nbsp;<br />
|mediumslateblue||bgcolor="7B68EE" | &nbsp;<br />
|-<br />
|lawngreen||bgcolor="7CFC00" | &nbsp;<br />
|chartreuse||bgcolor="7FFF00" | &nbsp;<br />
|aquamarine||bgcolor="7FFFD4" | &nbsp;<br />
|maroon||bgcolor="800000" | &nbsp;<br />
|-<br />
|purple||bgcolor="800080" | &nbsp;<br />
|olive||bgcolor="808000" | &nbsp;<br />
|gray||bgcolor="808080" | &nbsp;<br />
|grey||bgcolor="808080" | &nbsp;<br />
|-<br />
|skyblue||bgcolor="87CEEB" | &nbsp;<br />
|lightskyblue||bgcolor="87CEFA" | &nbsp;<br />
|blueviolet||bgcolor="8A2BE2" | &nbsp;<br />
|darkred||bgcolor="8B0000" | &nbsp;<br />
|-<br />
|darkmagenta||bgcolor="8B008B" | &nbsp;<br />
|saddlebrown||bgcolor="8B4513" | &nbsp;<br />
|darkseagreen||bgcolor="8FBC8F" | &nbsp;<br />
|lightgreen||bgcolor="90EE90" | &nbsp;<br />
|-<br />
|mediumpurple||bgcolor="9370DB" | &nbsp;<br />
|darkviolet||bgcolor="9400D3" | &nbsp;<br />
|palegreen||bgcolor="98FB98" | &nbsp;<br />
|darkorchid||bgcolor="9932CC" | &nbsp;<br />
|-<br />
|yellowgreen||bgcolor="9ACD32" | &nbsp;<br />
|sienna||bgcolor="A0522D" | &nbsp;<br />
|brown||bgcolor="A52A2A" | &nbsp;<br />
|darkgray||bgcolor="A9A9A9" | &nbsp;<br />
|-<br />
|darkgrey||bgcolor="A9A9A9" | &nbsp;<br />
|lightblue||bgcolor="ADD8E6" | &nbsp;<br />
|greenyellow||bgcolor="ADFF2F" | &nbsp;<br />
|paleturquoise||bgcolor="AFEEEE" | &nbsp;<br />
|-<br />
|lightsteelblue||bgcolor="B0C4DE" | &nbsp;<br />
|powderblue||bgcolor="B0E0E6" | &nbsp;<br />
|firebrick||bgcolor="B22222" | &nbsp;<br />
|darkgoldenrod||bgcolor="B8860B" | &nbsp;<br />
|-<br />
|mediumorchid||bgcolor="BA55D3" | &nbsp;<br />
|rosybrown||bgcolor="BC8F8F" | &nbsp;<br />
|darkkhaki||bgcolor="BDB76B" | &nbsp;<br />
|silver||bgcolor="C0C0C0" | &nbsp;<br />
|-<br />
|mediumvioletred||bgcolor="C71585" | &nbsp;<br />
|indianred||bgcolor="CD5C5C" | &nbsp;<br />
|peru||bgcolor="CD853F" | &nbsp;<br />
|chocolate||bgcolor="D2691E" | &nbsp;<br />
|-<br />
|tan||bgcolor="D2B48C" | &nbsp;<br />
|lightgray||bgcolor="D3D3D3" | &nbsp;<br />
|lightgrey||bgcolor="D3D3D3" | &nbsp;<br />
|thistle||bgcolor="D8BFD8" | &nbsp;<br />
|-<br />
|orchid||bgcolor="DA70D6" | &nbsp;<br />
|goldenrod||bgcolor="DAA520" | &nbsp;<br />
|palevioletred||bgcolor="DB7093" | &nbsp;<br />
|crimson||bgcolor="DC143C" | &nbsp;<br />
|-<br />
|gainsboro||bgcolor="DCDCDC" | &nbsp;<br />
|plum||bgcolor="DDA0DD" | &nbsp;<br />
|burlywood||bgcolor="DEB887" | &nbsp;<br />
|lightcyan||bgcolor="E0FFFF" | &nbsp;<br />
|-<br />
|lavender||bgcolor="E6E6FA" | &nbsp;<br />
|darksalmon||bgcolor="E9967A" | &nbsp;<br />
|violet||bgcolor="EE82EE" | &nbsp;<br />
|palegoldenrod||bgcolor="EEE8AA" | &nbsp;<br />
|-<br />
|lightcoral||bgcolor="F08080" | &nbsp;<br />
|khaki||bgcolor="F0E68C" | &nbsp;<br />
|aliceblue||bgcolor="F0F8FF" | &nbsp;<br />
|honeydew||bgcolor="F0FFF0" | &nbsp;<br />
|-<br />
|azure||bgcolor="F0FFFF" | &nbsp;<br />
|sandybrown||bgcolor="F4A460" | &nbsp;<br />
|wheat||bgcolor="F5DEB3" | &nbsp;<br />
|beige||bgcolor="F5F5DC" | &nbsp;<br />
|-<br />
|whitesmoke||bgcolor="F5F5F5" | &nbsp;<br />
|mintcream||bgcolor="F5FFFA" | &nbsp;<br />
|ghostwhite||bgcolor="F8F8FF" | &nbsp;<br />
|salmon||bgcolor="FA8072" | &nbsp;<br />
|-<br />
|antiquewhite||bgcolor="FAEBD7" | &nbsp;<br />
|linen||bgcolor="FAF0E6" | &nbsp;<br />
|lightgoldenrodyellow||bgcolor="FAFAD2" | &nbsp;<br />
|oldlace||bgcolor="FDF5E6" | &nbsp;<br />
|-<br />
|red||bgcolor="FF0000" | &nbsp;<br />
|fuchsia||bgcolor="FF00FF" | &nbsp;<br />
|magenta||bgcolor="FF00FF" | &nbsp;<br />
|deeppink||bgcolor="FF1493" | &nbsp;<br />
|-<br />
|orangered||bgcolor="FF4500" | &nbsp;<br />
|tomato||bgcolor="FF6347" | &nbsp;<br />
|hotpink||bgcolor="FF69B4" | &nbsp;<br />
|coral||bgcolor="FF7F50" | &nbsp;<br />
|-<br />
|darkorange||bgcolor="FF8C00" | &nbsp;<br />
|lightsalmon||bgcolor="FFA07A" | &nbsp;<br />
|orange||bgcolor="FFA500" | &nbsp;<br />
|lightpink||bgcolor="FFB6C1" | &nbsp;<br />
|-<br />
|pink||bgcolor="FFC0CB" | &nbsp;<br />
|gold||bgcolor="FFD700" | &nbsp;<br />
|peachpuff||bgcolor="FFDAB9" | &nbsp;<br />
|navajowhite||bgcolor="FFDEAD" | &nbsp;<br />
|-<br />
|moccasin||bgcolor="FFE4B5" | &nbsp;<br />
|bisque||bgcolor="FFE4C4" | &nbsp;<br />
|mistyrose||bgcolor="FFE4E1" | &nbsp;<br />
|blanchedalmond||bgcolor="FFEBCD" | &nbsp;<br />
|-<br />
|papayawhip||bgcolor="FFEFD5" | &nbsp;<br />
|lavenderblush||bgcolor="FFF0F5" | &nbsp;<br />
|seashell||bgcolor="FFF5EE" | &nbsp;<br />
|cornsilk||bgcolor="FFF8DC" | &nbsp;<br />
|-<br />
|lemonchiffon||bgcolor="FFFACD" | &nbsp;<br />
|floralwhite||bgcolor="FFFAF0" | &nbsp;<br />
|snow||bgcolor="FFFAFA" | &nbsp;<br />
|yellow||bgcolor="FFFF00" | &nbsp;<br />
|-<br />
|lightyellow||bgcolor="FFFFE0" | &nbsp;<br />
|ivory||bgcolor="FFFFF0" | &nbsp;<br />
|white||bgcolor="FFFFFF" | &nbsp;<br />
|}<br />
<br />
<br />
== X11 colors == <br />
<br />
[https://en.wikipedia.org/wiki/X11_color_names X11_color_names] defined in<br />
{{src|colo-imp-x11.mkiv}}. These can be loaded using<br />
<br />
<texcode>\usecolors[x11]</texcode><br />
<br />
<br />
{| style="text-align: right; padding-right: 20px;"<br />
!| Name !! Color <br />
!style="width: 100px;"| Name !! Color <br />
!style="width: 100px;"| Name !! Color <br />
!style="width: 100px;"| Name !! Color<br />
|-<br />
|snow||bgcolor="fffafa" | &nbsp;<br />
|ghostwhite||bgcolor="f8f8ff" | &nbsp;<br />
|whitesmoke||bgcolor="f5f5f5" | &nbsp;<br />
|gainsboro||bgcolor="dcdcdc" | &nbsp;<br />
|-<br />
|floralwhite||bgcolor="fffaf0" | &nbsp;<br />
|oldlace||bgcolor="fdf5e6" | &nbsp;<br />
|linen||bgcolor="faf0e6" | &nbsp;<br />
|antiquewhite||bgcolor="faebd7" | &nbsp;<br />
|-<br />
|papayawhip||bgcolor="ffefd5" | &nbsp;<br />
|blanchedalmond||bgcolor="ffebcd" | &nbsp;<br />
|bisque||bgcolor="ffe4c4" | &nbsp;<br />
|peachpuff||bgcolor="ffdab9" | &nbsp;<br />
|-<br />
|navajowhite||bgcolor="ffdead" | &nbsp;<br />
|moccasin||bgcolor="ffe4b5" | &nbsp;<br />
|cornsilk||bgcolor="fff8dc" | &nbsp;<br />
|ivory||bgcolor="fffff0" | &nbsp;<br />
|-<br />
|lemonchiffon||bgcolor="fffacd" | &nbsp;<br />
|seashell||bgcolor="fff5ee" | &nbsp;<br />
|honeydew||bgcolor="f0fff0" | &nbsp;<br />
|mintcream||bgcolor="f5fffa" | &nbsp;<br />
|-<br />
|azure||bgcolor="f0ffff" | &nbsp;<br />
|aliceblue||bgcolor="f0f8ff" | &nbsp;<br />
|lavender||bgcolor="e6e6fa" | &nbsp;<br />
|lavenderblush||bgcolor="fff0f5" | &nbsp;<br />
|-<br />
|mistyrose||bgcolor="ffe4e1" | &nbsp;<br />
|white||bgcolor="ffffff" | &nbsp;<br />
|black||bgcolor="000000" | &nbsp;<br />
|darkslategray||bgcolor="2f4f4f" | &nbsp;<br />
|-<br />
|dimgray||bgcolor="686868" | &nbsp;<br />
|slategray||bgcolor="708090" | &nbsp;<br />
|lightslategray||bgcolor="778899" | &nbsp;<br />
|gray||bgcolor="c0c0c0" | &nbsp;<br />
|-<br />
|lightgray|| bgcolor="d4d4d4" | &nbsp;<br />
|midnightblue||bgcolor="191970" | &nbsp;<br />
|navy||bgcolor="000080" | &nbsp;<br />
|navyblue||bgcolor="000080" | &nbsp;<br />
|-<br />
|cornflowerblue||bgcolor="6495ed" | &nbsp;<br />
|darkslateblue||bgcolor="483d8b" | &nbsp;<br />
|slateblue||bgcolor="6a5acd" | &nbsp;<br />
|mediumslateblue||bgcolor="7b68ee" | &nbsp;<br />
|-<br />
|lightslateblue||bgcolor="8470ff" | &nbsp;<br />
|mediumblue||bgcolor="0000cd" | &nbsp;<br />
|royalblue||bgcolor="4169e1" | &nbsp;<br />
|blue||bgcolor="0000ff" | &nbsp;<br />
|-<br />
|dodgerblue||bgcolor="1e90ff" | &nbsp;<br />
|deepskyblue||bgcolor="00bfff" | &nbsp;<br />
|skyblue||bgcolor="87ceeb" | &nbsp;<br />
|lightskyblue||bgcolor="87cefa" | &nbsp;<br />
|-<br />
|steelblue||bgcolor="4682b4" | &nbsp;<br />
|lightsteelblue||bgcolor="b0c4de" | &nbsp;<br />
|lightblue||bgcolor="add8e6" | &nbsp;<br />
|powderblue||bgcolor="b0e0e6" | &nbsp;<br />
|-<br />
|paleturquoise||bgcolor="afeeee" | &nbsp;<br />
|darkturquoise||bgcolor="00ced1" | &nbsp;<br />
|mediumturquoise||bgcolor="48d1cc" | &nbsp;<br />
|turquoise||bgcolor="40e0d0" | &nbsp;<br />
|-<br />
|cyan||bgcolor="00ffff" | &nbsp;<br />
|lightcyan||bgcolor="e0ffff" | &nbsp;<br />
|cadetblue||bgcolor="5f9ea0" | &nbsp;<br />
|mediumaquamarine||bgcolor="66cdaa" | &nbsp;<br />
|-<br />
|aquamarine||bgcolor="7fffd4" | &nbsp;<br />
|darkolivegreen||bgcolor="556b2f" | &nbsp;<br />
|darkseagreen||bgcolor="8fbc8f" | &nbsp;<br />
|seagreen||bgcolor="2e8b57" | &nbsp;<br />
|-<br />
|mediumseagreen||bgcolor="3cb371" | &nbsp;<br />
|lightseagreen||bgcolor="20b2aa" | &nbsp;<br />
|palegreen||bgcolor="98fb98" | &nbsp;<br />
|lightgreen||bgcolor="90ee90" | &nbsp;<br />
|-<br />
|springgreen||bgcolor="00ff7f" | &nbsp;<br />
|lawngreen||bgcolor="7cfc00" | &nbsp;<br />
|green||bgcolor="00ff00" | &nbsp;<br />
|chartreuse||bgcolor="7fff00" | &nbsp;<br />
|-<br />
|mediumspringgreen||bgcolor="00fa9a" | &nbsp;<br />
|greenyellow||bgcolor="adff2f" | &nbsp;<br />
|limegreen||bgcolor="32cd32" | &nbsp;<br />
|yellowgreen||bgcolor="9acd32" | &nbsp;<br />
|-<br />
|forestgreen||bgcolor="228b22" | &nbsp;<br />
|olivedrab||bgcolor="6b8e23" | &nbsp;<br />
|darkkhaki||bgcolor="bdb76b" | &nbsp;<br />
|khaki||bgcolor="f0e68c" | &nbsp;<br />
|-<br />
|palegoldenrod||bgcolor="eee8aa" | &nbsp;<br />
|lightgoldenrodyellow||bgcolor="fafad2" | &nbsp;<br />
|lightyellow||bgcolor="ffffe0" | &nbsp;<br />
|yellow||bgcolor="ffff00" | &nbsp;<br />
|-<br />
|gold||bgcolor="ffd700" | &nbsp;<br />
|lightgoldenrod||bgcolor="eedd82" | &nbsp;<br />
|goldenrod||bgcolor="daa520" | &nbsp;<br />
|darkgoldenrod||bgcolor="b8860b" | &nbsp;<br />
|-<br />
|rosybrown||bgcolor="bc8f8f" | &nbsp;<br />
|indianred||bgcolor="cd5c5c" | &nbsp;<br />
|saddlebrown||bgcolor="8b4513" | &nbsp;<br />
|sienna||bgcolor="a0522d" | &nbsp;<br />
|-<br />
|peru||bgcolor="cd853f" | &nbsp;<br />
|burlywood||bgcolor="deb887" | &nbsp;<br />
|beige||bgcolor="f5f5dc" | &nbsp;<br />
|wheat||bgcolor="f5deb3" | &nbsp;<br />
|-<br />
|sandybrown||bgcolor="f4a460" | &nbsp;<br />
|tan||bgcolor="d2b48c" | &nbsp;<br />
|chocolate||bgcolor="d2691e" | &nbsp;<br />
|firebrick||bgcolor="b22222" | &nbsp;<br />
|-<br />
|brown||bgcolor="a52a2a" | &nbsp;<br />
|darksalmon||bgcolor="e9967a" | &nbsp;<br />
|salmon||bgcolor="fa8072" | &nbsp;<br />
|lightsalmon||bgcolor="ffa07a" | &nbsp;<br />
|-<br />
|orange||bgcolor="ffa500" | &nbsp;<br />
|darkorange||bgcolor="ff8c00" | &nbsp;<br />
|coral||bgcolor="ff7f50" | &nbsp;<br />
|lightcoral||bgcolor="f08080" | &nbsp;<br />
|-<br />
|tomato||bgcolor="ff6347" | &nbsp;<br />
|orangered||bgcolor="ff4500" | &nbsp;<br />
|red||bgcolor="ff0000" | &nbsp;<br />
|hotpink||bgcolor="ff69b4" | &nbsp;<br />
|-<br />
|deeppink||bgcolor="ff1493" | &nbsp;<br />
|pink||bgcolor="ffc0cb" | &nbsp;<br />
|lightpink||bgcolor="ffb6c1" | &nbsp;<br />
|palevioletred||bgcolor="db7093" | &nbsp;<br />
|-<br />
|maroon||bgcolor="b03060" | &nbsp;<br />
|mediumvioletred||bgcolor="c71585" | &nbsp;<br />
|violetred||bgcolor="d02090" | &nbsp;<br />
|magenta||bgcolor="ff00ff" | &nbsp;<br />
|-<br />
|violet||bgcolor="ee82ee" | &nbsp;<br />
|plum||bgcolor="dda0dd" | &nbsp;<br />
|orchid||bgcolor="da70d6" | &nbsp;<br />
|mediumorchid||bgcolor="ba55d3" | &nbsp;<br />
|-<br />
|darkorchid||bgcolor="9932cc" | &nbsp;<br />
|darkviolet||bgcolor="9400d3" | &nbsp;<br />
|blueviolet||bgcolor="8a2be2" | &nbsp;<br />
|purple||bgcolor="a020f0" | &nbsp;<br />
|-<br />
|mediumpurple||bgcolor="9370db" | &nbsp;<br />
|thistle||bgcolor="d8bfd8" | &nbsp;<br />
|snow1||bgcolor="fffafa" | &nbsp;<br />
|snow2||bgcolor="eee9e9" | &nbsp;<br />
|-<br />
|snow3||bgcolor="cdc9c9" | &nbsp;<br />
|snow4||bgcolor="8b8989" | &nbsp;<br />
|seashell1||bgcolor="fff5ee" | &nbsp;<br />
|seashell2||bgcolor="eee5de" | &nbsp;<br />
|-<br />
|seashell3||bgcolor="cdc5bf" | &nbsp;<br />
|seashell4||bgcolor="8b8682" | &nbsp;<br />
|antiquewhite1||bgcolor="ffefdb" | &nbsp;<br />
|antiquewhite2||bgcolor="eedfcc" | &nbsp;<br />
|-<br />
|antiquewhite3||bgcolor="cdc0b0" | &nbsp;<br />
|antiquewhite4||bgcolor="8b8378" | &nbsp;<br />
|bisque1||bgcolor="ffe4c4" | &nbsp;<br />
|bisque2||bgcolor="eed5b7" | &nbsp;<br />
|-<br />
|bisque3||bgcolor="cdb79e" | &nbsp;<br />
|bisque4||bgcolor="8b7d6b" | &nbsp;<br />
|peachpuff1||bgcolor="ffdab9" | &nbsp;<br />
|peachpuff2||bgcolor="eecbad" | &nbsp;<br />
|-<br />
|peachpuff3||bgcolor="cdaf95" | &nbsp;<br />
|peachpuff4||bgcolor="8b7765" | &nbsp;<br />
|navajowhite1||bgcolor="ffdead" | &nbsp;<br />
|navajowhite2||bgcolor="eecfa1" | &nbsp;<br />
|-<br />
|navajowhite3||bgcolor="cdb38b" | &nbsp;<br />
|navajowhite4||bgcolor="8b795e" | &nbsp;<br />
|lemonchiffon1||bgcolor="fffacd" | &nbsp;<br />
|lemonchiffon2||bgcolor="eee9bf" | &nbsp;<br />
|-<br />
|lemonchiffon3||bgcolor="cdc9a5" | &nbsp;<br />
|lemonchiffon4||bgcolor="8b8970" | &nbsp;<br />
|cornsilk1||bgcolor="fff8dc" | &nbsp;<br />
|cornsilk2||bgcolor="eee8cd" | &nbsp;<br />
|-<br />
|cornsilk3||bgcolor="cdc8b1" | &nbsp;<br />
|cornsilk4||bgcolor="8b8878" | &nbsp;<br />
|ivory1||bgcolor="fffff0" | &nbsp;<br />
|ivory2||bgcolor="eeeee0" | &nbsp;<br />
|-<br />
|ivory3||bgcolor="cdcdc1" | &nbsp;<br />
|ivory4||bgcolor="8b8b83" | &nbsp;<br />
|honeydew1||bgcolor="f0fff0" | &nbsp;<br />
|honeydew2||bgcolor="e0eee0" | &nbsp;<br />
|-<br />
|honeydew3||bgcolor="c1cdc1" | &nbsp;<br />
|honeydew4||bgcolor="838b83" | &nbsp;<br />
|lavenderblush1||bgcolor="fff0f5" | &nbsp;<br />
|lavenderblush2||bgcolor="eee0e5" | &nbsp;<br />
|-<br />
|lavenderblush3||bgcolor="cdc1c5" | &nbsp;<br />
|lavenderblush4||bgcolor="8b8386" | &nbsp;<br />
|mistyrose1||bgcolor="ffe4e1" | &nbsp;<br />
|mistyrose2||bgcolor="eed5d2" | &nbsp;<br />
|-<br />
|mistyrose3||bgcolor="cdb7b5" | &nbsp;<br />
|mistyrose4||bgcolor="8b7d7b" | &nbsp;<br />
|azure1||bgcolor="f0ffff" | &nbsp;<br />
|azure2||bgcolor="e0eeee" | &nbsp;<br />
|-<br />
|azure3||bgcolor="c1cdcd" | &nbsp;<br />
|azure4||bgcolor="838b8b" | &nbsp;<br />
|slateblue1||bgcolor="836fff" | &nbsp;<br />
|slateblue2||bgcolor="7a67ee" | &nbsp;<br />
|-<br />
|slateblue3||bgcolor="6959cd" | &nbsp;<br />
|slateblue4||bgcolor="473c8b" | &nbsp;<br />
|royalblue1||bgcolor="4876ff" | &nbsp;<br />
|royalblue2||bgcolor="436eee" | &nbsp;<br />
|-<br />
|royalblue3||bgcolor="3a5fcd" | &nbsp;<br />
|royalblue4||bgcolor="27408b" | &nbsp;<br />
|blue1||bgcolor="0000ff" | &nbsp;<br />
|blue2||bgcolor="0000ee" | &nbsp;<br />
|-<br />
|blue3||bgcolor="0000cd" | &nbsp;<br />
|blue4||bgcolor="00008b" | &nbsp;<br />
|dodgerblue1||bgcolor="1e90ff" | &nbsp;<br />
|dodgerblue2||bgcolor="1c86ee" | &nbsp;<br />
|-<br />
|dodgerblue3||bgcolor="1874cd" | &nbsp;<br />
|dodgerblue4||bgcolor="104e8b" | &nbsp;<br />
|steelblue1||bgcolor="63b8ff" | &nbsp;<br />
|steelblue2||bgcolor="5cacee" | &nbsp;<br />
|-<br />
|steelblue3||bgcolor="4f94cd" | &nbsp;<br />
|steelblue4||bgcolor="36648b" | &nbsp;<br />
|deepskyblue1||bgcolor="00bfff" | &nbsp;<br />
|deepskyblue2||bgcolor="00b2ee" | &nbsp;<br />
|-<br />
|deepskyblue3||bgcolor="009acd" | &nbsp;<br />
|deepskyblue4||bgcolor="00688b" | &nbsp;<br />
|skyblue1||bgcolor="87ceff" | &nbsp;<br />
|skyblue2||bgcolor="7ec0ee" | &nbsp;<br />
|-<br />
|skyblue3||bgcolor="6ca6cd" | &nbsp;<br />
|skyblue4||bgcolor="4a708b" | &nbsp;<br />
|lightskyblue1||bgcolor="b0e2ff" | &nbsp;<br />
|lightskyblue2||bgcolor="a4d3ee" | &nbsp;<br />
|-<br />
|lightskyblue3||bgcolor="8db6cd" | &nbsp;<br />
|lightskyblue4||bgcolor="607b8b" | &nbsp;<br />
|slategray1||bgcolor="c6e2ff" | &nbsp;<br />
|slategray2||bgcolor="b9d3ee" | &nbsp;<br />
|-<br />
|slategray3||bgcolor="9fb6cd" | &nbsp;<br />
|slategray4||bgcolor="6c7b8b" | &nbsp;<br />
|lightsteelblue1||bgcolor="cae1ff" | &nbsp;<br />
|lightsteelblue2||bgcolor="bcd2ee" | &nbsp;<br />
|-<br />
|lightsteelblue3||bgcolor="a2b5cd" | &nbsp;<br />
|lightsteelblue4||bgcolor="6e7b8b" | &nbsp;<br />
|lightblue1||bgcolor="bfefff" | &nbsp;<br />
|lightblue2||bgcolor="b2dfee" | &nbsp;<br />
|-<br />
|lightblue3||bgcolor="9ac0cd" | &nbsp;<br />
|lightblue4||bgcolor="68838b" | &nbsp;<br />
|lightcyan1||bgcolor="e0ffff" | &nbsp;<br />
|lightcyan2||bgcolor="d1eeee" | &nbsp;<br />
|-<br />
|lightcyan3||bgcolor="b4cdcd" | &nbsp;<br />
|lightcyan4||bgcolor="7a8b8b" | &nbsp;<br />
|paleturquoise1||bgcolor="bbffff" | &nbsp;<br />
|paleturquoise2||bgcolor="aeeeee" | &nbsp;<br />
|-<br />
|paleturquoise3||bgcolor="96cdcd" | &nbsp;<br />
|paleturquoise4||bgcolor="668b8b" | &nbsp;<br />
|cadetblue1||bgcolor="98f5ff" | &nbsp;<br />
|cadetblue2||bgcolor="8ee5ee" | &nbsp;<br />
|-<br />
|cadetblue3||bgcolor="7ac5cd" | &nbsp;<br />
|cadetblue4||bgcolor="53868b" | &nbsp;<br />
|turquoise1||bgcolor="00f5ff" | &nbsp;<br />
|turquoise2||bgcolor="00e5ee" | &nbsp;<br />
|-<br />
|turquoise3||bgcolor="00c5cd" | &nbsp;<br />
|turquoise4||bgcolor="00868b" | &nbsp;<br />
|cyan1||bgcolor="00ffff" | &nbsp;<br />
|cyan2||bgcolor="00eeee" | &nbsp;<br />
|-<br />
|cyan3||bgcolor="00cdcd" | &nbsp;<br />
|cyan4||bgcolor="008b8b" | &nbsp;<br />
|darkslategray1||bgcolor="97ffff" | &nbsp;<br />
|darkslategray2||bgcolor="8deeee" | &nbsp;<br />
|-<br />
|darkslategray3||bgcolor="79cdcd" | &nbsp;<br />
|darkslategray4||bgcolor="528b8b" | &nbsp;<br />
|aquamarine1||bgcolor="7fffd4" | &nbsp;<br />
|aquamarine2||bgcolor="76eec6" | &nbsp;<br />
|-<br />
|aquamarine3||bgcolor="66cdaa" | &nbsp;<br />
|aquamarine4||bgcolor="458b74" | &nbsp;<br />
|darkseagreen1||bgcolor="c1ffc1" | &nbsp;<br />
|darkseagreen2||bgcolor="b4eeb4" | &nbsp;<br />
|-<br />
|darkseagreen3||bgcolor="9bcd9b" | &nbsp;<br />
|darkseagreen4||bgcolor="698b69" | &nbsp;<br />
|seagreen1||bgcolor="54ff9f" | &nbsp;<br />
|seagreen2||bgcolor="4eee94" | &nbsp;<br />
|-<br />
|seagreen3||bgcolor="43cd80" | &nbsp;<br />
|seagreen4||bgcolor="2e8b57" | &nbsp;<br />
|palegreen1||bgcolor="9aff9a" | &nbsp;<br />
|palegreen2||bgcolor="90ee90" | &nbsp;<br />
|-<br />
|palegreen3||bgcolor="7ccd7c" | &nbsp;<br />
|palegreen4||bgcolor="548b54" | &nbsp;<br />
|springgreen1||bgcolor="00ff7f" | &nbsp;<br />
|springgreen2||bgcolor="00ee76" | &nbsp;<br />
|-<br />
|springgreen3||bgcolor="00cd66" | &nbsp;<br />
|springgreen4||bgcolor="008b45" | &nbsp;<br />
|green1||bgcolor="00ff00" | &nbsp;<br />
|green2||bgcolor="00ee00" | &nbsp;<br />
|-<br />
|green3||bgcolor="00cd00" | &nbsp;<br />
|green4||bgcolor="008b00" | &nbsp;<br />
|chartreuse1||bgcolor="7fff00" | &nbsp;<br />
|chartreuse2||bgcolor="76ee00" | &nbsp;<br />
|-<br />
|chartreuse3||bgcolor="66cd00" | &nbsp;<br />
|chartreuse4||bgcolor="458b00" | &nbsp;<br />
|olivedrab1||bgcolor="c0ff3e" | &nbsp;<br />
|olivedrab2||bgcolor="b3ee3a" | &nbsp;<br />
|-<br />
|olivedrab3||bgcolor="9acd32" | &nbsp;<br />
|olivedrab4||bgcolor="698b22" | &nbsp;<br />
|darkolivegreen1||bgcolor="caff70" | &nbsp;<br />
|darkolivegreen2||bgcolor="bcee68" | &nbsp;<br />
|-<br />
|darkolivegreen3||bgcolor="a2cd5a" | &nbsp;<br />
|darkolivegreen4||bgcolor="6e8b3d" | &nbsp;<br />
|khaki1||bgcolor="fff68f" | &nbsp;<br />
|khaki2||bgcolor="eee685" | &nbsp;<br />
|-<br />
|khaki3||bgcolor="cdc673" | &nbsp;<br />
|khaki4||bgcolor="8b864e" | &nbsp;<br />
|lightgoldenrod1||bgcolor="ffec8b" | &nbsp;<br />
|lightgoldenrod2||bgcolor="eedc82" | &nbsp;<br />
|-<br />
|lightgoldenrod3||bgcolor="cdbe70" | &nbsp;<br />
|lightgoldenrod4||bgcolor="8b814c" | &nbsp;<br />
|lightyellow1||bgcolor="ffffe0" | &nbsp;<br />
|lightyellow2||bgcolor="eeeed1" | &nbsp;<br />
|-<br />
|lightyellow3||bgcolor="cdcdb4" | &nbsp;<br />
|lightyellow4||bgcolor="8b8b7a" | &nbsp;<br />
|yellow1||bgcolor="ffff00" | &nbsp;<br />
|yellow2||bgcolor="eeee00" | &nbsp;<br />
|-<br />
|yellow3||bgcolor="cdcd00" | &nbsp;<br />
|yellow4||bgcolor="8b8b00" | &nbsp;<br />
|gold1||bgcolor="ffd700" | &nbsp;<br />
|gold2||bgcolor="eec900" | &nbsp;<br />
|-<br />
|gold3||bgcolor="cdad00" | &nbsp;<br />
|gold4||bgcolor="8b7500" | &nbsp;<br />
|goldenrod1||bgcolor="ffc125" | &nbsp;<br />
|goldenrod2||bgcolor="eeb422" | &nbsp;<br />
|-<br />
|goldenrod3||bgcolor="cd9b1d" | &nbsp;<br />
|goldenrod4||bgcolor="8b6914" | &nbsp;<br />
|darkgoldenrod1||bgcolor="ffb90f" | &nbsp;<br />
|darkgoldenrod2||bgcolor="eead0e" | &nbsp;<br />
|-<br />
|darkgoldenrod3||bgcolor="cd950c" | &nbsp;<br />
|darkgoldenrod4||bgcolor="8b6508" | &nbsp;<br />
|rosybrown1||bgcolor="ffc1c1" | &nbsp;<br />
|rosybrown2||bgcolor="eeb4b4" | &nbsp;<br />
|-<br />
|rosybrown3||bgcolor="cd9b9b" | &nbsp;<br />
|rosybrown4||bgcolor="8b6969" | &nbsp;<br />
|indianred1||bgcolor="ff6a6a" | &nbsp;<br />
|indianred2||bgcolor="ee6363" | &nbsp;<br />
|-<br />
|indianred3||bgcolor="cd5555" | &nbsp;<br />
|indianred4||bgcolor="8b3a3a" | &nbsp;<br />
|sienna1||bgcolor="ff8247" | &nbsp;<br />
|sienna2||bgcolor="ee7942" | &nbsp;<br />
|-<br />
|sienna3||bgcolor="cd6839" | &nbsp;<br />
|sienna4||bgcolor="8b4726" | &nbsp;<br />
|burlywood1||bgcolor="ffd39b" | &nbsp;<br />
|burlywood2||bgcolor="eec591" | &nbsp;<br />
|-<br />
|burlywood3||bgcolor="cdaa7d" | &nbsp;<br />
|burlywood4||bgcolor="8b7355" | &nbsp;<br />
|wheat1||bgcolor="ffe7ba" | &nbsp;<br />
|wheat2||bgcolor="eed8ae" | &nbsp;<br />
|-<br />
|wheat3||bgcolor="cdba96" | &nbsp;<br />
|wheat4||bgcolor="8b7e66" | &nbsp;<br />
|tan1||bgcolor="ffa54f" | &nbsp;<br />
|tan2||bgcolor="ee9a49" | &nbsp;<br />
|-<br />
|tan3||bgcolor="cd853f" | &nbsp;<br />
|tan4||bgcolor="8b5a2b" | &nbsp;<br />
|chocolate1||bgcolor="ff7f24" | &nbsp;<br />
|chocolate2||bgcolor="ee7621" | &nbsp;<br />
|-<br />
|chocolate3||bgcolor="cd661d" | &nbsp;<br />
|chocolate4||bgcolor="8b4513" | &nbsp;<br />
|firebrick1||bgcolor="ff3030" | &nbsp;<br />
|firebrick2||bgcolor="ee2c2c" | &nbsp;<br />
|-<br />
|firebrick3||bgcolor="cd2626" | &nbsp;<br />
|firebrick4||bgcolor="8b1a1a" | &nbsp;<br />
|brown1||bgcolor="ff4040" | &nbsp;<br />
|brown2||bgcolor="ee3b3b" | &nbsp;<br />
|-<br />
|brown3||bgcolor="cd3333" | &nbsp;<br />
|brown4||bgcolor="8b2323" | &nbsp;<br />
|salmon1||bgcolor="ff8c69" | &nbsp;<br />
|salmon2||bgcolor="ee8262" | &nbsp;<br />
|-<br />
|salmon3||bgcolor="cd7054" | &nbsp;<br />
|salmon4||bgcolor="8b4c39" | &nbsp;<br />
|lightsalmon1||bgcolor="ffa07a" | &nbsp;<br />
|lightsalmon2||bgcolor="ee9572" | &nbsp;<br />
|-<br />
|lightsalmon3||bgcolor="cd8162" | &nbsp;<br />
|lightsalmon4||bgcolor="8b5742" | &nbsp;<br />
|orange1||bgcolor="ffa500" | &nbsp;<br />
|orange2||bgcolor="ee9a00" | &nbsp;<br />
|-<br />
|orange3||bgcolor="cd8500" | &nbsp;<br />
|orange4||bgcolor="8b5a00" | &nbsp;<br />
|darkorange1||bgcolor="ff7f00" | &nbsp;<br />
|darkorange2||bgcolor="ee7600" | &nbsp;<br />
|-<br />
|darkorange3||bgcolor="cd6600" | &nbsp;<br />
|darkorange4||bgcolor="8b4500" | &nbsp;<br />
|coral1||bgcolor="ff7256" | &nbsp;<br />
|coral2||bgcolor="ee6a50" | &nbsp;<br />
|-<br />
|coral3||bgcolor="cd5b45" | &nbsp;<br />
|coral4||bgcolor="8b3e2f" | &nbsp;<br />
|tomato1||bgcolor="ff6347" | &nbsp;<br />
|tomato2||bgcolor="ee5c42" | &nbsp;<br />
|-<br />
|tomato3||bgcolor="cd4f39" | &nbsp;<br />
|tomato4||bgcolor="8b3626" | &nbsp;<br />
|orangered1||bgcolor="ff4500" | &nbsp;<br />
|orangered2||bgcolor="ee4000" | &nbsp;<br />
|-<br />
|orangered3||bgcolor="cd3700" | &nbsp;<br />
|orangered4||bgcolor="8b2500" | &nbsp;<br />
|red1||bgcolor="ff0000" | &nbsp;<br />
|red2||bgcolor="ee0000" | &nbsp;<br />
|-<br />
|red3||bgcolor="cd0000" | &nbsp;<br />
|red4||bgcolor="8b0000" | &nbsp;<br />
|debianred||bgcolor="d70751" | &nbsp;<br />
|deeppink1||bgcolor="ff1493" | &nbsp;<br />
|-<br />
|deeppink2||bgcolor="ee1289" | &nbsp;<br />
|deeppink3||bgcolor="cd1076" | &nbsp;<br />
|deeppink4||bgcolor="8b0a50" | &nbsp;<br />
|hotpink1||bgcolor="ff6eb4" | &nbsp;<br />
|-<br />
|hotpink2||bgcolor="ee6aa7" | &nbsp;<br />
|hotpink3||bgcolor="cd6090" | &nbsp;<br />
|hotpink4||bgcolor="8b3a62" | &nbsp;<br />
|pink1||bgcolor="ffb5c5" | &nbsp;<br />
|-<br />
|pink2||bgcolor="eea9b8" | &nbsp;<br />
|pink3||bgcolor="cd919e" | &nbsp;<br />
|pink4||bgcolor="8b636c" | &nbsp;<br />
|lightpink1||bgcolor="ffaeb9" | &nbsp;<br />
|-<br />
|lightpink2||bgcolor="eea2ad" | &nbsp;<br />
|lightpink3||bgcolor="cd8c95" | &nbsp;<br />
|lightpink4||bgcolor="8b5f65" | &nbsp;<br />
|palevioletred1||bgcolor="ff82ab" | &nbsp;<br />
|-<br />
|palevioletred2||bgcolor="ee799f" | &nbsp;<br />
|palevioletred3||bgcolor="cd6889" | &nbsp;<br />
|palevioletred4||bgcolor="8b475d" | &nbsp;<br />
|maroon1||bgcolor="ff34b3" | &nbsp;<br />
|-<br />
|maroon2||bgcolor="ee30a7" | &nbsp;<br />
|maroon3||bgcolor="cd2990" | &nbsp;<br />
|maroon4||bgcolor="8b1c62" | &nbsp;<br />
|violetred1||bgcolor="ff3e96" | &nbsp;<br />
|-<br />
|violetred2||bgcolor="ee3a8c" | &nbsp;<br />
|violetred3||bgcolor="cd3278" | &nbsp;<br />
|violetred4||bgcolor="8b2252" | &nbsp;<br />
|magenta1||bgcolor="ff00ff" | &nbsp;<br />
|-<br />
|magenta2||bgcolor="ee00ee" | &nbsp;<br />
|magenta3||bgcolor="cd00cd" | &nbsp;<br />
|magenta4||bgcolor="8b008b" | &nbsp;<br />
|orchid1||bgcolor="ff83fa" | &nbsp;<br />
|-<br />
|orchid2||bgcolor="ee7ae9" | &nbsp;<br />
|orchid3||bgcolor="cd69c9" | &nbsp;<br />
|orchid4||bgcolor="8b4789" | &nbsp;<br />
|plum1||bgcolor="ffbbff" | &nbsp;<br />
|-<br />
|plum2||bgcolor="eeaeee" | &nbsp;<br />
|plum3||bgcolor="cd96cd" | &nbsp;<br />
|plum4||bgcolor="8b668b" | &nbsp;<br />
|mediumorchid1||bgcolor="e066ff" | &nbsp;<br />
|-<br />
|mediumorchid2||bgcolor="d15fee" | &nbsp;<br />
|mediumorchid3||bgcolor="b452cd" | &nbsp;<br />
|mediumorchid4||bgcolor="7a378b" | &nbsp;<br />
|darkorchid1||bgcolor="bf3eff" | &nbsp;<br />
|-<br />
|darkorchid2||bgcolor="b23aee" | &nbsp;<br />
|darkorchid3||bgcolor="9a32cd" | &nbsp;<br />
|darkorchid4||bgcolor="68228b" | &nbsp;<br />
|purple1||bgcolor="9b30ff" | &nbsp;<br />
|-<br />
|purple2||bgcolor="912cee" | &nbsp;<br />
|purple3||bgcolor="7d26cd" | &nbsp;<br />
|purple4||bgcolor="551a8b" | &nbsp;<br />
|mediumpurple1||bgcolor="ab82ff" | &nbsp;<br />
|-<br />
|mediumpurple2||bgcolor="9f79ee" | &nbsp;<br />
|mediumpurple3||bgcolor="8968cd" | &nbsp;<br />
|mediumpurple4||bgcolor="5d478b" | &nbsp;<br />
|thistle1||bgcolor="ffe1ff" | &nbsp;<br />
|-<br />
|thistle2||bgcolor="eed2ee" | &nbsp;<br />
|thistle3||bgcolor="cdb5cd" | &nbsp;<br />
|thistle4||bgcolor="8b7b8b" | &nbsp;<br />
|}<br />
<br />
The following additional colors are also defined.<br />
<br />
{| style="text-align: right; padding-right: 20px;"<br />
!| Name !! Color <br />
!style="width: 100px;"| Name !! Color <br />
!style="width: 100px;"| Name !! Color <br />
|-<br />
|darkgray||bgcolor="a8a8a8" | &nbsp;<br />
|darkblue||bgcolor="00008b" | &nbsp; <br />
|darkcyan||bgcolor="008b8b" | &nbsp;<br />
|-<br />
|darkmagenta||bgcolor="8b008b" | &nbsp;<br />
|darkred||bgcolor="8b000000" | &nbsp;<br />
|darkgreen||bgcolor="006400" | &nbsp;<br />
|}<br />
<br />
== XWI Colors ==<br />
<br />
The colors are defined in {{src|colo-imp-xwi.mkiv}}. The name suggests that they were from some color file distributed as part of the [https://en.wikipedia.org/wiki/X_Window_System X_Window_System]. These are a subset of the X11 colors, shown earlier. To load these colors, use:<br />
<br />
<texcode>\usecolors[xwi]</texcode><br />
<br />
This loads the following additional colors:<br />
<br />
{| style="text-align: right; padding-right: 20px;"<br />
!| Name !! Color <br />
!style="width: 80px;"| Name !! Color <br />
!style="width: 100px;"| Name !! Color <br />
!style="width: 100px;"| Name !! Color<br />
|-<br />
|-<br />
|aliceblue||bgcolor="#EFF7FF"|&nbsp;<br />
|antiquewhite||bgcolor="#F9EAD6"|&nbsp;<br />
|aquamarine||bgcolor="#7FFFD3"|&nbsp;<br />
|azure||bgcolor="#EFFFFF"|&nbsp;<br />
|-<br />
|beige||bgcolor="#F4F4DB"|&nbsp;<br />
|bisque||bgcolor="#FFE2C4"|&nbsp;<br />
|black||bgcolor="#000000"|&nbsp;<br />
|blanchedalmond||bgcolor="#FFEACC"|&nbsp;<br />
|-<br />
|blue||bgcolor="#0000FF"|&nbsp;<br />
|blueviolet||bgcolor="#892BE2"|&nbsp;<br />
|brown||bgcolor="#A52828"|&nbsp;<br />
|burlywood||bgcolor="#DDB787"|&nbsp;<br />
|-<br />
|cadetblue||bgcolor="#5E9EA0"|&nbsp;<br />
|chartreuse||bgcolor="#7FFF00"|&nbsp;<br />
|chocolate||bgcolor="#D1681E"|&nbsp;<br />
|coral||bgcolor="#FF7F4F"|&nbsp;<br />
|-<br />
|cornflowerblue||bgcolor="#6393ED"|&nbsp;<br />
|cornsilk||bgcolor="#FFF7DB"|&nbsp;<br />
|cyan||bgcolor="#00FFFF"|&nbsp;<br />
|darkgoldenrod||bgcolor="#B7870A"|&nbsp;<br />
|-<br />
|darkgreen||bgcolor="#006300"|&nbsp;<br />
|darkkhaki||bgcolor="#BCB76B"|&nbsp;<br />
|darkolivegreen||bgcolor="#546B2D"|&nbsp;<br />
|darkorange||bgcolor="#FF8C00"|&nbsp;<br />
|-<br />
|darkorchid||bgcolor="#9933CC"|&nbsp;<br />
|darksalmon||bgcolor="#E8967A"|&nbsp;<br />
|darkseagreen||bgcolor="#8EBC8E"|&nbsp;<br />
|darkslateblue||bgcolor="#473D8C"|&nbsp;<br />
|-<br />
|darkturquoise||bgcolor="#00CED1"|&nbsp;<br />
|darkviolet||bgcolor="#9300D3"|&nbsp;<br />
|deeppink||bgcolor="#FF1493"|&nbsp;<br />
|deepskyblue||bgcolor="#00BFFF"|&nbsp;<br />
|-<br />
|dodgerblue||bgcolor="#1E8EFF"|&nbsp;<br />
|firebrick||bgcolor="#B22121"|&nbsp;<br />
|floralwhite||bgcolor="#FFF9EF"|&nbsp;<br />
|forestgreen||bgcolor="#218C21"|&nbsp;<br />
|-<br />
|gainsboro||bgcolor="#DBDBDB"|&nbsp;<br />
|ghostwhite||bgcolor="#F7F7FF"|&nbsp;<br />
|gold||bgcolor="#FFD600"|&nbsp;<br />
|goldenrod||bgcolor="#D8A521"|&nbsp;<br />
|-<br />
|green||bgcolor="#00FF00"|&nbsp;<br />
|greenyellow||bgcolor="#ADFF2D"|&nbsp;<br />
|honeydew||bgcolor="#EFFFEF"|&nbsp;<br />
|hotpink||bgcolor="#FF68B5"|&nbsp;<br />
|-<br />
|indianred||bgcolor="#CC5B5B"|&nbsp;<br />
|ivory||bgcolor="#FFFFEF"|&nbsp;<br />
|khaki||bgcolor="#EFE58C"|&nbsp;<br />
|lavender||bgcolor="#E5E5F9"|&nbsp;<br />
|-<br />
|lavenderblush||bgcolor="#FFEFF4"|&nbsp;<br />
|lawngreen||bgcolor="#7CFC00"|&nbsp;<br />
|lemonchiffon||bgcolor="#FFF9CC"|&nbsp;<br />
|lightblue||bgcolor="#ADD8E5"|&nbsp;<br />
|-<br />
|lightcoral||bgcolor="#EF7F7F"|&nbsp;<br />
|lightcyan||bgcolor="#E0FFFF"|&nbsp;<br />
|lightgoldenrod||bgcolor="#EDDD82"|&nbsp;<br />
|lightgoldenrodyellow||bgcolor="#F9F9D1"|&nbsp;<br />
|-<br />
|lightpink||bgcolor="#FFB5C1"|&nbsp;<br />
|lightsalmon||bgcolor="#FFA07A"|&nbsp;<br />
|lightseagreen||bgcolor="#21B2AA"|&nbsp;<br />
|lightskyblue||bgcolor="#87CEF9"|&nbsp;<br />
|-<br />
|lightslateblue||bgcolor="#8470FF"|&nbsp;<br />
|lightsteelblue||bgcolor="#AFC4DD"|&nbsp;<br />
|lightyellow||bgcolor="#FFFFE0"|&nbsp;<br />
|limegreen||bgcolor="#33CC33"|&nbsp;<br />
|-<br />
|linen||bgcolor="#F9EFE5"|&nbsp;<br />
|magenta||bgcolor="#FF00FF"|&nbsp;<br />
|maroon||bgcolor="#AF3060"|&nbsp;<br />
|mediumaquamarine||bgcolor="#66CCAA"|&nbsp;<br />
|-<br />
|mediumblue||bgcolor="#0000CC"|&nbsp;<br />
|mediumorchid||bgcolor="#BA54D3"|&nbsp;<br />
|mediumpurple||bgcolor="#9370DB"|&nbsp;<br />
|mediumseagreen||bgcolor="#3DB270"|&nbsp;<br />
|-<br />
|mediumslateblue||bgcolor="#7A68ED"|&nbsp;<br />
|mediumspringgreen||bgcolor="#00F999"|&nbsp;<br />
|mediumturquoise||bgcolor="#47D1CC"|&nbsp;<br />
|mediumvioletred||bgcolor="#C61484"|&nbsp;<br />
|-<br />
|midnightblue||bgcolor="#191970"|&nbsp;<br />
|mintcream||bgcolor="#F4FFF9"|&nbsp;<br />
|mistyrose||bgcolor="#FFE2E0"|&nbsp;<br />
|moccasin||bgcolor="#FFE2B5"|&nbsp;<br />
|-<br />
|navajowhite||bgcolor="#FFDDAD"|&nbsp;<br />
|navy||bgcolor="#00007F"|&nbsp;<br />
|navyblue||bgcolor="#00007F"|&nbsp;<br />
|oldlace||bgcolor="#FCF4E5"|&nbsp;<br />
|-<br />
|olivedrab||bgcolor="#6B8E23"|&nbsp;<br />
|orange||bgcolor="#FFA500"|&nbsp;<br />
|orangered||bgcolor="#FF4400"|&nbsp;<br />
|orchid||bgcolor="#D870D6"|&nbsp;<br />
|-<br />
|palegoldenrod||bgcolor="#EDE8AA"|&nbsp;<br />
|palegreen||bgcolor="#99F999"|&nbsp;<br />
|paleturquoise||bgcolor="#AFEDED"|&nbsp;<br />
|palevioletred||bgcolor="#DB7093"|&nbsp;<br />
|-<br />
|papayawhip||bgcolor="#FFEFD6"|&nbsp;<br />
|peachpuff||bgcolor="#FFD8BA"|&nbsp;<br />
|peru||bgcolor="#CC843F"|&nbsp;<br />
|pink||bgcolor="#FFBFCC"|&nbsp;<br />
|-<br />
|plum||bgcolor="#DDA0DD"|&nbsp;<br />
|powderblue||bgcolor="#AFE0E5"|&nbsp;<br />
|purple||bgcolor="#A021EF"|&nbsp;<br />
|red ||bgcolor="#FF0000"|&nbsp;<br />
|-<br />
|rosybrown||bgcolor="#BC8E8E"|&nbsp;<br />
|royalblue||bgcolor="#3F68E0"|&nbsp;<br />
|saddlebrown||bgcolor="#8C4411"|&nbsp;<br />
|salmon||bgcolor="#F97F72"|&nbsp;<br />
|-<br />
|sandybrown||bgcolor="#F4A360"|&nbsp;<br />
|seagreen||bgcolor="#2D8C56"|&nbsp;<br />
|seashell||bgcolor="#FFF4ED"|&nbsp;<br />
|sienna||bgcolor="#A0512D"|&nbsp;<br />
|-<br />
|skyblue||bgcolor="#87CEEA"|&nbsp;<br />
|slateblue||bgcolor="#6B59CC"|&nbsp;<br />
|snow||bgcolor="#FFF9F9"|&nbsp;<br />
|springgreen||bgcolor="#00FF7F"|&nbsp;<br />
|-<br />
|steelblue||bgcolor="#4482B5"|&nbsp;<br />
|tan ||bgcolor="#D1B58C"|&nbsp;<br />
|thistle||bgcolor="#D8BFD8"|&nbsp;<br />
|tomato||bgcolor="#FF6347"|&nbsp;<br />
|-<br />
|turquoise||bgcolor="#3FE0D1"|&nbsp;<br />
|violet||bgcolor="#ED82ED"|&nbsp;<br />
|violetred||bgcolor="#D1218E"|&nbsp;<br />
|wheat||bgcolor="#F4DDB2"|&nbsp;<br />
|-<br />
|white||bgcolor="#FFFFFF"|&nbsp;<br />
|whitesmoke||bgcolor="#F4F4F4"|&nbsp;<br />
|yellow||bgcolor="#FFFF00"|&nbsp;<br />
|yellowgreen||bgcolor="#99CC33"|&nbsp;<br />
|}<br />
<br />
== Additional pre-defined colors ==<br />
<br />
In addition to the above, there are other pre-defined colors. <br />
<br />
{| class="wikitable"<br />
|-<br />
| ema || <code>\usecolors[ema]</code><br />
| {{src|colo-imp-ema.mkiv}} || 549 Emacs colors<br />
|}<br />
<br />
<br />
= Advanced Usage =<br />
<br />
== Using colors in MetaPost ==<br />
<br />
A color defined in TeX is available in MetaPost using `\MPcolor{...}`. For example:<br />
<br />
{|<br />
|-<br />
|<texcode><br />
\definecolor[highlight][r=0.8,g=0.8,b=0]<br />
\starttext<br />
\color[highlight]{Highlighted text in TeX}<br />
<br />
\startMPcode<br />
label("Highlighted text in MetaPost", origin)<br />
withcolor \MPcolor{highlight};<br />
\stopMPcode<br />
</texcode><br />
|<context mode=mkiv><br />
\definecolor[highlight][r=0.8,g=0.8,b=0]<br />
\starttext<br />
\color[highlight]{Highlighted text in TeX}<br />
<br />
\startMPcode<br />
label("Highlighted text in MetaPost", origin)<br />
withcolor \MPcolor{highlight};<br />
\stopMPcode<br />
</context><br />
|}<br />
<br />
Note that `\MPcolor{...}` behaves similar to a `color` primitive in MetaPost. For example, the following is valid MetaPost code.<br />
<texcode>color myColor; myColor = 0.5[\MPcolor{highlight}, white];</texcode><br />
<br />
For more further reading: [[Color in MetaPost]].<br />
<br />
== Testing if color is defined ==<br />
<br />
To test if a color is defined, use<br />
<br />
* {{cmd|doifcolor}}<br />
* {{cmd|doifcolorelse}}<br />
<br />
Usage:<br />
<br />
<texcode><br />
\doifcolor{color-name}{... if branch ... }<br />
\doifcolorelse{color-name}{... if branch ...}{... else branch ...}<br />
</texcode><br />
<br />
<br />
<br />
= Viewing pre-defined color =<br />
<br />
== View all defined colors ==<br />
<br />
To view pre-defined colors, you can use {{cmd|showcolor}}. For example, to see all the colors defined in {{src|colo-imp-x11.mkiv}}, use (output truncated for display here ...)<br />
<br />
{| <br />
|-<br />
|<texcode>\showcolor[x11]</texcode><br />
|<context mode=mkiv>\startTEXpage[height=5cm]\showcolor[x11]\stopTEXpage</context><br />
|}<br />
<br />
If you use {{cmd|showcolor}} without any argument, all currently defined colors are shown.<br />
<br />
== View specific defined colors ==<br />
<br />
To view the components of a defined color, you can use:<br />
<br />
* {{cmd|showcolorcomponents}}<br />
<texcode>\showcolorcomponents[color-1, color-2]</texcode><br />
<br />
For example,<br />
<br />
{| <br />
|-<br />
|<texcode>\showcolorcomponents[red,middlered,darkred]</texcode><br />
|<context mode=mkiv>\showcolorcomponents[red,middlered,darkred]</context><br />
|}<br />
<br />
* {{cmd|colorcomponents}}<br />
* {{cmd|transparencycomponents}}<br />
* {{cmd|processcolorcomponents}}<br />
<texcode>\colorcompoents{defined-color}<br />
\tranparencycomponents{defined-color}<br />
\processcolorcomponents{defined-color}<br />
</texcode><br />
<br />
For example,<br />
{|<br />
|-<br />
|<texcode><br />
\startlines<br />
\colorcomponents{red}<br />
\transparencycomponents{red}<br />
\processcolorcomponents{red}<br />
\stoplines<br />
</texcode><br />
|<br />
<context mode=mkiv><br />
\startlines<br />
\colorcomponents{red}<br />
\transparencycomponents{red}<br />
\processcolorcomponents{red}<br />
\stoplines<br />
</context><br />
|}<br />
<br />
<br />
= Further reading and specialized topics =<br />
<br />
* [[Transparency]] <br />
* [[Spot Colors]]<br />
* References<br />
** [http://paletton.com Paletton] - Website to choose color palettes<br />
** [http://colorbrewer2.org/ ColorBrewer] - website to choose colors for maps and graphics.<br />
** Tina Sutton, Bride M Whelan: The Complete Color Harmony. Rockport Publishers (2004). ISBN 978-1592530311 (recommanded in the mailing list)<br />
<br />
[[Category:Color]]<br />
[[Category:Graphics]]</div>Mæstrohttps://wiki.contextgarden.net/index.php?title=Debian_installation&diff=33414Debian installation2022-02-14T00:44:12Z<p>Mæstro: /* Install the ConTeXt packages */ - typo fix</p>
<hr />
<div>{{note|Releases of Debian (or any other distribution for that matter) usually contain way too old TeX distributions for ConTeXt MKIV (but should work fine for MKII). If you want to live on bleeding edge, consider using the packages from Debian/unstable, [[ConTeXt Standalone]], or at least install the latest version of [[TeX Live]] with [[TLContrib]] manually.}}<br />
<br />
== Install the ConTeXt packages ==<br />
<br />
The status of ConTeXt in Debian/unstable is currently up to date with TeX Live 2021, and includes all the necessary bits and pieces, plus the modules shipped in TeX Live.<br />
<br />
If you are running Debian sid or later, then the <code>context</code> and <code>context-modules</code> packages should already be visible.<br />
Then do<br />
<br />
aptitude update<br />
aptitude install context context-modules<br />
<br />
* The final version in debian bullseye (aka debian stable 11.2) is 2020.03.10.20200331-1<br />
* In ''unstable'' is a version that is from the TeX Live 2021<br />
<br />
=== Install latest unstable context .deb package ===<br />
<br />
<tt>unstable</tt> means ''(mature) development'', the version number may changes. The software is ''stable''<br />
<br />
1. Download the two .deb-s <br />
http://packages.debian.org/unstable/all/context/download<br />
http://packages.debian.org/unstable/all/context-modules/download<br />
<br />
2. run as root (the version number might have increased a bit)<br />
dpkg --install context_2021.03.05.20220211-1_all.deb<br />
mtxrun --generate<br />
<br />
3. run as user<br />
mtxrun --generate<br />
<br />
Step 2. is currently still necessary, but soon an update of tex-common will run mtxrun --generate automatically when packages have changed (like mktexlsr), and there will be no need to run this anymore.<br />
<br />
Step 3. needs to be done only when you have files in TEXMFHOME or you change things there.<br />
<br />
You have now a system wide context-installation!<br />
<br />
== See also ==<br />
<br />
{{Installation navbox}}<br />
<br />
[[Category:Installation]]</div>Mæstrohttps://wiki.contextgarden.net/index.php?title=Debian_installation&diff=33413Debian installation2022-02-14T00:42:47Z<p>Mæstro: /* Install the ConTeXt packages */ - update to latest debian package information</p>
<hr />
<div>{{note|Releases of Debian (or any other distribution for that matter) usually contain way too old TeX distributions for ConTeXt MKIV (but should work fine for MKII). If you want to live on bleeding edge, consider using the packages from Debian/unstable, [[ConTeXt Standalone]], or at least install the latest version of [[TeX Live]] with [[TLContrib]] manually.}}<br />
<br />
== Install the ConTeXt packages ==<br />
<br />
The status of ConTeXt in Debian/unstable is currently up to date with TeX Live 2021, and includes all the necessary bits and pieces, plus the modules shipped in TeX Live.<br />
<br />
If you are running Debian sid or later, then the <code>context</code> and <code>context-modules</code> packages should already be visible.<br />
Then do<br />
<br />
aptitude update<br />
aptitude install context context-modules<br />
<br />
* The final version in debian bullseye (aka debian stable 11.2) is 2020.03.10.20200331-1<br />
* In ''unstable'' is a the version that is from the TeX Live 2021<br />
<br />
=== Install latest unstable context .deb package ===<br />
<br />
<tt>unstable</tt> means ''(mature) development'', the version number may changes. The software is ''stable''<br />
<br />
1. Download the two .deb-s <br />
http://packages.debian.org/unstable/all/context/download<br />
http://packages.debian.org/unstable/all/context-modules/download<br />
<br />
2. run as root (the version number might have increased a bit)<br />
dpkg --install context_2021.03.05.20220211-1_all.deb<br />
mtxrun --generate<br />
<br />
3. run as user<br />
mtxrun --generate<br />
<br />
Step 2. is currently still necessary, but soon an update of tex-common will run mtxrun --generate automatically when packages have changed (like mktexlsr), and there will be no need to run this anymore.<br />
<br />
Step 3. needs to be done only when you have files in TEXMFHOME or you change things there.<br />
<br />
You have now a system wide context-installation!<br />
<br />
== See also ==<br />
<br />
{{Installation navbox}}<br />
<br />
[[Category:Installation]]</div>Mæstrohttps://wiki.contextgarden.net/index.php?title=User-Defined_Enumerations&diff=33339User-Defined Enumerations2021-12-29T03:47:53Z<p>Mæstro: /* Examples */ uncomment old syntax</p>
<hr />
<div>Sometimes, you might want to enumerate things using a number conversion (that is, the letter or symbol or whatever that "numbers" the item) which isn't one existing ConTeXt enumerations. (For a list of existing conversion, see {{cmd|convertnumber}}. For example, [[User:Mojca Miklavec|Mojca Miklavec]] pointed out on the mailing list that, in Slovenian, it is traditional to letter things using the Slovenian alphabet, which doesn't quite match the English one. [[User:Hagen|Hans]] provided this example of how to create a new enumeration in ConTeXt, which defines a "Mojcanian" numbering system, and a conversion based on those numbers:<br />
<br />
<texcode><br />
\def\mojcaniannumber#1%<br />
{\ifcase#1 \or m\or o\or j\or c\or a\or<br />
m\or i\or k\or l\or a\or v\or e\or c\else<br />
\expandafter\mojcaniannumber\expandafter{\the\numexpr#1-13\relax}\fi}<br />
<br />
\defineconversion[s][\mojcaniannumber]<br />
</texcode><br />
<br />
(The last line of the definition is a cleverness to repeat the letters over and over as needed; more traditional orderings tend to replace that with a simple <tt>-</tt> to indicate an out-of-range letter.)<br />
<br />
We can test this, using the following code:<br />
<br />
<texcode><br />
\starttext<br />
\startitemize[s,columns,five,packed,broad]<br />
\dorecurse{50}{\item test\endgraf}<br />
\stopitemize<br />
\stoptext<br />
</texcode><br />
<br />
<context><br />
\def\mojcaniannumber#1%<br />
{\ifcase#1 \or m\or o\or j\or c\or a\or<br />
m\or i\or k\or l\or a\or v\or e\or c\else<br />
\expandafter\mojcaniannumber\expandafter{\the\numexpr#1-13\relax}\fi}<br />
<br />
\defineconversion[s][\mojcaniannumber]<br />
<br />
\starttext<br />
\startitemize[s,columns,five,packed,broad]<br />
\dorecurse{50}{\item test\endgraf}<br />
\stopitemize<br />
\stoptext<br />
</context><br />
<br />
Conversions can also be language-specific. For instance, suppose that we want the default "character" conversion to be Mojcanian numbers when the language is Slovenian. This can be done with the following conversion defintion:<br />
<br />
<texcode><br />
\defineconversion[sl][a][\mojcaniannumber]<br />
</texcode><br />
<br />
We can test this one like so:<br />
<br />
<texcode><br />
\starttext<br />
English:<br />
\startitemize[a,columns,five,packed,broad]<br />
\dorecurse{15}{\item test\endgraf}<br />
\stopitemize<br />
<br />
Slovenian:<br />
\language[sl]<br />
\startitemize[a,columns,five,packed,broad]<br />
\dorecurse{15}{\item test\endgraf}<br />
\stopitemize<br />
<br />
\stoptext<br />
</texcode><br />
<br />
<context><br />
\def\mojcaniannumber#1%<br />
{\ifcase#1 \or m\or o\or j\or c\or a\or<br />
m\or i\or k\or l\or a\or v\or e\or c\else<br />
\expandafter\mojcaniannumber\expandafter{\the\numexpr#1-13\relax}\fi}<br />
<br />
\defineconversion[sl][a][\mojcaniannumber]<br />
<br />
\starttext<br />
English:<br />
\startitemize[a,columns,five,packed,broad]<br />
\dorecurse{15}{\item test\endgraf}<br />
\stopitemize<br />
<br />
Slovenian:<br />
\language[sl]<br />
\startitemize[a,columns,five,packed,broad]<br />
\dorecurse{15}{\item test\endgraf}<br />
\stopitemize<br />
<br />
\stoptext<br />
</context><br />
<br />
An alternate way of defining conversions is via a list. This has the advantage of being simpler and clearer to program, but the disadvantage that one can't include clever things like repeating the letters <i>ad infinitum</i>, or doubling them up ("..., x, y, z, aa, ab, ac, ...") as the default character enumerations do. For example:<br />
<br />
<texcode><br />
\defineconversion[s][m, o, j, c, a, m, i, k, l, a, v, e, c]<br />
</texcode><br />
<br />
This produces the following, using an <tt>itemize</tt> environment much like the previous examples. Notice how, once we run out of letters, the conversion simply produces empty labels.<br />
<br />
<context><br />
\defineconversion[s][m, o, j, c, a, m, i, k, l, a, v, e, c]<br />
\starttext<br />
\startitemize[s,columns,five,packed,broad]<br />
\dorecurse{20}{\item test\endgraf}<br />
\stopitemize<br />
\stoptext<br />
</context><br />
<br />
There are a number of additional examples of conversion definitions in <tt>core-con.lua</tt>, which is where ConTeXt's default conversions are defined.<br />
<br />
== Examples ==<br />
* Another example of conversion posted by Hans on the mailing list<br />
<br />
<texcode><br />
\defineconversion[ordinal][\enordinaldaynumber]<br />
<br />
\startitemize[ordinal,2*broad]<br />
\item test<br />
\item test<br />
\item test<br />
\item test<br />
\item test<br />
\stopitemize<br />
</texcode><br />
<br />
<context><br />
%\defineconversion[ordinal][\enordinaldaynumber]<br />
<br />
\startitemize[ordinal,2*broad]<br />
\item test<br />
\item test<br />
\item test<br />
\item test<br />
\item test<br />
\stopitemize<br />
</context><br />
<br />
* An example from [[source:meta-txt.tex]]<br />
<br />
<texcode><br />
\useMPlibrary[txt]<br />
\startitemize[fuzzy,2*broad]<br />
\item test<br />
\item test<br />
\item test<br />
\item test<br />
\item test<br />
\stopitemize<br />
</texcode><br />
<br />
<context><br />
%\useMPlibrary[txt]<br />
\startitemize[fuzzy,2*broad]<br />
\item test<br />
\item test<br />
\item test<br />
\item test<br />
\item test<br />
\stopitemize<br />
</context><br />
<br />
[[Category:Basics]]</div>Mæstrohttps://wiki.contextgarden.net/index.php?title=Dummy_text&diff=33338Dummy text2021-12-27T22:57:15Z<p>Mæstro: /* Fake text */ missing bracket</p>
<hr />
<div>* For various short quotations, see {{cmd|input}}. <br />
* For words and paragraphs where the letters are formed by black boxes, see [http://www.pragma-ade.com/general/magazines/mag-0007.pdf This Way: Faking Text and More]. The commands are defined in {{modulesrc|m-visual.mkiv}}.<br />
* For meaningless text, see [[M-ipsum]].<br />
<br />
== \input ==<br />
<br />
The {{cmd|input| ''basename''}} command lets you input text from a {{code|.tex}} file. You don't have to provide your own dummy text: ConTeXt ships with a number of lovely quotations. You can find them described on the {{cmd|input}} page.<br />
<br />
{{Multicol}}<br />
<texcode><br />
% mode=mkiv<br />
\setuppapersize[A7]<br />
\starttext<br />
\input khatt-en<br />
\stoptext<br />
</texcode><br />
{{Multicol-break}}<br />
<br />
<context mode=mkiv><br />
% mode=mkiv<br />
\setuppapersize[A7]<br />
<br />
\starttext<br />
\input khatt-en<br />
\stoptext<br />
</context><br />
{{Multicol-end}}<br />
<br />
== Fake text ==<br />
<br />
The module {{modulesrc|m-visual.mkiv}} contains code to produce word-sized black rectangles in random lengths and numbers.<br />
<br />
{{Multicol}}<br />
<texcode><br />
% mode=mkiv<br />
\setuppapersize[A7]<br />
<br />
\usemodule[visual]<br />
\setupsystem[random=10]<br />
<br />
\setupwhitespace[big]<br />
\setuphead[section][style=tfd]<br />
<br />
\starttext<br />
\section{ \fakewords{3}{4} }<br />
<br />
\fakewords{30}{40} % min, max<br />
<br />
\fakenwords{6}{2} % words, random seed<br />
<br />
\startformula<br />
\fakeformula<br />
\stopformula<br />
\stoptext<br />
</texcode><br />
{{Multicol-break}}<br />
<br />
<context mode=mkiv><br />
% mode=mkiv<br />
\setuppapersize[A7]<br />
<br />
\usemodule[visual]<br />
\setupsystem[random=10]<br />
<br />
\setupwhitespace[big]<br />
\setuphead[section][style=tfd]<br />
<br />
\starttext<br />
\section{ \fakewords{3}{4} }<br />
<br />
\fakewords{30}{40} % min, max<br />
<br />
\fakenwords{6}{2} % words, random seed<br />
<br />
\startformula<br />
\fakeformula<br />
\stopformula<br />
\stoptext<br />
</context><br />
{{Multicol-end}}<br />
<br />
== Lorem ipsum ==<br />
The {{modulesrc|m-ipsum.mkiv}} module lets you define your own lorem ipsum commands. Such a command samples a number of lines, words, or paragraphs from an input file you specify, and typesets them. Thanks to the {{code|1=before=, after=, left=}}, and {{code|1=right=}} keys, you can decorate the sampled lines or words with code, allowing you to fake itemizations, headers, and all sorts of things.<br />
<br />
<texcode><br />
\starttext<br />
\ipsum[<br />
alternative=paragraph,<br />
n=3,<br />
before=\blank,<br />
after=\blank,<br />
language=la<br />
]<br />
<br />
\ipsum[<br />
alternative=lines,<br />
before=\startitemize,<br />
after=\stopitemize,<br />
left=\startitem,<br />
right=\stopitem,<br />
language=la]<br />
<br />
\page<br />
<br />
\defineipsum<br />
[ward]<br />
[file=ward,<br />
before=\blank,<br />
after=\blank]<br />
<br />
\defineipsum<br />
[ward:itemize]<br />
[ward]<br />
[alternative=lines,<br />
before={\startitemize[packed]},<br />
after=\stopitemize,<br />
left=\startitem,<br />
right=\stopitem]<br />
<br />
\ipsum[ward:itemize]<br />
\stoptext<br />
</texcode><br />
<br />
== Letters to rectangles ==<br />
<br />
The typography chapter of the reference manual contains a piece of code that converts letters into black rectangles of the same width, height, and depth.<br />
<br />
{{Multicol}}<br />
<texcode><br />
% Converting every letter into a rectangle.<br />
\def\somecharacter#1%<br />
{\setbox0=\hbox{#1}%<br />
\blackrule[width=\wd0,<br />
height=\ht0,<br />
depth=\dp0]}<br />
<br />
\def\silhouette#1%<br />
{\noindent \processtokens\somecharacter%<br />
\somecharacter\relax\space<br />
{#1}}<br />
<br />
\starttext<br />
The height and depth of lines differs.<br />
<br />
\silhouette{The height and depth of lines <br />
differs.}<br />
\stoptext<br />
</texcode><br />
{{Multicol-break}}<br />
<context source=no><br />
\setuppapersize[A7]<br />
% Converting every letter into a rectangle.<br />
\def\somecharacter#1%<br />
{\setbox0=\hbox{#1}%<br />
\blackrule[width=\wd0,<br />
height=\ht0,<br />
depth=\dp0]}<br />
<br />
\def\silhouette#1%<br />
{\noindent \processtokens\somecharacter%<br />
\somecharacter\relax\space<br />
{#1}}<br />
<br />
\starttext<br />
The height and depth of lines differs.<br />
<br />
\silhouette{The height and depth of lines <br />
differs.}<br />
\stoptext<br />
</context><br />
{{Multicol-end}}<br />
<br />
[[Category:Tools]]</div>Mæstrohttps://wiki.contextgarden.net/index.php?title=Verbatim_text&diff=33337Verbatim text2021-12-27T22:38:29Z<p>Mæstro: /* Defining your own set of colors */ comment on mkii only setting</p>
<hr />
<div>=Displayed text=<br />
{{cmd|starttyping}},<br />
{{cmd|typebuffer}}<br />
<br />
Unlike LaTeX's <code>verbatim</code> environment, ConTeXt's <code>typing</code> environments have quite a range of built-in options for formatting the verbatim text, see below.<br />
<br />
=Inline text=<br />
<br />
To typeset code inside the paragraph, you have the command <code>\type</code>. It can be configured with <code>\setuptype[type][...]</code>. <br />
<br />
To have colored code, you need to use <code>\definetype[NAME][option=TEX]</code> and use it with the name you chose. Other values are: <code>mp lua xml parsed-xml nested tex context</code>.<br />
<br />
An example that shows both features:<br />
<br />
<context source="yes"><br />
\definetype[inlineTEX][option=TEX]<br />
<br />
This is the way to type code: \type{the \ConTeXt\ command}.<br />
<br />
And this is the way to have colored code: \inlineTEX{the \ConTeXt\ command},<br />
</context><br />
<br />
<br />
You can also refer to a TeX command with: {{cmd|tex}}<tt>{a tex command}</tt><br />
<context source="yes"><br />
\tex{a tex command}<br />
</context><br />
<br />
= Making a tight vertical fit =<br />
By default, typing environments include some blank space before the first line and after the last line of the verbatim text. This is because the <tt>before</tt> and <tt>after</tt> commands are set to <tt>\blank</tt> by default. For example:<br />
<br />
<context source="yes"><br />
\framed[offset=0mm,strut=no,align=right]{<br />
\starttyping<br />
Foo<br />
\stoptyping<br />
}<br />
</context><br />
<br />
Here, we've added a <tt>\framed</tt> so you can see the extra spacing, but with <tt>offset=0mm</tt> and <tt>strut=no</tt> to prevent framed from introducing spacing, and <tt>align=right</tt> to prevent framed from eating all newlines (not sure why that works like this).<br />
<br />
To prevent this extra vertical space, we must unset the <tt>before</tt> and <tt>after</tt> options:<br />
<context source="yes"><br />
\setuptyping[before=,after=]<br />
\framed[offset=0mm,strut=no,align=right]{<br />
\starttyping<br />
Foo<br />
\stoptyping<br />
}<br />
</context><br />
<br />
= Embedded formatting commands =<br />
<br />
The <tt>option=commands</tt> setting allows the usage of ConTeXt commands inside verbatim text, as in this example:<br />
<texcode><br />
\definetyping[C][option=commands]<br />
\startC<br />
#include &lt;stdio.h&gt;<br />
int main(){<br />
return 0;<br />
/BTEX{\em unreachedCode;}/ETEX<br />
}<br />
\stopC<br />
</texcode><br />
<br />
<context><br />
\definetyping[C][option=commands]<br />
\startC<br />
#include <stdio.h><br />
int main(){<br />
return 0;<br />
/BTEX{\em unreachedCode;}/ETEX<br />
}<br />
\stopC<br />
</context><br />
<br />
In mkiv option-commands is gone and escape no longer is an escape character but a condition (range or start), as in this example:<br />
<br />
<texcode><br />
\setuptyping[TEX][escape=yes]<br />
<br />
\startTEX<br />
/BTEX\em sometex/ETEX<br />
/BTEX\em sometex/ETEX \after<br />
\before /BTEX\em sometex/ETEX<br />
\before /BTEX\em sometex/ETEX \after<br />
\before /BTEX\em sometex/ETEX \inbetween /BTEX\em sometex/ETEX \after<br />
\before \after<br />
\stopTEX<br />
<br />
\setuptyping[TEX][escape={[[,]]}]<br />
<br />
\startTEX<br />
[[\em sometex]]<br />
[[\em sometex]] \after<br />
\before [[\em sometex]]<br />
\before [[\em sometex]] \after<br />
\before [[\em sometex]] \inbetween [[\em sometex]] \after<br />
\before \after<br />
\stopTEX<br />
<br />
\setuptyping[TEX][escape=//]<br />
<br />
\startTEX<br />
//\em sometex<br />
\before //\em sometex<br />
\stopTEX<br />
</texcode><br />
<br />
[[Image:Verbatim-mkiv.png]]<br />
<br />
= Verbatim with line breaks=<br />
<br />
[[Verbatim with line breaks|Dedicated page]]<br />
<br />
[[Line breaks marker]]<br />
<br />
= Pretty printing =<br />
The context distribution includes a number of formatters (or pretty<br />
printers), that can apply some nice formatting to your verbatim text.<br />
Each formatter knows how to handle a specific file format or programming<br />
language and applies syntax highlighting or other fancy displaying.<br />
<br />
ConTeXt includes a number of predefined formatters, but it is also<br />
possible to define your own. Pretty printing has been completely<br />
redesigned in MkIV, so there are a few differences between MkII and<br />
MkIV. In particular, MkII commonly refers to "formatters", while MkIV<br />
often uses "pretty printers".<br />
<br />
== Included Formatters ==<br />
There are already some formatters for several programming languages in<br />
the ConTeXt distributionr. The following list is for MkII and MkIV.<br />
<br />
{|<br />
! Language !! Code for MkII !! Code for MkIV<br />
|-<br />
| C || [[source:verb-c.mkii|C]] || [[modules:pret-c|C]]<br />
|-<br />
| Eiffel || [[source:verb-eif.mkii|EIF]] ||<br />
|-<br />
| JavaScript || [[source:verb-js.mkii|JS]] ||<br />
|-<br />
| Java || [[source:verb-jv.mkii|JV]] ||<br />
|-<br />
| Lua || || [[source:pret-lua.lua|LUA]]<br />
|-<br />
| MetaPost & MetaFont || [[source:verb-mp.mkii|MP]] || [[source:pret-mp.lua|MP]]<br />
|-<br />
| Pascal & Modula || [[source:verb-pas.mkii|PAS]] ||<br />
|-<br />
| Perl 5 || [[source:verb-pl.mkii|PL]] ||<br />
|-<br />
| SQL || [[source:verb-sql.mkii|SQL]] ||<br />
|-<br />
| TeX || [[source:verb-tex.mkii|TEX]] || [[source:pret-tex.lua|TEX]]<br />
|-<br />
| XML || [[source:verb-xml.mkii|XML]] || [[source:pret-xml.lua|XML]]<br />
|-<br />
|}<br />
<br />
== Your own formatter ==<br />
<br />
You should start from the definition that is closest to the language you want to define (especially wrt comment and string syntax) and can probably have a go at making a version of this. Some <br />
questions occur:<br />
<br />
=== How should I name my file? ===<br />
; MkII: <tt>verb-xxxx.tex</tt>, where <tt>xxxx</tt> is the lowercase name of the formatter.<br />
; MkIV: <tt>pret-xxxx.lua</tt>, where <tt>xxxx</tt> is the lowercase name of the pretty printer.<br />
<br />
=== Where should i put my file? ===<br />
<br />
# Possibly the best place is: In the context distribution, but that depends a bit on what language it is, precisely (you can email me the completed file, in that case).<br />
# Second best place: http://modules.contextgarden.net, so it can be included in cont-ext.zip (third-party addons that are distributed by Pragma-Ade alongside the normal distribution).<br />
# Third best: The directory <$HOME/texmf/tex/context/base> (the place where your TeX installation finds local files).<br />
# Final option: Same directory as the file to be processed<br />
<br />
=== Do I have to do anything else to get ConTeXt to recognise and use it? ===<br />
<br />
You refer to a pretty printer using its name (''e.g.'', the<br />
<tt>xxxx</tt> in <tt>verb-xxxx.tex</tt> or <tt>pret-xxxx.lua</tt>),<br />
which should be in lowercase. Before you can use a pretty printer, you<br />
should let ConTeXt know about it (this has already been done for the<br />
included formatters).<br />
<br />
<texcode><br />
\installprettytype [PHP] [PHP]<br />
</texcode><br />
<br />
This maps the command <code>\starttyping[option=PHP]</code> to the<br />
<tt>php</tt> pretty printer.<br />
<br />
The first argument is the option as passed to \starttyping, the second<br />
argument is an uppercase version of the pretty printer name<br />
(''e.g.'' <tt>xxxx</tt>) (thus allowing ConTeXt to find the file).<br />
<br />
And you probably also want:<br />
<texcode><br />
\definetyping[PHP] [option=PHP]<br />
</texcode><br />
Because that allows <code>\startPHP ... \stopPHP</code> as a shortcut<br />
to <tt>\starttyping[option=PHP] ... \stoptyping</tt>.<br />
<br />
=== How to write the pretty printer? ===<br />
For MkII, there seems to be no real documentation here. You should take<br />
a good look at the existing formatters and base your work off those.<br />
However, if you really need custom pretty printing, you might be better<br />
of to look at MkIV instead, since that allows you to write a pretty<br />
printer in lua, which is a lot less painful than writing them in plain<br />
TeX.<br />
<br />
For MkIV, you should simply write a lua script that processes each line<br />
of input and produces tex output. The details about this are discussed<br />
at [[Custom_pretty_printer]].<br />
<br />
== Improved pretty printing ==<br />
<br />
Default ConTeXt comment handling can be shown in the following sample:<br />
<br />
<context source="yes"><br />
\starttext<br />
\startbuffer[texcode]<br />
This is text. % and this is a comment<br />
\stopbuffer<br />
<br />
\startbuffer[xmlcode]<br />
<p>This is text.<!--and this is a comment--></p><br />
\stopbuffer<br />
<br />
\startbuffer[luacode]<br />
if code=="code" then --this is a comment<br />
<br />
--[[<br />
this is a<br />
<br />
multiline comment<br />
--]]<br />
<br />
---[[<br />
but this isn’t a<br />
<br />
multiline comment<br />
--]]<br />
\stopbuffer<br />
<br />
\typebuffer[texcode][option=TEX]<br />
\typebuffer[xmlcode][option=XML]<br />
\typebuffer[luacode][option=LUA]<br />
\stoptext<br />
</context><br />
<br />
If you want to improve Lua multiline comments and to color the whole comments (not only the comment marker), write <code>\usemodule[scite]</code> before <code>\starttext</code>. (I cannot show it here, since ConTeXt at the wiki seems to have a problem with that.)<br />
<br />
= Tabbing =<br />
<br />
The tab character normally corresponds to one character, as can be seen above. That value can be adjusted, using the following code (available in the 2005.06.01 version and later):<br />
<texcode><br />
\definetyping[C][tab=3]<br />
% for older ConTeXt versions: \chardef\spacespertab=3<br />
\startC<br />
int func(int a){<br />
if(a > 4)<br />
return 0;<br />
else<br />
return 10;<br />
}<br />
\stopC<br />
</texcode><br />
<br />
<context><br />
\definetyping[C][tab=3]<br />
\startC<br />
int func(int a){<br />
if(a > 4)<br />
return 0;<br />
else<br />
return 10;<br />
}<br />
\stopC<br />
</context><br />
<br />
= Syntax highlighting in color =<br />
<br />
<texcode><br />
\setupcolors[state=start]<br />
\setuptyping[option=color]<br />
<br />
\starttext<br />
\startXML<br />
... your XML code ...<br />
\stopXML<br />
\stoptext<br />
</texcode><br />
<br />
:<context><br />
\setupbodyfont[8pt]<br />
\setupcolors[state=start]<br />
\setuptyping[option=color]<br />
<br />
\starttext<br />
\startXML<br />
<?xml version="1.0" encoding="utf-8"?><br />
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"<br />
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><br />
<html><br />
<head><br />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><br />
<title>XML Code Highlighting in ConTeXt</title><br />
<br />
<style type="text/css"><br />
h1 {<br />
text-align: center;<br />
color: blue;<br />
font-family: verdana,sans-serif;<br />
}<br />
</style><br />
</head><br />
<br />
<body><br />
<h1>XML Code Highlighting in ConTeXt</h1><br />
<br />
<!-- To be written ... --><br />
</body><br />
</html><br />
\stopXML<br />
\stoptext<br />
</context><br />
<br />
== Defining your own set of colors ==<br />
<br />
Sometimes you may be not quite satisfied with the default colors used in the built-in syntax highlighting. [[User:Taco|Taco]] posted this solution in the discussion on the [http://archive.contextgarden.net/message/20050825.112308.db696b94.en.html mailing list]:<br />
<br />
<texcode><br />
\setupcolors[state=start]<br />
\setuptyping[option=color]<br />
<br />
% define the colors to fit your document style<br />
\definecolor[MYcolorone] [r=.8,g=.5,b=.5]<br />
\definecolor[MYcolortwo] [r=.8,g=.5,b=.2]<br />
\definecolor[MYcolorthree][r=.8,g=.5,b=.8]<br />
\definecolor[MYcolorfour] [r=.8,g=.2,b=.5]<br />
<br />
% define a palete using these four colors<br />
\definepalet[MYcolors]<br />
[prettyone=MYcolorone,<br />
prettytwo=MYcolortwo,<br />
prettythree=MYcolorthree,<br />
prettyfour=MYcolorfour]<br />
<br />
% XML code will be typeset with the palette you just defined<br />
\definepalet[XMLcolorpretty][MYcolors] % the name is magic ! - mkii only<br />
<br />
\starttext<br />
\startXML<br />
... your XML code ...<br />
\stopXML<br />
\stoptext<br />
</texcode><br />
<br />
This results in:<br />
<br />
<context><br />
\setupbodyfont[8pt]<br />
\definecolor[MYcolorone] [r=.8,g=.5,b=.5]<br />
\definecolor[MYcolortwo] [r=.8,g=.5,b=.2]<br />
\definecolor[MYcolorthree][r=.8,g=.5,b=.8]<br />
\definecolor[MYcolorfour] [r=.8,g=.2,b=.5]<br />
<br />
\definepalet[MYcolors]<br />
[prettyone=MYcolorone,<br />
prettytwo=MYcolortwo,<br />
prettythree=MYcolorthree,<br />
prettyfour=MYcolorfour]<br />
<br />
% \definepalet[XMLcolorpretty][MYcolors] % the name is magic !<br />
<br />
\setupcolors[state=start]<br />
\setuptyping[option=color]<br />
<br />
\starttext<br />
\startXML<br />
<?xml version="1.0" encoding="utf-8"?><br />
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"<br />
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><br />
<html><br />
<head><br />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><br />
<title>XML Code Highlighting in ConTeXt</title><br />
<br />
<style type="text/css"><br />
h1 {<br />
text-align: center;<br />
color: blue;<br />
font-family: verdana,sans-serif;<br />
}<br />
</style><br />
</head><br />
<br />
<body><br />
<h1>XML Code Highlighting in ConTeXt</h1><br />
<br />
<!-- To be written ... --><br />
</body><br />
</html><br />
\stopXML<br />
\stoptext<br />
</context><br />
<br />
== Syntax highlighting source code or configuration files ==<br />
<br />
see [[Verbatim_with_LuaTeX]] with Python, Apache httpd.conf and zc.buildout config files examples.<br />
<br />
= Colored background =<br />
<br />
<texcode><br />
\setupcolors[state=start]<br />
<br />
\definetextbackground[verbatim]<br />
[background=color,<br />
backgroundcolor=yellow,<br />
backgroundoffset=0cm,<br />
offset=0.5cm,<br />
frame=on,<br />
framecolor=black,<br />
location=paragraph,<br />
color=black]<br />
<br />
% Setup verbatim<br />
\setuptyping[typing][margin=1cm,bodyfont=8.0pt,<br />
before={\starttextbackground[verbatim]},<br />
after={\stoptextbackground}]<br />
<br />
\starttext<br />
\starttyping<br />
This is the first line.<br />
This is the second line.<br />
\stoptyping<br />
\stoptext<br />
</texcode><br />
<br />
= Line numbering =<br />
<br />
In technical documents it can be required to display some code listings with the line numbers. You can do this with ConTeXt, and even more. All the features shown here are also available when displaying external files with {{cmd|typefile}}.<br />
<br />
== Preliminary setting ==<br />
Let's define our own typing style, named "code". The typing is put in a framedtext, to demonstrate the wrapping feature in a next section.<br />
<br />
<texcode><br />
\defineframedtext<br />
[framedcode]<br />
[strut=yes,<br />
offset=2mm,<br />
width=7cm,<br />
align=right]<br />
<br />
\definetyping[code][numbering=line,<br />
bodyfont=small,<br />
before={\startframedcode},<br />
after={\stopframedcode}]<br />
</texcode><br />
<br />
== Default line numbering ==<br />
With the defined typing, every line is numbered, and the number goes in the margin. The option to have the line numbers displayed is <tt>numbering=line</tt>.<br />
<br />
<texcode><br />
\startcode<br />
This is the first line<br />
This is a rather long line that is wrapped, so look how the line numbering is done<br />
Another line<br />
<br />
Last line after an empty line<br />
\stopcode<br />
</texcode><br />
<br />
It is rendered as:<br />
<br />
<context><br />
\defineframedtext<br />
[framedcode]<br />
[strut=yes,<br />
offset=2mm,<br />
width=7cm,<br />
align=right]<br />
<br />
\definetyping[code][numbering=line,<br />
bodyfont=small,<br />
before={\startframedcode},<br />
after={\stopframedcode}]<br />
<br />
\startcode<br />
This is the first line<br />
This is a rather long line that is wrapped, so look how the line numbering is done<br />
Another line<br />
<br />
Last line after an empty line<br />
\stopcode<br />
</context><br />
<br />
== Line numbers in the text ==<br />
To have the line numbers in the text, change the linenumbering setup like this (<tt>location=text</tt> for mkiv resp.):<br />
<br />
<texcode><br />
\setuplinenumbering[location=text]<br />
\startcode<br />
This is the first line<br />
This is a rather long line that is wrapped, so look how the line numbering is done<br />
Another line<br />
<br />
Last line after an empty line<br />
\stopcode<br />
</texcode><br />
<br />
<context><br />
\defineframedtext<br />
[framedcode]<br />
[strut=yes,<br />
offset=2mm,<br />
width=7cm,<br />
align=right]<br />
<br />
\definetyping[code][numbering=line,<br />
bodyfont=small,<br />
before={\startframedcode},<br />
after={\stopframedcode}]<br />
<br />
\setuplinenumbering[location=text]<br />
\startcode<br />
This is the first line<br />
This is a rather long line that is wrapped, so look how the line numbering is done<br />
Another line<br />
<br />
Last line after an empty line<br />
\stopcode<br />
</context><br />
<br />
== Continuing the numbering ==<br />
Another handy feature is the ability to continue the numbering from one portion of code to another. Use the option <tt>continue</tt> for this.<br />
<br />
<texcode><br />
\startcode<br />
This is the first line<br />
This is a rather long line that is wrapped, so look how the line numbering is done<br />
Another line<br />
<br />
Last line after an empty line<br />
\stopcode<br />
<br />
Some normal text to explain the first piece of code,<br />
and introduce the following lines.<br />
<br />
\startcode[continue]<br />
This is the first continuing line<br />
This is a rather long line that is wrapped, so look how the line numbering is done<br />
Another line<br />
Last line<br />
\stopcode<br />
</texcode><br />
<br />
<context><br />
\defineframedtext<br />
[framedcode]<br />
[strut=yes,<br />
offset=2mm,<br />
width=7cm,<br />
align=right]<br />
<br />
\definetyping[code][numbering=line,<br />
bodyfont=small,<br />
before={\startframedcode},<br />
after={\stopframedcode}]<br />
<br />
\startcode<br />
This is the first line<br />
This is a rather long line that is wrapped, so look how the line numbering is done<br />
Another line<br />
<br />
Last line after an empty line<br />
\stopcode<br />
<br />
Some normal text to explain the first piece of code, and introduce the following lines.<br />
<br />
\startcode[continue]<br />
This is the first continuing line<br />
This is a rather long line that is wrapped, so look how the line numbering is done<br />
Another line<br />
Last line<br />
\stopcode<br />
</context><br />
<br />
== Arbitrary starting line number ==<br />
You can also decide what the starting line number is. Use the option <tt>start=number</tt> for this.<br />
<br />
<texcode><br />
\startcode[start=200]<br />
This is the first line<br />
This is a rather long line that is wrapped, so look how the line numbering is done<br />
Another line<br />
Last line<br />
\stopcode<br />
</texcode><br />
<br />
<context><br />
\defineframedtext<br />
[framedcode]<br />
[strut=yes,<br />
offset=2mm,<br />
width=7cm,<br />
align=right]<br />
<br />
\definetyping[code][numbering=line,<br />
bodyfont=small,<br />
before={\startframedcode},<br />
after={\stopframedcode}]<br />
<br />
\startcode[start=200]<br />
This is the first line<br />
This is a rather long line that is wrapped, so look how the line numbering is done<br />
Another line<br />
Last line<br />
\stopcode<br />
</context><br />
<br />
== Line number steps ==<br />
You want to print a number every two lines? Ok, just use the option <tt>step=number</tt> for this.<br />
<br />
<texcode><br />
\startcode[start=200,step=2]<br />
This is the first line<br />
This is a rather long line that is wrapped, so look how the line numbering is done<br />
Another line<br />
Last line<br />
\stopcode<br />
</texcode><br />
<br />
<context><br />
\defineframedtext<br />
[framedcode]<br />
[strut=yes,<br />
offset=2mm,<br />
width=7cm,<br />
align=right]<br />
<br />
\definetyping[code][numbering=line,<br />
bodyfont=small,<br />
before={\startframedcode},<br />
after={\stopframedcode}]<br />
<br />
\startcode[start=200,step=2]<br />
This is the first line<br />
This is a rather long line that is wrapped, so look how the line numbering is done<br />
Another line<br />
Last line<br />
\stopcode<br />
</context><br />
<br />
== Referencing line numbers ==<br />
The following example from the mailing list [http://archive.contextgarden.net/thread/20101026.191201.55344b94.en.html#20101026.191201.55344b94] shows how to reference line numbers from a typing in the surrounding text (MkIV).<br />
<br />
<texcode><br />
\setuptyping[numbering=line,escape=yes]<br />
<br />
\starttext<br />
<br />
See \inline[line:single] and also \inline[line:range].<br />
<br />
See \inline{typeline}[line:single] and also \inline{typelines}[line:range].<br />
<br />
See line~\inlinerange[line:single] and also lines~\inlinerange[line:range].<br />
<br />
\starttyping<br />
line 1<br />
line 2/BTEX\startline[line:range]/ETEX<br />
line 3/BTEX\someline[line:single]/ETEX<br />
line 4<br />
line 5/BTEX\stopline[line:range]/ETEX<br />
line 6<br />
\stoptyping<br />
<br />
\stoptext<br />
</texcode><br />
<br />
<br />
= A different approach to formatting and code colorization =<br />
<br />
Supposing that: <br />
<br />
a) you are much more fluent in another programming language than TeX <br />
<br />
b) you have a large project involving many code snippets to be inserted and colorized<br />
<br />
you can go for another, less elegant, way to format your verbatim text, which can include all the discussed ConTeXt benefits. <br />
<br />
== Writing a parser/formatter ==<br />
<br />
It is fairly simple to write a little parser which takes as its input your source file and gives in output a .tex file containing the code plus the opportune commands for colorization. You can then include the resulting .tex file in the global ConTeXt document file.<br />
As an example, [http://www.fonurgia.unito.it/andrea/sw/sc/scToConTeXt.py this] is a Python script for the SuperCollider language, which has a strict Smalltalk-like syntax.<br />
<br />
Fed with the following source code contained in e.g. example.sc file:<br />
<br />
<br />
<context><br />
\tfx<br />
\starttyping<br />
// an example starting with a comment<br />
"this is a string".postln ;<br />
<br />
\aSymbol ;<br />
<br />
ThisClassDoesNotExist ;<br />
\stoptyping<br />
</context><br />
<br />
<br />
the script outputs this tex code, which is written into a file contained in the same folder of the source file (named example.tex):<br />
<br />
<texcode><br />
\startSC<br />
/BTEX\color[SCred]{//// an example starting with a comment}/ETEX<br />
/BTEX\color[SCgrey]{"this is a string"}/ETEX .postln ;<br />
<br />
/BTEX\color[SCgreen]{\letterbackslash aSymbol}/ETEX ;<br />
<br />
/BTEX\color[SCblue]{ThisClassDoesNotExists}/ETEX ;<br />
\stopSC<br />
</texcode><br />
<br />
Basically, the idea is to envelope each item to be colorized inside a /BTEX /ETEX block. <br />
Note that inside the block the text is no more verbatim, so you have to define some string replacements for special characters (e.g. _, %, $, \, etc). <br />
As an example, the problem of the backslash (\) is solved here by replacing it with \letterbackslash. <br />
<br />
You can then insert example.tex in your ConTeXt file with<br />
<br />
<texcode><br />
\input example<br />
</texcode><br />
<br />
<br />
The example.tex file uses some definitions (explained in the previous sections) which have to be put in the ConTeXt file (use <tt>escape=yes</tt> instead of <tt>option=commands</tt> for mkiv). <br />
<br />
<texcode><br />
\defineframedtext<br />
[framedSC]<br />
[framecolor=cirmaBlue,<br />
strut=yes,<br />
offset=2mm,<br />
width=local,<br />
align=right]<br />
<br />
\definetyping[SC][option=commands, <br />
tab=2,numbering=line,<br />
before={\startframedSC},<br />
after={\stopframedSC}]<br />
</texcode><br />
<br />
Also, example.tex requires color definitions, which are created following SuperCollider colorization interpreter scheme and have to be inserted in the ConTeXt file too:<br />
<br />
<texcode><br />
%% SC colors %%<br />
\definecolor [SCwhite] [r=1.0, g=1.0, b=1.0] <br />
\definecolor [SCblack] [r=0.0, g=0.0, b=0.0] <br />
\definecolor [SCblue] [r=0.0, g=0.0, b=0.75] <br />
\definecolor [SCred] [r=0.75, g=0.0, b=0.0] <br />
\definecolor [SCgrey] [r=0.376, g=0.376, b=0.376] <br />
\definecolor [SCgreen] [r=0.0, g=0.45, b=0.0]<br />
<br />
\definecolor[cirmaBlue] [r=.0,g=.2,b=.6] % for frame<br />
</texcode><br />
<br />
The previous definitions will be used for all the code files inserted with \input.<br />
After compiling, this is the result of the discussed example:<br />
<br />
<br />
<context><br />
\setupcolors[state=start]<br />
\starttext<br />
%% SC colors %%<br />
\definecolor [SCwhite] [r=1.0, g=1.0, b=1.0] <br />
\definecolor [SCblack] [r=0.0, g=0.0, b=0.0] <br />
\definecolor [SCblue] [r=0.0, g=0.0, b=0.75] <br />
\definecolor [SCred] [r=0.75, g=0.0, b=0.0] <br />
<br />
\definecolor [SCgrey] [r=0.376, g=0.376, b=0.376] <br />
\definecolor [SCgreen] [r=0.0, g=0.45, b=0.0] <br />
\definecolor[cirmaBlue] [r=.0,g=.2,b=.6] <br />
<br />
\defineframedtext<br />
[framedSC]<br />
[framecolor=cirmaBlue,<br />
strut=yes,<br />
offset=2mm,<br />
width=local,<br />
align=right]<br />
<br />
\definetyping[SC][option=commands, <br />
tab=2,numbering=line,<br />
before={\startframedSC},<br />
after={\stopframedSC}]<br />
<br />
\startSC<br />
/BTEX{\color[SCred] //// an example starting with a comment}/ETEX<br />
/BTEX{\color[SCgrey] "this is a string"}/ETEX .postln ;<br />
<br />
/BTEX{\color[SCgreen] \letterbackslash aSymbol}/ETEX ;<br />
<br />
/BTEX{\color[SCblue] ThisClassDoesNotExists}/ETEX ;<br />
\stopSC<br />
<br />
\stoptext<br />
</context><br />
<br />
== Embedding the source code ==<br />
<br />
If your document is inteded to provide code examples to be tested by the readers, the presence of format signs (e.g. line numbers) can create some troubles while copying and pasting the code text from your document to the language environment. More generally, the copy and paste approach, being slow and possibly related to encodings, is not satisfying at all.<br />
You can include source files in the pdf with a couple of ConTeXt commands:<br />
<br />
<texcode><br />
\useattachment[ex][example.sc]<br />
\attachment[ex]<br />
</texcode><br />
<br />
<br />
So that you can have this structure for each code snippet:<br />
<br />
<texcode><br />
\input example<br />
<br />
\useattachment[ex][example.sc]<br />
\attachment[ex]<br />
</texcode><br />
<br />
<br />
The commands embed example.sc in the pdf, so that it is accessible by double-clicking on a generated icon. In this case the icon is placed after the colorized code frame.<br />
If you use Acrobat Reader (Preview.app in MacOSX does not provide support for the behaviour) example.sc will be open in the related application (e.g. SuperCollider.app in the discussed case).<br />
<br />
<br />
The discussed approach has been implemented [http://www.cirma.unito.it/andrea/sw/sc/prd_tSCIRMA.pdf here].<br />
<br />
(-a- --> [[User:Andrea]])<br />
<br />
<br />
[[Category:Basics]]</div>Mæstrohttps://wiki.contextgarden.net/index.php?title=Verbatim_text&diff=33336Verbatim text2021-12-27T22:30:56Z<p>Mæstro: /* Line numbers in the text */ change intext to text</p>
<hr />
<div>=Displayed text=<br />
{{cmd|starttyping}},<br />
{{cmd|typebuffer}}<br />
<br />
Unlike LaTeX's <code>verbatim</code> environment, ConTeXt's <code>typing</code> environments have quite a range of built-in options for formatting the verbatim text, see below.<br />
<br />
=Inline text=<br />
<br />
To typeset code inside the paragraph, you have the command <code>\type</code>. It can be configured with <code>\setuptype[type][...]</code>. <br />
<br />
To have colored code, you need to use <code>\definetype[NAME][option=TEX]</code> and use it with the name you chose. Other values are: <code>mp lua xml parsed-xml nested tex context</code>.<br />
<br />
An example that shows both features:<br />
<br />
<context source="yes"><br />
\definetype[inlineTEX][option=TEX]<br />
<br />
This is the way to type code: \type{the \ConTeXt\ command}.<br />
<br />
And this is the way to have colored code: \inlineTEX{the \ConTeXt\ command},<br />
</context><br />
<br />
<br />
You can also refer to a TeX command with: {{cmd|tex}}<tt>{a tex command}</tt><br />
<context source="yes"><br />
\tex{a tex command}<br />
</context><br />
<br />
= Making a tight vertical fit =<br />
By default, typing environments include some blank space before the first line and after the last line of the verbatim text. This is because the <tt>before</tt> and <tt>after</tt> commands are set to <tt>\blank</tt> by default. For example:<br />
<br />
<context source="yes"><br />
\framed[offset=0mm,strut=no,align=right]{<br />
\starttyping<br />
Foo<br />
\stoptyping<br />
}<br />
</context><br />
<br />
Here, we've added a <tt>\framed</tt> so you can see the extra spacing, but with <tt>offset=0mm</tt> and <tt>strut=no</tt> to prevent framed from introducing spacing, and <tt>align=right</tt> to prevent framed from eating all newlines (not sure why that works like this).<br />
<br />
To prevent this extra vertical space, we must unset the <tt>before</tt> and <tt>after</tt> options:<br />
<context source="yes"><br />
\setuptyping[before=,after=]<br />
\framed[offset=0mm,strut=no,align=right]{<br />
\starttyping<br />
Foo<br />
\stoptyping<br />
}<br />
</context><br />
<br />
= Embedded formatting commands =<br />
<br />
The <tt>option=commands</tt> setting allows the usage of ConTeXt commands inside verbatim text, as in this example:<br />
<texcode><br />
\definetyping[C][option=commands]<br />
\startC<br />
#include &lt;stdio.h&gt;<br />
int main(){<br />
return 0;<br />
/BTEX{\em unreachedCode;}/ETEX<br />
}<br />
\stopC<br />
</texcode><br />
<br />
<context><br />
\definetyping[C][option=commands]<br />
\startC<br />
#include <stdio.h><br />
int main(){<br />
return 0;<br />
/BTEX{\em unreachedCode;}/ETEX<br />
}<br />
\stopC<br />
</context><br />
<br />
In mkiv option-commands is gone and escape no longer is an escape character but a condition (range or start), as in this example:<br />
<br />
<texcode><br />
\setuptyping[TEX][escape=yes]<br />
<br />
\startTEX<br />
/BTEX\em sometex/ETEX<br />
/BTEX\em sometex/ETEX \after<br />
\before /BTEX\em sometex/ETEX<br />
\before /BTEX\em sometex/ETEX \after<br />
\before /BTEX\em sometex/ETEX \inbetween /BTEX\em sometex/ETEX \after<br />
\before \after<br />
\stopTEX<br />
<br />
\setuptyping[TEX][escape={[[,]]}]<br />
<br />
\startTEX<br />
[[\em sometex]]<br />
[[\em sometex]] \after<br />
\before [[\em sometex]]<br />
\before [[\em sometex]] \after<br />
\before [[\em sometex]] \inbetween [[\em sometex]] \after<br />
\before \after<br />
\stopTEX<br />
<br />
\setuptyping[TEX][escape=//]<br />
<br />
\startTEX<br />
//\em sometex<br />
\before //\em sometex<br />
\stopTEX<br />
</texcode><br />
<br />
[[Image:Verbatim-mkiv.png]]<br />
<br />
= Verbatim with line breaks=<br />
<br />
[[Verbatim with line breaks|Dedicated page]]<br />
<br />
[[Line breaks marker]]<br />
<br />
= Pretty printing =<br />
The context distribution includes a number of formatters (or pretty<br />
printers), that can apply some nice formatting to your verbatim text.<br />
Each formatter knows how to handle a specific file format or programming<br />
language and applies syntax highlighting or other fancy displaying.<br />
<br />
ConTeXt includes a number of predefined formatters, but it is also<br />
possible to define your own. Pretty printing has been completely<br />
redesigned in MkIV, so there are a few differences between MkII and<br />
MkIV. In particular, MkII commonly refers to "formatters", while MkIV<br />
often uses "pretty printers".<br />
<br />
== Included Formatters ==<br />
There are already some formatters for several programming languages in<br />
the ConTeXt distributionr. The following list is for MkII and MkIV.<br />
<br />
{|<br />
! Language !! Code for MkII !! Code for MkIV<br />
|-<br />
| C || [[source:verb-c.mkii|C]] || [[modules:pret-c|C]]<br />
|-<br />
| Eiffel || [[source:verb-eif.mkii|EIF]] ||<br />
|-<br />
| JavaScript || [[source:verb-js.mkii|JS]] ||<br />
|-<br />
| Java || [[source:verb-jv.mkii|JV]] ||<br />
|-<br />
| Lua || || [[source:pret-lua.lua|LUA]]<br />
|-<br />
| MetaPost & MetaFont || [[source:verb-mp.mkii|MP]] || [[source:pret-mp.lua|MP]]<br />
|-<br />
| Pascal & Modula || [[source:verb-pas.mkii|PAS]] ||<br />
|-<br />
| Perl 5 || [[source:verb-pl.mkii|PL]] ||<br />
|-<br />
| SQL || [[source:verb-sql.mkii|SQL]] ||<br />
|-<br />
| TeX || [[source:verb-tex.mkii|TEX]] || [[source:pret-tex.lua|TEX]]<br />
|-<br />
| XML || [[source:verb-xml.mkii|XML]] || [[source:pret-xml.lua|XML]]<br />
|-<br />
|}<br />
<br />
== Your own formatter ==<br />
<br />
You should start from the definition that is closest to the language you want to define (especially wrt comment and string syntax) and can probably have a go at making a version of this. Some <br />
questions occur:<br />
<br />
=== How should I name my file? ===<br />
; MkII: <tt>verb-xxxx.tex</tt>, where <tt>xxxx</tt> is the lowercase name of the formatter.<br />
; MkIV: <tt>pret-xxxx.lua</tt>, where <tt>xxxx</tt> is the lowercase name of the pretty printer.<br />
<br />
=== Where should i put my file? ===<br />
<br />
# Possibly the best place is: In the context distribution, but that depends a bit on what language it is, precisely (you can email me the completed file, in that case).<br />
# Second best place: http://modules.contextgarden.net, so it can be included in cont-ext.zip (third-party addons that are distributed by Pragma-Ade alongside the normal distribution).<br />
# Third best: The directory <$HOME/texmf/tex/context/base> (the place where your TeX installation finds local files).<br />
# Final option: Same directory as the file to be processed<br />
<br />
=== Do I have to do anything else to get ConTeXt to recognise and use it? ===<br />
<br />
You refer to a pretty printer using its name (''e.g.'', the<br />
<tt>xxxx</tt> in <tt>verb-xxxx.tex</tt> or <tt>pret-xxxx.lua</tt>),<br />
which should be in lowercase. Before you can use a pretty printer, you<br />
should let ConTeXt know about it (this has already been done for the<br />
included formatters).<br />
<br />
<texcode><br />
\installprettytype [PHP] [PHP]<br />
</texcode><br />
<br />
This maps the command <code>\starttyping[option=PHP]</code> to the<br />
<tt>php</tt> pretty printer.<br />
<br />
The first argument is the option as passed to \starttyping, the second<br />
argument is an uppercase version of the pretty printer name<br />
(''e.g.'' <tt>xxxx</tt>) (thus allowing ConTeXt to find the file).<br />
<br />
And you probably also want:<br />
<texcode><br />
\definetyping[PHP] [option=PHP]<br />
</texcode><br />
Because that allows <code>\startPHP ... \stopPHP</code> as a shortcut<br />
to <tt>\starttyping[option=PHP] ... \stoptyping</tt>.<br />
<br />
=== How to write the pretty printer? ===<br />
For MkII, there seems to be no real documentation here. You should take<br />
a good look at the existing formatters and base your work off those.<br />
However, if you really need custom pretty printing, you might be better<br />
of to look at MkIV instead, since that allows you to write a pretty<br />
printer in lua, which is a lot less painful than writing them in plain<br />
TeX.<br />
<br />
For MkIV, you should simply write a lua script that processes each line<br />
of input and produces tex output. The details about this are discussed<br />
at [[Custom_pretty_printer]].<br />
<br />
== Improved pretty printing ==<br />
<br />
Default ConTeXt comment handling can be shown in the following sample:<br />
<br />
<context source="yes"><br />
\starttext<br />
\startbuffer[texcode]<br />
This is text. % and this is a comment<br />
\stopbuffer<br />
<br />
\startbuffer[xmlcode]<br />
<p>This is text.<!--and this is a comment--></p><br />
\stopbuffer<br />
<br />
\startbuffer[luacode]<br />
if code=="code" then --this is a comment<br />
<br />
--[[<br />
this is a<br />
<br />
multiline comment<br />
--]]<br />
<br />
---[[<br />
but this isn’t a<br />
<br />
multiline comment<br />
--]]<br />
\stopbuffer<br />
<br />
\typebuffer[texcode][option=TEX]<br />
\typebuffer[xmlcode][option=XML]<br />
\typebuffer[luacode][option=LUA]<br />
\stoptext<br />
</context><br />
<br />
If you want to improve Lua multiline comments and to color the whole comments (not only the comment marker), write <code>\usemodule[scite]</code> before <code>\starttext</code>. (I cannot show it here, since ConTeXt at the wiki seems to have a problem with that.)<br />
<br />
= Tabbing =<br />
<br />
The tab character normally corresponds to one character, as can be seen above. That value can be adjusted, using the following code (available in the 2005.06.01 version and later):<br />
<texcode><br />
\definetyping[C][tab=3]<br />
% for older ConTeXt versions: \chardef\spacespertab=3<br />
\startC<br />
int func(int a){<br />
if(a > 4)<br />
return 0;<br />
else<br />
return 10;<br />
}<br />
\stopC<br />
</texcode><br />
<br />
<context><br />
\definetyping[C][tab=3]<br />
\startC<br />
int func(int a){<br />
if(a > 4)<br />
return 0;<br />
else<br />
return 10;<br />
}<br />
\stopC<br />
</context><br />
<br />
= Syntax highlighting in color =<br />
<br />
<texcode><br />
\setupcolors[state=start]<br />
\setuptyping[option=color]<br />
<br />
\starttext<br />
\startXML<br />
... your XML code ...<br />
\stopXML<br />
\stoptext<br />
</texcode><br />
<br />
:<context><br />
\setupbodyfont[8pt]<br />
\setupcolors[state=start]<br />
\setuptyping[option=color]<br />
<br />
\starttext<br />
\startXML<br />
<?xml version="1.0" encoding="utf-8"?><br />
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"<br />
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><br />
<html><br />
<head><br />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><br />
<title>XML Code Highlighting in ConTeXt</title><br />
<br />
<style type="text/css"><br />
h1 {<br />
text-align: center;<br />
color: blue;<br />
font-family: verdana,sans-serif;<br />
}<br />
</style><br />
</head><br />
<br />
<body><br />
<h1>XML Code Highlighting in ConTeXt</h1><br />
<br />
<!-- To be written ... --><br />
</body><br />
</html><br />
\stopXML<br />
\stoptext<br />
</context><br />
<br />
== Defining your own set of colors ==<br />
<br />
Sometimes you may be not quite satisfied with the default colors used in the built-in syntax highlighting. [[User:Taco|Taco]] posted this solution in the discussion on the [http://archive.contextgarden.net/message/20050825.112308.db696b94.en.html mailing list]:<br />
<br />
<texcode><br />
\setupcolors[state=start]<br />
\setuptyping[option=color]<br />
<br />
% define the colors to fit your document style<br />
\definecolor[MYcolorone] [r=.8,g=.5,b=.5]<br />
\definecolor[MYcolortwo] [r=.8,g=.5,b=.2]<br />
\definecolor[MYcolorthree][r=.8,g=.5,b=.8]<br />
\definecolor[MYcolorfour] [r=.8,g=.2,b=.5]<br />
<br />
% define a palete using these four colors<br />
\definepalet[MYcolors]<br />
[prettyone=MYcolorone,<br />
prettytwo=MYcolortwo,<br />
prettythree=MYcolorthree,<br />
prettyfour=MYcolorfour]<br />
<br />
% XML code will be typeset with the palette you just defined<br />
\definepalet[XMLcolorpretty] [MYcolors] % the name is magic !<br />
<br />
\starttext<br />
\startXML<br />
... your XML code ...<br />
\stopXML<br />
\stoptext<br />
</texcode><br />
<br />
This results in:<br />
<br />
:<context><br />
\setupbodyfont[8pt]<br />
\definecolor[MYcolorone] [r=.8,g=.5,b=.5]<br />
\definecolor[MYcolortwo] [r=.8,g=.5,b=.2]<br />
\definecolor[MYcolorthree][r=.8,g=.5,b=.8]<br />
\definecolor[MYcolorfour] [r=.8,g=.2,b=.5]<br />
<br />
\definepalet[MYcolors]<br />
[prettyone=MYcolorone,<br />
prettytwo=MYcolortwo,<br />
prettythree=MYcolorthree,<br />
prettyfour=MYcolorfour]<br />
<br />
\definepalet[XMLcolorpretty] [MYcolors] % the name is magic !<br />
<br />
\setupcolors[state=start]<br />
\setuptyping[option=color]<br />
<br />
\starttext<br />
\startXML<br />
<?xml version="1.0" encoding="utf-8"?><br />
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"<br />
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><br />
<html><br />
<head><br />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><br />
<title>XML Code Highlighting in ConTeXt</title><br />
<br />
<style type="text/css"><br />
h1 {<br />
text-align: center;<br />
color: blue;<br />
font-family: verdana,sans-serif;<br />
}<br />
</style><br />
</head><br />
<br />
<body><br />
<h1>XML Code Highlighting in ConTeXt</h1><br />
<br />
<!-- To be written ... --><br />
</body><br />
</html><br />
\stopXML<br />
\stoptext<br />
</context><br />
<br />
== Syntax highlighting source code or configuration files ==<br />
<br />
see [[Verbatim_with_LuaTeX]] with Python, Apache httpd.conf and zc.buildout config files examples.<br />
<br />
= Colored background =<br />
<br />
<texcode><br />
\setupcolors[state=start]<br />
<br />
\definetextbackground[verbatim]<br />
[background=color,<br />
backgroundcolor=yellow,<br />
backgroundoffset=0cm,<br />
offset=0.5cm,<br />
frame=on,<br />
framecolor=black,<br />
location=paragraph,<br />
color=black]<br />
<br />
% Setup verbatim<br />
\setuptyping[typing][margin=1cm,bodyfont=8.0pt,<br />
before={\starttextbackground[verbatim]},<br />
after={\stoptextbackground}]<br />
<br />
\starttext<br />
\starttyping<br />
This is the first line.<br />
This is the second line.<br />
\stoptyping<br />
\stoptext<br />
</texcode><br />
<br />
= Line numbering =<br />
<br />
In technical documents it can be required to display some code listings with the line numbers. You can do this with ConTeXt, and even more. All the features shown here are also available when displaying external files with {{cmd|typefile}}.<br />
<br />
== Preliminary setting ==<br />
Let's define our own typing style, named "code". The typing is put in a framedtext, to demonstrate the wrapping feature in a next section.<br />
<br />
<texcode><br />
\defineframedtext<br />
[framedcode]<br />
[strut=yes,<br />
offset=2mm,<br />
width=7cm,<br />
align=right]<br />
<br />
\definetyping[code][numbering=line,<br />
bodyfont=small,<br />
before={\startframedcode},<br />
after={\stopframedcode}]<br />
</texcode><br />
<br />
== Default line numbering ==<br />
With the defined typing, every line is numbered, and the number goes in the margin. The option to have the line numbers displayed is <tt>numbering=line</tt>.<br />
<br />
<texcode><br />
\startcode<br />
This is the first line<br />
This is a rather long line that is wrapped, so look how the line numbering is done<br />
Another line<br />
<br />
Last line after an empty line<br />
\stopcode<br />
</texcode><br />
<br />
It is rendered as:<br />
<br />
<context><br />
\defineframedtext<br />
[framedcode]<br />
[strut=yes,<br />
offset=2mm,<br />
width=7cm,<br />
align=right]<br />
<br />
\definetyping[code][numbering=line,<br />
bodyfont=small,<br />
before={\startframedcode},<br />
after={\stopframedcode}]<br />
<br />
\startcode<br />
This is the first line<br />
This is a rather long line that is wrapped, so look how the line numbering is done<br />
Another line<br />
<br />
Last line after an empty line<br />
\stopcode<br />
</context><br />
<br />
== Line numbers in the text ==<br />
To have the line numbers in the text, change the linenumbering setup like this (<tt>location=text</tt> for mkiv resp.):<br />
<br />
<texcode><br />
\setuplinenumbering[location=text]<br />
\startcode<br />
This is the first line<br />
This is a rather long line that is wrapped, so look how the line numbering is done<br />
Another line<br />
<br />
Last line after an empty line<br />
\stopcode<br />
</texcode><br />
<br />
<context><br />
\defineframedtext<br />
[framedcode]<br />
[strut=yes,<br />
offset=2mm,<br />
width=7cm,<br />
align=right]<br />
<br />
\definetyping[code][numbering=line,<br />
bodyfont=small,<br />
before={\startframedcode},<br />
after={\stopframedcode}]<br />
<br />
\setuplinenumbering[location=text]<br />
\startcode<br />
This is the first line<br />
This is a rather long line that is wrapped, so look how the line numbering is done<br />
Another line<br />
<br />
Last line after an empty line<br />
\stopcode<br />
</context><br />
<br />
== Continuing the numbering ==<br />
Another handy feature is the ability to continue the numbering from one portion of code to another. Use the option <tt>continue</tt> for this.<br />
<br />
<texcode><br />
\startcode<br />
This is the first line<br />
This is a rather long line that is wrapped, so look how the line numbering is done<br />
Another line<br />
<br />
Last line after an empty line<br />
\stopcode<br />
<br />
Some normal text to explain the first piece of code,<br />
and introduce the following lines.<br />
<br />
\startcode[continue]<br />
This is the first continuing line<br />
This is a rather long line that is wrapped, so look how the line numbering is done<br />
Another line<br />
Last line<br />
\stopcode<br />
</texcode><br />
<br />
<context><br />
\defineframedtext<br />
[framedcode]<br />
[strut=yes,<br />
offset=2mm,<br />
width=7cm,<br />
align=right]<br />
<br />
\definetyping[code][numbering=line,<br />
bodyfont=small,<br />
before={\startframedcode},<br />
after={\stopframedcode}]<br />
<br />
\startcode<br />
This is the first line<br />
This is a rather long line that is wrapped, so look how the line numbering is done<br />
Another line<br />
<br />
Last line after an empty line<br />
\stopcode<br />
<br />
Some normal text to explain the first piece of code, and introduce the following lines.<br />
<br />
\startcode[continue]<br />
This is the first continuing line<br />
This is a rather long line that is wrapped, so look how the line numbering is done<br />
Another line<br />
Last line<br />
\stopcode<br />
</context><br />
<br />
== Arbitrary starting line number ==<br />
You can also decide what the starting line number is. Use the option <tt>start=number</tt> for this.<br />
<br />
<texcode><br />
\startcode[start=200]<br />
This is the first line<br />
This is a rather long line that is wrapped, so look how the line numbering is done<br />
Another line<br />
Last line<br />
\stopcode<br />
</texcode><br />
<br />
<context><br />
\defineframedtext<br />
[framedcode]<br />
[strut=yes,<br />
offset=2mm,<br />
width=7cm,<br />
align=right]<br />
<br />
\definetyping[code][numbering=line,<br />
bodyfont=small,<br />
before={\startframedcode},<br />
after={\stopframedcode}]<br />
<br />
\startcode[start=200]<br />
This is the first line<br />
This is a rather long line that is wrapped, so look how the line numbering is done<br />
Another line<br />
Last line<br />
\stopcode<br />
</context><br />
<br />
== Line number steps ==<br />
You want to print a number every two lines? Ok, just use the option <tt>step=number</tt> for this.<br />
<br />
<texcode><br />
\startcode[start=200,step=2]<br />
This is the first line<br />
This is a rather long line that is wrapped, so look how the line numbering is done<br />
Another line<br />
Last line<br />
\stopcode<br />
</texcode><br />
<br />
<context><br />
\defineframedtext<br />
[framedcode]<br />
[strut=yes,<br />
offset=2mm,<br />
width=7cm,<br />
align=right]<br />
<br />
\definetyping[code][numbering=line,<br />
bodyfont=small,<br />
before={\startframedcode},<br />
after={\stopframedcode}]<br />
<br />
\startcode[start=200,step=2]<br />
This is the first line<br />
This is a rather long line that is wrapped, so look how the line numbering is done<br />
Another line<br />
Last line<br />
\stopcode<br />
</context><br />
<br />
== Referencing line numbers ==<br />
The following example from the mailing list [http://archive.contextgarden.net/thread/20101026.191201.55344b94.en.html#20101026.191201.55344b94] shows how to reference line numbers from a typing in the surrounding text (MkIV).<br />
<br />
<texcode><br />
\setuptyping[numbering=line,escape=yes]<br />
<br />
\starttext<br />
<br />
See \inline[line:single] and also \inline[line:range].<br />
<br />
See \inline{typeline}[line:single] and also \inline{typelines}[line:range].<br />
<br />
See line~\inlinerange[line:single] and also lines~\inlinerange[line:range].<br />
<br />
\starttyping<br />
line 1<br />
line 2/BTEX\startline[line:range]/ETEX<br />
line 3/BTEX\someline[line:single]/ETEX<br />
line 4<br />
line 5/BTEX\stopline[line:range]/ETEX<br />
line 6<br />
\stoptyping<br />
<br />
\stoptext<br />
</texcode><br />
<br />
<br />
= A different approach to formatting and code colorization =<br />
<br />
Supposing that: <br />
<br />
a) you are much more fluent in another programming language than TeX <br />
<br />
b) you have a large project involving many code snippets to be inserted and colorized<br />
<br />
you can go for another, less elegant, way to format your verbatim text, which can include all the discussed ConTeXt benefits. <br />
<br />
== Writing a parser/formatter ==<br />
<br />
It is fairly simple to write a little parser which takes as its input your source file and gives in output a .tex file containing the code plus the opportune commands for colorization. You can then include the resulting .tex file in the global ConTeXt document file.<br />
As an example, [http://www.fonurgia.unito.it/andrea/sw/sc/scToConTeXt.py this] is a Python script for the SuperCollider language, which has a strict Smalltalk-like syntax.<br />
<br />
Fed with the following source code contained in e.g. example.sc file:<br />
<br />
<br />
<context><br />
\tfx<br />
\starttyping<br />
// an example starting with a comment<br />
"this is a string".postln ;<br />
<br />
\aSymbol ;<br />
<br />
ThisClassDoesNotExist ;<br />
\stoptyping<br />
</context><br />
<br />
<br />
the script outputs this tex code, which is written into a file contained in the same folder of the source file (named example.tex):<br />
<br />
<texcode><br />
\startSC<br />
/BTEX\color[SCred]{//// an example starting with a comment}/ETEX<br />
/BTEX\color[SCgrey]{"this is a string"}/ETEX .postln ;<br />
<br />
/BTEX\color[SCgreen]{\letterbackslash aSymbol}/ETEX ;<br />
<br />
/BTEX\color[SCblue]{ThisClassDoesNotExists}/ETEX ;<br />
\stopSC<br />
</texcode><br />
<br />
Basically, the idea is to envelope each item to be colorized inside a /BTEX /ETEX block. <br />
Note that inside the block the text is no more verbatim, so you have to define some string replacements for special characters (e.g. _, %, $, \, etc). <br />
As an example, the problem of the backslash (\) is solved here by replacing it with \letterbackslash. <br />
<br />
You can then insert example.tex in your ConTeXt file with<br />
<br />
<texcode><br />
\input example<br />
</texcode><br />
<br />
<br />
The example.tex file uses some definitions (explained in the previous sections) which have to be put in the ConTeXt file (use <tt>escape=yes</tt> instead of <tt>option=commands</tt> for mkiv). <br />
<br />
<texcode><br />
\defineframedtext<br />
[framedSC]<br />
[framecolor=cirmaBlue,<br />
strut=yes,<br />
offset=2mm,<br />
width=local,<br />
align=right]<br />
<br />
\definetyping[SC][option=commands, <br />
tab=2,numbering=line,<br />
before={\startframedSC},<br />
after={\stopframedSC}]<br />
</texcode><br />
<br />
Also, example.tex requires color definitions, which are created following SuperCollider colorization interpreter scheme and have to be inserted in the ConTeXt file too:<br />
<br />
<texcode><br />
%% SC colors %%<br />
\definecolor [SCwhite] [r=1.0, g=1.0, b=1.0] <br />
\definecolor [SCblack] [r=0.0, g=0.0, b=0.0] <br />
\definecolor [SCblue] [r=0.0, g=0.0, b=0.75] <br />
\definecolor [SCred] [r=0.75, g=0.0, b=0.0] <br />
\definecolor [SCgrey] [r=0.376, g=0.376, b=0.376] <br />
\definecolor [SCgreen] [r=0.0, g=0.45, b=0.0]<br />
<br />
\definecolor[cirmaBlue] [r=.0,g=.2,b=.6] % for frame<br />
</texcode><br />
<br />
The previous definitions will be used for all the code files inserted with \input.<br />
After compiling, this is the result of the discussed example:<br />
<br />
<br />
<context><br />
\setupcolors[state=start]<br />
\starttext<br />
%% SC colors %%<br />
\definecolor [SCwhite] [r=1.0, g=1.0, b=1.0] <br />
\definecolor [SCblack] [r=0.0, g=0.0, b=0.0] <br />
\definecolor [SCblue] [r=0.0, g=0.0, b=0.75] <br />
\definecolor [SCred] [r=0.75, g=0.0, b=0.0] <br />
<br />
\definecolor [SCgrey] [r=0.376, g=0.376, b=0.376] <br />
\definecolor [SCgreen] [r=0.0, g=0.45, b=0.0] <br />
\definecolor[cirmaBlue] [r=.0,g=.2,b=.6] <br />
<br />
\defineframedtext<br />
[framedSC]<br />
[framecolor=cirmaBlue,<br />
strut=yes,<br />
offset=2mm,<br />
width=local,<br />
align=right]<br />
<br />
\definetyping[SC][option=commands, <br />
tab=2,numbering=line,<br />
before={\startframedSC},<br />
after={\stopframedSC}]<br />
<br />
\startSC<br />
/BTEX{\color[SCred] //// an example starting with a comment}/ETEX<br />
/BTEX{\color[SCgrey] "this is a string"}/ETEX .postln ;<br />
<br />
/BTEX{\color[SCgreen] \letterbackslash aSymbol}/ETEX ;<br />
<br />
/BTEX{\color[SCblue] ThisClassDoesNotExists}/ETEX ;<br />
\stopSC<br />
<br />
\stoptext<br />
</context><br />
<br />
== Embedding the source code ==<br />
<br />
If your document is inteded to provide code examples to be tested by the readers, the presence of format signs (e.g. line numbers) can create some troubles while copying and pasting the code text from your document to the language environment. More generally, the copy and paste approach, being slow and possibly related to encodings, is not satisfying at all.<br />
You can include source files in the pdf with a couple of ConTeXt commands:<br />
<br />
<texcode><br />
\useattachment[ex][example.sc]<br />
\attachment[ex]<br />
</texcode><br />
<br />
<br />
So that you can have this structure for each code snippet:<br />
<br />
<texcode><br />
\input example<br />
<br />
\useattachment[ex][example.sc]<br />
\attachment[ex]<br />
</texcode><br />
<br />
<br />
The commands embed example.sc in the pdf, so that it is accessible by double-clicking on a generated icon. In this case the icon is placed after the colorized code frame.<br />
If you use Acrobat Reader (Preview.app in MacOSX does not provide support for the behaviour) example.sc will be open in the related application (e.g. SuperCollider.app in the discussed case).<br />
<br />
<br />
The discussed approach has been implemented [http://www.cirma.unito.it/andrea/sw/sc/prd_tSCIRMA.pdf here].<br />
<br />
(-a- --> [[User:Andrea]])<br />
<br />
<br />
[[Category:Basics]]</div>Mæstrohttps://wiki.contextgarden.net/index.php?title=Programming_in_LuaTeX&diff=32565Programming in LuaTeX2021-05-29T13:21:05Z<p>Mæstro: /* Arithmetic without using an abacus */ - add math-fun examples for lmtx</p>
<hr />
<div>= Calling Lua from TeX =<br />
<br />
The interweaving of ConTeXt and Lua consists of two elements: first you tell TeX that you're starting some Lua code; then, once inside Lua, you need to use the appropriate functions to put things into the TeX stream.<br />
<br />
There are two main ways to execute Lua code in a ConTeXt document: The command <code>\ctxlua</code>, and the environment <code>\startluacode...\stopluacode</code>. Both are wrappers around the LuaTeX primitive <code>\directlua</code>, which you should never need to use. In general, you will define a function inside a <code>\startluacode</code> block, and then define a TeX command that calls the function using <code>\ctxlua</code>, especially because <code>\ctxlua</code> has a few idiosyncracies.<br />
<br />
The main thing about Lua code in a TeX document is this: the code is expanded by TeX ''before'' Lua gets to it. '''This means that all the Lua code, even the comments, must be valid TeX!''' A string like "\undefined" will cause an immediate failure.<br />
<br />
== Calling a bit of Lua inline: \ctxlua ==<br />
<br />
The command <code>\ctxlua</code> is for short inline snippets of Lua, such<br />
as<br />
<br />
<texcode><br />
$2 + 5 \neq \ctxlua{context(3+5)}$, but is equal to \ctxlua{context(2+5)}.<br />
This is \ctxlua{context(string.upper("absolutely"))} true.<br />
</texcode><br />
<br />
<code>\ctxlua</code> operates under the normal TeX catcodes (category codes). This means the following two things for the Lua code inside:<br />
* all newlines get treated as spaces<br />
* special TeX characters like &, #, $, {, }, etc., need to be escaped. <br />
<br />
In addition, the warning above still holds. All the Lua code, even the comments, must be valid TeX.<br />
<br />
Some code to illustrate the newline problem:<br />
<texcode><br />
\ctxlua<br />
{-- A Lua comment<br />
tex.print("This is not printed")}<br />
\ctxlua<br />
{% A Tex comment<br />
tex.print("This is printed")}<br />
</texcode><br />
<br />
The problem with special TeX characters. (<code>#t</code> is Lua for 'the length of array <code>t</code>.)<br />
<texcode><br />
% This doesn't work:<br />
%\ctxlua<br />
% {local t = {1,2,3,4}<br />
% tex.print("length " .. #t)}<br />
\ctxlua<br />
{local t = {1,2,3,4}<br />
tex.print("length " .. \string#t)}<br />
</texcode><br />
<br />
<br />
== Calling a lua function with \cldcontext and get the return ==<br />
<br />
One can execute a Lua code from within TeX and get back the result in TeX by using {{code|\cldcontext}}. Thus, if {{code|myfunction}} is a function of a variable {{code|x}} defined in Lua, {{code|\cldcontext{myfunction(5)}}} returns the value {{code|myfunction(5)}} in TeX. This is equivalent to {{code|\ctxlua{context(myfunction(5))}}}.<br />
<br />
<br />
== A larger Lua block: \startluacode...\stopluacode ==<br />
<br />
Inside the <code>\startluacode...\stopluacode</code> environment, newlines and special characters behave normally. This solves the catcode problem that <code>\ctxlua</code> suffers from. Apart from these special characters, the main warning remains in force: all the Lua code, even the comments, must be valid TeX.<br />
<br />
<texcode><br />
\startluacode<br />
-- The unknown command \undefined will cause this entire block to fail.<br />
<br />
-- Print a countdown '10, 8, ..., 0!'<br />
-- `..` is Lua for string concatenation<br />
for i = 10, 2, -2 do<br />
context(i .. ", ")<br />
end<br />
context("0!")<br />
<br />
-- \\par is equivalent to a blank line in the input<br />
-- (Notice the escaped backslash: TeX won't mind the above comment.)<br />
context.par()<br />
<br />
-- Look! we can use # and $ with impunity!<br />
context("Unless we print them, then we must \\#\\$\\& print the escape characters, too.")<br />
\stopluacode<br />
</texcode><br />
<br />
== Putting Lua code in an external file ==<br />
<br />
You can put your lua code in an external file (with the <code>.lua</code> extension) and include it with the <code>require</code> command:<br />
<br />
<texcode><br />
\startluacode<br />
-- include the file my-lua-lib.lua<br />
require("my-lua-lib")<br />
\stopluacode<br />
</texcode><br />
<br />
== Namespaces ==<br />
<br />
It is a good habit to put your custom-defined functions in their own namespace. The traditional namespace for this is <code>userdata</code>:<br />
<texcode><br />
\startluacode<br />
-- if userdata doesn't exist yet, create it<br />
userdata = userdata or {}<br />
-- define a shorter synonym<br />
u = userdata<br />
<br />
-- create my custom function inside the userdata namespace<br />
function u.myfunction()<br />
-- do stuff<br />
end <br />
\stopluacode<br />
</texcode><br />
<br />
The full list of canonical namespaces, taken from [http://minimals.contextgarden.net/current/context/alpha/tex/context/base/luat-ini.lua luat-ini.lua]:<br />
<br />
<code><pre><br />
userdata = userdata or { } -- for users (e.g. functions etc)<br />
thirddata = thirddata or { } -- only for third party modules<br />
moduledata = moduledata or { } -- only for development team<br />
documentdata = documentdata or { } -- for users (e.g. raw data)<br />
parametersets = parametersets or { } -- experimental for team<br />
</pre></code><br />
<br />
If your module, environment, or document is going to be used by other people, you should create your own subnamespaces within these tables.<br />
<br />
<code><pre><br />
moduledata['mymodule'] = { }<br />
mm = moduledata.mymodule<br />
function mm.mainfunction()<br />
-- do stuff<br />
end<br />
</pre></code><br />
<br />
= Calling TeX from Lua =<br />
<br />
Being a topic on itself, pages are dedicated:<br />
* '''[[CLD|ConTeXt Lua Documents]]''', or CLD, are way to access TeX from inside Lua scripts. A page give clues about [[CLD_passing_variables|passing variables]] within CLD (2018).<br />
* [[Lua|Wiki page dedicated to Lua]]<br />
** [[Extensions to the Lua I/O library]]<br />
** [[String manipulation]]<br />
** [[Table manipulation]]<br />
<br />
= Putting stuff in your TeX document from Lua =<br />
<br />
== Simple printing: context(), tex.print(), and tex.sprint() ==<br />
Use <code>context(...)</code> for most things. It is equivalent to <code>tex.print(string.format(...))</code>, so<br />
<br />
<texcode><br />
\startluacode<br />
name = "Jane"<br />
date = "today"<br />
context("Hello %s, how are you %s?", name, date)<br />
-- Becomes 'Hello Jane, how are you today?'<br />
\stopluacode<br />
</texcode><br />
<br />
More primitively, you have <code>tex.print()</code> and <code>tex.sprint()</code>. Either one can take as an argument either a number of strings, or an array of strings, and will then insert the strings into the TeX stream. The only difference is that <code>tex.print()</code> treats each string as a separate input line, while <code>tex.sprint()</code> doesn't. So the following lines<br />
<br />
<texcode><br />
\ctxlua{tex.print("a", "b")}<br />
\ctxlua{tex.print({"a", "b"})}<br />
</texcode><br />
<br />
are both interpreted by TeX as<br />
<br />
<texcode><br />
a<br />
b<br />
</texcode><br />
<br />
but when we use <code>tex.sprint</code> instead, either of the following<br />
<br />
<texcode><br />
\ctxlua{tex.sprint("a", "b")}<br />
\ctxlua{tex.sprint({"a", "b"})}<br />
</texcode><br />
<br />
will be read by TeX as<br />
<br />
<texcode><br />
ab<br />
</texcode> <br />
<br />
without any space in between.<br />
<br />
== Context commands ==<br />
<br />
Most commands that you would type with a backslash in plain ConTeXt, you can access from Lua with <code>context.<em>command</em></code>. Unadorned strings end up in TeX as arguments in curly braces; Lua tables end up in TeX as paramater blocks in square brackets. The following two pieces of code are equivalent:<br />
<br />
<texcode><br />
\startluacode<br />
context.chapter({first}, "Some title")<br />
context.startcolumns({n = 3, rule = "on"})<br />
context("Hello one")<br />
context.column()<br />
context("Hello two")<br />
context.column()<br />
context("Hello three")<br />
context.stopcolumns()<br />
\stopluacode<br />
</texcode><br />
<br />
<texcode><br />
\chapter[first]{Some title}<br />
\startcolumns[n=3, rule=on]<br />
Hello one<br />
\column<br />
Hello two<br />
\column<br />
Hello three<br />
\stopcolumns<br />
</texcode><br />
<br />
For a fuller account of the context.commands, see the [http://www.pragma-ade.com/general/manuals/cld-mkiv.pdf ConTeXt Lua document] manual. It is old, but most of it still applies.<br />
<br />
One final note: arguments can also be specified in the form of nested functions. Because LuaTeX evaluates the deepest-nested argument first, this may cause the <code>context()</code> calls to be evaluated in the wrong order. For more on this, see the article on [[CLD|ConTeXt Lua documents]], and also, again, the [http://www.pragma-ade.com/general/manuals/cld-mkiv.pdf CLD manual].<br />
<br />
= Passing arguments and buffers: ConTeXt commands that hook into Lua =<br />
<br />
== Making \command{arg1}{arg2} hook into Lua ==<br />
First, define a Lua function:<br />
<br />
<texcode><br />
\startluacode<br />
-- remember, using the userdata namespace prevents conflicts<br />
userdata = userdata or {}<br />
<br />
function userdata.surroundwithdashes(str)<br />
context("--" .. str .. "--")<br />
end<br />
\stopluacode<br />
</texcode><br />
<br />
Then define the TeX command that expands to a <code>\ctxlua</code> call:<br />
<br />
<texcode><br />
\def\surroundwd#1%<br />
{\ctxlua{userdata.surroundwithdashes([==[#1]==])}}<br />
</texcode><br />
<br />
''NB'': quoting with <code>[==[#1]==]</code><br />
([http://www.lua.org/manual/5.2/manual.html#3.1 long strings])<br />
works just like <code>"#1"</code> in most cases, but in addition <br />
it is robust against <code>#1</code> containing the quotation mark<br />
<code>"</code> which would terminate the Lua string prematurely.<br />
Inside <code>\protect .. \unprotect</code> the macros <code>\!!bs</code><br />
and <code>\!!es</code> are at your disposition.<br />
They are equivalent to <code>[===[</code> and <code>]===]</code> and --<br />
being single tokens to TeX -- parsed faster.<br />
(See [http://repo.or.cz/w/context.git/blob/refs/heads/origin:/tex/context/base/luat-ini.mkiv#l174 <code>luat-ini.mkiv</code>].)<br />
<br />
== Making \startenv...\stopenv hook into Lua ==<br />
The first job is, as ever, to have the Lua function at the ready<br />
<texcode><br />
\startluacode<br />
userdata = userdata or {}<br />
<br />
function userdata.verynarrow(buffer)<br />
-- equivalent to \startnarrower[10em]<br />
context.startnarrower({"10em"})<br />
context(buffer)<br />
context.stopnarrower()<br />
end<br />
\stopluacode<br />
</texcode><br />
<br />
Next, we define the start command of our custom buffer:<br />
<br />
<texcode><br />
\def\startverynarrow%<br />
{\dostartbuffer<br />
[verynarrow] % buffer name<br />
[startverynarrow] % command where buffer starts<br />
[stopverynarrow]} % command where buffer ends<br />
% also: command invoked when buffer stops<br />
<br />
</texcode><br />
<br />
Lastly, we define the <code>\stopverynarrow</code> command such that it passes the recently-complated buffer to our <code>verynarrow</code> Lua function:<br />
<br />
<texcode><br />
\def\stopverynarrow<br />
{\ctxlua<br />
{userdata.verynarrow(buffers.getcontent('verynarrow'))}}<br />
</texcode><br />
<br />
And that's it! The rest of this article will consist of examples.<br />
<br />
= Examples =<br />
<br />
== Arithmetic without using an abacus ==<br />
<br />
''This example demonstrates writing simple commands that invoke \ctxlua.''<br />
<br />
Doing simple arithmetic in TeX can be extremely difficult. With Lua, simple arithmetic becomes trivial. For example, if you want a macro to find the cosine of an angle (in degrees), you can write<br />
<texcode><br />
\def\COSINE#1%<br />
{\ctxlua{context(math.cos(#1*2*math.pi/360))}}<br />
</texcode><br />
<br />
The built-in <code>math.cos</code> function assumes that the argument is specified in radians, so we convert from degrees to radians on the fly. If you want to type the value of $\pi$ in an article, you can simply say<br />
<texcode><br />
$\pi = \ctxlua{context(math.pi)}$ <br />
</texcode><br />
or, if you want less precision:<br />
<texcode> <br />
$\pi = \ctxlua{context("\letterpercent.6f", math.pi)}$<br />
</texcode><br />
Notice that the percent sign is escaped with letterpercent.<br />
<br />
=== mathexpr with LMTX ===<br />
<br />
In LMTX there is a new way to use calculated expressions with mathexpr through ([https://github.com/contextgarden/context-mirror/blob/7fd782dace8f90e7e032ca8f449f8ca4eada450b/doc/context/sources/general/manuals/math/math-fun.tex math-fun]).<br />
<br />
Some examples are:<br />
<br />
<texcode><br />
$ \pi = \mathexpr[.40N]{pi} $<br />
$ \pi = \mathexpr[.80N]{sqrt(11)} $<br />
$ \pi = \decimalexpr[.80N]{sqrt(11)} $<br />
$ \pi = \decimalexpr{sqrt(11)} $<br />
$ c = \complexexpr{123 + new(456,789)} $<br />
</texcode><br />
<br />
== Loops without worrying about expansion ==<br />
<br />
''This example demonstrates using Lua to write a quasi-repetitive piece of ConTeXt code.''<br />
<br />
Loops in TeX are tricky, because macro assignments and macro expansion interact in strange ways. For example, suppose we want to typeset a table showing the sum of the roll of two dice and want the output to look like this:<br />
<context source="yes"><br />
\setupcolors[state=start]<br />
\setupTABLE[each][each][width=2em,height=2em,align={middle,middle}] <br />
\setupTABLE[r][1][background=color,backgroundcolor=gray] <br />
\setupTABLE[c][1][background=color,backgroundcolor=gray]<br />
<br />
\bTABLE <br />
\bTR \bTD $(+)$ \eTD \bTD 1 \eTD \bTD 2 \eTD <br />
\bTD 3 \eTD \bTD 4 \eTD \bTD 5 \eTD \bTD 6 \eTD \eTR <br />
\bTR \bTD 1 \eTD \bTD 2 \eTD \bTD 3 \eTD <br />
\bTD 4 \eTD \bTD 5 \eTD \bTD 6 \eTD \bTD 7 \eTD \eTR <br />
\bTR \bTD 2 \eTD \bTD 3 \eTD \bTD 4 \eTD <br />
\bTD 5 \eTD \bTD 6 \eTD \bTD 7 \eTD \bTD 8 \eTD \eTR <br />
\bTR \bTD 3 \eTD \bTD 4 \eTD \bTD 5 \eTD<br />
\bTD 6 \eTD \bTD 7 \eTD \bTD 8 \eTD \bTD 9 \eTD \eTR <br />
\bTR \bTD 4 \eTD \bTD 5 \eTD \bTD 6 \eTD<br />
\bTD 7 \eTD \bTD 8 \eTD \bTD 9 \eTD \bTD 10 \eTD \eTR <br />
\bTR \bTD 5 \eTD \bTD 6 \eTD \bTD 7 \eTD <br />
\bTD 8 \eTD \bTD 9 \eTD \bTD 10 \eTD \bTD 11 \eTD \eTR <br />
\bTR \bTD 6 \eTD \bTD 7 \eTD \bTD 8 \eTD <br />
\bTD 9 \eTD \bTD 10 \eTD \bTD 11 \eTD \bTD 12 \eTD \eTR <br />
\eTABLE<br />
</context><br />
<br />
This is easy in LuaTeX. Once a Lua instance starts, TeX does not see anything until the Lua instance exits. So, we can write the loop in Lua, and simply print the values that we would have typed to the TeX stream. When the control is passed to TeX, TeX sees the input as if we had typed it by hand. This is the Lua code for the above table:<br />
<br />
<texcode><br />
\setupcolors[state=start]<br />
\setupTABLE[each][each][width=2em,height=2em,align={middle,middle}] <br />
\setupTABLE[r][1][background=color,backgroundcolor=gray] <br />
\setupTABLE[c][1][background=color,backgroundcolor=gray]<br />
<br />
\startluacode<br />
context.bTABLE()<br />
context.bTR()<br />
context.bTD() context("$(+)$") context.eTD()<br />
for j=1,6 do<br />
context.bTD() context(j) context.eTD()<br />
end<br />
context.eTR()<br />
for i=1,6 do<br />
context.bTR()<br />
context.bTD() context(i) context.eTD()<br />
for j=1,6 do<br />
context.bTD() context(i+j) context.eTD()<br />
end<br />
context.eTR()<br />
end<br />
context.eTABLE()<br />
\stopluacode<br />
</texcode><br />
<br />
== Parsing input without exploding your head ==<br />
<br />
''This example demonstrates parsing simple ASCII notation with Lua's lpeg parser.''<br />
<br />
As an example, let's consider typesetting chemical molecules in TeX. Normally, molecules should be typeset in text mode rather than math mode. <br />
If we want <br />
:H<sub>3</sub>SO<sub>4</sub><sup>+</sup>,<br />
we must type <br />
:<code>H\low{3}SO\lohi{4}{\textplus}</code>,<br />
but we'd much rather type<br />
:<code>\molecule{H_3SO_4^+}</code>.<br />
<br />
So, we need a function that can take a string like that, parse it, and turn it into the appropriate TeX code. LuaTeX includes a general parser based on PEG (parsing expression grammar) called [http://www.inf.puc-rio.br/~roberto/lpeg/lpeg.html lpeg], and it makes writing little parsers positively joyful. (Once you've got the knack of it, at least.) For example, the above <code>\molecule</code> macro can be written as follows.<br />
<br />
<texcode><br />
\startluacode<br />
<br />
-- we will put our molecule function in the userdata namespace.<br />
userdata = userdata or { }<br />
<br />
-- The formatting functions into which the captured<br />
-- superscript/subscript blocks will be fed<br />
local formatters = { }<br />
<br />
function formatters.low(one)<br />
return string.format("\\low{%s}", one)<br />
end<br />
<br />
function formatters.high(one)<br />
return string.format("\\high{%s}", one)<br />
end<br />
<br />
function formatters.lowhigh(one, two)<br />
return string.format("\\lohi{%s}{%s}", one, two)<br />
end<br />
<br />
function formatters.highlow(one, two,three)<br />
return string.format("\\lohi{%s}{%s}", one,two)<br />
end<br />
<br />
-- These are the characters we may encounter<br />
-- The `/` means we want to expand + and - to \textplus c.q. \textminus;<br />
-- this substition is not instant, but will take place inside the first <br />
-- surrounding lpeg.Cs() call.<br />
local plus = lpeg.P("+") / "\\textplus "<br />
local minus = lpeg.P("-") / "\\textminus "<br />
local character = lpeg.R("az", "AZ", "09") -- R is for 'range'<br />
local subscript = lpeg.P("_") -- P is simply for 'pattern'<br />
local superscript = lpeg.P("^")<br />
local leftbrace = lpeg.P("{")<br />
local rightbrace = lpeg.P("}")<br />
<br />
-- a ^ or _ affects either a single character, or a brace-delimited<br />
-- block. Whichever it is, call it `content`.<br />
local single = character + plus + minus<br />
local multiple = leftbrace * single^1 * rightbrace<br />
local content = single + multiple<br />
<br />
-- These are our top-level elements: non-special text, of course, and<br />
-- blocks of superscript/subscript/both.<br />
-- lpeg.Cs(content) does two things:<br />
-- (1) not all matches go into the `/ function` construction; only<br />
-- *captures* go in. The C in Cs stands for Capture. This way, <br />
-- the superscript/subscript mark gets discarded.<br />
-- (2) it expands plus/minus before they go into the formatter. The<br />
-- s in Cs stands for 'substitute in the replacement values, if any'<br />
local text = single^1<br />
local low = subscript * lpeg.Cs(content) <br />
/ formatters.low<br />
local high = superscript * lpeg.Cs(content) <br />
/ formatters.high<br />
local lowhigh = subscript * lpeg.Cs(content) * <br />
superscript * lpeg.Cs(content) <br />
/ formatters.lowhigh<br />
local highlow = superscript * lpeg.Cs(content) * <br />
subscript * lpeg.Cs(content) <br />
/ formatters.highlow<br />
<br />
-- Finally, the root element: 'moleculepattern'<br />
local moleculepattern = lpeg.Cs((lowhigh + highlow + low + high + text)^0)<br />
<br />
function thirddata.molecule(string)<br />
-- * `:match` returns the matched string. Our pattern<br />
-- `moleculepattern` should match the entire input string. Any<br />
-- *performed* substitutions are retained. (`.Cs()` performs a<br />
-- previously defined substitution.)<br />
-- * `context()` inserts the resulting string into the stream, ready for<br />
-- TeX to evaluate.<br />
context(moleculepattern:match(string))<br />
end<br />
<br />
\stopluacode<br />
<br />
\def\molecule#1{\ctxlua{thirddata.molecule("#1")}}<br />
<br />
\starttext<br />
\molecule{Hg^+}, \molecule{SO_4^{2-}}<br />
\stoptext<br />
</texcode><br />
<br />
Quite terse and readable by parser standards, isn't it?<br />
<br />
== Manipulating verbatim text ==<br />
<br />
''This example demonstrates defining a custom \start...\stop buffer that gets processed through Lua in its entirety.''<br />
<br />
Suppose we want to write an environment <code>\startdedentedtyping</code> ... <code>\stopdedentedtyping</code> that removes the indentation of the first line from every line. Thus, the output of ...<br />
<br />
<texcode><br />
\startdedentedtyping<br />
#include &lt;stdio.h&gt;<br />
void main()<br />
{<br />
print("Hello world \n") ;<br />
}<br />
\stopdedentedtyping<br />
</texcode><br />
... should be the same as the output of ...<br />
<br />
<texcode><br />
\starttyping<br />
#include &lt;stdio.h&gt;<br />
void main()<br />
{<br />
print("Hello world \n") ;<br />
}<br />
\stoptyping<br />
</texcode><br />
... even though the leading whitespace is different.<br />
<br />
Defining an environment in TeX that removes the leading spaces but leaves<br />
other spaces untouched is complicated. On the other hand, once we capture the<br />
contents of the environment, removing the leading indent or ''dedenting'' the<br />
content in Lua is easy. Here is a Lua function that uses simple string<br />
substitutions.<br />
<br />
<texcode><br />
\startluacode<br />
-- Initialize a userdata name space to keep our own functions in.<br />
-- That way, we won't interfere with anything ConTeXt keeps in <br />
-- the global name space.<br />
userdata = userdata or {}<br />
<br />
function userdata.dedentedtyping(content)<br />
local lines = string.splitlines(content)<br />
local indent = string.match(lines[1], '^ +') or ''<br />
local pattern = '^' .. indent<br />
for i=1,#lines do<br />
lines[i] = string.gsub(lines[i],pattern,"")<br />
end<br />
<br />
content = table.concat(lines,'\n')<br />
<br />
tex.sprint("\\starttyping\n" .. content .. "\\stoptyping\n")<br />
<br />
-- The typing environment looks for an explicit \type{\stoptyping}. So,<br />
-- context.starttyping() context(content) context.stoptyping()<br />
-- does not work. But<br />
-- context.starttyping() context(content) tex.sprint("\\stoptyping")<br />
-- does.<br />
end<br />
\stopluacode<br />
</texcode><br />
<br />
Here is the code for defining the <code>\startdedentedtyping...\stopdedentedtyping</code> pair:<br />
<br />
<texcode><br />
% Create an environment that stores everything <br />
% between \startdedentedtyping and \stopdedentedtyping <br />
% in a buffer named 'dedentedtyping'.<br />
\def\startdedentedtyping<br />
{\dostartbuffer<br />
[dedentedtyping]<br />
[startdedentedtyping]<br />
[stopdedentedtyping]}<br />
<br />
% On closing the dedentedtyping environment, call the LuaTeX<br />
% function dedentedtyping(), and pass it the contents of <br />
% the buffer called 'dedentedtyping'<br />
\def\stopdedentedtyping<br />
{\ctxlua<br />
{userdata.dedentedtyping(buffers.getcontent('dedentedtyping'))}}<br />
</texcode><br />
<br />
That's all. Finally, we will go into a little more detail on how TeX and Lua communicate with each other.<br />
<br />
== Other examples ==<br />
<br />
* [[Calculations_in_Lua|Calculations in Lua]] (warning date 2012)<br />
* [[LPeg|Writing a parser with LPeg]] (Lua Parsing Expression Grammars)<br />
* [[Random|Random numbers]] in ConTeXt and MetaPost<br />
* [[SQL|An example with SQL database]]<br />
* [[Pascal's Triangle]]<br />
<br />
= In detail: the interaction between TeX and Lua =<br />
<br />
To a first approximation, the interaction between TeX and Lua is straightforward. When TeX (i.e., the LuaTeX engine) starts, it loads the input file in memory and processes it token by token. When TeX encounters <code>\directlua</code>, it stops reading the file in memory, <em>fully expands the argument of <code>\directlua</code></em>, and passes the control to a Lua instance. The Lua instance, which runs with a few preloaded libraries, processes the expanded arguments of <code>\directlua</code>. This Lua instance has a special output stream which can be accessed using <code>tex.print(...)</code>. The function <code>tex.print(...)</code> is just like the Lua function <code>print(...)</code> except that <code>tex.print(...)</code> prints to a <em>TeX stream</em> rather than to the standard output. When the Lua instance finishes processing its input, it passes the contents of the <em>TeX stream</em> back to TeX.<ref>The output of <code>tex.print(...)</code> is buffered and not passed to TeX until the Lua instance has stopped.</ref> TeX then inserts the contents of the <em>TeX stream</em> at the current location of the file that it was reading; expands the contents of the <em>TeX stream</em>; and continues. If TeX encounters another <code>\directlua</code>, the above process is repeated. <br />
<br />
As an exercise, imagine what happens when the following input is processed by LuaTeX. The answer is in the footnotes. <ref>In this example, two different kinds of quotations are used to avoid escaping quotes. Escaping quotes inside <code>\directlua</code> is tricky. The above was a contrived example; if you ever need to escape quotes, you can use the <code>\startluacode ... \stopluacode</code> syntax.</ref><br />
<br />
<texcode><br />
\directlua%<br />
{tex.print("Depth 1 <br />
\\directlua{tex.print('Depth 2')}")}<br />
</texcode><br />
<br />
For more on this, see the [http://wiki.luatex.org/index.php/Writing_Lua_in_TeX] article on the [http://wiki.luatex.org/index.php/Main_Page LuaTeX wiki].<br />
<br />
= Notes =<br />
<references /><br />
<br />
{{note | This article is originally based on [https://www.tug.org/members/TUGboat/tb30-2/tb95mahajan-luatex.pdf this TugBoat article ]. Feel free to modify it.}}<br />
<br />
[[Category:Programming and Databases]]</div>Mæstrohttps://wiki.contextgarden.net/index.php?title=Programming_in_LuaTeX&diff=32564Programming in LuaTeX2021-05-29T13:14:22Z<p>Mæstro: /* Arithmetic without using an abacus */ - fix percent escape</p>
<hr />
<div>= Calling Lua from TeX =<br />
<br />
The interweaving of ConTeXt and Lua consists of two elements: first you tell TeX that you're starting some Lua code; then, once inside Lua, you need to use the appropriate functions to put things into the TeX stream.<br />
<br />
There are two main ways to execute Lua code in a ConTeXt document: The command <code>\ctxlua</code>, and the environment <code>\startluacode...\stopluacode</code>. Both are wrappers around the LuaTeX primitive <code>\directlua</code>, which you should never need to use. In general, you will define a function inside a <code>\startluacode</code> block, and then define a TeX command that calls the function using <code>\ctxlua</code>, especially because <code>\ctxlua</code> has a few idiosyncracies.<br />
<br />
The main thing about Lua code in a TeX document is this: the code is expanded by TeX ''before'' Lua gets to it. '''This means that all the Lua code, even the comments, must be valid TeX!''' A string like "\undefined" will cause an immediate failure.<br />
<br />
== Calling a bit of Lua inline: \ctxlua ==<br />
<br />
The command <code>\ctxlua</code> is for short inline snippets of Lua, such<br />
as<br />
<br />
<texcode><br />
$2 + 5 \neq \ctxlua{context(3+5)}$, but is equal to \ctxlua{context(2+5)}.<br />
This is \ctxlua{context(string.upper("absolutely"))} true.<br />
</texcode><br />
<br />
<code>\ctxlua</code> operates under the normal TeX catcodes (category codes). This means the following two things for the Lua code inside:<br />
* all newlines get treated as spaces<br />
* special TeX characters like &, #, $, {, }, etc., need to be escaped. <br />
<br />
In addition, the warning above still holds. All the Lua code, even the comments, must be valid TeX.<br />
<br />
Some code to illustrate the newline problem:<br />
<texcode><br />
\ctxlua<br />
{-- A Lua comment<br />
tex.print("This is not printed")}<br />
\ctxlua<br />
{% A Tex comment<br />
tex.print("This is printed")}<br />
</texcode><br />
<br />
The problem with special TeX characters. (<code>#t</code> is Lua for 'the length of array <code>t</code>.)<br />
<texcode><br />
% This doesn't work:<br />
%\ctxlua<br />
% {local t = {1,2,3,4}<br />
% tex.print("length " .. #t)}<br />
\ctxlua<br />
{local t = {1,2,3,4}<br />
tex.print("length " .. \string#t)}<br />
</texcode><br />
<br />
<br />
== Calling a lua function with \cldcontext and get the return ==<br />
<br />
One can execute a Lua code from within TeX and get back the result in TeX by using {{code|\cldcontext}}. Thus, if {{code|myfunction}} is a function of a variable {{code|x}} defined in Lua, {{code|\cldcontext{myfunction(5)}}} returns the value {{code|myfunction(5)}} in TeX. This is equivalent to {{code|\ctxlua{context(myfunction(5))}}}.<br />
<br />
<br />
== A larger Lua block: \startluacode...\stopluacode ==<br />
<br />
Inside the <code>\startluacode...\stopluacode</code> environment, newlines and special characters behave normally. This solves the catcode problem that <code>\ctxlua</code> suffers from. Apart from these special characters, the main warning remains in force: all the Lua code, even the comments, must be valid TeX.<br />
<br />
<texcode><br />
\startluacode<br />
-- The unknown command \undefined will cause this entire block to fail.<br />
<br />
-- Print a countdown '10, 8, ..., 0!'<br />
-- `..` is Lua for string concatenation<br />
for i = 10, 2, -2 do<br />
context(i .. ", ")<br />
end<br />
context("0!")<br />
<br />
-- \\par is equivalent to a blank line in the input<br />
-- (Notice the escaped backslash: TeX won't mind the above comment.)<br />
context.par()<br />
<br />
-- Look! we can use # and $ with impunity!<br />
context("Unless we print them, then we must \\#\\$\\& print the escape characters, too.")<br />
\stopluacode<br />
</texcode><br />
<br />
== Putting Lua code in an external file ==<br />
<br />
You can put your lua code in an external file (with the <code>.lua</code> extension) and include it with the <code>require</code> command:<br />
<br />
<texcode><br />
\startluacode<br />
-- include the file my-lua-lib.lua<br />
require("my-lua-lib")<br />
\stopluacode<br />
</texcode><br />
<br />
== Namespaces ==<br />
<br />
It is a good habit to put your custom-defined functions in their own namespace. The traditional namespace for this is <code>userdata</code>:<br />
<texcode><br />
\startluacode<br />
-- if userdata doesn't exist yet, create it<br />
userdata = userdata or {}<br />
-- define a shorter synonym<br />
u = userdata<br />
<br />
-- create my custom function inside the userdata namespace<br />
function u.myfunction()<br />
-- do stuff<br />
end <br />
\stopluacode<br />
</texcode><br />
<br />
The full list of canonical namespaces, taken from [http://minimals.contextgarden.net/current/context/alpha/tex/context/base/luat-ini.lua luat-ini.lua]:<br />
<br />
<code><pre><br />
userdata = userdata or { } -- for users (e.g. functions etc)<br />
thirddata = thirddata or { } -- only for third party modules<br />
moduledata = moduledata or { } -- only for development team<br />
documentdata = documentdata or { } -- for users (e.g. raw data)<br />
parametersets = parametersets or { } -- experimental for team<br />
</pre></code><br />
<br />
If your module, environment, or document is going to be used by other people, you should create your own subnamespaces within these tables.<br />
<br />
<code><pre><br />
moduledata['mymodule'] = { }<br />
mm = moduledata.mymodule<br />
function mm.mainfunction()<br />
-- do stuff<br />
end<br />
</pre></code><br />
<br />
= Calling TeX from Lua =<br />
<br />
Being a topic on itself, pages are dedicated:<br />
* '''[[CLD|ConTeXt Lua Documents]]''', or CLD, are way to access TeX from inside Lua scripts. A page give clues about [[CLD_passing_variables|passing variables]] within CLD (2018).<br />
* [[Lua|Wiki page dedicated to Lua]]<br />
** [[Extensions to the Lua I/O library]]<br />
** [[String manipulation]]<br />
** [[Table manipulation]]<br />
<br />
= Putting stuff in your TeX document from Lua =<br />
<br />
== Simple printing: context(), tex.print(), and tex.sprint() ==<br />
Use <code>context(...)</code> for most things. It is equivalent to <code>tex.print(string.format(...))</code>, so<br />
<br />
<texcode><br />
\startluacode<br />
name = "Jane"<br />
date = "today"<br />
context("Hello %s, how are you %s?", name, date)<br />
-- Becomes 'Hello Jane, how are you today?'<br />
\stopluacode<br />
</texcode><br />
<br />
More primitively, you have <code>tex.print()</code> and <code>tex.sprint()</code>. Either one can take as an argument either a number of strings, or an array of strings, and will then insert the strings into the TeX stream. The only difference is that <code>tex.print()</code> treats each string as a separate input line, while <code>tex.sprint()</code> doesn't. So the following lines<br />
<br />
<texcode><br />
\ctxlua{tex.print("a", "b")}<br />
\ctxlua{tex.print({"a", "b"})}<br />
</texcode><br />
<br />
are both interpreted by TeX as<br />
<br />
<texcode><br />
a<br />
b<br />
</texcode><br />
<br />
but when we use <code>tex.sprint</code> instead, either of the following<br />
<br />
<texcode><br />
\ctxlua{tex.sprint("a", "b")}<br />
\ctxlua{tex.sprint({"a", "b"})}<br />
</texcode><br />
<br />
will be read by TeX as<br />
<br />
<texcode><br />
ab<br />
</texcode> <br />
<br />
without any space in between.<br />
<br />
== Context commands ==<br />
<br />
Most commands that you would type with a backslash in plain ConTeXt, you can access from Lua with <code>context.<em>command</em></code>. Unadorned strings end up in TeX as arguments in curly braces; Lua tables end up in TeX as paramater blocks in square brackets. The following two pieces of code are equivalent:<br />
<br />
<texcode><br />
\startluacode<br />
context.chapter({first}, "Some title")<br />
context.startcolumns({n = 3, rule = "on"})<br />
context("Hello one")<br />
context.column()<br />
context("Hello two")<br />
context.column()<br />
context("Hello three")<br />
context.stopcolumns()<br />
\stopluacode<br />
</texcode><br />
<br />
<texcode><br />
\chapter[first]{Some title}<br />
\startcolumns[n=3, rule=on]<br />
Hello one<br />
\column<br />
Hello two<br />
\column<br />
Hello three<br />
\stopcolumns<br />
</texcode><br />
<br />
For a fuller account of the context.commands, see the [http://www.pragma-ade.com/general/manuals/cld-mkiv.pdf ConTeXt Lua document] manual. It is old, but most of it still applies.<br />
<br />
One final note: arguments can also be specified in the form of nested functions. Because LuaTeX evaluates the deepest-nested argument first, this may cause the <code>context()</code> calls to be evaluated in the wrong order. For more on this, see the article on [[CLD|ConTeXt Lua documents]], and also, again, the [http://www.pragma-ade.com/general/manuals/cld-mkiv.pdf CLD manual].<br />
<br />
= Passing arguments and buffers: ConTeXt commands that hook into Lua =<br />
<br />
== Making \command{arg1}{arg2} hook into Lua ==<br />
First, define a Lua function:<br />
<br />
<texcode><br />
\startluacode<br />
-- remember, using the userdata namespace prevents conflicts<br />
userdata = userdata or {}<br />
<br />
function userdata.surroundwithdashes(str)<br />
context("--" .. str .. "--")<br />
end<br />
\stopluacode<br />
</texcode><br />
<br />
Then define the TeX command that expands to a <code>\ctxlua</code> call:<br />
<br />
<texcode><br />
\def\surroundwd#1%<br />
{\ctxlua{userdata.surroundwithdashes([==[#1]==])}}<br />
</texcode><br />
<br />
''NB'': quoting with <code>[==[#1]==]</code><br />
([http://www.lua.org/manual/5.2/manual.html#3.1 long strings])<br />
works just like <code>"#1"</code> in most cases, but in addition <br />
it is robust against <code>#1</code> containing the quotation mark<br />
<code>"</code> which would terminate the Lua string prematurely.<br />
Inside <code>\protect .. \unprotect</code> the macros <code>\!!bs</code><br />
and <code>\!!es</code> are at your disposition.<br />
They are equivalent to <code>[===[</code> and <code>]===]</code> and --<br />
being single tokens to TeX -- parsed faster.<br />
(See [http://repo.or.cz/w/context.git/blob/refs/heads/origin:/tex/context/base/luat-ini.mkiv#l174 <code>luat-ini.mkiv</code>].)<br />
<br />
== Making \startenv...\stopenv hook into Lua ==<br />
The first job is, as ever, to have the Lua function at the ready<br />
<texcode><br />
\startluacode<br />
userdata = userdata or {}<br />
<br />
function userdata.verynarrow(buffer)<br />
-- equivalent to \startnarrower[10em]<br />
context.startnarrower({"10em"})<br />
context(buffer)<br />
context.stopnarrower()<br />
end<br />
\stopluacode<br />
</texcode><br />
<br />
Next, we define the start command of our custom buffer:<br />
<br />
<texcode><br />
\def\startverynarrow%<br />
{\dostartbuffer<br />
[verynarrow] % buffer name<br />
[startverynarrow] % command where buffer starts<br />
[stopverynarrow]} % command where buffer ends<br />
% also: command invoked when buffer stops<br />
<br />
</texcode><br />
<br />
Lastly, we define the <code>\stopverynarrow</code> command such that it passes the recently-complated buffer to our <code>verynarrow</code> Lua function:<br />
<br />
<texcode><br />
\def\stopverynarrow<br />
{\ctxlua<br />
{userdata.verynarrow(buffers.getcontent('verynarrow'))}}<br />
</texcode><br />
<br />
And that's it! The rest of this article will consist of examples.<br />
<br />
= Examples =<br />
<br />
== Arithmetic without using an abacus ==<br />
<br />
''This example demonstrates writing simple commands that invoke \ctxlua.''<br />
<br />
Doing simple arithmetic in TeX can be extremely difficult. With Lua, simple arithmetic becomes trivial. For example, if you want a macro to find the cosine of an angle (in degrees), you can write<br />
<texcode><br />
\def\COSINE#1%<br />
{\ctxlua{context(math.cos(#1*2*math.pi/360))}}<br />
</texcode><br />
<br />
The built-in <code>math.cos</code> function assumes that the argument is specified in radians, so we convert from degrees to radians on the fly. If you want to type the value of $\pi$ in an article, you can simply say<br />
<texcode><br />
$\pi = \ctxlua{context(math.pi)}$ <br />
</texcode><br />
or, if you want less precision:<br />
<texcode> <br />
$\pi = \ctxlua{context("\letterpercent.6f", math.pi)}$<br />
</texcode><br />
Notice that the percent sign is escaped with letterpercent.<br />
<br />
== Loops without worrying about expansion ==<br />
<br />
''This example demonstrates using Lua to write a quasi-repetitive piece of ConTeXt code.''<br />
<br />
Loops in TeX are tricky, because macro assignments and macro expansion interact in strange ways. For example, suppose we want to typeset a table showing the sum of the roll of two dice and want the output to look like this:<br />
<context source="yes"><br />
\setupcolors[state=start]<br />
\setupTABLE[each][each][width=2em,height=2em,align={middle,middle}] <br />
\setupTABLE[r][1][background=color,backgroundcolor=gray] <br />
\setupTABLE[c][1][background=color,backgroundcolor=gray]<br />
<br />
\bTABLE <br />
\bTR \bTD $(+)$ \eTD \bTD 1 \eTD \bTD 2 \eTD <br />
\bTD 3 \eTD \bTD 4 \eTD \bTD 5 \eTD \bTD 6 \eTD \eTR <br />
\bTR \bTD 1 \eTD \bTD 2 \eTD \bTD 3 \eTD <br />
\bTD 4 \eTD \bTD 5 \eTD \bTD 6 \eTD \bTD 7 \eTD \eTR <br />
\bTR \bTD 2 \eTD \bTD 3 \eTD \bTD 4 \eTD <br />
\bTD 5 \eTD \bTD 6 \eTD \bTD 7 \eTD \bTD 8 \eTD \eTR <br />
\bTR \bTD 3 \eTD \bTD 4 \eTD \bTD 5 \eTD<br />
\bTD 6 \eTD \bTD 7 \eTD \bTD 8 \eTD \bTD 9 \eTD \eTR <br />
\bTR \bTD 4 \eTD \bTD 5 \eTD \bTD 6 \eTD<br />
\bTD 7 \eTD \bTD 8 \eTD \bTD 9 \eTD \bTD 10 \eTD \eTR <br />
\bTR \bTD 5 \eTD \bTD 6 \eTD \bTD 7 \eTD <br />
\bTD 8 \eTD \bTD 9 \eTD \bTD 10 \eTD \bTD 11 \eTD \eTR <br />
\bTR \bTD 6 \eTD \bTD 7 \eTD \bTD 8 \eTD <br />
\bTD 9 \eTD \bTD 10 \eTD \bTD 11 \eTD \bTD 12 \eTD \eTR <br />
\eTABLE<br />
</context><br />
<br />
This is easy in LuaTeX. Once a Lua instance starts, TeX does not see anything until the Lua instance exits. So, we can write the loop in Lua, and simply print the values that we would have typed to the TeX stream. When the control is passed to TeX, TeX sees the input as if we had typed it by hand. This is the Lua code for the above table:<br />
<br />
<texcode><br />
\setupcolors[state=start]<br />
\setupTABLE[each][each][width=2em,height=2em,align={middle,middle}] <br />
\setupTABLE[r][1][background=color,backgroundcolor=gray] <br />
\setupTABLE[c][1][background=color,backgroundcolor=gray]<br />
<br />
\startluacode<br />
context.bTABLE()<br />
context.bTR()<br />
context.bTD() context("$(+)$") context.eTD()<br />
for j=1,6 do<br />
context.bTD() context(j) context.eTD()<br />
end<br />
context.eTR()<br />
for i=1,6 do<br />
context.bTR()<br />
context.bTD() context(i) context.eTD()<br />
for j=1,6 do<br />
context.bTD() context(i+j) context.eTD()<br />
end<br />
context.eTR()<br />
end<br />
context.eTABLE()<br />
\stopluacode<br />
</texcode><br />
<br />
== Parsing input without exploding your head ==<br />
<br />
''This example demonstrates parsing simple ASCII notation with Lua's lpeg parser.''<br />
<br />
As an example, let's consider typesetting chemical molecules in TeX. Normally, molecules should be typeset in text mode rather than math mode. <br />
If we want <br />
:H<sub>3</sub>SO<sub>4</sub><sup>+</sup>,<br />
we must type <br />
:<code>H\low{3}SO\lohi{4}{\textplus}</code>,<br />
but we'd much rather type<br />
:<code>\molecule{H_3SO_4^+}</code>.<br />
<br />
So, we need a function that can take a string like that, parse it, and turn it into the appropriate TeX code. LuaTeX includes a general parser based on PEG (parsing expression grammar) called [http://www.inf.puc-rio.br/~roberto/lpeg/lpeg.html lpeg], and it makes writing little parsers positively joyful. (Once you've got the knack of it, at least.) For example, the above <code>\molecule</code> macro can be written as follows.<br />
<br />
<texcode><br />
\startluacode<br />
<br />
-- we will put our molecule function in the userdata namespace.<br />
userdata = userdata or { }<br />
<br />
-- The formatting functions into which the captured<br />
-- superscript/subscript blocks will be fed<br />
local formatters = { }<br />
<br />
function formatters.low(one)<br />
return string.format("\\low{%s}", one)<br />
end<br />
<br />
function formatters.high(one)<br />
return string.format("\\high{%s}", one)<br />
end<br />
<br />
function formatters.lowhigh(one, two)<br />
return string.format("\\lohi{%s}{%s}", one, two)<br />
end<br />
<br />
function formatters.highlow(one, two,three)<br />
return string.format("\\lohi{%s}{%s}", one,two)<br />
end<br />
<br />
-- These are the characters we may encounter<br />
-- The `/` means we want to expand + and - to \textplus c.q. \textminus;<br />
-- this substition is not instant, but will take place inside the first <br />
-- surrounding lpeg.Cs() call.<br />
local plus = lpeg.P("+") / "\\textplus "<br />
local minus = lpeg.P("-") / "\\textminus "<br />
local character = lpeg.R("az", "AZ", "09") -- R is for 'range'<br />
local subscript = lpeg.P("_") -- P is simply for 'pattern'<br />
local superscript = lpeg.P("^")<br />
local leftbrace = lpeg.P("{")<br />
local rightbrace = lpeg.P("}")<br />
<br />
-- a ^ or _ affects either a single character, or a brace-delimited<br />
-- block. Whichever it is, call it `content`.<br />
local single = character + plus + minus<br />
local multiple = leftbrace * single^1 * rightbrace<br />
local content = single + multiple<br />
<br />
-- These are our top-level elements: non-special text, of course, and<br />
-- blocks of superscript/subscript/both.<br />
-- lpeg.Cs(content) does two things:<br />
-- (1) not all matches go into the `/ function` construction; only<br />
-- *captures* go in. The C in Cs stands for Capture. This way, <br />
-- the superscript/subscript mark gets discarded.<br />
-- (2) it expands plus/minus before they go into the formatter. The<br />
-- s in Cs stands for 'substitute in the replacement values, if any'<br />
local text = single^1<br />
local low = subscript * lpeg.Cs(content) <br />
/ formatters.low<br />
local high = superscript * lpeg.Cs(content) <br />
/ formatters.high<br />
local lowhigh = subscript * lpeg.Cs(content) * <br />
superscript * lpeg.Cs(content) <br />
/ formatters.lowhigh<br />
local highlow = superscript * lpeg.Cs(content) * <br />
subscript * lpeg.Cs(content) <br />
/ formatters.highlow<br />
<br />
-- Finally, the root element: 'moleculepattern'<br />
local moleculepattern = lpeg.Cs((lowhigh + highlow + low + high + text)^0)<br />
<br />
function thirddata.molecule(string)<br />
-- * `:match` returns the matched string. Our pattern<br />
-- `moleculepattern` should match the entire input string. Any<br />
-- *performed* substitutions are retained. (`.Cs()` performs a<br />
-- previously defined substitution.)<br />
-- * `context()` inserts the resulting string into the stream, ready for<br />
-- TeX to evaluate.<br />
context(moleculepattern:match(string))<br />
end<br />
<br />
\stopluacode<br />
<br />
\def\molecule#1{\ctxlua{thirddata.molecule("#1")}}<br />
<br />
\starttext<br />
\molecule{Hg^+}, \molecule{SO_4^{2-}}<br />
\stoptext<br />
</texcode><br />
<br />
Quite terse and readable by parser standards, isn't it?<br />
<br />
== Manipulating verbatim text ==<br />
<br />
''This example demonstrates defining a custom \start...\stop buffer that gets processed through Lua in its entirety.''<br />
<br />
Suppose we want to write an environment <code>\startdedentedtyping</code> ... <code>\stopdedentedtyping</code> that removes the indentation of the first line from every line. Thus, the output of ...<br />
<br />
<texcode><br />
\startdedentedtyping<br />
#include &lt;stdio.h&gt;<br />
void main()<br />
{<br />
print("Hello world \n") ;<br />
}<br />
\stopdedentedtyping<br />
</texcode><br />
... should be the same as the output of ...<br />
<br />
<texcode><br />
\starttyping<br />
#include &lt;stdio.h&gt;<br />
void main()<br />
{<br />
print("Hello world \n") ;<br />
}<br />
\stoptyping<br />
</texcode><br />
... even though the leading whitespace is different.<br />
<br />
Defining an environment in TeX that removes the leading spaces but leaves<br />
other spaces untouched is complicated. On the other hand, once we capture the<br />
contents of the environment, removing the leading indent or ''dedenting'' the<br />
content in Lua is easy. Here is a Lua function that uses simple string<br />
substitutions.<br />
<br />
<texcode><br />
\startluacode<br />
-- Initialize a userdata name space to keep our own functions in.<br />
-- That way, we won't interfere with anything ConTeXt keeps in <br />
-- the global name space.<br />
userdata = userdata or {}<br />
<br />
function userdata.dedentedtyping(content)<br />
local lines = string.splitlines(content)<br />
local indent = string.match(lines[1], '^ +') or ''<br />
local pattern = '^' .. indent<br />
for i=1,#lines do<br />
lines[i] = string.gsub(lines[i],pattern,"")<br />
end<br />
<br />
content = table.concat(lines,'\n')<br />
<br />
tex.sprint("\\starttyping\n" .. content .. "\\stoptyping\n")<br />
<br />
-- The typing environment looks for an explicit \type{\stoptyping}. So,<br />
-- context.starttyping() context(content) context.stoptyping()<br />
-- does not work. But<br />
-- context.starttyping() context(content) tex.sprint("\\stoptyping")<br />
-- does.<br />
end<br />
\stopluacode<br />
</texcode><br />
<br />
Here is the code for defining the <code>\startdedentedtyping...\stopdedentedtyping</code> pair:<br />
<br />
<texcode><br />
% Create an environment that stores everything <br />
% between \startdedentedtyping and \stopdedentedtyping <br />
% in a buffer named 'dedentedtyping'.<br />
\def\startdedentedtyping<br />
{\dostartbuffer<br />
[dedentedtyping]<br />
[startdedentedtyping]<br />
[stopdedentedtyping]}<br />
<br />
% On closing the dedentedtyping environment, call the LuaTeX<br />
% function dedentedtyping(), and pass it the contents of <br />
% the buffer called 'dedentedtyping'<br />
\def\stopdedentedtyping<br />
{\ctxlua<br />
{userdata.dedentedtyping(buffers.getcontent('dedentedtyping'))}}<br />
</texcode><br />
<br />
That's all. Finally, we will go into a little more detail on how TeX and Lua communicate with each other.<br />
<br />
== Other examples ==<br />
<br />
* [[Calculations_in_Lua|Calculations in Lua]] (warning date 2012)<br />
* [[LPeg|Writing a parser with LPeg]] (Lua Parsing Expression Grammars)<br />
* [[Random|Random numbers]] in ConTeXt and MetaPost<br />
* [[SQL|An example with SQL database]]<br />
* [[Pascal's Triangle]]<br />
<br />
= In detail: the interaction between TeX and Lua =<br />
<br />
To a first approximation, the interaction between TeX and Lua is straightforward. When TeX (i.e., the LuaTeX engine) starts, it loads the input file in memory and processes it token by token. When TeX encounters <code>\directlua</code>, it stops reading the file in memory, <em>fully expands the argument of <code>\directlua</code></em>, and passes the control to a Lua instance. The Lua instance, which runs with a few preloaded libraries, processes the expanded arguments of <code>\directlua</code>. This Lua instance has a special output stream which can be accessed using <code>tex.print(...)</code>. The function <code>tex.print(...)</code> is just like the Lua function <code>print(...)</code> except that <code>tex.print(...)</code> prints to a <em>TeX stream</em> rather than to the standard output. When the Lua instance finishes processing its input, it passes the contents of the <em>TeX stream</em> back to TeX.<ref>The output of <code>tex.print(...)</code> is buffered and not passed to TeX until the Lua instance has stopped.</ref> TeX then inserts the contents of the <em>TeX stream</em> at the current location of the file that it was reading; expands the contents of the <em>TeX stream</em>; and continues. If TeX encounters another <code>\directlua</code>, the above process is repeated. <br />
<br />
As an exercise, imagine what happens when the following input is processed by LuaTeX. The answer is in the footnotes. <ref>In this example, two different kinds of quotations are used to avoid escaping quotes. Escaping quotes inside <code>\directlua</code> is tricky. The above was a contrived example; if you ever need to escape quotes, you can use the <code>\startluacode ... \stopluacode</code> syntax.</ref><br />
<br />
<texcode><br />
\directlua%<br />
{tex.print("Depth 1 <br />
\\directlua{tex.print('Depth 2')}")}<br />
</texcode><br />
<br />
For more on this, see the [http://wiki.luatex.org/index.php/Writing_Lua_in_TeX] article on the [http://wiki.luatex.org/index.php/Main_Page LuaTeX wiki].<br />
<br />
= Notes =<br />
<references /><br />
<br />
{{note | This article is originally based on [https://www.tug.org/members/TUGboat/tb30-2/tb95mahajan-luatex.pdf this TugBoat article ]. Feel free to modify it.}}<br />
<br />
[[Category:Programming and Databases]]</div>Mæstrohttps://wiki.contextgarden.net/index.php?title=Math/Display&diff=32507Math/Display2021-03-21T22:48:31Z<p>Mæstro: /* List of Formulas with MKIV/LMTX */ update list option requirement for MKIV latest</p>
<hr />
<div>= Display Math =<br />
<br />
Display math is enclosed in a {{cmd|startformula}} / {{cmd|stopformula}} pair. Thus <br />
<br />
<table width="100%" cols="2"><tr valign="top"><td width="50%"><br />
<texcode><br />
The famous result (once more) is given by<br />
\startformula<br />
c^2 = a^2 + b^2.<br />
\stopformula<br />
</texcode><br />
</td><td><br />
This, when typeset, produces the following:<br />
<br />
<context><br />
\setuppapersize[A5]<br />
\setuplayout[width=8cm]<br />
The famous result (once more) is given by<br />
\startformula<br />
c^2 = a^2 + b^2.<br />
\stopformula<br />
</context><br />
</td></tr></table><br />
<br />
= Numbering Formulae =<br />
<br />
ConTeXt provides an easy way to number the display maths equations. Simply, put {{cmd|placeformula}} before {{cmd|startformula}} and you will get numbered equations. Thus,<br />
<table width="100%" cols="2"><tr valign="top"><td width="50%"><br />
<texcode><br />
The famous result (once more) is given by<br />
\placeformula<br />
\startformula<br />
c^2 = a^2 + b^2.<br />
\stopformula<br />
</texcode><br />
</td><td><br />
This, when typeset, produces the following:<br />
<br />
<context><br />
\setuppapersize[A5]<br />
\setuplayout[width=8cm]<br />
The famous result (once more) is given by<br />
\placeformula<br />
\startformula<br />
c^2 = a^2 + b^2.<br />
\stopformula<br />
</context><br />
</td></tr></table><br />
<br />
The {{cmd|placeformula}} command is optional, and produces the equation number; leaving it off produces an unnumbered equation.<br />
<br />
== Changing format of numbers ==<br />
You can use {{cmd|setupformulas}} to change the format of numbers. For example to get bold numbers inside square brackets use<br />
<br />
<table width="100%" cols="2" cellpadding="5"><tr valign="top"><td width="50%"><br />
<texcode><br />
\setupformulas[left={[},right={]},numberstyle=bold]<br />
</texcode><br />
</td><br />
<br />
<td>which gives<br />
<br />
<context><br />
\setuppapersize[A5]<br />
\setuplayout[width=8cm]<br />
\setupformulas[left={[},right={]},numberstyle=bold]<br />
The famous result (once more) is given by<br />
\placeformula<br />
\startformula<br />
c^2 = a^2 + b^2.<br />
\stopformula<br />
</context><br />
</td></tr></table><br />
<br />
To get equations also numbered by section, add the command:<br />
<texcode><br />
\setupnumber[formula][way=bysection] <br />
</texcode><br />
To the start of your document.<br />
<br />
To get alphabets instead of numbers, use<br />
<table width="100%" cols="2" cellpadding="5"><tr valign="top"><td width="50%"><br />
<texcode><br />
\setupformulas[numberconversion=Character]<br />
</texcode><br />
</td><br />
<td>which gives<br />
<context><br />
\setuppapersize[A5]<br />
\setuplayout[width=8cm]<br />
\setupformulas[numberconversion=Character]<br />
\placeformula<br />
\startformula<br />
c^2 = a^2 + b^2<br />
\stopformula<br />
</context><br />
</td></tr></table><br />
<br />
== Changing Formula alignment ==<br />
<br />
Normally a formula is centered, but in case you want to align it left or right, you can set up formulas to behave<br />
that way. Normally a formula will adapt its left indentation to the environment:<br />
<br />
<context><br />
\setuppapersize[A5]<br />
\setuppapersize[A5]<br />
\setuplayout[textwidth=8cm]<br />
This is a bit of text for purpose of example.\epar<br />
\startitemize<br />
\item This is some other example text.\epar<br />
\placeformula \startformula c^2 = a^2 + b^2 \stopformula<br />
\item This is yet other example text.\epar<br />
\stopitemize<br />
This is a bit more text for other purpose of example.\epar<br />
</context><br />
<br />
In the next examples we explicitly align formulas to the left ({{cmd|raggedleft}}), center and right ({{cmd|raggedright}}):<br />
<br />
<context source="yes" text="Or in print:"><br />
\setuppapersize[A5]<br />
\setuplayout[textwidth=8cm]<br />
\setupformulas[align=left]<br />
\startformula c^2 = a^2 + b^2 \stopformula<br />
\setupformulas[align=middle]<br />
\startformula c^2 = a^2 + b^2 \stopformula<br />
\setupformulas[align=right]<br />
\startformula c^2 = a^2 + b^2 \stopformula<br />
</context><br />
<br />
With formula numbers the code is:<br />
<br />
<context source="yes" text="And the formulas look like:"><br />
\setuppapersize[A5]<br />
\setuplayout[textwidth=8cm]<br />
\setupformulas[align=left]<br />
\placeformula \startformula c^2 = a^2 + b^2 \stopformula<br />
\setupformulas[align=middle]<br />
\placeformula \startformula c^2 = a^2 + b^2 \stopformula<br />
\setupformulas[align=right]<br />
\placeformula \startformula c^2 = a^2 + b^2 \stopformula<br />
</context><br />
<br />
When tracing is turned on ({{cmd|tracemathtrue}}) you can visualize the bounding box of the formula,<br />
<br />
<context><br />
\setuppapersize[A5]<br />
\setuplayout[textwidth=8cm]<br />
\tracemathtrue<br />
\setupformulas[align=left]<br />
\placeformula \startformula c^2 = a^2 + b^2 \stopformula<br />
\setupformulas[align=middle]<br />
\placeformula \startformula c^2 = a^2 + b^2 \stopformula<br />
\setupformulas[align=right]<br />
\placeformula \startformula c^2 = a^2 + b^2 \stopformula<br />
</context><br />
<br />
As you can see, the dimensions are the natural ones, but if needed you can force a normalized line:<br />
<br />
<context source="yes" text="This time we get a more spacy result. [Ed. Note: For this example equation, there appears to be no visible change.]"><br />
\setuppapersize[A5]<br />
\setuplayout[textwidth=8cm]<br />
\setupformulas[align=middle,strut=yes]<br />
\tracemathtrue<br />
\placeformula \startformula c^2 = a^2 + b^2 \stopformula<br />
</context><br />
<br />
We will now show a couple of more settings and combinations of settings. In centered formulas, the number takes no space<br />
<br />
<context source="yes"><br />
\setuppapersize[A5]<br />
\setuplayout[textwidth=8cm]<br />
\tracemathtrue<br />
\setupformulas[align=middle]<br />
\startformula c^2 = a^2 + b^2 \stopformula<br />
\placeformula \startformula c^2 = a^2 + b^2 \stopformula<br />
</context><br />
<br />
You can influence the placement of the whole box with the parameters <tt>leftmargin</tt> and <tt>rightmargin</tt>.<br />
<br />
<context source="yes"><br />
\setuppapersize[A5]<br />
\setuplayout[textwidth=8cm]<br />
Some example text, again, to show where the right and left margins of the text block are.<br />
\tracemathtrue<br />
\setupformulas[align=right,leftmargin=3em]<br />
\startformula c^2 = a^2 + b^2 \stopformula<br />
\placeformula \startformula c^2 = a^2 + b^2 \stopformula<br />
<br />
\setupformulas[align=left,rightmargin=1em]<br />
\startformula c^2 = a^2 + b^2 \stopformula<br />
\placeformula \startformula c^2 = a^2 + b^2 \stopformula<br />
</context><br />
<br />
You can also inherit the margin from the environment.<br />
<br />
<context source="yes"><br />
\setuppapersize[A5]<br />
\setuplayout[textwidth=8cm]<br />
Some example text, again, to show where the right and left margins of the text block are.<br />
\tracemathtrue<br />
\setupformulas[align=right,margin=standard]<br />
\startformula c^2 = a^2 + b^2 \stopformula<br />
\placeformula \startformula c^2 = a^2 + b^2 \stopformula<br />
</context><br />
<br />
The distance between the formula and the number is only applied when the formula is left or right aligned.<br />
<br />
<context source="yes"><br />
\setuppapersize[A5]<br />
\setuplayout[textwidth=8cm]<br />
\tracemathtrue<br />
\setupformulas[align=left,distance=2em]<br />
\startformula c^2 = a^2 + b^2 \stopformula<br />
\placeformula \startformula c^2 = a^2 + b^2 \stopformula<br />
</context><br />
<br />
= Referencing formulae =<br />
Equations can be referred to by simply adding a label to {{cmd|placeformula}} and using {{cmd|ref}} to create the reference:<br />
<br />
<table width="100%" cols="2" cellpadding="5"><tr valign="top"><td width="50%"><br />
<texcode><br />
The famous result (and again) is given by<br />
\placeformula[formulalabel]<br />
\startformula<br />
c^2 = a^2 + b^2.<br />
\stopformula<br />
And now we can refer to formula \ref[][formulalabel].<br />
</texcode><br />
</td><td><br />
This, when typeset, produces the following:<br />
<br />
<context><br />
\setuppapersize[A5]<br />
\setuplayout[width=8cm]<br />
The famous result (and again) is given by<br />
\placeformula[formulalabel]<br />
\startformula<br />
c^2 = a^2 + b^2.<br />
\stopformula<br />
<br />
And now we can refer to formula \ref[][formulalabel].<br />
</context><br />
</td></tr></table><br />
<br />
Note, that {{cmd|ref}} expects two arguments, therefore you need the brackets twice.<br />
<br />
By default, only the formula number appears as a reference. This can be changed by using {{cmd|definereferenceformat}}. For example, to create a command <code>\eqref</code> which shows the formula number in brackets, use<br />
<texcode><br />
\definereferenceformat[eqref][left=(,right=)]<br />
</texcode><br />
See [[References]] for more examples of {{cmd|definereferenceformat}}.<br />
<br />
=Sub-Formula Numbering=<br />
<br />
== Automatic Sub-Formula Numbering ==<br />
<br />
To use subformula numbering, you can use {{cmd|startsubformulas}}/{{cmd|stopsubformulas}}. For example<br />
<br />
<table width="100%" cols="2"><tr valign="top"><td width="50%"><br />
<texcode><br />
Examples:<br />
\startsubformulas[eq:1]<br />
\placeformula[eq:first]<br />
\startformula<br />
c^2 = a^2 + b^2<br />
\stopformula<br />
<br />
\placeformula[eq:second]<br />
\startformula<br />
c^2 = a^2 + b^2<br />
\stopformula<br />
\stopsubformulas<br />
Formula (\in[eq:1]) states <br />
the Pythagora's Theorem twice,<br />
once in (\in[eq:first]) and <br />
again in (\in[eq:second]).<br />
</texcode><br />
</td><td><br />
<context><br />
\setuppapersize[A5]<br />
\setuplayout[width=8cm]<br />
Examples:<br />
\startsubformulas[eq:1]<br />
\placeformula[eq:first]<br />
\startformula<br />
c^2 = a^2 + b^2<br />
\stopformula<br />
<br />
\placeformula[eq:second]<br />
\startformula<br />
c^2 = a^2 + b^2<br />
\stopformula<br />
\stopsubformulas<br />
Formula (\in[eq:1]) states the Pythagora's Theorem twice, once in (\in[eq:first]) and again in (\in[eq:second]).<br />
</context><br />
</td></tr></table><br />
<br />
<br />
== The Manual Method ==<br />
<br />
Sometimes, you need more fine grained control over numbering of subformulas. In that case one can make use of the optional agument of {{cmd|placeformula}} command and the related {{cmd|placesubformula}} commands which can be used to produce sub-formula numbering. For example:<br />
<br />
<table width="100%" cols="2"><tr valign="top"><td width="50%"><br />
<texcode><br />
Examples:<br />
\placeformula{a}<br />
\startformula<br />
c^2 = a^2 + b^2<br />
\stopformula<br />
<br />
\placesubformula{b}<br />
\startformula<br />
c^2 = a^2 + b^2<br />
\stopformula<br />
</texcode><br />
</td><td><br />
<context><br />
\setuppapersize[A5]<br />
\setuplayout[width=8cm]<br />
Examples:<br />
\placeformula{a}<br />
\startformula<br />
c^2 = a^2 + b^2<br />
\stopformula<br />
<br />
\placesubformula{b}<br />
\startformula<br />
c^2 = a^2 + b^2<br />
\stopformula<br />
</context><br />
</td></tr></table><br />
<br />
What's going on here is simpler than it might appear at first glance. Both {{cmd|placeformula}} and {{cmd|placesubformula}} produce equation numbers with the optional tag added at the end; the sole difference is that the former increments the equation number first, while the latter does not (and thus can be used for the second and subsequent formulas that use the same formula number but presumably have different tags).<br />
<br />
This is sufficient for cases where the standard ConTeXt equation numbers suffice, and where only one equation number is needed per formula. However, there are many cases where this is insufficient, and {{cmd|placeformula}} defines {{cmd|formulanumber}} and {{cmd|subformulanumber}} commands, which provide hooks to allow the use of ConTeXt-managed formula numbers with plain TeX equation numbering. These, when used within a formula, simply return the formula number in properly formatted form, as can be seen in this simple example with plain TeX's {{cmd|eqno}}. Note that the optional tag is inherited from {{cmd|placeformula}}.<br />
<br />
<table width="100%" cols="2"><tr valign="top"><td width="50%"><br />
<texcode><br />
More examples:<br />
\placeformula{c}<br />
\startformula<br />
\let\doplaceformulanumber\empty<br />
c^2 = a^2 + b^2 \eqno{\formulanumber}<br />
\stopformula<br />
</texcode><br />
</td><td><br />
<context><br />
\setuppapersize[A5]<br />
\setuplayout[width=8cm]<br />
More examples:<br />
\placeformula{c}<br />
\startformula<br />
\let\doplaceformulanumber\empty<br />
c^2 = a^2 + b^2 \eqno{\formulanumber}<br />
\stopformula<br />
</context><br />
</td></tr></table><br />
<br />
In order for this to work properly, we need to turn off ConTeXt's automatic formula number placement; thus the {{cmd|let}} command to empty {{cmd|doplaceformulanumber}}, which must be placed <em>after</em> the start of the formula. In many practical examples, however, this is not necessary; ConTeXt redefines {{cmd|displaylines}} and {{cmd|eqalignno}} to do this automatically.<br />
<br />
For more control over sub-formula numbering, {{cmd|formulanumber}} and {{cmd|subformulanumber}} have an optional argument parallel to that of {{cmd|placeformula}}, as demonstrated in this use of plain TeX's {{cmd|eqalignno}}, which places multiple equation numbers within one formula.<br />
<br />
<table width="100%" cols="2"><tr valign="top"><td width="50%"><br />
<texcode><br />
\placeformula<br />
\startformula<br />
\eqalignno{<br />
c^2 &= a^2 + b^2 &\formulanumber{a} \cr<br />
c &= \left(a^2 + b^2\right)^{\vfrac{1}{2}} &\subformulanumber{b}\cr<br />
a^2 + b^2 &= c^2 &\subformulanumber{c} \cr<br />
d^2 &= e^2 &\formulanumber\cr}<br />
\stopformula<br />
</texcode><br />
</td><td><br />
<context><br />
\setuppapersize[A5]<br />
\setuplayout[width=8cm]<br />
\placeformula<br />
\startformula<br />
\eqalignno{<br />
c^2 &= a^2 + b^2 &\formulanumber{a} \cr<br />
c &= \left(a^2 + b^2\right)^{\vfrac{1}{2}} &\subformulanumber{b}\cr<br />
a^2 + b^2 &= c^2 &\subformulanumber{c} \cr<br />
d^2 &= e^2 &\formulanumber\cr}<br />
\stopformula<br />
</context><br />
</td></tr></table><br />
<br />
Note that both {{cmd|formulanumber}} and {{cmd|subformulanumber}} can be used within the same formula, and the formula number is incremented as expected. Also, if an optional argument is specified in both {{cmd|placefigure}} and {{cmd|formulanumber}}, the latter takes precedence.<br />
<br />
<table width="100%" cols="2"><tr valign="top"><td width="50%"><br />
<texcode><br />
More examples for left-located equation number:<br />
\setupformulas[location=left]<br />
\placeformula{d}<br />
\startformula<br />
\let\doplaceformulanumber\empty<br />
c^2 = a^2 + b^2 \leqno{\formulanumber}<br />
\stopformula<br />
and<br />
\placeformula<br />
\startformula<br />
\leqalignno{c^2 &= a^2 + b^2 &\formulanumber{a} \cr<br />
a^2 + b^2 &= c^2 &\subformulanumber{b} \cr<br />
d^2 &= e^2 &\formulanumber\cr}<br />
\stopformula<br />
</texcode><br />
</td><td><br />
<context><br />
\setuppapersize[A5]<br />
\setuplayout[width=8cm]<br />
More examples for left-located equation no.:<br />
\setupformulas[location=left]<br />
\placeformula{d}<br />
\startformula<br />
\let\doplaceformulanumber\empty<br />
c^2 = a^2 + b^2 \leqno{\formulanumber}<br />
\stopformula<br />
and<br />
\placeformula<br />
\startformula<br />
\leqalignno{c^2 &= a^2 + b^2 &\formulanumber{a} \cr<br />
a^2 + b^2 &= c^2 &\subformulanumber{b} \cr<br />
d^2 &= e^2 &\formulanumber\cr}<br />
\stopformula<br />
</context><br />
</td></tr></table><br />
<br />
-- 23:46, 15 Aug 2005 (CEST) Prinse Wang<br />
<br />
=List of Formulas=<br />
<br />
You can have a list of the formulas contained in a document by using {{cmd|placenamedformula}} instead of {{cmd|placeformula}}. Only the formulas written with {{cmd|placenamedformula}} are not put in the list, so that you can control precisely the content of the list.<br />
<br />
{{cmd|placenamedformula}} takes as first parameter the name of the formula put in the list. The other {{cmd|placeformula}} features are still available. The list can be formatted like any other list.<br />
<br />
Example:<br />
<texcode><br />
\subsubject{List of Formulas}<br />
\placelist[formula][criterium=text,alternative=c]<br />
<br />
\subsubject{Formulas}<br />
\placenamedformula[one]{First listed Formula}<br />
\startformula a = 1 \stopformula \endgraf<br />
<br />
\placeformula<br />
\startformula a = 2 \stopformula \endgraf<br />
<br />
\placenamedformula{Second listed Formula}{b}<br />
\startformula a = 3 \stopformula \endgraf<br />
</texcode><br />
<br />
Gives:<br />
<br />
<context><br />
\setuppapersize[A5]<br />
\setuplayout[width=13cm]<br />
\subsubject{List of Formulas}<br />
\placelist[formula][criterium=text,alternative=c]<br />
<br />
\subsubject{Formulas}<br />
\placenamedformula[one]{First listed Formula}<br />
\startformula a = 1 \stopformula \endgraf<br />
<br />
\placeformula<br />
\startformula a = 2 \stopformula \endgraf<br />
<br />
\placenamedformula{Second listed Formula}{b}<br />
\startformula a = 3 \stopformula \endgraf<br />
</context><br />
<br />
== List of Formulas with MKIV/LMTX ==<br />
Since MKIV there are two types of formulas: numbered and named. Numbered formulas have the number as a reference and caption next to the formula and are listed only with the number and pagenumber in the list of formulas. Named formulas use the name as the caption instead of a number and are referenced with the name and pagenumber in the list of formulas.<br />
<br />
<context source=yes><br />
% equivalent to \placenamedformula[formula:mass]{Mass-energy equivalence}<br />
\startplaceformula[title={Mass-energy equivalence},reference=formula:mass] \startformula e=mc^2 \stopformula\stopplaceformula<br />
<br />
% equivalent to \placeformula[formula:mass] (note: placeformula is listed in the list of formulas if it has a reference)<br />
\startplaceformula[reference=formula:mass] \startformula e=mc^2 \stopformula \stopplaceformula<br />
<br />
% equivalent to \placeformula (with no entry in the list of formulas)<br />
\startplaceformula \startformula e=mc^2 \stopformula \stopplaceformula<br />
<br />
\placelist[formula][criterium=text,alternative=c]<br />
</context><br />
<br />
{{cmd|startplaceformula}} comes with the following key options: bookmark, list, reference, suffix, title.<br />
<br />
To name a numbered formula in the list of formulas, one can use the list option:<br />
<context source=yes><br />
% named formula<br />
\startplaceformula[reference=formula:mass,title={Mass-energy equivalence}] \startformula e=mc^2 \stopformula<br />
\stopplaceformula<br />
<br />
% numbered formula with list text, note without a reference option the formula is just a placeformula that is not listed in the list of formulas -- needs ConTeXt latest version 2021-03-21 or later<br />
\startplaceformula[reference=formula:mass,list={Mass-energy equivalence}] \startformula e=mc^2 \stopformula \stopplaceformula<br />
<br />
\placelist[formula][criterium=text,alternative=c]<br />
</context><br />
<br />
Note: The title option changes the formula to a named formula and will use that name in the list of formulas regardless of the list option.<br />
<br />
= Shaded background for part of a displayed equation =<br />
(see also [[Framed]])<br />
<br />
To highlight part of a formula, you can give it a gray background using {{cmd|mframed}}: the following is the code you can use in mkii (see below what one has to do in mkiv):<br />
<br />
<context source="yes"><br />
\setuppapersize[A5]<br />
\setupcolors[state=start]<br />
\def\graymath{\mframed[frame=off,<br />
background=color,<br />
backgroundcolor=gray,<br />
backgroundoffset=3pt]}<br />
<br />
\startformula<br />
\ln (1+x) =\, \graymath{x - {x^2\over2}} \,+ {x^3\over3}-\cdots.<br />
\stopformula<br />
</context><br />
<br />
In mkiv the code is slightly different: one may define {{cmd|graymath}} directly using {{cmd|definemathframed}}<br />
<br />
<texcode><br />
\setuppapersize[A5]<br />
\definemathframed[graymath]<br />
[<br />
frame=off,<br />
location=mathematics,<br />
background=color,<br />
backgroundcolor=lightgray,<br />
backgroundoffset=2pt<br />
]<br />
\starttext<br />
Since for $|x| < 1$ we have<br />
\startformula<br />
\log(1+x) = \graymath{x- \displaystyle{x^2\over2}} + {x^3 \over 3} + \cdots<br />
\stopformula<br />
we may write $\log(1+x) = x + O(x^2)$.<br />
\stoptext<br />
</texcode><br />
<br />
The result is shown below (possibly the framed part of the formula is not aligned correctly with the remainder of the formula because the mkiv engine on Context Garden is not up to date…).<br />
<br />
<context mode=mkiv><br />
\setuppapersize[A5]<br />
\definemathframed[graymath]<br />
[<br />
frame=off,<br />
location=mathematics,<br />
background=color,<br />
backgroundcolor=lightgray,<br />
backgroundoffset=2pt<br />
]<br />
<br />
Since for $|x| < 1$ we have<br />
\startformula<br />
\log(1+x) = \graymath{x- \displaystyle{x^2\over2}} + {x^3 \over 3} + \cdots<br />
\stopformula<br />
we may write $\log(1+x) = x + O(x^2)$.<br />
</context><br />
<br />
[[Category:Math]]</div>Mæstrohttps://wiki.contextgarden.net/index.php?title=Command/setupformulae&diff=32505Command/setupformulae2021-03-21T17:28:33Z<p>Mæstro: /* Example */ add Hans' example from mailman.ntg.nl/pipermail/ntg-context/2021/101671.html</p>
<hr />
<div>{{Reference<br />
|name=setupformulae<br />
|attributes=<br />
}}<br />
<br />
== [[Help:Reference|Syntax]] (autogenerated) ==<br />
<syntax>setupformulae</syntax><br />
<br />
== [[Help:Reference|Syntax]] ==<br />
<table cellspacing="4" cellpadding="2" class="cmd"><br />
<tr><br />
<td colspan="2" class="cmd">\setupformulae<span class="first" >[...,...=...,...]</span></td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:color|color]]</td><br />
<td>name</td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:location|location]]</td><br />
<td>[[Command/value:left|left]] [[Command/value:right|right]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:left|left]]</td><br />
<td>[[Command/value:text|text]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:right|right]]</td><br />
<td>[[Command/value:text|text]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:align|align]]</td><br />
<td>[[Command/value:flushleft|flushleft]] [[Command/value:middle|middle]] [[Command/value:flushright|flushright]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:option|option]]</td><br />
<td>[[Command/value:middle|middle]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:strut|strut]]</td><br />
<td>[[Command/value:yes|yes]] [[Command/value:no|no]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:distance|distance]]</td><br />
<td>[[Command/value:dimension|dimension]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:margin|margin]]</td><br />
<td>[[Command/value:dimension|dimension]] [[Command/value:standard|standard]] [[Command/value:yes|yes]] [[Command/value:no|no]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:leftmargin|leftmargin]]</td><br />
<td>[[Command/value:dimension|dimension]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:rightmargin|rightmargin]]</td><br />
<td>[[Command/value:dimension|dimension]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:indentnext|indentnext]]</td><br />
<td>[[Command/value:yes|yes]] [[Command/value:no|no]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:alternative|alternative]]</td><br />
<td>[[Command/value:name|name]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:spacebefore|spacebefore]]</td><br />
<td>[[Command/value:dimension|dimension]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:after|spaceafter]]</td><br />
<td>[[Command/value:dimension|dimension]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:separator|separator]]</td><br />
<td>[[Command/value:text|text]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:numberconversion|numberconversion]]</td><br />
<td>[[Command/value:numbers|numbers]] [[Command/value:characters|characters]] [[Command/value:Characters|Characters]] [[Command/value:romannumerals|romannumerals]] [[Command/value:Romannumerals|Romannumerals]] [[Command/value:text|text]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">...=...,...</td><br />
<td>inherits from {{cmd|setupcounter}}</td><br />
</tr><br />
</table><br />
<br />
== Description ==<br />
Using option <code>[way=bysection]</code> resets the numbering to 1 at each new section, but does not prefix the numbers with the section number, to do that, use the following options:<br />
<code><br />
\setupformulae[way=bysection,prefixsegments=section]<br />
</code><br />
<br />
== Example ==<br />
In order to show all section numbering in the formula, one can use the prefixset option (by default it is limited to 3 levels, see strc-def) as follows:<br />
<br />
<context source=yes><br />
\setupcounter[formula][way=bytext]<br />
\setupformulas[way=bytext,prefixsegments=1:*,prefixset=all]<br />
<br />
\startchapter[title=Chapter]<br />
\dorecurse{4}{<br />
\startsection[title=Section]<br />
\startsubsection[title=Subsection]<br />
\startplaceformula[reference=eq1] \startformula c^2 = a^2 + b^2 \stopformula \stopplaceformula<br />
\stopsubsection<br />
\startsubsection[title=Subsection]<br />
\startplaceformula[reference=eq2] \startformula c^2 = a^2 + b^2 \stopformula \stopplaceformula<br />
\stopsubsection<br />
\stopsection<br />
}<br />
\stopchapter<br />
<br />
\placelist[formula][criterium=all,alternative=c]<br />
</context><br />
<br />
== See also ==<br />
<!-- something like {{cmd|goto}} --><br />
<br />
== Help from ConTeXt-Mailinglist/Forum ==<br />
All issues with:<br />
{{Forum|{{SUBPAGENAME}}}}<br />
<br />
[[Category:Command/Mathematics|setupformulae]]</div>Mæstrohttps://wiki.contextgarden.net/index.php?title=Command/setupformulae&diff=32504Command/setupformulae2021-03-21T14:41:56Z<p>Mæstro: /* Syntax */ correct cmd link reference</p>
<hr />
<div>{{Reference<br />
|name=setupformulae<br />
|attributes=<br />
}}<br />
<br />
== [[Help:Reference|Syntax]] (autogenerated) ==<br />
<syntax>setupformulae</syntax><br />
<br />
== [[Help:Reference|Syntax]] ==<br />
<table cellspacing="4" cellpadding="2" class="cmd"><br />
<tr><br />
<td colspan="2" class="cmd">\setupformulae<span class="first" >[...,...=...,...]</span></td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:color|color]]</td><br />
<td>name</td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:location|location]]</td><br />
<td>[[Command/value:left|left]] [[Command/value:right|right]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:left|left]]</td><br />
<td>[[Command/value:text|text]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:right|right]]</td><br />
<td>[[Command/value:text|text]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:align|align]]</td><br />
<td>[[Command/value:flushleft|flushleft]] [[Command/value:middle|middle]] [[Command/value:flushright|flushright]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:option|option]]</td><br />
<td>[[Command/value:middle|middle]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:strut|strut]]</td><br />
<td>[[Command/value:yes|yes]] [[Command/value:no|no]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:distance|distance]]</td><br />
<td>[[Command/value:dimension|dimension]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:margin|margin]]</td><br />
<td>[[Command/value:dimension|dimension]] [[Command/value:standard|standard]] [[Command/value:yes|yes]] [[Command/value:no|no]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:leftmargin|leftmargin]]</td><br />
<td>[[Command/value:dimension|dimension]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:rightmargin|rightmargin]]</td><br />
<td>[[Command/value:dimension|dimension]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:indentnext|indentnext]]</td><br />
<td>[[Command/value:yes|yes]] [[Command/value:no|no]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:alternative|alternative]]</td><br />
<td>[[Command/value:name|name]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:spacebefore|spacebefore]]</td><br />
<td>[[Command/value:dimension|dimension]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:after|spaceafter]]</td><br />
<td>[[Command/value:dimension|dimension]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:separator|separator]]</td><br />
<td>[[Command/value:text|text]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:numberconversion|numberconversion]]</td><br />
<td>[[Command/value:numbers|numbers]] [[Command/value:characters|characters]] [[Command/value:Characters|Characters]] [[Command/value:romannumerals|romannumerals]] [[Command/value:Romannumerals|Romannumerals]] [[Command/value:text|text]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">...=...,...</td><br />
<td>inherits from {{cmd|setupcounter}}</td><br />
</tr><br />
</table><br />
<br />
== Description ==<br />
Using option <code>[way=bysection]</code> resets the numbering to 1 at each new section, but does not prefix the numbers with the section number, to do that, use the following options:<br />
<code><br />
\setupformulae[way=bysection,prefixsegments=section]<br />
</code><br />
<br />
== Example ==<br />
<!-- Please fill in an example if you can --><br />
<br />
== See also ==<br />
<!-- something like {{cmd|goto}} --><br />
<br />
== Help from ConTeXt-Mailinglist/Forum ==<br />
All issues with:<br />
{{Forum|{{SUBPAGENAME}}}}<br />
<br />
[[Category:Command/Mathematics|setupformulae]]</div>Mæstrohttps://wiki.contextgarden.net/index.php?title=Command/setupformulae&diff=32503Command/setupformulae2021-03-21T14:39:02Z<p>Mæstro: /* Syntax */ add inherit from setupcounter for prefixes</p>
<hr />
<div>{{Reference<br />
|name=setupformulae<br />
|attributes=<br />
}}<br />
<br />
== [[Help:Reference|Syntax]] (autogenerated) ==<br />
<syntax>setupformulae</syntax><br />
<br />
== [[Help:Reference|Syntax]] ==<br />
<table cellspacing="4" cellpadding="2" class="cmd"><br />
<tr><br />
<td colspan="2" class="cmd">\setupformulae<span class="first" >[...,...=...,...]</span></td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:color|color]]</td><br />
<td>name</td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:location|location]]</td><br />
<td>[[Command/value:left|left]] [[Command/value:right|right]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:left|left]]</td><br />
<td>[[Command/value:text|text]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:right|right]]</td><br />
<td>[[Command/value:text|text]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:align|align]]</td><br />
<td>[[Command/value:flushleft|flushleft]] [[Command/value:middle|middle]] [[Command/value:flushright|flushright]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:option|option]]</td><br />
<td>[[Command/value:middle|middle]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:strut|strut]]</td><br />
<td>[[Command/value:yes|yes]] [[Command/value:no|no]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:distance|distance]]</td><br />
<td>[[Command/value:dimension|dimension]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:margin|margin]]</td><br />
<td>[[Command/value:dimension|dimension]] [[Command/value:standard|standard]] [[Command/value:yes|yes]] [[Command/value:no|no]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:leftmargin|leftmargin]]</td><br />
<td>[[Command/value:dimension|dimension]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:rightmargin|rightmargin]]</td><br />
<td>[[Command/value:dimension|dimension]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:indentnext|indentnext]]</td><br />
<td>[[Command/value:yes|yes]] [[Command/value:no|no]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:alternative|alternative]]</td><br />
<td>[[Command/value:name|name]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:spacebefore|spacebefore]]</td><br />
<td>[[Command/value:dimension|dimension]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:after|spaceafter]]</td><br />
<td>[[Command/value:dimension|dimension]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:separator|separator]]</td><br />
<td>[[Command/value:text|text]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[[Command/keyword:numberconversion|numberconversion]]</td><br />
<td>[[Command/value:numbers|numbers]] [[Command/value:characters|characters]] [[Command/value:Characters|Characters]] [[Command/value:romannumerals|romannumerals]] [[Command/value:Romannumerals|Romannumerals]] [[Command/value:text|text]] </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">...=...,...</td><br />
<td>inherits from [[Command/value:setupcounter|setupcounter]]</td><br />
</tr><br />
</table><br />
<br />
== Description ==<br />
Using option <code>[way=bysection]</code> resets the numbering to 1 at each new section, but does not prefix the numbers with the section number, to do that, use the following options:<br />
<code><br />
\setupformulae[way=bysection,prefixsegments=section]<br />
</code><br />
<br />
== Example ==<br />
<!-- Please fill in an example if you can --><br />
<br />
== See also ==<br />
<!-- something like {{cmd|goto}} --><br />
<br />
== Help from ConTeXt-Mailinglist/Forum ==<br />
All issues with:<br />
{{Forum|{{SUBPAGENAME}}}}<br />
<br />
[[Category:Command/Mathematics|setupformulae]]</div>Mæstrohttps://wiki.contextgarden.net/index.php?title=Math/Display&diff=32501Math/Display2021-03-20T00:39:49Z<p>Mæstro: /* List of Formulas with MKIV/LMTX */</p>
<hr />
<div>= Display Math =<br />
<br />
Display math is enclosed in a {{cmd|startformula}} / {{cmd|stopformula}} pair. Thus <br />
<br />
<table width="100%" cols="2"><tr valign="top"><td width="50%"><br />
<texcode><br />
The famous result (once more) is given by<br />
\startformula<br />
c^2 = a^2 + b^2.<br />
\stopformula<br />
</texcode><br />
</td><td><br />
This, when typeset, produces the following:<br />
<br />
<context><br />
\setuppapersize[A5]<br />
\setuplayout[width=8cm]<br />
The famous result (once more) is given by<br />
\startformula<br />
c^2 = a^2 + b^2.<br />
\stopformula<br />
</context><br />
</td></tr></table><br />
<br />
= Numbering Formulae =<br />
<br />
ConTeXt provides an easy way to number the display maths equations. Simply, put {{cmd|placeformula}} before {{cmd|startformula}} and you will get numbered equations. Thus,<br />
<table width="100%" cols="2"><tr valign="top"><td width="50%"><br />
<texcode><br />
The famous result (once more) is given by<br />
\placeformula<br />
\startformula<br />
c^2 = a^2 + b^2.<br />
\stopformula<br />
</texcode><br />
</td><td><br />
This, when typeset, produces the following:<br />
<br />
<context><br />
\setuppapersize[A5]<br />
\setuplayout[width=8cm]<br />
The famous result (once more) is given by<br />
\placeformula<br />
\startformula<br />
c^2 = a^2 + b^2.<br />
\stopformula<br />
</context><br />
</td></tr></table><br />
<br />
The {{cmd|placeformula}} command is optional, and produces the equation number; leaving it off produces an unnumbered equation.<br />
<br />
== Changing format of numbers ==<br />
You can use {{cmd|setupformulas}} to change the format of numbers. For example to get bold numbers inside square brackets use<br />
<br />
<table width="100%" cols="2" cellpadding="5"><tr valign="top"><td width="50%"><br />
<texcode><br />
\setupformulas[left={[},right={]},numberstyle=bold]<br />
</texcode><br />
</td><br />
<br />
<td>which gives<br />
<br />
<context><br />
\setuppapersize[A5]<br />
\setuplayout[width=8cm]<br />
\setupformulas[left={[},right={]},numberstyle=bold]<br />
The famous result (once more) is given by<br />
\placeformula<br />
\startformula<br />
c^2 = a^2 + b^2.<br />
\stopformula<br />
</context><br />
</td></tr></table><br />
<br />
To get equations also numbered by section, add the command:<br />
<texcode><br />
\setupnumber[formula][way=bysection] <br />
</texcode><br />
To the start of your document.<br />
<br />
To get alphabets instead of numbers, use<br />
<table width="100%" cols="2" cellpadding="5"><tr valign="top"><td width="50%"><br />
<texcode><br />
\setupformulas[numberconversion=Character]<br />
</texcode><br />
</td><br />
<td>which gives<br />
<context><br />
\setuppapersize[A5]<br />
\setuplayout[width=8cm]<br />
\setupformulas[numberconversion=Character]<br />
\placeformula<br />
\startformula<br />
c^2 = a^2 + b^2<br />
\stopformula<br />
</context><br />
</td></tr></table><br />
<br />
== Changing Formula alignment ==<br />
<br />
Normally a formula is centered, but in case you want to align it left or right, you can set up formulas to behave<br />
that way. Normally a formula will adapt its left indentation to the environment:<br />
<br />
<context><br />
\setuppapersize[A5]<br />
\setuppapersize[A5]<br />
\setuplayout[textwidth=8cm]<br />
This is a bit of text for purpose of example.\epar<br />
\startitemize<br />
\item This is some other example text.\epar<br />
\placeformula \startformula c^2 = a^2 + b^2 \stopformula<br />
\item This is yet other example text.\epar<br />
\stopitemize<br />
This is a bit more text for other purpose of example.\epar<br />
</context><br />
<br />
In the next examples we explicitly align formulas to the left ({{cmd|raggedleft}}), center and right ({{cmd|raggedright}}):<br />
<br />
<context source="yes" text="Or in print:"><br />
\setuppapersize[A5]<br />
\setuplayout[textwidth=8cm]<br />
\setupformulas[align=left]<br />
\startformula c^2 = a^2 + b^2 \stopformula<br />
\setupformulas[align=middle]<br />
\startformula c^2 = a^2 + b^2 \stopformula<br />
\setupformulas[align=right]<br />
\startformula c^2 = a^2 + b^2 \stopformula<br />
</context><br />
<br />
With formula numbers the code is:<br />
<br />
<context source="yes" text="And the formulas look like:"><br />
\setuppapersize[A5]<br />
\setuplayout[textwidth=8cm]<br />
\setupformulas[align=left]<br />
\placeformula \startformula c^2 = a^2 + b^2 \stopformula<br />
\setupformulas[align=middle]<br />
\placeformula \startformula c^2 = a^2 + b^2 \stopformula<br />
\setupformulas[align=right]<br />
\placeformula \startformula c^2 = a^2 + b^2 \stopformula<br />
</context><br />
<br />
When tracing is turned on ({{cmd|tracemathtrue}}) you can visualize the bounding box of the formula,<br />
<br />
<context><br />
\setuppapersize[A5]<br />
\setuplayout[textwidth=8cm]<br />
\tracemathtrue<br />
\setupformulas[align=left]<br />
\placeformula \startformula c^2 = a^2 + b^2 \stopformula<br />
\setupformulas[align=middle]<br />
\placeformula \startformula c^2 = a^2 + b^2 \stopformula<br />
\setupformulas[align=right]<br />
\placeformula \startformula c^2 = a^2 + b^2 \stopformula<br />
</context><br />
<br />
As you can see, the dimensions are the natural ones, but if needed you can force a normalized line:<br />
<br />
<context source="yes" text="This time we get a more spacy result. [Ed. Note: For this example equation, there appears to be no visible change.]"><br />
\setuppapersize[A5]<br />
\setuplayout[textwidth=8cm]<br />
\setupformulas[align=middle,strut=yes]<br />
\tracemathtrue<br />
\placeformula \startformula c^2 = a^2 + b^2 \stopformula<br />
</context><br />
<br />
We will now show a couple of more settings and combinations of settings. In centered formulas, the number takes no space<br />
<br />
<context source="yes"><br />
\setuppapersize[A5]<br />
\setuplayout[textwidth=8cm]<br />
\tracemathtrue<br />
\setupformulas[align=middle]<br />
\startformula c^2 = a^2 + b^2 \stopformula<br />
\placeformula \startformula c^2 = a^2 + b^2 \stopformula<br />
</context><br />
<br />
You can influence the placement of the whole box with the parameters <tt>leftmargin</tt> and <tt>rightmargin</tt>.<br />
<br />
<context source="yes"><br />
\setuppapersize[A5]<br />
\setuplayout[textwidth=8cm]<br />
Some example text, again, to show where the right and left margins of the text block are.<br />
\tracemathtrue<br />
\setupformulas[align=right,leftmargin=3em]<br />
\startformula c^2 = a^2 + b^2 \stopformula<br />
\placeformula \startformula c^2 = a^2 + b^2 \stopformula<br />
<br />
\setupformulas[align=left,rightmargin=1em]<br />
\startformula c^2 = a^2 + b^2 \stopformula<br />
\placeformula \startformula c^2 = a^2 + b^2 \stopformula<br />
</context><br />
<br />
You can also inherit the margin from the environment.<br />
<br />
<context source="yes"><br />
\setuppapersize[A5]<br />
\setuplayout[textwidth=8cm]<br />
Some example text, again, to show where the right and left margins of the text block are.<br />
\tracemathtrue<br />
\setupformulas[align=right,margin=standard]<br />
\startformula c^2 = a^2 + b^2 \stopformula<br />
\placeformula \startformula c^2 = a^2 + b^2 \stopformula<br />
</context><br />
<br />
The distance between the formula and the number is only applied when the formula is left or right aligned.<br />
<br />
<context source="yes"><br />
\setuppapersize[A5]<br />
\setuplayout[textwidth=8cm]<br />
\tracemathtrue<br />
\setupformulas[align=left,distance=2em]<br />
\startformula c^2 = a^2 + b^2 \stopformula<br />
\placeformula \startformula c^2 = a^2 + b^2 \stopformula<br />
</context><br />
<br />
= Referencing formulae =<br />
Equations can be referred to by simply adding a label to {{cmd|placeformula}} and using {{cmd|ref}} to create the reference:<br />
<br />
<table width="100%" cols="2" cellpadding="5"><tr valign="top"><td width="50%"><br />
<texcode><br />
The famous result (and again) is given by<br />
\placeformula[formulalabel]<br />
\startformula<br />
c^2 = a^2 + b^2.<br />
\stopformula<br />
And now we can refer to formula \ref[][formulalabel].<br />
</texcode><br />
</td><td><br />
This, when typeset, produces the following:<br />
<br />
<context><br />
\setuppapersize[A5]<br />
\setuplayout[width=8cm]<br />
The famous result (and again) is given by<br />
\placeformula[formulalabel]<br />
\startformula<br />
c^2 = a^2 + b^2.<br />
\stopformula<br />
<br />
And now we can refer to formula \ref[][formulalabel].<br />
</context><br />
</td></tr></table><br />
<br />
Note, that {{cmd|ref}} expects two arguments, therefore you need the brackets twice.<br />
<br />
By default, only the formula number appears as a reference. This can be changed by using {{cmd|definereferenceformat}}. For example, to create a command <code>\eqref</code> which shows the formula number in brackets, use<br />
<texcode><br />
\definereferenceformat[eqref][left=(,right=)]<br />
</texcode><br />
See [[References]] for more examples of {{cmd|definereferenceformat}}.<br />
<br />
=Sub-Formula Numbering=<br />
<br />
== Automatic Sub-Formula Numbering ==<br />
<br />
To use subformula numbering, you can use {{cmd|startsubformulas}}/{{cmd|stopsubformulas}}. For example<br />
<br />
<table width="100%" cols="2"><tr valign="top"><td width="50%"><br />
<texcode><br />
Examples:<br />
\startsubformulas[eq:1]<br />
\placeformula[eq:first]<br />
\startformula<br />
c^2 = a^2 + b^2<br />
\stopformula<br />
<br />
\placeformula[eq:second]<br />
\startformula<br />
c^2 = a^2 + b^2<br />
\stopformula<br />
\stopsubformulas<br />
Formula (\in[eq:1]) states <br />
the Pythagora's Theorem twice,<br />
once in (\in[eq:first]) and <br />
again in (\in[eq:second]).<br />
</texcode><br />
</td><td><br />
<context><br />
\setuppapersize[A5]<br />
\setuplayout[width=8cm]<br />
Examples:<br />
\startsubformulas[eq:1]<br />
\placeformula[eq:first]<br />
\startformula<br />
c^2 = a^2 + b^2<br />
\stopformula<br />
<br />
\placeformula[eq:second]<br />
\startformula<br />
c^2 = a^2 + b^2<br />
\stopformula<br />
\stopsubformulas<br />
Formula (\in[eq:1]) states the Pythagora's Theorem twice, once in (\in[eq:first]) and again in (\in[eq:second]).<br />
</context><br />
</td></tr></table><br />
<br />
<br />
== The Manual Method ==<br />
<br />
Sometimes, you need more fine grained control over numbering of subformulas. In that case one can make use of the optional agument of {{cmd|placeformula}} command and the related {{cmd|placesubformula}} commands which can be used to produce sub-formula numbering. For example:<br />
<br />
<table width="100%" cols="2"><tr valign="top"><td width="50%"><br />
<texcode><br />
Examples:<br />
\placeformula{a}<br />
\startformula<br />
c^2 = a^2 + b^2<br />
\stopformula<br />
<br />
\placesubformula{b}<br />
\startformula<br />
c^2 = a^2 + b^2<br />
\stopformula<br />
</texcode><br />
</td><td><br />
<context><br />
\setuppapersize[A5]<br />
\setuplayout[width=8cm]<br />
Examples:<br />
\placeformula{a}<br />
\startformula<br />
c^2 = a^2 + b^2<br />
\stopformula<br />
<br />
\placesubformula{b}<br />
\startformula<br />
c^2 = a^2 + b^2<br />
\stopformula<br />
</context><br />
</td></tr></table><br />
<br />
What's going on here is simpler than it might appear at first glance. Both {{cmd|placeformula}} and {{cmd|placesubformula}} produce equation numbers with the optional tag added at the end; the sole difference is that the former increments the equation number first, while the latter does not (and thus can be used for the second and subsequent formulas that use the same formula number but presumably have different tags).<br />
<br />
This is sufficient for cases where the standard ConTeXt equation numbers suffice, and where only one equation number is needed per formula. However, there are many cases where this is insufficient, and {{cmd|placeformula}} defines {{cmd|formulanumber}} and {{cmd|subformulanumber}} commands, which provide hooks to allow the use of ConTeXt-managed formula numbers with plain TeX equation numbering. These, when used within a formula, simply return the formula number in properly formatted form, as can be seen in this simple example with plain TeX's {{cmd|eqno}}. Note that the optional tag is inherited from {{cmd|placeformula}}.<br />
<br />
<table width="100%" cols="2"><tr valign="top"><td width="50%"><br />
<texcode><br />
More examples:<br />
\placeformula{c}<br />
\startformula<br />
\let\doplaceformulanumber\empty<br />
c^2 = a^2 + b^2 \eqno{\formulanumber}<br />
\stopformula<br />
</texcode><br />
</td><td><br />
<context><br />
\setuppapersize[A5]<br />
\setuplayout[width=8cm]<br />
More examples:<br />
\placeformula{c}<br />
\startformula<br />
\let\doplaceformulanumber\empty<br />
c^2 = a^2 + b^2 \eqno{\formulanumber}<br />
\stopformula<br />
</context><br />
</td></tr></table><br />
<br />
In order for this to work properly, we need to turn off ConTeXt's automatic formula number placement; thus the {{cmd|let}} command to empty {{cmd|doplaceformulanumber}}, which must be placed <em>after</em> the start of the formula. In many practical examples, however, this is not necessary; ConTeXt redefines {{cmd|displaylines}} and {{cmd|eqalignno}} to do this automatically.<br />
<br />
For more control over sub-formula numbering, {{cmd|formulanumber}} and {{cmd|subformulanumber}} have an optional argument parallel to that of {{cmd|placeformula}}, as demonstrated in this use of plain TeX's {{cmd|eqalignno}}, which places multiple equation numbers within one formula.<br />
<br />
<table width="100%" cols="2"><tr valign="top"><td width="50%"><br />
<texcode><br />
\placeformula<br />
\startformula<br />
\eqalignno{<br />
c^2 &= a^2 + b^2 &\formulanumber{a} \cr<br />
c &= \left(a^2 + b^2\right)^{\vfrac{1}{2}} &\subformulanumber{b}\cr<br />
a^2 + b^2 &= c^2 &\subformulanumber{c} \cr<br />
d^2 &= e^2 &\formulanumber\cr}<br />
\stopformula<br />
</texcode><br />
</td><td><br />
<context><br />
\setuppapersize[A5]<br />
\setuplayout[width=8cm]<br />
\placeformula<br />
\startformula<br />
\eqalignno{<br />
c^2 &= a^2 + b^2 &\formulanumber{a} \cr<br />
c &= \left(a^2 + b^2\right)^{\vfrac{1}{2}} &\subformulanumber{b}\cr<br />
a^2 + b^2 &= c^2 &\subformulanumber{c} \cr<br />
d^2 &= e^2 &\formulanumber\cr}<br />
\stopformula<br />
</context><br />
</td></tr></table><br />
<br />
Note that both {{cmd|formulanumber}} and {{cmd|subformulanumber}} can be used within the same formula, and the formula number is incremented as expected. Also, if an optional argument is specified in both {{cmd|placefigure}} and {{cmd|formulanumber}}, the latter takes precedence.<br />
<br />
<table width="100%" cols="2"><tr valign="top"><td width="50%"><br />
<texcode><br />
More examples for left-located equation number:<br />
\setupformulas[location=left]<br />
\placeformula{d}<br />
\startformula<br />
\let\doplaceformulanumber\empty<br />
c^2 = a^2 + b^2 \leqno{\formulanumber}<br />
\stopformula<br />
and<br />
\placeformula<br />
\startformula<br />
\leqalignno{c^2 &= a^2 + b^2 &\formulanumber{a} \cr<br />
a^2 + b^2 &= c^2 &\subformulanumber{b} \cr<br />
d^2 &= e^2 &\formulanumber\cr}<br />
\stopformula<br />
</texcode><br />
</td><td><br />
<context><br />
\setuppapersize[A5]<br />
\setuplayout[width=8cm]<br />
More examples for left-located equation no.:<br />
\setupformulas[location=left]<br />
\placeformula{d}<br />
\startformula<br />
\let\doplaceformulanumber\empty<br />
c^2 = a^2 + b^2 \leqno{\formulanumber}<br />
\stopformula<br />
and<br />
\placeformula<br />
\startformula<br />
\leqalignno{c^2 &= a^2 + b^2 &\formulanumber{a} \cr<br />
a^2 + b^2 &= c^2 &\subformulanumber{b} \cr<br />
d^2 &= e^2 &\formulanumber\cr}<br />
\stopformula<br />
</context><br />
</td></tr></table><br />
<br />
-- 23:46, 15 Aug 2005 (CEST) Prinse Wang<br />
<br />
=List of Formulas=<br />
<br />
You can have a list of the formulas contained in a document by using {{cmd|placenamedformula}} instead of {{cmd|placeformula}}. Only the formulas written with {{cmd|placenamedformula}} are not put in the list, so that you can control precisely the content of the list.<br />
<br />
{{cmd|placenamedformula}} takes as first parameter the name of the formula put in the list. The other {{cmd|placeformula}} features are still available. The list can be formatted like any other list.<br />
<br />
Example:<br />
<texcode><br />
\subsubject{List of Formulas}<br />
\placelist[formula][criterium=text,alternative=c]<br />
<br />
\subsubject{Formulas}<br />
\placenamedformula[one]{First listed Formula}<br />
\startformula a = 1 \stopformula \endgraf<br />
<br />
\placeformula<br />
\startformula a = 2 \stopformula \endgraf<br />
<br />
\placenamedformula{Second listed Formula}{b}<br />
\startformula a = 3 \stopformula \endgraf<br />
</texcode><br />
<br />
Gives:<br />
<br />
<context><br />
\setuppapersize[A5]<br />
\setuplayout[width=13cm]<br />
\subsubject{List of Formulas}<br />
\placelist[formula][criterium=text,alternative=c]<br />
<br />
\subsubject{Formulas}<br />
\placenamedformula[one]{First listed Formula}<br />
\startformula a = 1 \stopformula \endgraf<br />
<br />
\placeformula<br />
\startformula a = 2 \stopformula \endgraf<br />
<br />
\placenamedformula{Second listed Formula}{b}<br />
\startformula a = 3 \stopformula \endgraf<br />
</context><br />
<br />
== List of Formulas with MKIV/LMTX ==<br />
Since MKIV there are two types of formulas: numbered and named. Numbered formulas have the number as a reference and caption next to the formula and are listed only with the number and pagenumber in the list of formulas. Named formulas use the name as the caption instead of a number and are referenced with the name and pagenumber in the list of formulas.<br />
<br />
<context source=yes><br />
% equivalent to \placenamedformula[formula:mass]{Mass-energy equivalence}<br />
\startplaceformula[title={Mass-energy equivalence},reference=formula:mass] \startformula e=mc^2 \stopformula\stopplaceformula<br />
<br />
% equivalent to \placeformula[formula:mass] (note: placeformula is listed in the list of formulas if it has a reference)<br />
\startplaceformula[reference=formula:mass] \startformula e=mc^2 \stopformula \stopplaceformula<br />
<br />
% equivalent to \placeformula (with no entry in the list of formulas)<br />
\startplaceformula \startformula e=mc^2 \stopformula \stopplaceformula<br />
<br />
\placelist[formula][criterium=text,alternative=c]<br />
</context><br />
<br />
{{cmd|startplaceformula}} comes with the following key options: bookmark, list, reference, suffix, title.<br />
<br />
To name a numbered formula in the list of formulas, one can use the list option:<br />
<context source=yes><br />
% named formula<br />
\startplaceformula[reference=formula:mass,title={Mass-energy equivalence}] \startformula e=mc^2 \stopformula<br />
\stopplaceformula<br />
<br />
% numbered formula with list text, note without a reference option the formula is just a placeformula that is not listed in the list of formulas -- needs ConTeXt latest version 2021-03-20 or later<br />
\startplaceformula[reference=formula:mass,list={Mass-energy equivalence}] \startformula e=mc^2 \stopformula \stopplaceformula<br />
<br />
\placelist[formula][criterium=text,alternative=c]<br />
</context><br />
<br />
Note: The title option changes the formula to a named formula and will use that name in the list of formulas regardless of the list option.<br />
<br />
= Shaded background for part of a displayed equation =<br />
(see also [[Framed]])<br />
<br />
To highlight part of a formula, you can give it a gray background using {{cmd|mframed}}: the following is the code you can use in mkii (see below what one has to do in mkiv):<br />
<br />
<context source="yes"><br />
\setuppapersize[A5]<br />
\setupcolors[state=start]<br />
\def\graymath{\mframed[frame=off,<br />
background=color,<br />
backgroundcolor=gray,<br />
backgroundoffset=3pt]}<br />
<br />
\startformula<br />
\ln (1+x) =\, \graymath{x - {x^2\over2}} \,+ {x^3\over3}-\cdots.<br />
\stopformula<br />
</context><br />
<br />
In mkiv the code is slightly different: one may define {{cmd|graymath}} directly using {{cmd|definemathframed}}<br />
<br />
<texcode><br />
\setuppapersize[A5]<br />
\definemathframed[graymath]<br />
[<br />
frame=off,<br />
location=mathematics,<br />
background=color,<br />
backgroundcolor=lightgray,<br />
backgroundoffset=2pt<br />
]<br />
\starttext<br />
Since for $|x| < 1$ we have<br />
\startformula<br />
\log(1+x) = \graymath{x- \displaystyle{x^2\over2}} + {x^3 \over 3} + \cdots<br />
\stopformula<br />
we may write $\log(1+x) = x + O(x^2)$.<br />
\stoptext<br />
</texcode><br />
<br />
The result is shown below (possibly the framed part of the formula is not aligned correctly with the remainder of the formula because the mkiv engine on Context Garden is not up to date…).<br />
<br />
<context mode=mkiv><br />
\setuppapersize[A5]<br />
\definemathframed[graymath]<br />
[<br />
frame=off,<br />
location=mathematics,<br />
background=color,<br />
backgroundcolor=lightgray,<br />
backgroundoffset=2pt<br />
]<br />
<br />
Since for $|x| < 1$ we have<br />
\startformula<br />
\log(1+x) = \graymath{x- \displaystyle{x^2\over2}} + {x^3 \over 3} + \cdots<br />
\stopformula<br />
we may write $\log(1+x) = x + O(x^2)$.<br />
</context><br />
<br />
[[Category:Math]]</div>Mæstrohttps://wiki.contextgarden.net/index.php?title=Math/Display&diff=32498Math/Display2021-03-18T23:22:47Z<p>Mæstro: /* List of Formulas */ -- add new list option, see: https://mailman.ntg.nl/pipermail/ntg-context/2021/101611.html</p>
<hr />
<div>= Display Math =<br />
<br />
Display math is enclosed in a {{cmd|startformula}} / {{cmd|stopformula}} pair. Thus <br />
<br />
<table width="100%" cols="2"><tr valign="top"><td width="50%"><br />
<texcode><br />
The famous result (once more) is given by<br />
\startformula<br />
c^2 = a^2 + b^2.<br />
\stopformula<br />
</texcode><br />
</td><td><br />
This, when typeset, produces the following:<br />
<br />
<context><br />
\setuppapersize[A5]<br />
\setuplayout[width=8cm]<br />
The famous result (once more) is given by<br />
\startformula<br />
c^2 = a^2 + b^2.<br />
\stopformula<br />
</context><br />
</td></tr></table><br />
<br />
= Numbering Formulae =<br />
<br />
ConTeXt provides an easy way to number the display maths equations. Simply, put {{cmd|placeformula}} before {{cmd|startformula}} and you will get numbered equations. Thus,<br />
<table width="100%" cols="2"><tr valign="top"><td width="50%"><br />
<texcode><br />
The famous result (once more) is given by<br />
\placeformula<br />
\startformula<br />
c^2 = a^2 + b^2.<br />
\stopformula<br />
</texcode><br />
</td><td><br />
This, when typeset, produces the following:<br />
<br />
<context><br />
\setuppapersize[A5]<br />
\setuplayout[width=8cm]<br />
The famous result (once more) is given by<br />
\placeformula<br />
\startformula<br />
c^2 = a^2 + b^2.<br />
\stopformula<br />
</context><br />
</td></tr></table><br />
<br />
The {{cmd|placeformula}} command is optional, and produces the equation number; leaving it off produces an unnumbered equation.<br />
<br />
== Changing format of numbers ==<br />
You can use {{cmd|setupformulas}} to change the format of numbers. For example to get bold numbers inside square brackets use<br />
<br />
<table width="100%" cols="2" cellpadding="5"><tr valign="top"><td width="50%"><br />
<texcode><br />
\setupformulas[left={[},right={]},numberstyle=bold]<br />
</texcode><br />
</td><br />
<br />
<td>which gives<br />
<br />
<context><br />
\setuppapersize[A5]<br />
\setuplayout[width=8cm]<br />
\setupformulas[left={[},right={]},numberstyle=bold]<br />
The famous result (once more) is given by<br />
\placeformula<br />
\startformula<br />
c^2 = a^2 + b^2.<br />
\stopformula<br />
</context><br />
</td></tr></table><br />
<br />
To get equations also numbered by section, add the command:<br />
<texcode><br />
\setupnumber[formula][way=bysection] <br />
</texcode><br />
To the start of your document.<br />
<br />
To get alphabets instead of numbers, use<br />
<table width="100%" cols="2" cellpadding="5"><tr valign="top"><td width="50%"><br />
<texcode><br />
\setupformulas[numberconversion=Character]<br />
</texcode><br />
</td><br />
<td>which gives<br />
<context><br />
\setuppapersize[A5]<br />
\setuplayout[width=8cm]<br />
\setupformulas[numberconversion=Character]<br />
\placeformula<br />
\startformula<br />
c^2 = a^2 + b^2<br />
\stopformula<br />
</context><br />
</td></tr></table><br />
<br />
== Changing Formula alignment ==<br />
<br />
Normally a formula is centered, but in case you want to align it left or right, you can set up formulas to behave<br />
that way. Normally a formula will adapt its left indentation to the environment:<br />
<br />
<context><br />
\setuppapersize[A5]<br />
\setuppapersize[A5]<br />
\setuplayout[textwidth=8cm]<br />
This is a bit of text for purpose of example.\epar<br />
\startitemize<br />
\item This is some other example text.\epar<br />
\placeformula \startformula c^2 = a^2 + b^2 \stopformula<br />
\item This is yet other example text.\epar<br />
\stopitemize<br />
This is a bit more text for other purpose of example.\epar<br />
</context><br />
<br />
In the next examples we explicitly align formulas to the left ({{cmd|raggedleft}}), center and right ({{cmd|raggedright}}):<br />
<br />
<context source="yes" text="Or in print:"><br />
\setuppapersize[A5]<br />
\setuplayout[textwidth=8cm]<br />
\setupformulas[align=left]<br />
\startformula c^2 = a^2 + b^2 \stopformula<br />
\setupformulas[align=middle]<br />
\startformula c^2 = a^2 + b^2 \stopformula<br />
\setupformulas[align=right]<br />
\startformula c^2 = a^2 + b^2 \stopformula<br />
</context><br />
<br />
With formula numbers the code is:<br />
<br />
<context source="yes" text="And the formulas look like:"><br />
\setuppapersize[A5]<br />
\setuplayout[textwidth=8cm]<br />
\setupformulas[align=left]<br />
\placeformula \startformula c^2 = a^2 + b^2 \stopformula<br />
\setupformulas[align=middle]<br />
\placeformula \startformula c^2 = a^2 + b^2 \stopformula<br />
\setupformulas[align=right]<br />
\placeformula \startformula c^2 = a^2 + b^2 \stopformula<br />
</context><br />
<br />
When tracing is turned on ({{cmd|tracemathtrue}}) you can visualize the bounding box of the formula,<br />
<br />
<context><br />
\setuppapersize[A5]<br />
\setuplayout[textwidth=8cm]<br />
\tracemathtrue<br />
\setupformulas[align=left]<br />
\placeformula \startformula c^2 = a^2 + b^2 \stopformula<br />
\setupformulas[align=middle]<br />
\placeformula \startformula c^2 = a^2 + b^2 \stopformula<br />
\setupformulas[align=right]<br />
\placeformula \startformula c^2 = a^2 + b^2 \stopformula<br />
</context><br />
<br />
As you can see, the dimensions are the natural ones, but if needed you can force a normalized line:<br />
<br />
<context source="yes" text="This time we get a more spacy result. [Ed. Note: For this example equation, there appears to be no visible change.]"><br />
\setuppapersize[A5]<br />
\setuplayout[textwidth=8cm]<br />
\setupformulas[align=middle,strut=yes]<br />
\tracemathtrue<br />
\placeformula \startformula c^2 = a^2 + b^2 \stopformula<br />
</context><br />
<br />
We will now show a couple of more settings and combinations of settings. In centered formulas, the number takes no space<br />
<br />
<context source="yes"><br />
\setuppapersize[A5]<br />
\setuplayout[textwidth=8cm]<br />
\tracemathtrue<br />
\setupformulas[align=middle]<br />
\startformula c^2 = a^2 + b^2 \stopformula<br />
\placeformula \startformula c^2 = a^2 + b^2 \stopformula<br />
</context><br />
<br />
You can influence the placement of the whole box with the parameters <tt>leftmargin</tt> and <tt>rightmargin</tt>.<br />
<br />
<context source="yes"><br />
\setuppapersize[A5]<br />
\setuplayout[textwidth=8cm]<br />
Some example text, again, to show where the right and left margins of the text block are.<br />
\tracemathtrue<br />
\setupformulas[align=right,leftmargin=3em]<br />
\startformula c^2 = a^2 + b^2 \stopformula<br />
\placeformula \startformula c^2 = a^2 + b^2 \stopformula<br />
<br />
\setupformulas[align=left,rightmargin=1em]<br />
\startformula c^2 = a^2 + b^2 \stopformula<br />
\placeformula \startformula c^2 = a^2 + b^2 \stopformula<br />
</context><br />
<br />
You can also inherit the margin from the environment.<br />
<br />
<context source="yes"><br />
\setuppapersize[A5]<br />
\setuplayout[textwidth=8cm]<br />
Some example text, again, to show where the right and left margins of the text block are.<br />
\tracemathtrue<br />
\setupformulas[align=right,margin=standard]<br />
\startformula c^2 = a^2 + b^2 \stopformula<br />
\placeformula \startformula c^2 = a^2 + b^2 \stopformula<br />
</context><br />
<br />
The distance between the formula and the number is only applied when the formula is left or right aligned.<br />
<br />
<context source="yes"><br />
\setuppapersize[A5]<br />
\setuplayout[textwidth=8cm]<br />
\tracemathtrue<br />
\setupformulas[align=left,distance=2em]<br />
\startformula c^2 = a^2 + b^2 \stopformula<br />
\placeformula \startformula c^2 = a^2 + b^2 \stopformula<br />
</context><br />
<br />
= Referencing formulae =<br />
Equations can be referred to by simply adding a label to {{cmd|placeformula}} and using {{cmd|ref}} to create the reference:<br />
<br />
<table width="100%" cols="2" cellpadding="5"><tr valign="top"><td width="50%"><br />
<texcode><br />
The famous result (and again) is given by<br />
\placeformula[formulalabel]<br />
\startformula<br />
c^2 = a^2 + b^2.<br />
\stopformula<br />
And now we can refer to formula \ref[][formulalabel].<br />
</texcode><br />
</td><td><br />
This, when typeset, produces the following:<br />
<br />
<context><br />
\setuppapersize[A5]<br />
\setuplayout[width=8cm]<br />
The famous result (and again) is given by<br />
\placeformula[formulalabel]<br />
\startformula<br />
c^2 = a^2 + b^2.<br />
\stopformula<br />
<br />
And now we can refer to formula \ref[][formulalabel].<br />
</context><br />
</td></tr></table><br />
<br />
Note, that {{cmd|ref}} expects two arguments, therefore you need the brackets twice.<br />
<br />
By default, only the formula number appears as a reference. This can be changed by using {{cmd|definereferenceformat}}. For example, to create a command <code>\eqref</code> which shows the formula number in brackets, use<br />
<texcode><br />
\definereferenceformat[eqref][left=(,right=)]<br />
</texcode><br />
See [[References]] for more examples of {{cmd|definereferenceformat}}.<br />
<br />
=Sub-Formula Numbering=<br />
<br />
== Automatic Sub-Formula Numbering ==<br />
<br />
To use subformula numbering, you can use {{cmd|startsubformulas}}/{{cmd|stopsubformulas}}. For example<br />
<br />
<table width="100%" cols="2"><tr valign="top"><td width="50%"><br />
<texcode><br />
Examples:<br />
\startsubformulas[eq:1]<br />
\placeformula[eq:first]<br />
\startformula<br />
c^2 = a^2 + b^2<br />
\stopformula<br />
<br />
\placeformula[eq:second]<br />
\startformula<br />
c^2 = a^2 + b^2<br />
\stopformula<br />
\stopsubformulas<br />
Formula (\in[eq:1]) states <br />
the Pythagora's Theorem twice,<br />
once in (\in[eq:first]) and <br />
again in (\in[eq:second]).<br />
</texcode><br />
</td><td><br />
<context><br />
\setuppapersize[A5]<br />
\setuplayout[width=8cm]<br />
Examples:<br />
\startsubformulas[eq:1]<br />
\placeformula[eq:first]<br />
\startformula<br />
c^2 = a^2 + b^2<br />
\stopformula<br />
<br />
\placeformula[eq:second]<br />
\startformula<br />
c^2 = a^2 + b^2<br />
\stopformula<br />
\stopsubformulas<br />
Formula (\in[eq:1]) states the Pythagora's Theorem twice, once in (\in[eq:first]) and again in (\in[eq:second]).<br />
</context><br />
</td></tr></table><br />
<br />
<br />
== The Manual Method ==<br />
<br />
Sometimes, you need more fine grained control over numbering of subformulas. In that case one can make use of the optional agument of {{cmd|placeformula}} command and the related {{cmd|placesubformula}} commands which can be used to produce sub-formula numbering. For example:<br />
<br />
<table width="100%" cols="2"><tr valign="top"><td width="50%"><br />
<texcode><br />
Examples:<br />
\placeformula{a}<br />
\startformula<br />
c^2 = a^2 + b^2<br />
\stopformula<br />
<br />
\placesubformula{b}<br />
\startformula<br />
c^2 = a^2 + b^2<br />
\stopformula<br />
</texcode><br />
</td><td><br />
<context><br />
\setuppapersize[A5]<br />
\setuplayout[width=8cm]<br />
Examples:<br />
\placeformula{a}<br />
\startformula<br />
c^2 = a^2 + b^2<br />
\stopformula<br />
<br />
\placesubformula{b}<br />
\startformula<br />
c^2 = a^2 + b^2<br />
\stopformula<br />
</context><br />
</td></tr></table><br />
<br />
What's going on here is simpler than it might appear at first glance. Both {{cmd|placeformula}} and {{cmd|placesubformula}} produce equation numbers with the optional tag added at the end; the sole difference is that the former increments the equation number first, while the latter does not (and thus can be used for the second and subsequent formulas that use the same formula number but presumably have different tags).<br />
<br />
This is sufficient for cases where the standard ConTeXt equation numbers suffice, and where only one equation number is needed per formula. However, there are many cases where this is insufficient, and {{cmd|placeformula}} defines {{cmd|formulanumber}} and {{cmd|subformulanumber}} commands, which provide hooks to allow the use of ConTeXt-managed formula numbers with plain TeX equation numbering. These, when used within a formula, simply return the formula number in properly formatted form, as can be seen in this simple example with plain TeX's {{cmd|eqno}}. Note that the optional tag is inherited from {{cmd|placeformula}}.<br />
<br />
<table width="100%" cols="2"><tr valign="top"><td width="50%"><br />
<texcode><br />
More examples:<br />
\placeformula{c}<br />
\startformula<br />
\let\doplaceformulanumber\empty<br />
c^2 = a^2 + b^2 \eqno{\formulanumber}<br />
\stopformula<br />
</texcode><br />
</td><td><br />
<context><br />
\setuppapersize[A5]<br />
\setuplayout[width=8cm]<br />
More examples:<br />
\placeformula{c}<br />
\startformula<br />
\let\doplaceformulanumber\empty<br />
c^2 = a^2 + b^2 \eqno{\formulanumber}<br />
\stopformula<br />
</context><br />
</td></tr></table><br />
<br />
In order for this to work properly, we need to turn off ConTeXt's automatic formula number placement; thus the {{cmd|let}} command to empty {{cmd|doplaceformulanumber}}, which must be placed <em>after</em> the start of the formula. In many practical examples, however, this is not necessary; ConTeXt redefines {{cmd|displaylines}} and {{cmd|eqalignno}} to do this automatically.<br />
<br />
For more control over sub-formula numbering, {{cmd|formulanumber}} and {{cmd|subformulanumber}} have an optional argument parallel to that of {{cmd|placeformula}}, as demonstrated in this use of plain TeX's {{cmd|eqalignno}}, which places multiple equation numbers within one formula.<br />
<br />
<table width="100%" cols="2"><tr valign="top"><td width="50%"><br />
<texcode><br />
\placeformula<br />
\startformula<br />
\eqalignno{<br />
c^2 &= a^2 + b^2 &\formulanumber{a} \cr<br />
c &= \left(a^2 + b^2\right)^{\vfrac{1}{2}} &\subformulanumber{b}\cr<br />
a^2 + b^2 &= c^2 &\subformulanumber{c} \cr<br />
d^2 &= e^2 &\formulanumber\cr}<br />
\stopformula<br />
</texcode><br />
</td><td><br />
<context><br />
\setuppapersize[A5]<br />
\setuplayout[width=8cm]<br />
\placeformula<br />
\startformula<br />
\eqalignno{<br />
c^2 &= a^2 + b^2 &\formulanumber{a} \cr<br />
c &= \left(a^2 + b^2\right)^{\vfrac{1}{2}} &\subformulanumber{b}\cr<br />
a^2 + b^2 &= c^2 &\subformulanumber{c} \cr<br />
d^2 &= e^2 &\formulanumber\cr}<br />
\stopformula<br />
</context><br />
</td></tr></table><br />
<br />
Note that both {{cmd|formulanumber}} and {{cmd|subformulanumber}} can be used within the same formula, and the formula number is incremented as expected. Also, if an optional argument is specified in both {{cmd|placefigure}} and {{cmd|formulanumber}}, the latter takes precedence.<br />
<br />
<table width="100%" cols="2"><tr valign="top"><td width="50%"><br />
<texcode><br />
More examples for left-located equation number:<br />
\setupformulas[location=left]<br />
\placeformula{d}<br />
\startformula<br />
\let\doplaceformulanumber\empty<br />
c^2 = a^2 + b^2 \leqno{\formulanumber}<br />
\stopformula<br />
and<br />
\placeformula<br />
\startformula<br />
\leqalignno{c^2 &= a^2 + b^2 &\formulanumber{a} \cr<br />
a^2 + b^2 &= c^2 &\subformulanumber{b} \cr<br />
d^2 &= e^2 &\formulanumber\cr}<br />
\stopformula<br />
</texcode><br />
</td><td><br />
<context><br />
\setuppapersize[A5]<br />
\setuplayout[width=8cm]<br />
More examples for left-located equation no.:<br />
\setupformulas[location=left]<br />
\placeformula{d}<br />
\startformula<br />
\let\doplaceformulanumber\empty<br />
c^2 = a^2 + b^2 \leqno{\formulanumber}<br />
\stopformula<br />
and<br />
\placeformula<br />
\startformula<br />
\leqalignno{c^2 &= a^2 + b^2 &\formulanumber{a} \cr<br />
a^2 + b^2 &= c^2 &\subformulanumber{b} \cr<br />
d^2 &= e^2 &\formulanumber\cr}<br />
\stopformula<br />
</context><br />
</td></tr></table><br />
<br />
-- 23:46, 15 Aug 2005 (CEST) Prinse Wang<br />
<br />
=List of Formulas=<br />
<br />
You can have a list of the formulas contained in a document by using {{cmd|placenamedformula}} instead of {{cmd|placeformula}}. Only the formulas written with {{cmd|placenamedformula}} are not put in the list, so that you can control precisely the content of the list.<br />
<br />
{{cmd|placenamedformula}} takes as first parameter the name of the formula put in the list. The other {{cmd|placeformula}} features are still available. The list can be formatted like any other list.<br />
<br />
Example:<br />
<texcode><br />
\subsubject{List of Formulas}<br />
\placelist[formula][criterium=text,alternative=c]<br />
<br />
\subsubject{Formulas}<br />
\placenamedformula[one]{First listed Formula}<br />
\startformula a = 1 \stopformula \endgraf<br />
<br />
\placeformula<br />
\startformula a = 2 \stopformula \endgraf<br />
<br />
\placenamedformula{Second listed Formula}{b}<br />
\startformula a = 3 \stopformula \endgraf<br />
</texcode><br />
<br />
Gives:<br />
<br />
<context><br />
\setuppapersize[A5]<br />
\setuplayout[width=13cm]<br />
\subsubject{List of Formulas}<br />
\placelist[formula][criterium=text,alternative=c]<br />
<br />
\subsubject{Formulas}<br />
\placenamedformula[one]{First listed Formula}<br />
\startformula a = 1 \stopformula \endgraf<br />
<br />
\placeformula<br />
\startformula a = 2 \stopformula \endgraf<br />
<br />
\placenamedformula{Second listed Formula}{b}<br />
\startformula a = 3 \stopformula \endgraf<br />
</context><br />
<br />
== List of Formulas with MKIV/LMTX ==<br />
Since MKIV there are two types of formulas: numbered and named. Numbered formulas have the number as a reference and caption next to the formula and are listed only with the number and pagenumber in the list of formulas. Named formulas use the name as the caption instead of a number and are referenced with the name and pagenumber in the list of formulas.<br />
<br />
<context source=yes><br />
% equivalent to \placenamedformula[formula:mass]{Mass-energy equivalence}<br />
\startplaceformula[title={Mass-energy equivalence},reference=formula:mass] \startformula e=mc^2 \stopformula\stopplaceformula<br />
<br />
% equivalent to \placeformula[formula:mass] (note: placeformula is listed in the list of formulas if it has a reference)<br />
\startplaceformula[reference=formula:mass] \startformula e=mc^2 \stopformula \stopplaceformula<br />
<br />
% equivalent to \placeformula (with no entry in the list of formulas)<br />
\startplaceformula \startformula e=mc^2 \stopformula \stopplaceformula<br />
<br />
\placelist[formula][criterium=text,alternative=c]<br />
</context><br />
<br />
{{cmd|startplaceformula}} comes with the following key options: bookmark, list, reference, suffix, title.<br />
<br />
To name a numbered formula in the list of formulas, one can use the list option:<br />
<context source=yes><br />
% named formula<br />
\startplaceformula[reference=formula:mass,title={Mass-energy equivalence}] \startformula e=mc^2 \stopformula<br />
\stopplaceformula<br />
<br />
% numbered formula with list text, note without a reference option the formula is just a placeformula that is not listed in the list of formulas -- needs ConTeXt latest after 2021-03-17<br />
\startplaceformula[reference=formula:mass,list={Mass-energy equivalence}] \startformula e=mc^2 \stopformula \stopplaceformula<br />
<br />
\placelist[formula][criterium=text,alternative=c]<br />
</context><br />
<br />
Note: The title option changes the formula to a named formula and will use that name in the list of formulas regardless of the list option.<br />
<br />
= Shaded background for part of a displayed equation =<br />
(see also [[Framed]])<br />
<br />
To highlight part of a formula, you can give it a gray background using {{cmd|mframed}}: the following is the code you can use in mkii (see below what one has to do in mkiv):<br />
<br />
<context source="yes"><br />
\setuppapersize[A5]<br />
\setupcolors[state=start]<br />
\def\graymath{\mframed[frame=off,<br />
background=color,<br />
backgroundcolor=gray,<br />
backgroundoffset=3pt]}<br />
<br />
\startformula<br />
\ln (1+x) =\, \graymath{x - {x^2\over2}} \,+ {x^3\over3}-\cdots.<br />
\stopformula<br />
</context><br />
<br />
In mkiv the code is slightly different: one may define {{cmd|graymath}} directly using {{cmd|definemathframed}}<br />
<br />
<texcode><br />
\setuppapersize[A5]<br />
\definemathframed[graymath]<br />
[<br />
frame=off,<br />
location=mathematics,<br />
background=color,<br />
backgroundcolor=lightgray,<br />
backgroundoffset=2pt<br />
]<br />
\starttext<br />
Since for $|x| < 1$ we have<br />
\startformula<br />
\log(1+x) = \graymath{x- \displaystyle{x^2\over2}} + {x^3 \over 3} + \cdots<br />
\stopformula<br />
we may write $\log(1+x) = x + O(x^2)$.<br />
\stoptext<br />
</texcode><br />
<br />
The result is shown below (possibly the framed part of the formula is not aligned correctly with the remainder of the formula because the mkiv engine on Context Garden is not up to date…).<br />
<br />
<context mode=mkiv><br />
\setuppapersize[A5]<br />
\definemathframed[graymath]<br />
[<br />
frame=off,<br />
location=mathematics,<br />
background=color,<br />
backgroundcolor=lightgray,<br />
backgroundoffset=2pt<br />
]<br />
<br />
Since for $|x| < 1$ we have<br />
\startformula<br />
\log(1+x) = \graymath{x- \displaystyle{x^2\over2}} + {x^3 \over 3} + \cdots<br />
\stopformula<br />
we may write $\log(1+x) = x + O(x^2)$.<br />
</context><br />
<br />
[[Category:Math]]</div>Mæstrohttps://wiki.contextgarden.net/index.php?title=Command/defineresetset&diff=32339Command/defineresetset2021-01-12T03:29:32Z<p>Mæstro: typo</p>
<hr />
<div><cd:commandgroup name="defineresetset" xmlns:cd="http://wiki.contextgarden.net/commanddoc/20200807"><br />
<cd:shortdesc><!-- a short command summary goes here --><br />
The command <tt>\defineresetset</tt> is used to configure the continuous numbering of sections of a lower level regardless of higher levels. E.g. if you use parts but want to have all chapters numbered continously.<br />
</cd:shortdesc><br />
<cd:variants><br />
<cd:command category="counter" file="strc-ini.mkvi" interfacedate="2020-07-14T09:24" interfacefile="i-counter.xml" level="style" name="defineresetset" variantnumber="1"><br />
<cd:arguments><br />
<cd:keywords ordinal="1"><br />
<cd:keywordsdoc>name of the reset set (default or your own)</cd:keywordsdoc><br />
<cd:constant type="cd:name"></cd:constant><br />
<cd:constant method="range" prefix="cd:sectionblock" type="cd:name"></cd:constant><br />
</cd:keywords><br />
<cd:keywords list="yes" ordinal="2"><br />
<cd:keywordsdoc>List of 1 or 0 for every section level, "0,1" means "part no, chapter yes" etc. (second example). If empty, affect just the section in whose setup the reset set is used (first example).</cd:keywordsdoc><br />
<cd:constant type="cd:number"></cd:constant><br />
</cd:keywords><br />
<cd:keywords optional="yes" ordinal="3"><br />
<cd:keywordsdoc>1 = reset, 0 = don’t reset (refering to the previous list or the current level)</cd:keywordsdoc><br />
<cd:constant type="cd:number"></cd:constant><br />
</cd:keywords><br />
</cd:arguments><br />
</cd:command><br />
</cd:variants><br />
<cd:description><!-- the long description of the command goes here --><br />
<tt>\definestructureresetset</tt> is an alias of this command for backward compatibility.</cd:description><br />
<cd:examples><cd:example title="define for one section level"><texcode><br />
\defineresetset[mybook][][0]<br />
\setuphead[chapter][sectionresetset=mybook]<br />
</texcode></cd:example><cd:example title="define generally"><texcode><br />
\defineresetset[default][1,1,0][1] %% reset part, chapter, but not section<br />
\setuphead[sectionresetset=default]<br />
</texcode></cd:example></cd:examples><br />
<cd:notes></cd:notes><br />
<cd:seealso><br />
<cd:source file="strc-ini.mkvi" originator="system"></cd:source><br />
<cd:wikipage originator="system" page="Category:Counter"></cd:wikipage><br />
<cd:wikipage page="Titles"></cd:wikipage><br />
<cd:commandref name="setuphead"></cd:commandref></cd:seealso><br />
</cd:commandgroup></div>Mæstrohttps://wiki.contextgarden.net/index.php?title=Gantt_charts&diff=32011Gantt charts2020-11-08T00:08:06Z<p>Mæstro: /* Minimal example */</p>
<hr />
<div>[http://modules.contextgarden.net/gantt Gantt] is a (third party) ConTeXt module for drawing Gantt charts via MetaPost or PGF/TikZ.<br />
<br />
== Description ==<br />
<br />
To switch between the two drawing engines (MetaPost and TikZ) use the style option.<br />
<texcode>\usemodule[gantt][alternative=mp]</texcode><br />
<texcode>\usemodule[gantt][alternative=tikz]</texcode><br />
<br />
The default engine is MetaPost.<br />
<br />
<br />
Here is a short description of the environments and commands:<br />
<br />
=== Gantt ===<br />
The '''gantt''' environment draws the canvas of a gantt figure.<br />
<texcode>\startgantt[...]{no of Tasks to plot}{no of time slots}</texcode><br />
The optional argument [...] can be filled in a key=value syntax, using one or more of the following keys:<br />
<br />
* ''factor'' - MetaPost scale factor (default: 1)<br />
* ''xunitlength'' - length of one time slot (default: 1cm)<br />
* ''style'' - fontsize of labels (default: \tf)<br />
* ''titlestyle'' - fontsize of title section (default: \tfx)<br />
* ''drawledgerline'' - switch to enable/disable the drawing of horizontal ledger lines (default value: false)<br />
<br />
=== Ganttitle ===<br />
This is the environment for drawing the title section.<br />
<texcode>\startganttitle (...) \stopganttitle</texcode><br />
<br />
=== Titleelement ===<br />
This draws one element of the title.<br />
<texcode>\titleelement{label}{length}</texcode><br />
<br />
=== Numtitle ===<br />
This draws a numbered sequence of title elements.<br />
<texcode>\numtitle{start number}{increment}{end number}{length of each title element}</texcode><br />
<br />
=== Ganttbar ===<br />
This draws a single, unconnected bar for representing a task.<br />
<texcode>\ganttbar[pattern=value,color=value]{label}{start}{length}</texcode><br />
The optional comma separated arguments are:<br />
<br />
* ''<pattern>'' - TikZ pattern (e.g. north east lines (default), north west lines, crosshatch, crosshatch dots, grid, …) or see [[#Regressions | Regressions]] section for MetaPost<br />
* ''<color>'' - a color of the pattern (e.g. black (default), red, green blue gray, dark gray)<br />
<br />
=== Ganttcon ===<br />
This draws an arrow between the bars specified by coordinates.<br />
<texcode>\ganttcon{startx}{starty}{endx}{endy}</texcode><br />
<br />
=== Ganttbarcon ===<br />
This draws a single bar and connects the bar with the previous bar for consecutive tasks.<br />
<texcode>\ganttbarcon[pattern=value,color=value]{label}{start}{length}</texcode><br />
The optional pattern argument are the same as for \ganttbar.<br />
<br />
=== Ganttgroup ===<br />
This draws a bar to group tasks.<br />
<texcode>\ganttgroup{label}{start}{length}</texcode><br />
<br />
=== Ganttmilestone ===<br />
This draws a milestone using a diamond.<br />
<texcode>\ganttmilestone[color=value]{label}{start}</texcode><br />
The optional color argument argument is:<br />
<br />
* ''<color>'' - a color of the pattern (e.g. black (default), red, green blue gray, dark gray)<br />
<br />
=== Ganttmilestonecon ===<br />
This draws a milestone using a diamond and connects the milestone with the previous bar or milestone.<br />
<texcode>\ganttmilestonecon[color=value]{label}{start}</texcode><br />
The optional color argument argument is:<br />
<br />
* ''<color>'' - a color of the pattern (e.g. black (default), red, green blue gray, dark gray)<br />
<br />
== Examples ==<br />
<br />
=== Minimal example ===<br />
<texcode><br />
\usemodule[gantt]<br />
\setuppagenumbering[location=]<br />
<br />
\starttext<br />
\startgantt{7}{12}<br />
\startganttitle<br />
\numtitle{1}{1}{12}{1}<br />
\stopganttitle<br />
\ganttbar{a task}{0}{2}<br />
\ganttbarcon{a consecutive task}{2}{4}<br />
\ganttbarcon{another consecutive task}{8}{2}<br />
\ganttbar{another task}{2}{2}<br />
\ganttbar{another task}{4}{2}<br />
\ganttbar{another task}{4}{2}<br />
\ganttcon{4}{4}{4}{6}<br />
\stopgantt<br />
\stoptext<br />
</texcode><br />
<br />
[[File:gantt-minimal.jpg]]<br />
<br />
=== Similar example using names of calendar months ===<br />
<texcode><br />
\usemodule[gantt]<br />
\setuppagenumbering[location=]<br />
<br />
\starttext<br />
\startgantt{3}{12}<br />
\startganttitle<br />
\titleelement{Jan}{1}<br />
\titleelement{Feb}{1}<br />
\titleelement{Mar}{1}<br />
\titleelement{Apr}{1}<br />
\titleelement{May}{1}<br />
\titleelement{Jun}{1}<br />
\titleelement{Jul}{1}<br />
\titleelement{Aug}{1}<br />
\titleelement{Sep}{1}<br />
\titleelement{Oct}{1}<br />
\titleelement{Nov}{1}<br />
\titleelement{Dec}{1}<br />
\stopganttitle<br />
\ganttbar{Task 1}{0}{2}<br />
\ganttbarcon{a consecutive task}{2}{4}<br />
\stopgantt<br />
\stoptext<br />
</texcode><br />
<br />
[[File:gantt-calendar.jpg]]<br />
<br />
=== Multiple titles with different length ===<br />
<texcode><br />
\usemodule[gantt]<br />
\setuppagenumbering[location=]<br />
<br />
\starttext<br />
\startgantt{4}{12}<br />
\startganttitle<br />
\numtitle{2010}{1}{2012}{4}<br />
\stopganttitle<br />
\startganttitle<br />
\numtitle{1}{1}{4}{1}<br />
\numtitle{1}{1}{4}{1}<br />
\numtitle{1}{1}{4}{1}<br />
\stopganttitle<br />
\ganttbar{Task 1}{0}{2}<br />
\ganttbarcon{a consecutive task}{2}{4}<br />
\stopgantt<br />
\stoptext<br />
</texcode><br />
<br />
[[File:gantt-titles.jpg]]<br />
<br />
=== Milestone example ===<br />
<texcode><br />
\usemodule[gantt]<br />
\setuppagenumbering[location=]<br />
<br />
\starttext<br />
\startgantt{10}{12}<br />
\startganttitle<br />
\numtitle{1}{1}{12}{1}<br />
\stopganttitle<br />
\ganttbar{a task}{0}{2}<br />
\ganttbarcon{a consecutive task}{2}{4}<br />
\ganttbarcon{another consecutive task}{8}{2}<br />
\ganttmilestone[color=cyan]{Milestone with color!}{4}<br />
\ganttbar{another task}{2}{2}<br />
\ganttbar[color=cyan]{another coloured task}{4}{4}<br />
\ganttbar{another task}{4}{2}<br />
\ganttcon{4}{5}{4}{7}<br />
\ganttmilestonecon{A connected Milestone}{7}<br />
\ganttbarcon{another consecutive task}{8}{2}<br />
\stopgantt<br />
\stoptext<br />
</texcode><br />
<br />
[[File:gantt-milestone.jpg]]<br />
<br />
=== More complex example (using groups and optional arguments) ===<br />
<texcode><br />
\usemodule[gantt]<br />
\setuppapersize[A4,landscape][A4,landscape]<br />
\setuplayout[scale=0.8]<br />
\setuppagenumbering[location=]<br />
<br />
\starttext<br />
\startgantt[xunitlength=0.5cm,style=\tfx,titlestyle=\tfx,drawledgerline=true]{10}{48}<br />
\startganttitle<br />
\titleelement{2009}{7}<br />
\numtitle{2010}{1}{2012}{12} <br />
\titleelement{2013}{5}<br />
\stopganttitle<br />
\startganttitle<br />
\numtitle{6}{1}{12}{1} <br />
\numtitle{1}{1}{12}{1} <br />
\numtitle{1}{1}{12}{1} <br />
\numtitle{1}{1}{12}{1} <br />
\numtitle{1}{1}{5}{1} <br />
\stopganttitle<br />
\ganttbar{task 1}{2}{17} <br />
\ganttgroup{a group of tasks}{6}{18}<br />
\ganttbar{task 2}{5}{10} <br />
\ganttbar[color=blue]{task 3}{15}{3} <br />
\ganttbar{task 4}{20}{3} <br />
\ganttcon{15}{4}{20}{6}<br />
\ganttbar{task 5}{15}{5} <br />
\ganttbarcon[color=red]{task 6}{20}{5}<br />
\ganttbarcon{task 7}{30}{5}<br />
\stopgantt<br />
\stoptext<br />
</texcode><br />
<br />
[[File:gantt-complex.jpg]]<br />
<br />
== Regressions ==<br />
<br />
There are no default color patterns in MetaPost. This needs to be implemented separately in order to have a pattern option in this module.<br />
<br />
As a temporary solution the [http://www.ctan.org/tex-archive/graphics/metapost/contrib/macros/hatching/ hatching] MetaPost package is used.<br />
<br />
== See also ==<br />
<br />
* [http://www.ctan.org/pkg/pgfgantt Draw Gantt charts with TikZ]<br />
* [http://www.martin-kumm.de/tex_gantt_package.php A LaTeX package for drawing gantt plots using pgf/tikz]<br />
* [http://www.kese.hu/p/tikz.html Gantt Chart with TikZ]<br />
<br />
[[Category:Modules]]<br />
[[Category:Graphics]]<br />
[[Category:Metapost]]<br />
[[Category:Sciences]]</div>Mæstrohttps://wiki.contextgarden.net/index.php?title=File:gantt-minimal.jpg&diff=32010File:gantt-minimal.jpg2020-11-08T00:07:37Z<p>Mæstro: minimal example</p>
<hr />
<div>== Summary ==<br />
minimal example</div>Mæstrohttps://wiki.contextgarden.net/index.php?title=Gantt_charts&diff=32009Gantt charts2020-11-08T00:05:37Z<p>Mæstro: /* Similar example using names of calendar months */</p>
<hr />
<div>[http://modules.contextgarden.net/gantt Gantt] is a (third party) ConTeXt module for drawing Gantt charts via MetaPost or PGF/TikZ.<br />
<br />
== Description ==<br />
<br />
To switch between the two drawing engines (MetaPost and TikZ) use the style option.<br />
<texcode>\usemodule[gantt][alternative=mp]</texcode><br />
<texcode>\usemodule[gantt][alternative=tikz]</texcode><br />
<br />
The default engine is MetaPost.<br />
<br />
<br />
Here is a short description of the environments and commands:<br />
<br />
=== Gantt ===<br />
The '''gantt''' environment draws the canvas of a gantt figure.<br />
<texcode>\startgantt[...]{no of Tasks to plot}{no of time slots}</texcode><br />
The optional argument [...] can be filled in a key=value syntax, using one or more of the following keys:<br />
<br />
* ''factor'' - MetaPost scale factor (default: 1)<br />
* ''xunitlength'' - length of one time slot (default: 1cm)<br />
* ''style'' - fontsize of labels (default: \tf)<br />
* ''titlestyle'' - fontsize of title section (default: \tfx)<br />
* ''drawledgerline'' - switch to enable/disable the drawing of horizontal ledger lines (default value: false)<br />
<br />
=== Ganttitle ===<br />
This is the environment for drawing the title section.<br />
<texcode>\startganttitle (...) \stopganttitle</texcode><br />
<br />
=== Titleelement ===<br />
This draws one element of the title.<br />
<texcode>\titleelement{label}{length}</texcode><br />
<br />
=== Numtitle ===<br />
This draws a numbered sequence of title elements.<br />
<texcode>\numtitle{start number}{increment}{end number}{length of each title element}</texcode><br />
<br />
=== Ganttbar ===<br />
This draws a single, unconnected bar for representing a task.<br />
<texcode>\ganttbar[pattern=value,color=value]{label}{start}{length}</texcode><br />
The optional comma separated arguments are:<br />
<br />
* ''<pattern>'' - TikZ pattern (e.g. north east lines (default), north west lines, crosshatch, crosshatch dots, grid, …) or see [[#Regressions | Regressions]] section for MetaPost<br />
* ''<color>'' - a color of the pattern (e.g. black (default), red, green blue gray, dark gray)<br />
<br />
=== Ganttcon ===<br />
This draws an arrow between the bars specified by coordinates.<br />
<texcode>\ganttcon{startx}{starty}{endx}{endy}</texcode><br />
<br />
=== Ganttbarcon ===<br />
This draws a single bar and connects the bar with the previous bar for consecutive tasks.<br />
<texcode>\ganttbarcon[pattern=value,color=value]{label}{start}{length}</texcode><br />
The optional pattern argument are the same as for \ganttbar.<br />
<br />
=== Ganttgroup ===<br />
This draws a bar to group tasks.<br />
<texcode>\ganttgroup{label}{start}{length}</texcode><br />
<br />
=== Ganttmilestone ===<br />
This draws a milestone using a diamond.<br />
<texcode>\ganttmilestone[color=value]{label}{start}</texcode><br />
The optional color argument argument is:<br />
<br />
* ''<color>'' - a color of the pattern (e.g. black (default), red, green blue gray, dark gray)<br />
<br />
=== Ganttmilestonecon ===<br />
This draws a milestone using a diamond and connects the milestone with the previous bar or milestone.<br />
<texcode>\ganttmilestonecon[color=value]{label}{start}</texcode><br />
The optional color argument argument is:<br />
<br />
* ''<color>'' - a color of the pattern (e.g. black (default), red, green blue gray, dark gray)<br />
<br />
== Examples ==<br />
<br />
=== Minimal example ===<br />
<texcode><br />
\usemodule[gantt]<br />
\setuppagenumbering[location=]<br />
<br />
\starttext<br />
\startgantt{7}{12}<br />
\startganttitle<br />
\numtitle{1}{1}{12}{1}<br />
\stopganttitle<br />
\ganttbar{a task}{0}{2}<br />
\ganttbarcon{a consecutive task}{2}{4}<br />
\ganttbarcon{another consecutive task}{8}{2}<br />
\ganttbar{another task}{2}{2}<br />
\ganttbar{another task}{4}{2}<br />
\ganttbar{another task}{4}{2}<br />
\ganttcon{4}{4}{4}{6}<br />
\stopgantt<br />
\stoptext<br />
</texcode><br />
<br />
<br />
=== Similar example using names of calendar months ===<br />
<texcode><br />
\usemodule[gantt]<br />
\setuppagenumbering[location=]<br />
<br />
\starttext<br />
\startgantt{3}{12}<br />
\startganttitle<br />
\titleelement{Jan}{1}<br />
\titleelement{Feb}{1}<br />
\titleelement{Mar}{1}<br />
\titleelement{Apr}{1}<br />
\titleelement{May}{1}<br />
\titleelement{Jun}{1}<br />
\titleelement{Jul}{1}<br />
\titleelement{Aug}{1}<br />
\titleelement{Sep}{1}<br />
\titleelement{Oct}{1}<br />
\titleelement{Nov}{1}<br />
\titleelement{Dec}{1}<br />
\stopganttitle<br />
\ganttbar{Task 1}{0}{2}<br />
\ganttbarcon{a consecutive task}{2}{4}<br />
\stopgantt<br />
\stoptext<br />
</texcode><br />
<br />
[[File:gantt-calendar.jpg]]<br />
<br />
=== Multiple titles with different length ===<br />
<texcode><br />
\usemodule[gantt]<br />
\setuppagenumbering[location=]<br />
<br />
\starttext<br />
\startgantt{4}{12}<br />
\startganttitle<br />
\numtitle{2010}{1}{2012}{4}<br />
\stopganttitle<br />
\startganttitle<br />
\numtitle{1}{1}{4}{1}<br />
\numtitle{1}{1}{4}{1}<br />
\numtitle{1}{1}{4}{1}<br />
\stopganttitle<br />
\ganttbar{Task 1}{0}{2}<br />
\ganttbarcon{a consecutive task}{2}{4}<br />
\stopgantt<br />
\stoptext<br />
</texcode><br />
<br />
[[File:gantt-titles.jpg]]<br />
<br />
=== Milestone example ===<br />
<texcode><br />
\usemodule[gantt]<br />
\setuppagenumbering[location=]<br />
<br />
\starttext<br />
\startgantt{10}{12}<br />
\startganttitle<br />
\numtitle{1}{1}{12}{1}<br />
\stopganttitle<br />
\ganttbar{a task}{0}{2}<br />
\ganttbarcon{a consecutive task}{2}{4}<br />
\ganttbarcon{another consecutive task}{8}{2}<br />
\ganttmilestone[color=cyan]{Milestone with color!}{4}<br />
\ganttbar{another task}{2}{2}<br />
\ganttbar[color=cyan]{another coloured task}{4}{4}<br />
\ganttbar{another task}{4}{2}<br />
\ganttcon{4}{5}{4}{7}<br />
\ganttmilestonecon{A connected Milestone}{7}<br />
\ganttbarcon{another consecutive task}{8}{2}<br />
\stopgantt<br />
\stoptext<br />
</texcode><br />
<br />
[[File:gantt-milestone.jpg]]<br />
<br />
=== More complex example (using groups and optional arguments) ===<br />
<texcode><br />
\usemodule[gantt]<br />
\setuppapersize[A4,landscape][A4,landscape]<br />
\setuplayout[scale=0.8]<br />
\setuppagenumbering[location=]<br />
<br />
\starttext<br />
\startgantt[xunitlength=0.5cm,style=\tfx,titlestyle=\tfx,drawledgerline=true]{10}{48}<br />
\startganttitle<br />
\titleelement{2009}{7}<br />
\numtitle{2010}{1}{2012}{12} <br />
\titleelement{2013}{5}<br />
\stopganttitle<br />
\startganttitle<br />
\numtitle{6}{1}{12}{1} <br />
\numtitle{1}{1}{12}{1} <br />
\numtitle{1}{1}{12}{1} <br />
\numtitle{1}{1}{12}{1} <br />
\numtitle{1}{1}{5}{1} <br />
\stopganttitle<br />
\ganttbar{task 1}{2}{17} <br />
\ganttgroup{a group of tasks}{6}{18}<br />
\ganttbar{task 2}{5}{10} <br />
\ganttbar[color=blue]{task 3}{15}{3} <br />
\ganttbar{task 4}{20}{3} <br />
\ganttcon{15}{4}{20}{6}<br />
\ganttbar{task 5}{15}{5} <br />
\ganttbarcon[color=red]{task 6}{20}{5}<br />
\ganttbarcon{task 7}{30}{5}<br />
\stopgantt<br />
\stoptext<br />
</texcode><br />
<br />
[[File:gantt-complex.jpg]]<br />
<br />
== Regressions ==<br />
<br />
There are no default color patterns in MetaPost. This needs to be implemented separately in order to have a pattern option in this module.<br />
<br />
As a temporary solution the [http://www.ctan.org/tex-archive/graphics/metapost/contrib/macros/hatching/ hatching] MetaPost package is used.<br />
<br />
== See also ==<br />
<br />
* [http://www.ctan.org/pkg/pgfgantt Draw Gantt charts with TikZ]<br />
* [http://www.martin-kumm.de/tex_gantt_package.php A LaTeX package for drawing gantt plots using pgf/tikz]<br />
* [http://www.kese.hu/p/tikz.html Gantt Chart with TikZ]<br />
<br />
[[Category:Modules]]<br />
[[Category:Graphics]]<br />
[[Category:Metapost]]<br />
[[Category:Sciences]]</div>Mæstrohttps://wiki.contextgarden.net/index.php?title=File:gantt-calendar.jpg&diff=32008File:gantt-calendar.jpg2020-11-08T00:05:09Z<p>Mæstro: calendar months</p>
<hr />
<div>== Summary ==<br />
calendar months</div>Mæstrohttps://wiki.contextgarden.net/index.php?title=Gantt_charts&diff=32007Gantt charts2020-11-08T00:01:25Z<p>Mæstro: /* Multiple titles with different length */</p>
<hr />
<div>[http://modules.contextgarden.net/gantt Gantt] is a (third party) ConTeXt module for drawing Gantt charts via MetaPost or PGF/TikZ.<br />
<br />
== Description ==<br />
<br />
To switch between the two drawing engines (MetaPost and TikZ) use the style option.<br />
<texcode>\usemodule[gantt][alternative=mp]</texcode><br />
<texcode>\usemodule[gantt][alternative=tikz]</texcode><br />
<br />
The default engine is MetaPost.<br />
<br />
<br />
Here is a short description of the environments and commands:<br />
<br />
=== Gantt ===<br />
The '''gantt''' environment draws the canvas of a gantt figure.<br />
<texcode>\startgantt[...]{no of Tasks to plot}{no of time slots}</texcode><br />
The optional argument [...] can be filled in a key=value syntax, using one or more of the following keys:<br />
<br />
* ''factor'' - MetaPost scale factor (default: 1)<br />
* ''xunitlength'' - length of one time slot (default: 1cm)<br />
* ''style'' - fontsize of labels (default: \tf)<br />
* ''titlestyle'' - fontsize of title section (default: \tfx)<br />
* ''drawledgerline'' - switch to enable/disable the drawing of horizontal ledger lines (default value: false)<br />
<br />
=== Ganttitle ===<br />
This is the environment for drawing the title section.<br />
<texcode>\startganttitle (...) \stopganttitle</texcode><br />
<br />
=== Titleelement ===<br />
This draws one element of the title.<br />
<texcode>\titleelement{label}{length}</texcode><br />
<br />
=== Numtitle ===<br />
This draws a numbered sequence of title elements.<br />
<texcode>\numtitle{start number}{increment}{end number}{length of each title element}</texcode><br />
<br />
=== Ganttbar ===<br />
This draws a single, unconnected bar for representing a task.<br />
<texcode>\ganttbar[pattern=value,color=value]{label}{start}{length}</texcode><br />
The optional comma separated arguments are:<br />
<br />
* ''<pattern>'' - TikZ pattern (e.g. north east lines (default), north west lines, crosshatch, crosshatch dots, grid, …) or see [[#Regressions | Regressions]] section for MetaPost<br />
* ''<color>'' - a color of the pattern (e.g. black (default), red, green blue gray, dark gray)<br />
<br />
=== Ganttcon ===<br />
This draws an arrow between the bars specified by coordinates.<br />
<texcode>\ganttcon{startx}{starty}{endx}{endy}</texcode><br />
<br />
=== Ganttbarcon ===<br />
This draws a single bar and connects the bar with the previous bar for consecutive tasks.<br />
<texcode>\ganttbarcon[pattern=value,color=value]{label}{start}{length}</texcode><br />
The optional pattern argument are the same as for \ganttbar.<br />
<br />
=== Ganttgroup ===<br />
This draws a bar to group tasks.<br />
<texcode>\ganttgroup{label}{start}{length}</texcode><br />
<br />
=== Ganttmilestone ===<br />
This draws a milestone using a diamond.<br />
<texcode>\ganttmilestone[color=value]{label}{start}</texcode><br />
The optional color argument argument is:<br />
<br />
* ''<color>'' - a color of the pattern (e.g. black (default), red, green blue gray, dark gray)<br />
<br />
=== Ganttmilestonecon ===<br />
This draws a milestone using a diamond and connects the milestone with the previous bar or milestone.<br />
<texcode>\ganttmilestonecon[color=value]{label}{start}</texcode><br />
The optional color argument argument is:<br />
<br />
* ''<color>'' - a color of the pattern (e.g. black (default), red, green blue gray, dark gray)<br />
<br />
== Examples ==<br />
<br />
=== Minimal example ===<br />
<texcode><br />
\usemodule[gantt]<br />
\setuppagenumbering[location=]<br />
<br />
\starttext<br />
\startgantt{7}{12}<br />
\startganttitle<br />
\numtitle{1}{1}{12}{1}<br />
\stopganttitle<br />
\ganttbar{a task}{0}{2}<br />
\ganttbarcon{a consecutive task}{2}{4}<br />
\ganttbarcon{another consecutive task}{8}{2}<br />
\ganttbar{another task}{2}{2}<br />
\ganttbar{another task}{4}{2}<br />
\ganttbar{another task}{4}{2}<br />
\ganttcon{4}{4}{4}{6}<br />
\stopgantt<br />
\stoptext<br />
</texcode><br />
<br />
<br />
=== Similar example using names of calendar months ===<br />
<texcode><br />
\usemodule[gantt]<br />
\setuppagenumbering[location=]<br />
<br />
\starttext<br />
\startgantt{3}{12}<br />
\startganttitle<br />
\titleelement{Jan}{1}<br />
\titleelement{Feb}{1}<br />
\titleelement{Mar}{1}<br />
\titleelement{Apr}{1}<br />
\titleelement{May}{1}<br />
\titleelement{Jun}{1}<br />
\titleelement{Jul}{1}<br />
\titleelement{Aug}{1}<br />
\titleelement{Sep}{1}<br />
\titleelement{Oct}{1}<br />
\titleelement{Nov}{1}<br />
\titleelement{Dec}{1}<br />
\stopganttitle<br />
\ganttbar{Task 1}{0}{2}<br />
\ganttbarcon{a consecutive task}{2}{4}<br />
\stopgantt<br />
\stoptext<br />
</texcode><br />
<br />
<br />
=== Multiple titles with different length ===<br />
<texcode><br />
\usemodule[gantt]<br />
\setuppagenumbering[location=]<br />
<br />
\starttext<br />
\startgantt{4}{12}<br />
\startganttitle<br />
\numtitle{2010}{1}{2012}{4}<br />
\stopganttitle<br />
\startganttitle<br />
\numtitle{1}{1}{4}{1}<br />
\numtitle{1}{1}{4}{1}<br />
\numtitle{1}{1}{4}{1}<br />
\stopganttitle<br />
\ganttbar{Task 1}{0}{2}<br />
\ganttbarcon{a consecutive task}{2}{4}<br />
\stopgantt<br />
\stoptext<br />
</texcode><br />
<br />
[[File:gantt-titles.jpg]]<br />
<br />
=== Milestone example ===<br />
<texcode><br />
\usemodule[gantt]<br />
\setuppagenumbering[location=]<br />
<br />
\starttext<br />
\startgantt{10}{12}<br />
\startganttitle<br />
\numtitle{1}{1}{12}{1}<br />
\stopganttitle<br />
\ganttbar{a task}{0}{2}<br />
\ganttbarcon{a consecutive task}{2}{4}<br />
\ganttbarcon{another consecutive task}{8}{2}<br />
\ganttmilestone[color=cyan]{Milestone with color!}{4}<br />
\ganttbar{another task}{2}{2}<br />
\ganttbar[color=cyan]{another coloured task}{4}{4}<br />
\ganttbar{another task}{4}{2}<br />
\ganttcon{4}{5}{4}{7}<br />
\ganttmilestonecon{A connected Milestone}{7}<br />
\ganttbarcon{another consecutive task}{8}{2}<br />
\stopgantt<br />
\stoptext<br />
</texcode><br />
<br />
[[File:gantt-milestone.jpg]]<br />
<br />
=== More complex example (using groups and optional arguments) ===<br />
<texcode><br />
\usemodule[gantt]<br />
\setuppapersize[A4,landscape][A4,landscape]<br />
\setuplayout[scale=0.8]<br />
\setuppagenumbering[location=]<br />
<br />
\starttext<br />
\startgantt[xunitlength=0.5cm,style=\tfx,titlestyle=\tfx,drawledgerline=true]{10}{48}<br />
\startganttitle<br />
\titleelement{2009}{7}<br />
\numtitle{2010}{1}{2012}{12} <br />
\titleelement{2013}{5}<br />
\stopganttitle<br />
\startganttitle<br />
\numtitle{6}{1}{12}{1} <br />
\numtitle{1}{1}{12}{1} <br />
\numtitle{1}{1}{12}{1} <br />
\numtitle{1}{1}{12}{1} <br />
\numtitle{1}{1}{5}{1} <br />
\stopganttitle<br />
\ganttbar{task 1}{2}{17} <br />
\ganttgroup{a group of tasks}{6}{18}<br />
\ganttbar{task 2}{5}{10} <br />
\ganttbar[color=blue]{task 3}{15}{3} <br />
\ganttbar{task 4}{20}{3} <br />
\ganttcon{15}{4}{20}{6}<br />
\ganttbar{task 5}{15}{5} <br />
\ganttbarcon[color=red]{task 6}{20}{5}<br />
\ganttbarcon{task 7}{30}{5}<br />
\stopgantt<br />
\stoptext<br />
</texcode><br />
<br />
[[File:gantt-complex.jpg]]<br />
<br />
== Regressions ==<br />
<br />
There are no default color patterns in MetaPost. This needs to be implemented separately in order to have a pattern option in this module.<br />
<br />
As a temporary solution the [http://www.ctan.org/tex-archive/graphics/metapost/contrib/macros/hatching/ hatching] MetaPost package is used.<br />
<br />
== See also ==<br />
<br />
* [http://www.ctan.org/pkg/pgfgantt Draw Gantt charts with TikZ]<br />
* [http://www.martin-kumm.de/tex_gantt_package.php A LaTeX package for drawing gantt plots using pgf/tikz]<br />
* [http://www.kese.hu/p/tikz.html Gantt Chart with TikZ]<br />
<br />
[[Category:Modules]]<br />
[[Category:Graphics]]<br />
[[Category:Metapost]]<br />
[[Category:Sciences]]</div>Mæstrohttps://wiki.contextgarden.net/index.php?title=File:gantt-titles.jpg&diff=32006File:gantt-titles.jpg2020-11-08T00:00:52Z<p>Mæstro: multiple titles with different length</p>
<hr />
<div>== Summary ==<br />
multiple titles with different length</div>Mæstrohttps://wiki.contextgarden.net/index.php?title=Gantt_charts&diff=32005Gantt charts2020-11-07T23:58:28Z<p>Mæstro: /* Milestone example */</p>
<hr />
<div>[http://modules.contextgarden.net/gantt Gantt] is a (third party) ConTeXt module for drawing Gantt charts via MetaPost or PGF/TikZ.<br />
<br />
== Description ==<br />
<br />
To switch between the two drawing engines (MetaPost and TikZ) use the style option.<br />
<texcode>\usemodule[gantt][alternative=mp]</texcode><br />
<texcode>\usemodule[gantt][alternative=tikz]</texcode><br />
<br />
The default engine is MetaPost.<br />
<br />
<br />
Here is a short description of the environments and commands:<br />
<br />
=== Gantt ===<br />
The '''gantt''' environment draws the canvas of a gantt figure.<br />
<texcode>\startgantt[...]{no of Tasks to plot}{no of time slots}</texcode><br />
The optional argument [...] can be filled in a key=value syntax, using one or more of the following keys:<br />
<br />
* ''factor'' - MetaPost scale factor (default: 1)<br />
* ''xunitlength'' - length of one time slot (default: 1cm)<br />
* ''style'' - fontsize of labels (default: \tf)<br />
* ''titlestyle'' - fontsize of title section (default: \tfx)<br />
* ''drawledgerline'' - switch to enable/disable the drawing of horizontal ledger lines (default value: false)<br />
<br />
=== Ganttitle ===<br />
This is the environment for drawing the title section.<br />
<texcode>\startganttitle (...) \stopganttitle</texcode><br />
<br />
=== Titleelement ===<br />
This draws one element of the title.<br />
<texcode>\titleelement{label}{length}</texcode><br />
<br />
=== Numtitle ===<br />
This draws a numbered sequence of title elements.<br />
<texcode>\numtitle{start number}{increment}{end number}{length of each title element}</texcode><br />
<br />
=== Ganttbar ===<br />
This draws a single, unconnected bar for representing a task.<br />
<texcode>\ganttbar[pattern=value,color=value]{label}{start}{length}</texcode><br />
The optional comma separated arguments are:<br />
<br />
* ''<pattern>'' - TikZ pattern (e.g. north east lines (default), north west lines, crosshatch, crosshatch dots, grid, …) or see [[#Regressions | Regressions]] section for MetaPost<br />
* ''<color>'' - a color of the pattern (e.g. black (default), red, green blue gray, dark gray)<br />
<br />
=== Ganttcon ===<br />
This draws an arrow between the bars specified by coordinates.<br />
<texcode>\ganttcon{startx}{starty}{endx}{endy}</texcode><br />
<br />
=== Ganttbarcon ===<br />
This draws a single bar and connects the bar with the previous bar for consecutive tasks.<br />
<texcode>\ganttbarcon[pattern=value,color=value]{label}{start}{length}</texcode><br />
The optional pattern argument are the same as for \ganttbar.<br />
<br />
=== Ganttgroup ===<br />
This draws a bar to group tasks.<br />
<texcode>\ganttgroup{label}{start}{length}</texcode><br />
<br />
=== Ganttmilestone ===<br />
This draws a milestone using a diamond.<br />
<texcode>\ganttmilestone[color=value]{label}{start}</texcode><br />
The optional color argument argument is:<br />
<br />
* ''<color>'' - a color of the pattern (e.g. black (default), red, green blue gray, dark gray)<br />
<br />
=== Ganttmilestonecon ===<br />
This draws a milestone using a diamond and connects the milestone with the previous bar or milestone.<br />
<texcode>\ganttmilestonecon[color=value]{label}{start}</texcode><br />
The optional color argument argument is:<br />
<br />
* ''<color>'' - a color of the pattern (e.g. black (default), red, green blue gray, dark gray)<br />
<br />
== Examples ==<br />
<br />
=== Minimal example ===<br />
<texcode><br />
\usemodule[gantt]<br />
\setuppagenumbering[location=]<br />
<br />
\starttext<br />
\startgantt{7}{12}<br />
\startganttitle<br />
\numtitle{1}{1}{12}{1}<br />
\stopganttitle<br />
\ganttbar{a task}{0}{2}<br />
\ganttbarcon{a consecutive task}{2}{4}<br />
\ganttbarcon{another consecutive task}{8}{2}<br />
\ganttbar{another task}{2}{2}<br />
\ganttbar{another task}{4}{2}<br />
\ganttbar{another task}{4}{2}<br />
\ganttcon{4}{4}{4}{6}<br />
\stopgantt<br />
\stoptext<br />
</texcode><br />
<br />
<br />
=== Similar example using names of calendar months ===<br />
<texcode><br />
\usemodule[gantt]<br />
\setuppagenumbering[location=]<br />
<br />
\starttext<br />
\startgantt{3}{12}<br />
\startganttitle<br />
\titleelement{Jan}{1}<br />
\titleelement{Feb}{1}<br />
\titleelement{Mar}{1}<br />
\titleelement{Apr}{1}<br />
\titleelement{May}{1}<br />
\titleelement{Jun}{1}<br />
\titleelement{Jul}{1}<br />
\titleelement{Aug}{1}<br />
\titleelement{Sep}{1}<br />
\titleelement{Oct}{1}<br />
\titleelement{Nov}{1}<br />
\titleelement{Dec}{1}<br />
\stopganttitle<br />
\ganttbar{Task 1}{0}{2}<br />
\ganttbarcon{a consecutive task}{2}{4}<br />
\stopgantt<br />
\stoptext<br />
</texcode><br />
<br />
<br />
=== Multiple titles with different length ===<br />
<texcode><br />
\usemodule[gantt]<br />
\setuppagenumbering[location=]<br />
<br />
\starttext<br />
\startgantt{4}{12}<br />
\startganttitle<br />
\numtitle{2010}{1}{2012}{4}<br />
\stopganttitle<br />
\startganttitle<br />
\numtitle{1}{1}{4}{1}<br />
\numtitle{1}{1}{4}{1}<br />
\numtitle{1}{1}{4}{1}<br />
\stopganttitle<br />
\ganttbar{Task 1}{0}{2}<br />
\ganttbarcon{a consecutive task}{2}{4}<br />
\stopgantt<br />
\stoptext<br />
</texcode><br />
<br />
<br />
=== Milestone example ===<br />
<texcode><br />
\usemodule[gantt]<br />
\setuppagenumbering[location=]<br />
<br />
\starttext<br />
\startgantt{10}{12}<br />
\startganttitle<br />
\numtitle{1}{1}{12}{1}<br />
\stopganttitle<br />
\ganttbar{a task}{0}{2}<br />
\ganttbarcon{a consecutive task}{2}{4}<br />
\ganttbarcon{another consecutive task}{8}{2}<br />
\ganttmilestone[color=cyan]{Milestone with color!}{4}<br />
\ganttbar{another task}{2}{2}<br />
\ganttbar[color=cyan]{another coloured task}{4}{4}<br />
\ganttbar{another task}{4}{2}<br />
\ganttcon{4}{5}{4}{7}<br />
\ganttmilestonecon{A connected Milestone}{7}<br />
\ganttbarcon{another consecutive task}{8}{2}<br />
\stopgantt<br />
\stoptext<br />
</texcode><br />
<br />
[[File:gantt-milestone.jpg]]<br />
<br />
=== More complex example (using groups and optional arguments) ===<br />
<texcode><br />
\usemodule[gantt]<br />
\setuppapersize[A4,landscape][A4,landscape]<br />
\setuplayout[scale=0.8]<br />
\setuppagenumbering[location=]<br />
<br />
\starttext<br />
\startgantt[xunitlength=0.5cm,style=\tfx,titlestyle=\tfx,drawledgerline=true]{10}{48}<br />
\startganttitle<br />
\titleelement{2009}{7}<br />
\numtitle{2010}{1}{2012}{12} <br />
\titleelement{2013}{5}<br />
\stopganttitle<br />
\startganttitle<br />
\numtitle{6}{1}{12}{1} <br />
\numtitle{1}{1}{12}{1} <br />
\numtitle{1}{1}{12}{1} <br />
\numtitle{1}{1}{12}{1} <br />
\numtitle{1}{1}{5}{1} <br />
\stopganttitle<br />
\ganttbar{task 1}{2}{17} <br />
\ganttgroup{a group of tasks}{6}{18}<br />
\ganttbar{task 2}{5}{10} <br />
\ganttbar[color=blue]{task 3}{15}{3} <br />
\ganttbar{task 4}{20}{3} <br />
\ganttcon{15}{4}{20}{6}<br />
\ganttbar{task 5}{15}{5} <br />
\ganttbarcon[color=red]{task 6}{20}{5}<br />
\ganttbarcon{task 7}{30}{5}<br />
\stopgantt<br />
\stoptext<br />
</texcode><br />
<br />
[[File:gantt-complex.jpg]]<br />
<br />
== Regressions ==<br />
<br />
There are no default color patterns in MetaPost. This needs to be implemented separately in order to have a pattern option in this module.<br />
<br />
As a temporary solution the [http://www.ctan.org/tex-archive/graphics/metapost/contrib/macros/hatching/ hatching] MetaPost package is used.<br />
<br />
== See also ==<br />
<br />
* [http://www.ctan.org/pkg/pgfgantt Draw Gantt charts with TikZ]<br />
* [http://www.martin-kumm.de/tex_gantt_package.php A LaTeX package for drawing gantt plots using pgf/tikz]<br />
* [http://www.kese.hu/p/tikz.html Gantt Chart with TikZ]<br />
<br />
[[Category:Modules]]<br />
[[Category:Graphics]]<br />
[[Category:Metapost]]<br />
[[Category:Sciences]]</div>Mæstrohttps://wiki.contextgarden.net/index.php?title=File:gantt-milestone.jpg&diff=32004File:gantt-milestone.jpg2020-11-07T23:57:51Z<p>Mæstro: milestone</p>
<hr />
<div>== Summary ==<br />
milestone</div>Mæstrohttps://wiki.contextgarden.net/index.php?title=Gantt_charts&diff=32003Gantt charts2020-11-07T23:54:21Z<p>Mæstro: /* More complex example (using groups and optional arguments) */</p>
<hr />
<div>[http://modules.contextgarden.net/gantt Gantt] is a (third party) ConTeXt module for drawing Gantt charts via MetaPost or PGF/TikZ.<br />
<br />
== Description ==<br />
<br />
To switch between the two drawing engines (MetaPost and TikZ) use the style option.<br />
<texcode>\usemodule[gantt][alternative=mp]</texcode><br />
<texcode>\usemodule[gantt][alternative=tikz]</texcode><br />
<br />
The default engine is MetaPost.<br />
<br />
<br />
Here is a short description of the environments and commands:<br />
<br />
=== Gantt ===<br />
The '''gantt''' environment draws the canvas of a gantt figure.<br />
<texcode>\startgantt[...]{no of Tasks to plot}{no of time slots}</texcode><br />
The optional argument [...] can be filled in a key=value syntax, using one or more of the following keys:<br />
<br />
* ''factor'' - MetaPost scale factor (default: 1)<br />
* ''xunitlength'' - length of one time slot (default: 1cm)<br />
* ''style'' - fontsize of labels (default: \tf)<br />
* ''titlestyle'' - fontsize of title section (default: \tfx)<br />
* ''drawledgerline'' - switch to enable/disable the drawing of horizontal ledger lines (default value: false)<br />
<br />
=== Ganttitle ===<br />
This is the environment for drawing the title section.<br />
<texcode>\startganttitle (...) \stopganttitle</texcode><br />
<br />
=== Titleelement ===<br />
This draws one element of the title.<br />
<texcode>\titleelement{label}{length}</texcode><br />
<br />
=== Numtitle ===<br />
This draws a numbered sequence of title elements.<br />
<texcode>\numtitle{start number}{increment}{end number}{length of each title element}</texcode><br />
<br />
=== Ganttbar ===<br />
This draws a single, unconnected bar for representing a task.<br />
<texcode>\ganttbar[pattern=value,color=value]{label}{start}{length}</texcode><br />
The optional comma separated arguments are:<br />
<br />
* ''<pattern>'' - TikZ pattern (e.g. north east lines (default), north west lines, crosshatch, crosshatch dots, grid, …) or see [[#Regressions | Regressions]] section for MetaPost<br />
* ''<color>'' - a color of the pattern (e.g. black (default), red, green blue gray, dark gray)<br />
<br />
=== Ganttcon ===<br />
This draws an arrow between the bars specified by coordinates.<br />
<texcode>\ganttcon{startx}{starty}{endx}{endy}</texcode><br />
<br />
=== Ganttbarcon ===<br />
This draws a single bar and connects the bar with the previous bar for consecutive tasks.<br />
<texcode>\ganttbarcon[pattern=value,color=value]{label}{start}{length}</texcode><br />
The optional pattern argument are the same as for \ganttbar.<br />
<br />
=== Ganttgroup ===<br />
This draws a bar to group tasks.<br />
<texcode>\ganttgroup{label}{start}{length}</texcode><br />
<br />
=== Ganttmilestone ===<br />
This draws a milestone using a diamond.<br />
<texcode>\ganttmilestone[color=value]{label}{start}</texcode><br />
The optional color argument argument is:<br />
<br />
* ''<color>'' - a color of the pattern (e.g. black (default), red, green blue gray, dark gray)<br />
<br />
=== Ganttmilestonecon ===<br />
This draws a milestone using a diamond and connects the milestone with the previous bar or milestone.<br />
<texcode>\ganttmilestonecon[color=value]{label}{start}</texcode><br />
The optional color argument argument is:<br />
<br />
* ''<color>'' - a color of the pattern (e.g. black (default), red, green blue gray, dark gray)<br />
<br />
== Examples ==<br />
<br />
=== Minimal example ===<br />
<texcode><br />
\usemodule[gantt]<br />
\setuppagenumbering[location=]<br />
<br />
\starttext<br />
\startgantt{7}{12}<br />
\startganttitle<br />
\numtitle{1}{1}{12}{1}<br />
\stopganttitle<br />
\ganttbar{a task}{0}{2}<br />
\ganttbarcon{a consecutive task}{2}{4}<br />
\ganttbarcon{another consecutive task}{8}{2}<br />
\ganttbar{another task}{2}{2}<br />
\ganttbar{another task}{4}{2}<br />
\ganttbar{another task}{4}{2}<br />
\ganttcon{4}{4}{4}{6}<br />
\stopgantt<br />
\stoptext<br />
</texcode><br />
<br />
<br />
=== Similar example using names of calendar months ===<br />
<texcode><br />
\usemodule[gantt]<br />
\setuppagenumbering[location=]<br />
<br />
\starttext<br />
\startgantt{3}{12}<br />
\startganttitle<br />
\titleelement{Jan}{1}<br />
\titleelement{Feb}{1}<br />
\titleelement{Mar}{1}<br />
\titleelement{Apr}{1}<br />
\titleelement{May}{1}<br />
\titleelement{Jun}{1}<br />
\titleelement{Jul}{1}<br />
\titleelement{Aug}{1}<br />
\titleelement{Sep}{1}<br />
\titleelement{Oct}{1}<br />
\titleelement{Nov}{1}<br />
\titleelement{Dec}{1}<br />
\stopganttitle<br />
\ganttbar{Task 1}{0}{2}<br />
\ganttbarcon{a consecutive task}{2}{4}<br />
\stopgantt<br />
\stoptext<br />
</texcode><br />
<br />
<br />
=== Multiple titles with different length ===<br />
<texcode><br />
\usemodule[gantt]<br />
\setuppagenumbering[location=]<br />
<br />
\starttext<br />
\startgantt{4}{12}<br />
\startganttitle<br />
\numtitle{2010}{1}{2012}{4}<br />
\stopganttitle<br />
\startganttitle<br />
\numtitle{1}{1}{4}{1}<br />
\numtitle{1}{1}{4}{1}<br />
\numtitle{1}{1}{4}{1}<br />
\stopganttitle<br />
\ganttbar{Task 1}{0}{2}<br />
\ganttbarcon{a consecutive task}{2}{4}<br />
\stopgantt<br />
\stoptext<br />
</texcode><br />
<br />
<br />
=== Milestone example ===<br />
<texcode><br />
\usemodule[gantt]<br />
\setuppagenumbering[location=]<br />
<br />
\starttext<br />
\startgantt{10}{12}<br />
\startganttitle<br />
\numtitle{1}{1}{12}{1}<br />
\stopganttitle<br />
\ganttbar{a task}{0}{2}<br />
\ganttbarcon{a consecutive task}{2}{4}<br />
\ganttbarcon{another consecutive task}{8}{2}<br />
\ganttmilestone[color=cyan]{Milestone with color!}{4}<br />
\ganttbar{another task}{2}{2}<br />
\ganttbar[color=cyan]{another coloured task}{4}{4}<br />
\ganttbar{another task}{4}{2}<br />
\ganttcon{4}{5}{4}{7}<br />
\ganttmilestonecon{A connected Milestone}{7}<br />
\ganttbarcon{another consecutive task}{8}{2}<br />
\stopgantt<br />
\stoptext<br />
</texcode><br />
<br />
<br />
=== More complex example (using groups and optional arguments) ===<br />
<texcode><br />
\usemodule[gantt]<br />
\setuppapersize[A4,landscape][A4,landscape]<br />
\setuplayout[scale=0.8]<br />
\setuppagenumbering[location=]<br />
<br />
\starttext<br />
\startgantt[xunitlength=0.5cm,style=\tfx,titlestyle=\tfx,drawledgerline=true]{10}{48}<br />
\startganttitle<br />
\titleelement{2009}{7}<br />
\numtitle{2010}{1}{2012}{12} <br />
\titleelement{2013}{5}<br />
\stopganttitle<br />
\startganttitle<br />
\numtitle{6}{1}{12}{1} <br />
\numtitle{1}{1}{12}{1} <br />
\numtitle{1}{1}{12}{1} <br />
\numtitle{1}{1}{12}{1} <br />
\numtitle{1}{1}{5}{1} <br />
\stopganttitle<br />
\ganttbar{task 1}{2}{17} <br />
\ganttgroup{a group of tasks}{6}{18}<br />
\ganttbar{task 2}{5}{10} <br />
\ganttbar[color=blue]{task 3}{15}{3} <br />
\ganttbar{task 4}{20}{3} <br />
\ganttcon{15}{4}{20}{6}<br />
\ganttbar{task 5}{15}{5} <br />
\ganttbarcon[color=red]{task 6}{20}{5}<br />
\ganttbarcon{task 7}{30}{5}<br />
\stopgantt<br />
\stoptext<br />
</texcode><br />
<br />
[[File:gantt-complex.jpg]]<br />
<br />
== Regressions ==<br />
<br />
There are no default color patterns in MetaPost. This needs to be implemented separately in order to have a pattern option in this module.<br />
<br />
As a temporary solution the [http://www.ctan.org/tex-archive/graphics/metapost/contrib/macros/hatching/ hatching] MetaPost package is used.<br />
<br />
== See also ==<br />
<br />
* [http://www.ctan.org/pkg/pgfgantt Draw Gantt charts with TikZ]<br />
* [http://www.martin-kumm.de/tex_gantt_package.php A LaTeX package for drawing gantt plots using pgf/tikz]<br />
* [http://www.kese.hu/p/tikz.html Gantt Chart with TikZ]<br />
<br />
[[Category:Modules]]<br />
[[Category:Graphics]]<br />
[[Category:Metapost]]<br />
[[Category:Sciences]]</div>Mæstrohttps://wiki.contextgarden.net/index.php?title=File:gantt-complex.jpg&diff=32002File:gantt-complex.jpg2020-11-07T23:53:27Z<p>Mæstro: complex example (using groups and optional arguments)</p>
<hr />
<div>== Summary ==<br />
complex example (using groups and optional arguments)</div>Mæstrohttps://wiki.contextgarden.net/index.php?title=Gantt_charts&diff=32001Gantt charts2020-11-07T23:41:20Z<p>Mæstro: /* More complex example (using groups and optional arguments) */</p>
<hr />
<div>[http://modules.contextgarden.net/gantt Gantt] is a (third party) ConTeXt module for drawing Gantt charts via MetaPost or PGF/TikZ.<br />
<br />
== Description ==<br />
<br />
To switch between the two drawing engines (MetaPost and TikZ) use the style option.<br />
<texcode>\usemodule[gantt][alternative=mp]</texcode><br />
<texcode>\usemodule[gantt][alternative=tikz]</texcode><br />
<br />
The default engine is MetaPost.<br />
<br />
<br />
Here is a short description of the environments and commands:<br />
<br />
=== Gantt ===<br />
The '''gantt''' environment draws the canvas of a gantt figure.<br />
<texcode>\startgantt[...]{no of Tasks to plot}{no of time slots}</texcode><br />
The optional argument [...] can be filled in a key=value syntax, using one or more of the following keys:<br />
<br />
* ''factor'' - MetaPost scale factor (default: 1)<br />
* ''xunitlength'' - length of one time slot (default: 1cm)<br />
* ''style'' - fontsize of labels (default: \tf)<br />
* ''titlestyle'' - fontsize of title section (default: \tfx)<br />
* ''drawledgerline'' - switch to enable/disable the drawing of horizontal ledger lines (default value: false)<br />
<br />
=== Ganttitle ===<br />
This is the environment for drawing the title section.<br />
<texcode>\startganttitle (...) \stopganttitle</texcode><br />
<br />
=== Titleelement ===<br />
This draws one element of the title.<br />
<texcode>\titleelement{label}{length}</texcode><br />
<br />
=== Numtitle ===<br />
This draws a numbered sequence of title elements.<br />
<texcode>\numtitle{start number}{increment}{end number}{length of each title element}</texcode><br />
<br />
=== Ganttbar ===<br />
This draws a single, unconnected bar for representing a task.<br />
<texcode>\ganttbar[pattern=value,color=value]{label}{start}{length}</texcode><br />
The optional comma separated arguments are:<br />
<br />
* ''<pattern>'' - TikZ pattern (e.g. north east lines (default), north west lines, crosshatch, crosshatch dots, grid, …) or see [[#Regressions | Regressions]] section for MetaPost<br />
* ''<color>'' - a color of the pattern (e.g. black (default), red, green blue gray, dark gray)<br />
<br />
=== Ganttcon ===<br />
This draws an arrow between the bars specified by coordinates.<br />
<texcode>\ganttcon{startx}{starty}{endx}{endy}</texcode><br />
<br />
=== Ganttbarcon ===<br />
This draws a single bar and connects the bar with the previous bar for consecutive tasks.<br />
<texcode>\ganttbarcon[pattern=value,color=value]{label}{start}{length}</texcode><br />
The optional pattern argument are the same as for \ganttbar.<br />
<br />
=== Ganttgroup ===<br />
This draws a bar to group tasks.<br />
<texcode>\ganttgroup{label}{start}{length}</texcode><br />
<br />
=== Ganttmilestone ===<br />
This draws a milestone using a diamond.<br />
<texcode>\ganttmilestone[color=value]{label}{start}</texcode><br />
The optional color argument argument is:<br />
<br />
* ''<color>'' - a color of the pattern (e.g. black (default), red, green blue gray, dark gray)<br />
<br />
=== Ganttmilestonecon ===<br />
This draws a milestone using a diamond and connects the milestone with the previous bar or milestone.<br />
<texcode>\ganttmilestonecon[color=value]{label}{start}</texcode><br />
The optional color argument argument is:<br />
<br />
* ''<color>'' - a color of the pattern (e.g. black (default), red, green blue gray, dark gray)<br />
<br />
== Examples ==<br />
<br />
=== Minimal example ===<br />
<texcode><br />
\usemodule[gantt]<br />
\setuppagenumbering[location=]<br />
<br />
\starttext<br />
\startgantt{7}{12}<br />
\startganttitle<br />
\numtitle{1}{1}{12}{1}<br />
\stopganttitle<br />
\ganttbar{a task}{0}{2}<br />
\ganttbarcon{a consecutive task}{2}{4}<br />
\ganttbarcon{another consecutive task}{8}{2}<br />
\ganttbar{another task}{2}{2}<br />
\ganttbar{another task}{4}{2}<br />
\ganttbar{another task}{4}{2}<br />
\ganttcon{4}{4}{4}{6}<br />
\stopgantt<br />
\stoptext<br />
</texcode><br />
<br />
<br />
=== Similar example using names of calendar months ===<br />
<texcode><br />
\usemodule[gantt]<br />
\setuppagenumbering[location=]<br />
<br />
\starttext<br />
\startgantt{3}{12}<br />
\startganttitle<br />
\titleelement{Jan}{1}<br />
\titleelement{Feb}{1}<br />
\titleelement{Mar}{1}<br />
\titleelement{Apr}{1}<br />
\titleelement{May}{1}<br />
\titleelement{Jun}{1}<br />
\titleelement{Jul}{1}<br />
\titleelement{Aug}{1}<br />
\titleelement{Sep}{1}<br />
\titleelement{Oct}{1}<br />
\titleelement{Nov}{1}<br />
\titleelement{Dec}{1}<br />
\stopganttitle<br />
\ganttbar{Task 1}{0}{2}<br />
\ganttbarcon{a consecutive task}{2}{4}<br />
\stopgantt<br />
\stoptext<br />
</texcode><br />
<br />
<br />
=== Multiple titles with different length ===<br />
<texcode><br />
\usemodule[gantt]<br />
\setuppagenumbering[location=]<br />
<br />
\starttext<br />
\startgantt{4}{12}<br />
\startganttitle<br />
\numtitle{2010}{1}{2012}{4}<br />
\stopganttitle<br />
\startganttitle<br />
\numtitle{1}{1}{4}{1}<br />
\numtitle{1}{1}{4}{1}<br />
\numtitle{1}{1}{4}{1}<br />
\stopganttitle<br />
\ganttbar{Task 1}{0}{2}<br />
\ganttbarcon{a consecutive task}{2}{4}<br />
\stopgantt<br />
\stoptext<br />
</texcode><br />
<br />
<br />
=== Milestone example ===<br />
<texcode><br />
\usemodule[gantt]<br />
\setuppagenumbering[location=]<br />
<br />
\starttext<br />
\startgantt{10}{12}<br />
\startganttitle<br />
\numtitle{1}{1}{12}{1}<br />
\stopganttitle<br />
\ganttbar{a task}{0}{2}<br />
\ganttbarcon{a consecutive task}{2}{4}<br />
\ganttbarcon{another consecutive task}{8}{2}<br />
\ganttmilestone[color=cyan]{Milestone with color!}{4}<br />
\ganttbar{another task}{2}{2}<br />
\ganttbar[color=cyan]{another coloured task}{4}{4}<br />
\ganttbar{another task}{4}{2}<br />
\ganttcon{4}{5}{4}{7}<br />
\ganttmilestonecon{A connected Milestone}{7}<br />
\ganttbarcon{another consecutive task}{8}{2}<br />
\stopgantt<br />
\stoptext<br />
</texcode><br />
<br />
<br />
=== More complex example (using groups and optional arguments) ===<br />
<texcode><br />
\usemodule[gantt]<br />
\setuppapersize[A4,landscape][A4,landscape]<br />
\setuplayout[scale=0.8]<br />
\setuppagenumbering[location=]<br />
<br />
\starttext<br />
\startgantt[xunitlength=0.5cm,style=\tfx,titlestyle=\tfx,drawledgerline=true]{10}{48}<br />
\startganttitle<br />
\titleelement{2009}{7}<br />
\numtitle{2010}{1}{2012}{12} <br />
\titleelement{2013}{5}<br />
\stopganttitle<br />
\startganttitle<br />
\numtitle{6}{1}{12}{1} <br />
\numtitle{1}{1}{12}{1} <br />
\numtitle{1}{1}{12}{1} <br />
\numtitle{1}{1}{12}{1} <br />
\numtitle{1}{1}{5}{1} <br />
\stopganttitle<br />
\ganttbar{task 1}{2}{17} <br />
\ganttgroup{a group of tasks}{6}{18}<br />
\ganttbar{task 2}{5}{10} <br />
\ganttbar[color=blue]{task 3}{15}{3} <br />
\ganttbar{task 4}{20}{3} <br />
\ganttcon{15}{4}{20}{6}<br />
\ganttbar{task 5}{15}{5} <br />
\ganttbarcon[color=red]{task 6}{20}{5}<br />
\ganttbarcon{task 7}{30}{5}<br />
\stopgantt<br />
\stoptext<br />
</texcode><br />
<br />
== Regressions ==<br />
<br />
There are no default color patterns in MetaPost. This needs to be implemented separately in order to have a pattern option in this module.<br />
<br />
As a temporary solution the [http://www.ctan.org/tex-archive/graphics/metapost/contrib/macros/hatching/ hatching] MetaPost package is used.<br />
<br />
== See also ==<br />
<br />
* [http://www.ctan.org/pkg/pgfgantt Draw Gantt charts with TikZ]<br />
* [http://www.martin-kumm.de/tex_gantt_package.php A LaTeX package for drawing gantt plots using pgf/tikz]<br />
* [http://www.kese.hu/p/tikz.html Gantt Chart with TikZ]<br />
<br />
[[Category:Modules]]<br />
[[Category:Graphics]]<br />
[[Category:Metapost]]<br />
[[Category:Sciences]]</div>Mæstrohttps://wiki.contextgarden.net/index.php?title=Ubuntu&diff=30978Ubuntu2020-08-22T23:58:29Z<p>Mæstro: /* With Ubuntu packages – should work with Ubuntu 7.10 and above */</p>
<hr />
<div>Here are instructions for ConTeXt installation on Ubuntu and its derivatives [K/X/L]ubuntu.<br />
<br />
== Precompiled / Packaged Nightly Builds From PPA ==<br />
<br />
Adam Reviczky was most generous to provide us with an Ubuntu PPA (Personal Package Archive) that contains precompiled Ubuntu packages for both ConTeXt and LuaTeX nightlies. Instructions for your version of Ubuntu are available for [https://launchpad.net/~reviczky/+archive/context-daily ConTeXt] and [https://launchpad.net/~reviczky/+archive/luatex-daily LuaTeX].<br />
<br />
== With Ubuntu packages – should work with Ubuntu 16.04 and above ==<br />
<br />
Note that Ubuntu's packaged version of ConTeXt is quite old ([https://packages.ubuntu.com/search?keywords=context circa 2015]), so a better option is the ConTeXt Standalone.<br />
<br />
TeX Live and ConTeXt have been part of Ubuntu's main repositories since Ubuntu 7.10, so you can simply <br />
<br />
apt-get install context<br />
<br />
to install ConTeXt and its dependencies (LuaTeX is part of the [https://packages.ubuntu.com/search?keywords=texlive-binaries texlive-binaries] package).<br />
<br />
The dependencies pull in various PDF utilities which you will probably find useful, including <code>pdfcrop</code>.<br />
<br />
If you would like to use the [http://www.tug.org/texworks/ TeXworks] GUI-based TeX editing environment usually included with TeX Live CDs, it is available via<br />
<br />
apt-get install texworks<br />
<br />
and will appear under Applications, Science & Math.<br />
<br />
See also:<br />
* Setting up [[TeXworks]]<br />
* Setting up [[Scite]]<br />
<br />
=== Adding the system fonts ===<br />
<br />
The standard Ubuntu LuaTeX package does not scan any of your installed system fonts. Therefore you will want to set up the OSFONTDIR environment variable to point to all the font paths. For example:<br />
<br />
export OSFONTDIR=~/.fonts:/usr/share/fonts:/usr/share/texmf/fonts/opentype/:/opt/libreoffice/basis3.3/share/fonts/<br />
<br />
Once you have done that, run<br />
<br />
mtxrun --script fonts --reload<br />
<br />
If you have an error do this <br />
<br />
luatools --generate<br />
<br />
to scan all the font directories. Then run<br />
<br />
mtxrun --script fonts --list --all --pattern=*<br />
<br />
to list all the fonts LuaTeX now knows about. Finally, run<br />
<br />
context --reload<br />
<br />
to make sure ConTeXt's font cache is up to date.<br />
<br />
If you are using TeXworks, you need to make sure that OSFONTDIR is set in the environment TeXworks runs in, because ConTeXt may decide it needs to rescan fonts.<br />
<br />
== With ConTeXt Standalone – should work with all Ubuntu versions==<br />
<br />
Example of setting up [[ConTeXt Standalone]]:<br />
<br />
sudo mkdir /usr/local/context<br />
sudo chown yourusername /usr/local/context<br />
cd /usr/local/context<br />
wget http://minimals.contextgarden.net/setup/first-setup.sh<br />
sh first-setup.sh<br />
vi ~/.bashrc<br />
<br />
Add these three lines:<br />
<br />
export OSFONTDIR=~/.fonts:/usr/share/fonts <br />
export TEXROOT=/usr/local/context/tex <br />
export PATH=/usr/local/context/tex/texmf-linux-64/bin:/usr/local/context/bin:$PATH<br />
<br />
Note that the order of items in the PATH is significant. If you put /usr/local/context/bin in the path first, you will get an error at run time.<br />
<br />
Also, remember that you have to source ~/.bashrc after changing it, in order to have the changes take effect in your current shell. (Either that, or start a new shell.)<br />
<br />
===Installing third party modules in ConTeXt Standalone ===<br />
<br />
See here: [[ConTeXt_Standalone#Installing_third_party_modules|Installing third party modules]]<br />
<br />
===Updating ConTeXt Standalone===<br />
The update procedure is similar to [[ConTeXt_Standalone#Updating|the normal procedure]]. If you installed the ConTeXt Standalone with the commands from above, you can update to a new (beta) version like this:<br />
cd /usr/local/context<br />
wget http://minimals.contextgarden.net/setup/first-setup.sh<br />
./first-setup.sh --keep<br />
<br />
{{Installation navbox}}</div>Mæstrohttps://wiki.contextgarden.net/index.php?title=Gnuplot&diff=29648Gnuplot2020-07-13T23:56:41Z<p>Mæstro: lmtx example for gnuplot inclusion</p>
<hr />
<div>< [[Modules]] | [[Graphics]] | [[Math]] ><br />
<br />
http://www.gnuplot.info/figs/title2.png<br />
<br />
[http://www.gnuplot.info Gnuplot] is a portable command-line driven utility for function plotting for many platforms.<br />
<br />
To make the examples on this page work, you need Gnuplot 4.6.0 or later (or self-compiled binary).<br />
<br />
== Minimal Example ==<br />
<br />
<texcode><br />
\usemodule[gnuplot]<br />
<br />
% write a script for gnuplot<br />
\startGNUPLOTscript[sin]<br />
plot sin(x)<br />
\stopGNUPLOTscript<br />
<br />
% include the resulting graphic into the document<br />
\useGNUPLOTgraphic[sin]<br />
</texcode><br />
<br />
Calling gnuplot to create the graphic and postprocessing should happen automatically.<br />
<br />
== Requirements ==<br />
<br />
* '''[http://modules.contextgarden.net/gnuplot Gnuplot module]'''<br />
** in TeX Live you need to have <code>context-gnuplot</code> installed, in [[ConTeXt Standalone]] you can install it with <code>--modules=t-gnuplot</code> switch<br />
* '''Gnuplot has to be installed''' (and in your PATH)<br />
:On most Linux installations this is probably already the case. On Windows gnuplot.exe is usually also shipped and you need to make sure that it is in PATH. In case that the binary has a different name, you could create a file <code>gnuplot.bat</code> with something like:<br />
"C:\Program Files\gnuplot\bin\wgnupl32.exe" %*<br />
:(if that was the binary name) and put that file to a <i>"visible place"</i> (has to be found in PATH). Please note: if calling <code>gnuplot</code> from cmd works for you, there is no need to do anything extra.<br />
* '''[[Write18]]''' has to be enabled<br />
=== To use the ConTeXt terminal (recommended) ===<br />
==== Windows ====<br />
You can fetch binaries from [http://sourceforge.net/projects/gnuplot/files/gnuplot/ sourceforge (released versions)] or from [http://www.tatsuromatsuoka.com/gnuplot/Eng/winbin/ Tatsuro Matsuoka (latest cvs version)].<br />
==== Unix or Mac ====<br />
The easiest way is to use version 4.6.0 or later shipped by your distribution. If that version is too old, you need to compile your own.<br />
<br />
If you want to use the version from trunk:<br />
# unofficial; you can also use official cvs<br />
git clone git://github.com/gnuplot/gnuplot.git<br />
./prepare<br />
./configure<br />
make<br />
make install<br />
I use <code>./configure --prefix=$PWD/inst</code> to avoid cluttering the system and install gnuplot to my personal directory. You can use other flags to configure for a different choice of GUI terminals.<br />
<br />
If you want to use the released version, get it from [http://sourceforge.net/projects/gnuplot/files/gnuplot/ sourceforge] and do the same, just skip the <code>./prepare</code>.<br />
<br />
The latest version of context terminal is available at http://github.com/mojca/gnuplot/raw/master/term/context.trm.<br />
<br />
Feel free to contact [[User:Mojca Miklavec|Mojca]] in case of problems.<br />
<br />
== Creating stand-alone, whole-page plots ==<br />
<br />
Here's an example of how to make a stand-alone ConTeXt document with one plot per page:<br />
<br />
set term context standalone size 15cm,10cm header '\usetypescript[iwona]' font 'iwona,ss' 10dd<br />
set output 'example.tex'<br />
plot ...<br />
<br />
== More complex example ==<br />
<br />
<texcode><br />
\usemodule[gnuplot]<br />
<br />
\setupGNUPLOT[terminal=tikz,option=color] % terminal=mp if you only have an old gnuplot at hand<br />
<br />
% general settings for the whole document<br />
\startGNUPLOTinclusions<br />
<br />
# you may use TeX commands to format the titles and axes<br />
set title '\bf Trigonometry'<br />
set xlabel '$x$'<br />
set ylabel '$y$'<br />
<br />
# to prevent uneven numbering: will result in<br />
# (0.0, 0.5, 1.0, 1.5, ...) instead of<br />
# (0, 0.5, 1, 1.5, ...)<br />
set format y '%.1f'<br />
\stopGNUPLOTinclusions<br />
<br />
\startGNUPLOTscript[tan]<br />
plot tan(x) t '$\tan(x)$'<br />
\stopGNUPLOTscript<br />
<br />
\startGNUPLOTscript[sin]<br />
plot 4*sin(x)+x t '$4\sin(x)+x$', x t '$x$' lt 3<br />
\stopGNUPLOTscript<br />
<br />
\useGNUPLOTgraphic[tan]<br />
\useGNUPLOTgraphic[sin][width=10cm]<br />
</texcode><br />
<br />
== Example with externalfigure ==<br />
<br />
In [[LMTX]] we can use externalfigure for gnuplot files like this:<br />
<br />
m-gnuplot-demo.gp<br />
<texcode><br />
set format xy "$%g$"<br />
<br />
set title 'This is a plot of $y=\\sin(x)$'<br />
set xlabel 'This is the $x$ axis'<br />
set ylabel 'This is the $y$ axis'<br />
<br />
plot [0:6.28] [0:1] sin(x)<br />
</texcode><br />
<br />
Then including it in the .tex file with externalfigure and svg conversion:<br />
<br />
<texcode><br />
\usemodule[gnuplot]<br />
<br />
\starttext<br />
\externalfigure[m-gnuplot-demo.gp][conversion=svg,width=4cm]<br />
\stoptext<br />
</texcode><br />
<br />
== Using other terminals ==<br />
<br />
<i>(Needs a revision.)</i><br />
<br />
Gnuplot support output in different formats with, for example<br />
set terminal mp color solid<br />
will output a metapost document with colors and without dashed lines. After some appropriate preprocessing (with [[MPtoPDF]] for this particular case) this file can be included in PDF documents.<br />
<br />
You can specify the terminal with<br />
<texcode><br />
\setupGNUPLOT[terminal=mp,options=color solid]<br />
</texcode><br />
<br />
* <code>terminal=</code> is mandatory since that't the only way to tell ConTeXt how to preprocess the file.<br />
* <code>options=</code> is optional and is appended to the end of <code>set terminal [terminal name]</code>. You can also override it by saying<br />
<texcode><br />
\startGNUPLOTinclusions<br />
set terminal mp color solid<br />
\stopGNUPLOTinclusions<br />
</texcode><br />
But you have to be careful that you don't set any other terminal with <code>output=</code> then.<br />
<br />
<!-- Another way to specify it is to override the terminal setting --><br />
<br />
Currently supported terminals are (attention: links not from the latest documentation):<br />
* [http://www.gnuplot.info/docs/gnuplot.html#mp mp/metapost]: uses [[MPtoPDF]] to convert images to pdf, but the context terminal should replace it<br />
* [http://www.gnuplot.info/docs/gnuplot.html#postscript_ ps/postscript]: most advanced in the number of supported features<br />
* [http://www.gnuplot.info/docs_4.0/gnuplot.html#png_%28NEW%29 png (1)],[http://www.gnuplot.info/docs_4.2/gnuplot.html#x1-41500051.53 png (2)]: outputs bitmap images (no preprocessing needed)<br />
* [http://www.gnuplot.info/docs_4.0/gnuplot.html#pdf pdf (old)],[http://www.gnuplot.info/docs_4.2/gnuplot.html#x1-41300051.51 pdf (new)]: outputs PDF directly for (no preprocessing needed), but is usually not available in most binaries of gnuplot<br />
* '''context''':<br />
<br />
The current gnuplot-documentation can be downloaded [http://www.gnuplot.info/docs_4.6/gnuplot.pdf here].<br />
<br />
== History ==<br />
<br />
I ([[User:Mojca Miklavec|Mojca Miklavec]]) probably mentioned long time ago that I would like to have (or write?) support for Gnuplot inside ConTeXt, but I had no knowledge to do that. Peter Münster posted the very first module for gnuplut support on the mailing list [http://article.gmane.org/gmane.comp.tex.context/24884], but that version only worked with bash. In the days to follow Hans Hagen has written a new module (based on my numerous "possible and impossible" requests) and Taco additionally provided some bugfixes and minor changes.<br />
<br />
The module provides an option to select the most appropriate/suitable driver according to the user's choice (metapost, png, pdf, postscript were the firs ones to be supported). Hans was wondering why there was no '''context terminal'''. I took over it's development, the code is almost finished by now, but I guess that Hans now regrets that question already.<br />
<br />
He had to invest quite some time into fixing buggy inclusion of text into graphics using <code>textext</code> (if nothing else, he had to read and reply to all the mails [complaints] that me and Taco sent him), just to lead to the conclusion that <code>textext</code> was useless for graphics produced by Gnuplot: too slow and TeX ran out of memory after 10 minutes while processing approximately the 13<sup>th</sup> plot. After that the new marvellous <code>\sometxt</code> command was born.<br />
<br />
I'm currently sticking tiny pieces together in the way I want the module to work. Hans could probably finish the same work that costs me a few days in a few minutes, but after dropping me a bone, he decided to leave me the joy of diving into ConTeXt internals and to let me figure out how to program in ConTeXt by myself. So I still keep spamming the mailing list with numerous questions and both Taco and Hans - without whom implementing the module would be impossible - keep answering.<br />
<br />
== Old wiki pages ==<br />
* 2006 - [[Gnuplot Development]]<br />
<br />
<br />
== Alternatives for Function Plotting ==<br />
<br />
* in [[MetaPost]]<br />
** [[source:m-graph.tex|m-graph]] Module (see [http://cm.bell-labs.com/who/hobby/cstr_164.pdf Drawing Graphs with MetaPost] by John D. Hobby)<br />
** functions in [[MetaFun - MetaPost in ConTeXt|MetaFun]], see [[manual:metafun-s.pdf|metafun-s.pdf]], section 9.3<br />
* others<br />
** [http://pyx.sourceforge.net/ PyX] - graph drawing through python interface with TeX typesetting & PostScript capabilities<br />
** [http://theory.kitp.ucsb.edu/~paxton/tioga.html Tioga] - creating figures and plots using Ruby, PDF, and TeX<br />
** [http://comp.uark.edu/~luecking/tex/mfpic.html mfpic] - a scheme for producing pictures from LaTeX commands. The LaTeX commands generate a input file to be processed by Metapost.<br />
** [http://matplotlib.sourceforge.net matplotlib] - a Matlab-inspired Python based plotting tool which incorporates many features, including the use of TeX in labels, titles etc.<br />
** [http://tug.ctan.org/tex-archive/graphics/pgf/contrib/pgfplots/ pgfplots] - a TikZ-based LaTeX package for drawing graphs<br />
<br />
=== Other links ===<br />
* [http://tug.ctan.org/tex-archive/macros/latex/contrib/exceltex/ exceltex] - an interesting LaTeX package to get data from Excel into LaTeX<br />
<br />
[[Image:Slo Ministry of Higher Education Science and Technology.jpg]]<br />
<br />
[[Category:Modules]]<br />
[[Category:Graphics]]<br />
[[Category:Sciences]]</div>Mæstrohttps://wiki.contextgarden.net/index.php?title=Command/definesynonyms&diff=25307Command/definesynonyms2019-12-08T02:54:41Z<p>Mæstro: /* Description */ update for mkiv</p>
<hr />
<div>{{Reference<br />
|name=definesynonyms<br />
|attributes=<br />
}}<br />
<br />
== [[Help:Reference|Syntax]] ==<br />
<table cellspacing="4" cellpadding="2" class="cmd"><br />
<tr><br />
<td colspan="2" class="cmd">\definesynonyms<span class="first" >[...]</span><span class="second" >[...]</span><span class="third" >[...]</span><span class="first" style="color:red;">[...]</span></td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[...]</td><br />
<td>singular </td><br />
</tr><br />
<tr valign="top" class="second"><br />
<td class="cmd">[...]</td><br />
<td>plural </td><br />
</tr><br />
<tr valign="top" class="third"><br />
<td class="cmd">[...]</td><br />
<td>command </td><br />
</tr><br />
<tr valign="top" class="first"><br />
<td class="cmd">[...]</td><br />
<td>command </td><br />
</tr><br />
</table><br />
<br />
<br />
== Description == <br />
<br />
The first bracket pair contains the singular form of the synonym, and the second contains<br />
the plural form. The third bracket pair contains a command.<br />
<br />
For example the command \abbreviation is defined by:<br />
<br />
<texcode><br />
\definesynonyms[abbreviation][abbreviations][\infull]<br />
\setupsynonyms[abbreviation][textstyle=cap]<br />
</texcode><br />
<br />
Now the command \abbreviation is available and can be used to state your abbreviations:<br />
<br />
<texcode><br />
\abbreviation{ANWB}{Dutch Automobile Association}<br />
\abbreviation{VVV}{Bureau of Tourist Information}<br />
\abbreviation{NS}{Dutch Railways}<br />
</texcode><br />
<br />
If you would type:<br />
<br />
<texcode><br />
The Dutch \VVV\ (\infull{VVV}) can provide you with the tourist<br />
information on Hasselt.<br />
</texcode><br />
<br />
You would obtain something like this:<br />
<br />
<pre><br />
The Dutch VVV (Bureau of Tourist Information) can provide you with the tourist information<br />
on Hasselt.<br />
</pre><br />
<br />
If you want to put a list of the abbreviations used in your document you can type:<br />
<br />
<texcode><br />
\subject{Abbreviations}<br />
\placelistofabbreviations<br />
</texcode><br />
<br />
or with automatic chapter<br />
<br />
<texcode><br />
\completelistofabbreviations % only ones used in the text<br />
\completelistofabbreviations[criterium=all] % this prints even the unused<br />
</texcode><br />
<br />
== Example ==<br />
<context source="yes" text="looks like this:"> <br />
\definesynonyms[test][tests][\infull]<br />
<br />
\setupsynonyms[test][criterium=all]<br />
<br />
\test{ITU}{International Telecommunication Union}<br />
\test{MID}{Maritime Identification Digit}<br />
\test{Ch}{Switzerland}<br />
<br />
\starttext<br />
<br />
The \ITU\ is an organisation in \infull{Ch}<br />
<br />
\subject{Short is nice}<br />
\placelistoftests<br />
<br />
\stoptext<br />
</context><br />
<br />
== Hint ==<br />
<texcode><br />
\abbreviation{\alpha}{Angle of something}<br />
</texcode><br />
<br />
This will '''fail''' because to create a macro \alpha which expands to \alpha <br />
Use uppercase letter to prevent this, when your font contains greek you can also use a text alpha,<br />
<br />
<context source=yes><br />
\abbreviation[ALPHA]{\alpha}{Angle of something}<br />
\abbreviation[PLANCK]{\hbar}{planckconstant}<br />
\starttext<br />
\ALPHA\ and \PLANCK<br />
\stoptext<br />
</context><br />
<br />
== See also ==<br />
<!-- something like {{cmd|goto}} --><br />
<br />
== Help from ConTeXt-Mailinglist/Forum ==<br />
All issues with:<br />
{{Forum|{{SUBPAGENAME}}}}<br />
<br />
[[Category:Commands|definesynonyms]]</div>Mæstrohttps://wiki.contextgarden.net/index.php?title=Using_Graphics&diff=23809Using Graphics2018-06-25T00:33:07Z<p>Mæstro: update for the latest beta (pdfe supports png streams as well now)</p>
<hr />
<div>< [[Graphics]] | [[Combinations]] | [[File Formats|Supported Media File Formats]] | [[Including pages from PDF documents]] | [[Animation]] | [[Downsampling]] ><br />
<br />
= Usage =<br />
<br />
The simplest way to insert an image is to use:<br />
<br />
<texcode>\externalfigure[logo.pdf]</texcode><br />
<br />
This command places the PDF image <tt>logo.pdf</tt> in a {{cmd|vbox}}; the width and height of the image are equal to the natural dimensions of the image.<br />
<br />
To set the width of the image to a specific size, say <tt>1cm</tt>, use:<br />
<br />
<texcode>\externalfigure[logo.pdf][width=1cm]</texcode><br />
<br />
Similarly, to set the height of the image to a specific size, say <tt>2cm</tt>, use:<br />
<br />
<texcode>\externalfigure[logo.pdf][height=2cm]</texcode><br />
<br />
If only the <tt>width</tt> or <tt>height</tt> of the image is specified, the other dimension is scaled appropriately to keep the aspect ratio.<br />
<br />
To include a specific page, say page 5, of a multi-page PDF file, use:<br />
<br />
<texcode>\externalfigure[logo.pdf][page=5]</texcode><br />
<br />
These four variations cover the most common use cases.<br />
<br />
== File Formats ==<br />
<br />
ConTeXt supports the image formats enumerated below. The image format is determined from the file extension (case insensitive).<br />
<br />
* '''PDF''': File extension <tt>.pdf</tt><br />
* '''MPS''' (MetaPost output): File extension <tt>.mps</tt> or <tt>.&lt;digits&gt;</tt><br />
* '''JPEG''': File extension <tt>.jpg</tt> or <tt>.jpeg</tt><br />
* '''PNG''': File extension <tt>.png</tt><br />
* '''JPEG 2000''': File extension <tt>.jp2</tt><br />
* '''JBIG''' or '''JBIG2''': File extension <tt>.jbig</tt>, <tt>.jbig2</tt>, or <tt>.jb2</tt><br />
<br />
== Image Conversion ==<br />
<br />
The image file formats listed in the previous section are the ones that may be embedded directly in a PDF. ConTeXt also supports a few other formats that are first converted to PDF using an external program. Of course, for such a conversion to work, the corresponding converter must be in the <tt>PATH</tt>.<br />
<br />
<table><br />
<tr class="odd"><br />
<td align="left">Format</td><br />
<td align="left">Extension</td><br />
<td align="left">Converter</td><br />
</tr><br />
<tr class="even"><br />
<td align="left"><strong>SVG</strong></td><br />
<td align="left"><code>.svg</code>, <code>.svgz</code></td><br />
<td align="left"><code>inkscape</code></td><br />
</tr><br />
<tr class="odd"><br />
<td align="left"><strong>EPS</strong></td><br />
<td align="left"><code>.eps</code>, <code>.ai</code></td><br />
<td align="left"><code>gs</code> (or <code>gswin32c</code> on Windows) from Ghostscript</td><br />
</tr><br />
<tr class="even"><br />
<td align="left"><strong>GIF</strong></td><br />
<td align="left"><code>.gif</code></td><br />
<td align="left"><code>gm</code> from GraphicsMagick</td><br />
</tr><br />
<tr class="odd"><br />
<td align="left"><strong>TIFF</strong></td><br />
<td align="left"><code>.tiff</code></td><br />
<td align="left"><code>gm</code> from GraphicsMagick</td><br />
</tr><br />
</table><br />
<br />
The conversion generates a PDF file with prefix <tt>m_k_i_v_</tt> and a suffix <tt>.pdf</tt> added to the name of the original file. The result is cached, and the conversion is rerun if the timestamp of the original file is newer than that of the converted file.<br />
<br />
== Interaction ==<br />
<br />
By default, the interactive elements of the included PDF file are discarded. To enable the interactive elements of the included PDF file, use<br />
<texcode>\externalfigure[filename.pdf][interaction=yes]</texcode><br />
<br />
== Image Directory ==<br />
<br />
By default, ConTeXt searches an image in the current directory, the parent directory, and the grand-parent directory.<br />
<br />
To search for images in other directories, for example a <tt>./images</tt> subdirectory and <tt>/home/user/images</tt>, use:<br />
<br />
<texcode>\setupexternalfigures[directory={images, /home/user/images}]</texcode><br />
<br />
Note: always use forward slashes (`/`) in path names, regardless of operating system.<br />
<br />
The default search order is: the current directory, the parent directory, the grand-parent directory, and then the paths specified by the <tt>directory</tt> key. To restrict image search only to the paths specified by the <tt>directory</tt> key, use:<br />
<br />
<texcode>\setupexternalfigures[location=global]</texcode><br />
<br />
To restore the default search behavior, use:<br />
<br />
<texcode>\setupexternalfigures[location={local,global}]</texcode><br />
<br />
The ConTeXt distribution includes three sample images: <tt>cow.pdf</tt>, <tt>mill.png</tt>, and <tt>hacker.jpg</tt>, that are useful when creating minimum working examples to illustrate a bug on the mailing list. These images are locating in the <tt>TEXMF</tt> directory. To add the <tt>TEXMF</tt> directory to the image search path, use:<br />
<br />
<texcode>\setupexternalfigures[location={local,global,default}]</texcode><br />
<br />
The above alternative adds the ''entire'' <tt>TEXMF</tt> directory to the search path, ''including the'' <tt>doc/</tt> ''directory!'' Therefore, one needs to be extremely careful when using this option. In fact, I would advise not using <tt>location=default</tt> except for illustrative minimal working examples.<br />
<br />
== Remote Images ==<br />
<br />
The {{cmd|externalfigure}} command supports reading files from web servers, for example:<br />
<br />
<texcode>\externalfigure[http://tug.org/images/logobw.jpg]</texcode><br />
When a document containing a remote file is compiled for the first time, the remote file is downloaded from the server and stored in the LuaTeX cache directory. This cached file is used during subsequent runs.<br />
<br />
Normally, the remote image is downloaded again if the image in the cache is older than 1~day. To change this threshold to, for example, 2<sub>minutes (120</sub>seconds), either add<br />
<br />
<texcode>\enabledirectives[schemes.threshold=120]</texcode><br />
<br />
in the ConTeXt file, or compile the ConTeXt file using the command<br />
<br />
<pre>context --directives=schemes.threshold=120 <em>filename</em></pre><br />
The variable <tt>schemes.threshold</tt> is global, so changing its value affects all other macros like <tt>\input</tt>, <tt>\usemodule</tt>, <tt>\component</tt>, etc. that load remote files.<br />
<br />
=== HTTP Proxy ===<br />
<br />
To use an http proxy for fetching images, the http variable ([http://w3.impa.br/~diego/software/luasocket/http.html LuaSocket]) has to be set up as follows:<br />
<br />
<texcode><br />
\ctxlua{http = require("socket.http"); http.PROXY = "http://proxy.example.com:3128"}<br />
</texcode><br />
<br />
Replace `http://proxy.example.com:3128` with the proxy URL.<br />
<br />
To disable the proxy again:<br />
<br />
<texcode><br />
\ctxlua{http = require("socket.http"); http.PROXY = nil}<br />
</texcode><br />
<br />
=== HTTPS ===<br />
<br />
For self-signed certificates retrieved over HTTPS, the `curl` command requires a flag to retrieve insecure files, which is not enabled by default. Open `tex/texmf-context/tex/context/base/mkiv/data-sch.lua` to find:<br />
<br />
<pre><br />
local function runcurl(name,cachename) -- we use sockets instead or the curl library when possible<br />
local command = "curl --silent --create-dirs --output " .. cachename .. " " .. name<br />
os.spawn(command)<br />
end<br />
</pre><br />
<br />
Insert the `-k` or `--insecure` option:<br />
<br />
<pre><br />
local command = "curl --insecure --silent --create-dirs --output " .. cachename .. " " .. name<br />
</pre><br />
<br />
== Inline Images ==<br />
<br />
Embedding inline images via base64 encoding using the memstream function (supports pdf and png streams):<br />
<br />
<texcode><br />
\startluacode<br />
local cow = mime.unb64("JVBERi0xLjQKJcfsj6IKNSAwIG9iago8PC9MZW5ndGggNiAwIFIvRmlsdGVyIC9GbGF0ZURlY29kZT4+CnN0cmVhbQp4nJWayY40SW6E7/UUcRaQIafvfp6bAAkY9SM0oHXmMBAgvb7sM0ZmVf86CYNB/+HpC500Ghevv13ljqvwv+e/v//16+//eV3/+l9f8y4nRlz/8xVx99XW9Y9fcf2D/v8f+v+/a9q5/vSb/vnbn/7p629a+oq79L639jpjRKzcmC1fsUe927xaO3fRLwydsu/Q0C7afmj5Pv3WMb32+6zGgP61rz77Xdu4fv/KkWjXiHH3xpp12r3ONeq+W3QG1r7G6Pc8yyvmOHev19LBbXtFb/fo1zkan6GBqS3qFTWaBnLNLLfmRuvnPocpq96jXdFHu8/0ms4mMYaEP160usSMK9bUTZnS9l32VUurjGuC9LjWVWvM+1ky1t3qVZumxGZKPVftTb/zNbclraPW+/TnNkP31NAKycwh6+58Hx3C7cYJtqqzzHvkKT3qXXTKlGBoqOqnsr6/S5RbuqzzTKTRkmOl9s/Q68x1j6U9FvpfGqiyY2kMLG6nRbtqbkiWNePeUtIOWUE214AMer2WFLKbLrjWfNasVm5J+hl6zaLtuoTZq3PBga4O32PfVsHQLq3phrsvIVRThu2m7wnCXqPrWqhtozYviXPPxSblcOOu2+SmghFLescOEn3LEMvHdB0jIDKHW7Co3Xsh/T73lmgd3Pp6Sygx2LqwtiZa2fMWDr93WTJl0f16FYAWSpIBnzWyXGGKzIEs0l6UwYwC1L+lNVpmrnlv23/dtg8brOFKGH1JK8W+AwxCuKpy5RRuAFg2lpJ9RYEooqZRE3BjCkbrY+bXtJPo0nNvb7Kk0mBC6Q/elpwnNrIU3UwGOlJ/w+540QE8cpqGkScu40VngidwK2Bx0K64oFHarAYQsrxLDnASiDueM43KHtJL+CThSgNtYryei7Z113ST8Rl4Sc0iIXtH3JMB2fDYHXIPLanS4a55Z+lS311MhxKkZZirBmv4Xo+y8bGDKk0u0lMtIePF9yZx0KzPkQsnV22Jhubgn2LekQibg5YcUt+CdtTvCaxpwtHmhtAa++oebaADMd7afxiIe9jtQi4TFcXJndlX/6kVWUSjnQHEPzZHTbfbYEVcaKaBncCvDx44iClBbqcb9/1hK9Hn3IwcCEjHbs1kDzFOQddvLUGjy/fRPaRbiTa0jaR9tW7KrWOOdAfBeLPr0MyHEbSbd9F5gH9ItRWodHkdokGkC2rqeyC8Fs2FTRkS8rpIYWr/jTfgFpDCnFuIbvBxYGUWwUbBkNSCx4xVHM4+i0ZDk2gBJ7Oyu6TqrBG1jZ+XbiMJKypW1bdESsCBmUAJTYiA1hcUcCRtm9DgS9cYY7fPHhjoe6hZCz8Gwur/HpBEY+aFdHcu/Z6j7eaYnuOg8d+wp/jIwtRBeH5NQwGB8VGrV/7tXYgkNglqho/qGdIHBKWZU2hphSAgLQgSBwhW+VC3Sb6HdAOEkfHaAlKhoAbmZIhqSwdy+tZLTgsawNrCZeLxhxrJPgHZKHZX2eh90NsCcsYbiMG8lSnEPam7K/hsJQAVMkg/A0ob5T1DMr02IYxWcS9wEREKkwirGOIwOs5J943prEVrTiL1Le3YkID0hMOtmYwrW+sADaWTjI7XdAYWBw0RWCNrKMA8A1zl0ozIZxw1JQLyF4iRgxsRcDLQH9MP2WhgkUK+spCF0OuBINmR+LCPblgE7p12/QyRXiDM4WZKhI7IXonQi3RLg1fs7ZwGkIkuuzTidIdbi5G16GhA/tTwPQ7QnUVVmwEjc9/CWMAuwsSH/qPJNmV9ZxOhOC/LeI0i8tFVouoGJJBjO7PR91Ie+dFCKKPid8y6nODIBTep1qsXud5hC1ICydoKGcr5DBinOqazqAep5Us5ggZY1ADJzwEFhtGT1zYh4j3yYrvugedk1goJ+jZrkCQKc/oug4WKSwzsK8AXp76jRYSg2ZLXhS85t4YU3ZxBTxQrUcFO4A2H4KmBIkIf6Q31sVjBmbiOPH4pt5MrNeteCcI9OYg01Qc1CdVYo4zYa5rMNRTWNBCQ2asNu5/WOAtmzcbL1veUHoqWvgAIJ/VpBl7gsrX9TKjeQ59ULmCAY2TDAKhFFDPTGwZiMlR9x7+A25EQVLLrfcgY+u7fd1ziMmVGzBgPNsh1m9xXipk2K0lQIM1noKAY3aDIuiVxO1n0Gfl4VeBmeBnZS+VbN5rpiYg5WKNAsOGjxrYcLEehZhHpSFrO6QWvMIdxo8UQtQ45CAed713kgWI5D7QHhLHwBw5X5jRccCwHNHHNU9g8oDoKFlKpFz2QOWtYQxQUjvTnkMaxC7WV4H4WVUKWUI1soF1H+NiEcfmgFN+uLanGrt+8rDChTHX+zH82JEVaW2UUlSDXFpEG8iqA6/7nUpi4d0/HkmmLfjtks1iyKdsYislHaYFYg7SWf0gWREjTjnJcRIhoMTYIAU8C/abSgZIkZ9fRB7UKOSIgOayQvOU45AkEH2dh41pk1qQDR3joIonVSGLQTNEq3XYeIfwpx+p0QUoKd0hOok3HyC4CUDbyPVDt1/tRp3yGGCajU7O1SqC+iCNOFJ8lZAcrMplsSX6USyITm23fFA0CTq/OJilvyVGVPGdkDHQ1L0pHaB4jGc7mJvwmKMh0oeXc0qmkkrrAq6UDV+STeChIwdOZxA7X166Snvo6K24RGckTdTBoIReTxIalUwqyZzHReqgNkGmO/nOyOUDuRY7kRO7TYlDOKksmH9qa1IoC3fCi5naB6tR7U4r82pf4/evfvn67/vyVnYu4/vNLyYj8SXGHwHb9Vd9UHe9v0Tj/ieZaWl/Nc2dmzVXqI9qQqFaoC1IKUm5q+vS68DzwKmbwhuQkR5ae1G/PjsRbpKtUlAP2EKD0KwVUsiNJaEBoI6te54Em5MnpTRfvl4MyWbxKYZ2ylVs3q0rIovrcqtA2SlX9rUvi4Tm9CTT6JARi9iq9ff8qZNyQE9Agt6G9EUWZwcypCCRCFsGSCiFHKMYiP+Gjo6+cWahyVJwo4rErCwSn4i+5+SZjKHm7IGUAVOIp+a8kJOdoXEJ3nQk4ltTmg8V0NXXda/46PJdqRSuXOwMCV1wG8E6rWFY6DtQb1bqmV4A1f6IC1IgmO/petCOEE2VEyxJC/nvlmWFR9sCY8oJim8b2lkEuZa/wTUkNBbOzSYJqljpKzRYru3xTmudCCnsLvRaRMvJYSGbSmAJ7vlcZtsBGk6XZWqovfMs4y5qExDmdiJso4gu+JXZ15/X6fiztSetYGoLSRMEk/04SfKs1iu1+Tl623U5/+DfBLnY2QJTzeZdo3oWG1s5oWZ+ZxUUqOypTgcabYafimCsSLPw5FDWb+ToxqguC4S0wAGmpVyHuQip+D3qETcSM9WL41Elnx79VRJpS6WTn1hBg0XrLnWHmKQ6M3Iq6tl1kt9O5lo10qMzsW8+AfHjbWUU3uv2wsggYOoAmCjOLbBFv/qDq8q/SL2pIW9R9PHPY3s4e2efc/aO1IgeqbxsyN4wodw/e+xDgrZbnc8735SSndFwsvI5BafszuVqlD0v8/gUGUdFpSSQieBuD2Mt2Z6QK3dn19rDuFvBZb6R7W5numJyswGL/1dyRBONjpzMFLyNz0rxN4cIhLRWvBVKDZzxEtTaLe7X1tJcmfV909TTfe4RkzjPwpJNoSHFoNmuBCmN0TceoX+MRIiDWeRFbLWqnz6PJvZT3AH7casoaJL30xtrzScqbfObDRSiQzTTE63u1btDojrn/bBJbiCiLU7/Q2kGwUaq3fn4aTlJ8TnenOsgFprcdyhzTVHzsYqZWWptXmko2cMXEu1zX4DppdMXmkcSu4+wtazv6VAdCQgrdqNShPkfe7/l1mY4qxLZgbmV+eSZejd5oRFhvRBclRVKjN6IlHVd/TO23Ayw+aCf49wJpDwIqv+P15zKZIPMuw9NXedavRfzcfHJYhooPABdJO3jqGS5F3Fhljf42Yq5OtEVz8rT3s3czxHdO3SXj9zA5rjLfqh5W8YbR5Pb4vxRuzg5HPH1FEnTsnoHQ8SXIl59aOqvDeH/BTL2bmTsOEy3jzeoleeRkQEo4C0zre224eYYmSsbZk0HT9AjT8eUyOvA7At00Yf8h7P3+9S9/9/98GGrFma1vW6+fI5LTXcNWXFVX2nq/DJSn3So9FDof1dDNBubTsxXmyQ4PuTqtuyllZBf00HfzEHyptNOpPW0TIjG9VFKyTk/nx0nahJZK5dnB6a1LSjI6GkPTA42cuRJFskYRPUvVTnDh95ccUg5NvkH/XgcBxLK+G34UFxKq0QdSZeVHqINNJ102us4MDKRkAPt60WcO+Zuq4tdZWW7WSlVoxfRMiWlAZMtVgHMqW7cbZC/3NWhbySh5o1bynYoEvdYsFGbWDrAAjSD4xWqgwbHbj6epKlc4z3tX+CqVXoY2/oufwNKWqsby0QtXm05tx/MKdvyPyuvEYwNa5s0N35JPa1iQhwA6bm6uE915RJnih6e4VP0PTT1dcOqjQStAgKh+z/kFieR0nPQ84lE1heE5p2uuIMh0FzzimgVBTj9fvtzFKmRotK5T4qH19B/wFks8wo+flaTZNfVwv6sWaPHpntdEmps470Jxk8Ftb/ZyXws9BM3mtyOQWDgJ95sqP9G2lEZoMAJFMgZl11LzG5zSonuD7i8Kv5VOVCXFcEu10NxBCeDMVR/kDe1WOhQd98JIJt79PGXSYKL62RDDg7OepSJFmOdws/Xk5r4hSSBtpYU9s4Qr2pB9SCB9aTQ24DgKKd4dCF90yr4XbT+camiLAEHnrulfsueglfXa7qjDuTT8spVMqNFkMeH0ScsmErfxErDzhUB6hYnXu0s5UR3S8aJBKzy6y+AAifRDF4+Qw0GBqp+20qCRYD5umFxT6GCQ2oXbkq8TFPPuDVau6vcxYeDUzxCqIhiRSfKwDRiGlRh+3HmaMEmU70bYy4krb9S0jqcR1LJYBxXxWGm5AfZplX0UHk9f+A0QmabRnkoMNVupTPeaXkC/j/HZ+EVBuxHv+6RN3jC5grNEaBEYU5tIblqcbw4MvCK7ldtvI84ZD+2NF8lkby37Xphg8/gg3B7dsSdbUeQPpd2n0UfiPZtOEy0h+TLNJ+FXIuzjuhugoPLd/AcCHJCLaBaJVA9msrykmeI8et8nWfvNyVxlO4QcOmwXj+PFaH30sCgA3nHoGVr5bPV/20iHxza6Llwxu6kJBBUwFOrZYMtWNu8S3Z7e6LNmzrSfd7/WzSA9eG31nMGZV2t0vdxIWtlVUfVZ+xtFxQ9Ygqmp69mEp4V5POBXgYtexN4P2eYfU/CYS4dMAy3DjizcDaJ38+mZ4UU7m010Q/23HLTp5JyO2H7K9MNG/KH7FHYvHbdKdp+m63n5wHJk2BgNnlVIe5rkxRyMtwEcuk05QDTJPxGZ1krlbxCe6LHo4K0fc/bDmvRVzJK7Wwt06p7u09FBEqJR/hUOoiXQU/3LPrvdFb0g/5hPD7T64c39hbB0w0GTthO9BP5IhCAv/S+3NfNKlHrkedvKfYIo2ff0ozCdh95+wjt4liFTpQ5PvFDAgkwFcGOBh474QNlQIK3GS+Q2tPDDT/DUTMUda4Jhc9+/8Pb1dPsi46PiV5IOz2B2c23jTjUVyHZu2x6+cwAnNMgh3AKXIV3b1ppPRp/vfOrJrCD/SAfW81sHhA05N79V+894CrxidNZnUW5DfDatrkjKnE4OnX5sIqn7j08aI9STH6maGU/A31ZlUJk6Q/0lbXh3Ff/89b/apSg4ZW5kc3RyZWFtCmVuZG9iago2IDAgb2JqCjQzMjEKZW5kb2JqCjQgMCBvYmoKPDwvVHlwZS9QYWdlL01lZGlhQm94IFswIDAgMjc1IDIwMF0KL1BhcmVudCAzIDAgUgovUmVzb3VyY2VzPDwvUHJvY1NldFsvUERGXQovQ29sb3JTcGFjZSAxMCAwIFIKL0V4dEdTdGF0ZSAxMSAwIFIKPj4KL0NvbnRlbnRzIDUgMCBSCj4+CmVuZG9iagozIDAgb2JqCjw8IC9UeXBlIC9QYWdlcyAvS2lkcyBbCjQgMCBSCl0gL0NvdW50IDEKPj4KZW5kb2JqCjEgMCBvYmoKPDwvVHlwZSAvQ2F0YWxvZyAvUGFnZXMgMyAwIFIKPj4KZW5kb2JqCjcgMCBvYmoKPDwvVHlwZS9FeHRHU3RhdGUKL09QTSAxPj5lbmRvYmoKOSAwIG9iagpbL1NlcGFyYXRpb24KL0JsYWNrCi9EZXZpY2VDTVlLCjggMCBSXWVuZG9iagoxMCAwIG9iago8PC9SOQo5IDAgUj4+CmVuZG9iagoxMSAwIG9iago8PC9SNwo3IDAgUj4+CmVuZG9iago4IDAgb2JqCjw8L0ZpbHRlci9GbGF0ZURlY29kZQovRnVuY3Rpb25UeXBlIDQKL0RvbWFpblswCjFdCi9SYW5nZVswCjEKMAoxCjAKMQowCjFdL0xlbmd0aCAyOT4+c3RyZWFtCnicq04pLVAwUMgtzVFIrUjOUMDPNQQzawHfFRGFCmVuZHN0cmVhbQplbmRvYmoKMiAwIG9iago8PC9Qcm9kdWNlcihBRlBMIEdob3N0c2NyaXB0IDguNTIpCi9DcmVhdGlvbkRhdGUoRDoyMDA2MDUxNTEyMjA1OSkKL01vZERhdGUoRDoyMDA2MDUxNTEyMjA1OSkKL0NyZWF0b3IoQ29yZWxEUkFXISkKL1RpdGxlKENPVy5FUFMpPj5lbmRvYmoKeHJlZgowIDEyCjAwMDAwMDAwMDAgNjU1MzUgZiAKMDAwMDAwNDYzNiAwMDAwMCBuIAowMDAwMDA0OTg2IDAwMDAwIG4gCjAwMDAwMDQ1NzcgMDAwMDAgbiAKMDAwMDAwNDQyNiAwMDAwMCBuIAowMDAwMDAwMDE1IDAwMDAwIG4gCjAwMDAwMDQ0MDYgMDAwMDAgbiAKMDAwMDAwNDY4NCAwMDAwMCBuIAowMDAwMDA0ODM4IDAwMDAwIG4gCjAwMDAwMDQ3MjUgMDAwMDAgbiAKMDAwMDAwNDc3OCAwMDAwMCBuIAowMDAwMDA0ODA4IDAwMDAwIG4gCnRyYWlsZXIKPDwgL1NpemUgMTIgL1Jvb3QgMSAwIFIgL0luZm8gMiAwIFIKL0lEIFs8ODE0NjQ5NTc3Qzg3MTE1QzRDQzBDQjg0QkU3RTQ1MEY+PDgxNDY0OTU3N0M4NzExNUM0Q0MwQ0I4NEJFN0U0NTBGPl0KPj4Kc3RhcnR4cmVmCjUxMzMKJSVFT0YK")<br />
figures.setmemstream("inline",cow)<br />
context.externalfigure({"memstream:///inline"})<br />
\stopluacode<br />
</texcode><br />
<br />
= Transformations =<br />
<br />
== Image Scaling ==<br />
<br />
To scale an image use the <tt>scale</tt> key: <tt>scale=1000</tt> corresponds to the original dimensions of the image, <tt>scale=500</tt> scales the image to 50% of the original size, <tt>scale=1500</tt> scales the images to 150% of the original size, and so on. For example:<br />
<br />
<texcode>\externalfigure[logo.pdf][scale=500]</texcode><br />
<br />
Use <tt>\setupexternalfigures</tt> to set the scale of all images. For example, to scale all images to be twice their original size, use:<br />
<br />
<texcode>\setupexternalfigures[scale=2000]</texcode><br />
<br />
If either <tt>width</tt> or <tt>height</tt> is specified, then the <tt>scale</tt> key has no effect.<br />
<br />
In addition, the <tt>xscale</tt> and <tt>yscale</tt> keys scale the image in only one dimension. For example:<br />
<br />
<texcode>\externalfigure[logo.pdf][xscale=500]<br />
\externalfigure[logo.pdf][yscale=500]</texcode><br />
<br />
Scaling changes the visible size of a picture, but not the data or file size. If you want to reduce your file size by decreasing image resolution, see [[Downsampling]].<br />
<br />
== Image Dimension Restriction ==<br />
<br />
ConTeXt can limit included images to particular dimensions. For example, to ensure that an included image is not more than <tt>0.2\textwidth</tt>:<br />
<br />
<texcode>\externalfigure[logo.pdf][maxwidth=0.2\textwidth]</texcode><br />
<br />
If <tt>maxwidth</tt> is specified and the width of the image is less than <tt>maxwidth</tt>, then the image is not scaled; if the width of the image is greater than <tt>maxwidth</tt>, then the width is restricted to <tt>maxwidth</tt> and the height is scaled appropriately to maintain the original aspect ratio.<br />
<br />
The option <tt>maxheight</tt> is analogous to <tt>maxwidth</tt>, for checking the height of the image.<br />
<br />
For example, to ensure that figures do not overflow the text~area, one may set:<br />
<br />
<texcode>\setupexternalfigures<br />
[maxwidth=\textwidth,<br />
maxheight=0.8\textheight]</texcode><br />
<br />
== Image Rotation ==<br />
<br />
Rotate included images by 90°, 180°, or 270° using the <tt>orientation</tt> key. For example:<br />
<br />
<texcode>\externalfigure[logo.pdf][orientation=90]</texcode><br />
<br />
To rotate by an arbitrary angle, use the {{cmd|rotate}} command. For example:<br />
<br />
<texcode>\rotate[rotation=45]{\externalfigure[logo.pdf]}</texcode><br />
<br />
== Image Mirroring ==<br />
<br />
To mirror (flip) an image, use the generic {{cmd|mirror}} command. For example, to mirror horizontally:<br />
<br />
<texcode>\mirror{\externalfigure[logo.pdf]}</texcode><br />
<br />
To mirror vertically, first rotate the image by 180° and then mirror it:<br />
<br />
<texcode>\mirror{\externalfigure[logo.pdf][orientation=180]}</texcode><br />
<br />
== Image Clipping ==<br />
<br />
Clip an image using the generic {{cmd|clip}} command. For example, to clip the original image to a <tt>1cm x 2cm</tt> rectangle at an offset of <tt>(3mm,5mm)</tt> from the top left corner:<br />
<br />
<texcode>\clip[width=1cm, height=2cm, hoffset=3mm, voffset=5mm]<br />
{\externalfigure[logo.pdf]}</texcode><br />
<br />
As another example, this cuts the image into a <tt>3x3</tt> pieces and then outputs the <tt>(2,2)</tt> piece:<br />
<br />
<texcode>\clip[nx=3,ny=3,x=2,y=2]<br />
{\externalfigure[logo.pdf]}</texcode><br />
<br />
= Troubleshooting =<br />
<br />
This section describes various tips for discovering problems with embedded images.<br />
<br />
== Visualize Bounding Box ==<br />
<br />
If, for instance, the image is taking more space than expected, it can be useful to visualize the bounding box of the image. To do this:<br />
<br />
<texcode>\externalfigure[logo.pdf][frame=on]</texcode><br />
<br />
ConTeXt includes a Perl script <tt>pdftrimwhite</tt> that removes extra white space at the borders of a PDF file. To run this script:<br />
<br />
<pre>mtxrun --script pdftrimwhite <em>[flags] input output</em></pre><br />
<br />
The most important flag is <tt>--offset=dimen</tt>, which keeps some extra space around the trimmed image.<br />
<br />
Similar functionality is provided by another Perl script, <tt>pdfcrop</tt>, that is included in most TeX distributions.<br />
<br />
== Diagnostic Tracking ==<br />
<br />
To get diagnostic information about image inclusion, enable the tracker <tt>graphics.locating</tt> by editing the ConTeXt file and adding:<br />
<br />
<texcode>\enabletrackers[graphics.locating]</texcode><br />
<br />
Alternatively, compile the ConTeXt file using:<br />
<br />
<texcode>context --trackers=graphics.locating filename</texcode><br />
<br />
The tracker writes diagnostics to the console. Suppose we use <tt>\externalfigure[somefile.pdf]</tt> and ConTeXt finds the file in the current search path; then the following information is printed on the console:<br />
<br />
<pre>graphics &gt; inclusion &gt; locations: local,global<br />
graphics &gt; inclusion &gt; path list: . .. ../..<br />
graphics &gt; inclusion &gt; strategy: forced format pdf<br />
graphics &gt; inclusion &gt; found: somefile.pdf -&gt; somefile.pdf<br />
graphics &gt; inclusion &gt; format natively supported by backend: pdf</pre><br />
If the file <tt>somefile.pdf</tt> is not found in the current search path, then the following information is printed on the console (even if the <tt>graphics.locating</tt> tracker is not set):<br />
<br />
<pre>graphics &gt; inclusion &gt; strategy: forced format pdf<br />
graphics &gt; inclusion &gt; not found: somefile.pdf<br />
graphics &gt; inclusion &gt; not found: ./somefile.pdf<br />
graphics &gt; inclusion &gt; not found: ../somefile.pdf<br />
graphics &gt; inclusion &gt; not found: ../../somefile.pdf<br />
graphics &gt; inclusion &gt; not found: images/somefile.pdf<br />
graphics &gt; inclusion &gt; not found: /home/user/images/somefile.pdf<br />
graphics &gt; inclusion &gt; format not supported: </pre><br />
and a placeholder gray box is put in the output:<br />
<br />
<context> </context><br />
<br />
Sometimes, one would rather use a placeholder image for an image that is yet to be made. In such cases, load the MP library <tt>dum</tt> via:<br />
<br />
<texcode>\useMPlibrary[dum]</texcode><br />
<br />
Then, whenever an image file is not found in the current search path, a random MetaPost image is shown in the output.<br />
<br />
<context> </context><br />
<br />
== Leading Paragraph ==<br />
<br />
Using {{cmd|externalfigure}}<tt>[...]</tt> at the beginning of a paragraph results in a line break after the image. This is because {{cmd|externalfigure}} is a {{cmd|vbox}} and when a {{cmd|vbox}} is encountered at (what appears to be) the beginning of a paragraph, it remains in vertical mode. To prevent this, add {{cmd|dontleavehmode}} before {{cmd|externalfigure}}, like this:<br />
<br />
<texcode>\dontleavehmode<br />
\externalfigure[...] ... first line ...</texcode><br />
<br />
= Multiple Image Settings =<br />
<br />
== Image Settings ==<br />
<br />
Suppose your document contains many side-by-side images, and you want all of these images to be of the same size. In addition, you want to control the size of all images by changing only one setup. To do this, you can use the {{cmd|defineexternalfigure}} macro, which defines a named collection of image settings. For example, to define a collection where the image width is <tt>3cm</tt>, use:<br />
<br />
<texcode>\defineexternalfigure[logo-settings]<br />
[width=3cm]</texcode><br />
<br />
And then to use these settings in an image, use:<br />
<br />
<texcode>\externalfigure[group.pdf][logo-settings]</texcode><br />
<br />
or, if you want to add or override settings, use:<br />
<br />
<texcode>\externalfigure[group.pdf][logo-settings]<br />
[height=2cm]</texcode><br />
<br />
== Image Labels ==<br />
<br />
Suppose your document contains an image at multiple locations; all of these images are to be of the same size, which is not necessarily the same as the natural size of the image. Furthermore, as before, you want to set the size of all the images by changing only one setup. Here, the macro to use is {{cmd|useexternalfigure}}, which defines a symbolic label for inserting an image plus settings. For example:<br />
<br />
<texcode>\useexternalfigure[mylogo]<br />
[logo.pdf][width=2cm]</texcode><br />
<br />
defines an image label <tt>mylogo</tt> that maps to the image file <tt>logo.pdf</tt> and sets its width to <tt>2cm</tt>. This image label may be used as a normal image filename:<br />
<br />
<texcode>\externalfigure[mylogo]</texcode><br />
<br />
<br />
= [[Floating Objects]] =<br />
<br />
Floats are numbered and placed by ConTeXt, with a configurable (and optional) caption.<br />
<br />
<texcode><br />
\placefigure[place]{My Caption}{\externalfigure[myone]}<br />
</texcode><br />
<tt>place</tt> is one of:<br />
left, right, here, top, bottom, inleft, inright, inmargin, margin, page, opposite, always, force, tall<br />
<br />
You get ''no'' caption with <tt>none</tt>.<br />
You get a table of figures with {{cmd|showexternalfigures}}<code>[alternative=a]</code>. Alternatives (styles) a, b and c are predefined.<br />
<br />
The second brackets of {{cmd|placefigure}} can contain any command, e.g. {{cmd|getbuffer}}.<br />
<br />
You find more about floats ([[Floating Objects]]) in the manual.<br />
= Movies =<br />
<br />
Movies aren't recognized automatically yet; they must be delcared verbosely:<br />
<br />
<texcode><br />
\externalfigure[demo.mov][label=demo,width=4cm,height=4cm,preview=yes]<br />
</texcode><br />
<br />
<tt>preview=yes</tt> shows the first image as preview.<br />
You find more about interactive Elements in [http://www.pragma-ade.com/general/manuals/mwidget-s.pdf mwidget-s.pdf]<br />
<br />
Unfortunately, people who are fond of Linux cannot embed movies because the linux release of acroread doesn't support that. An alternative solution consists in launching your prefered player (MPlayer) from acroread:<br />
<br />
<texcode><br />
\defineprogram[dummy.mpeg][dummy.mpeg.sh]<br />
<br />
\starttext<br />
\goto{\externalfigure[dummy-preview][width=0.48\textwidth]}[program(dummy.mpeg{})]<br />
\stoptext<br />
</texcode><br />
<br />
The script dummy.mpeg.sh should contain:<br />
<pre><nowiki><br />
FILE=$(basename "$0"); mplayer -fs -zoom ${FILE/.sh/}<br />
</nowiki></pre><br />
<br />
= See Also =<br />
<br />
* [[Animation]]<br />
* [[Example photo page layout]]<br />
* [[Graphical_text_manipulation|scaling, rotating, mirroring, clipping]]<br />
<br />
[[Category:Graphics]]<br />
<br />
<br />
{{Getting started navbox}}</div>Mæstrohttps://wiki.contextgarden.net/index.php?title=Page_Layout&diff=23700Page Layout2017-12-24T23:48:06Z<p>Mæstro: removed whitespace in texcode</p>
<hr />
<div>{{todo | Merge with [[PaperSetup]] and [[Paper sizes]] }}<br />
< [[Visuals]] | [[Layers]] | [[Columns]] | [[Visual Debugging]] ><br />
<br />
For more on [http://context.aanhet.net/svn/contextman/context-reference/en/co-pagedesign.pdf layout and page design] see the [http://context.aanhet.net/svn/contextman/context-reference/en/co-pagedesign.pdf manual chapter].<br />
<br />
<div style="border: 3px solid red; background: #ffaaaa; padding: 0.4em;"><br />
<div style="font-size: 1.3em; fontweight: bold">Warning!</div><br />
At the moment a layoutchange (setuplayout) inside a page is not proper working in mkiv duplex mode.<br />
For more details and actual state see mailing list and [http://wiki.contextgarden.net/User_talk:Zenlima Bug Layoutchange inside page while duplexmode].<br />
</div><br />
<br />
<br />
== Typesetting areas ==<br />
<br />
The 25 typesetting areas of a ConTeXt page are divided into 5 columns and 5 rows. From left to right, one encounters {{code|leftedge}}, {{code|leftmargin}}, {{code|text}}, {{code|rightmargin}}, and {{code|rightedge}}. From top to bottom, the areas are called: {{code|top}}, {{code|header}}, {{code|text}}, {{code|footer}}, {{code|bottom}}. E.g. {{code|leftmargin}} is the margin area to the left of the main text area; {{code|{leftmargin,bottom}|}} is below it, at the same height as the {{code|bottom}} area. In between the two lies the area {{code|{leftmargin,footer}|}}.<br />
<br />
The graphic below illustrates the areas and dimensions. The row and column names are written<br />
along the edges of the page. The arrows correspond to layout dimensions; the<br />
more important a dimension is (i.e. the more of the layout is pushed around<br />
when you change it), the thicker its arrow and the larger its name.<br />
<br />
[[Image:layout.svg||||Diagram of \setuplayout[] dimensions]]<br />
<br />
== Defining the layout ==<br />
<br />
Positioning the areas is by setting the following dimensions using {{cmd|setuplayout|[backspace=5cm,...]}}. The dimensions are mentioned in order of how ‘primitive’ they are: e.g. altering the {{code|topspace}} pushes around all other vertical dimensions, but altering the {{code|header}} affects only the {{code|headerdistance}} and the {{code|textheight}}.<br />
<br />
You always define a right page; if you use a double page layout, 'right' and 'left' values are mirrored on a left page. Doublesided typesetting is activated with {{cmd|setuppagenumbering|[alternative=doublesided]}}.<br />
<br />
# Set the {{code|backspace}} and {{code|width}}, and the {{code|topspace}} and {{code|height}}. The {{code|width}} is the width of the main typesetting area; the {{code|backspace}} is its distance from the left edge of the page. The {{code|height}} is the distance ''from the top of the header to the bottom of the footer''; the {{code|topspace}} is the distance from the top edge of the page to the top of the header.<br />
# Set the {{code|header}} and {{code|headerdistance}}, and the {{code|footer}} and {{code|footerdistance}}. The {{code|header}} is the vertical size of the header area; the {{code|headerdistance}} is the distance from the header area to the text area. The {{code|footer}} and {{code|footerdistance}} work likewise.<br />
# Once the header(distance) and footer(distance) are subtracted from the {{code|height}}, what remains is the {{code|textheight}}: the height of the main typesetting area. Although it would be very useful, you cannot set this dimension directly.<br />
# If you want to typeset anything above the header, define {{code|topdistance}} (the distance from the top of the header to the bottom of the topmost typesetting area) and {{code|top}} (the height of the topmost typesetting area). For typesetting below the footer, define {{code|bottomdistance}} and {{code|bottom}}.<br />
# As for the horizontal dimensions apart from the {{code|width}}: starting at the left edge of the main text area, and moving away from the center, one first sets the {{code|leftmargindistance}}; then one sets the width {{code|leftmargin}} of the margin typesetting area; then one sets the {{code|leftedgedistance}}; and then there is the {{code|leftedge}} typesetting area. On the right: {{code|rightmargindistance}}, {{code|rightmargin}}, {{code|rightedgedistance}}, {{code|rightedge}}.<br />
<br />
== Paper size ==<br />
<br />
Page size and paper size are set with {{cmd|setuppapersize}}. Many paper sizes are already defined by name; see the list of [[PaperSizes|paper sizes]]. To define a new paper size, use {{cmd|definepapersize}}.<br />
<br />
== Example layout ==<br />
<br />
<texcode><br />
\setuppapersize[A4][A4] % this is the default and may be omitted<br />
\setuplayout[backspace=20mm,<br />
width=160mm,<br />
topspace=20mm,<br />
header=0mm,<br />
footer=0mm,<br />
height=250mm]<br />
</texcode><br />
<br />
== Multiple layouts ==<br />
<br />
If you need to use different layouts in some parts of the document, you can set up a global layout, and then define additional named layouts for the deviating parts. You only need to specify the dimensions that differ: unspecified dimensions will be inherited from the global layout.<br />
<br />
To switch to a different layout, call it up in the appropriate place in the document. To revert back to the global layout, use {{cmd|setuplayout|[reset]}}.<br />
<br />
<texcode><br />
\setuplayout[...] % global layout<br />
\definelayout[wide][...] % layout of the first page<br />
<br />
\setuplayout[wide] % switch to layout called 'wide'<br />
\setuplayout[reset] % switch back to the global layout<br />
</texcode><br />
<br />
To specify in advance that you want to change layouts starting from page 4 (e.g.), use {{cmd|definelayout|[4][...]}}. Resetting the layout must be done explicitly; else, the new layout will be used until the end of the document.<br />
<br />
<texcode><br />
% different layout for first two pages<br />
\definelayout[1][wide]<br />
\definelayout[3][reset]<br />
</texcode><br />
<br />
== Advanced features ==<br />
<br />
* To allow Acrobat Reader users (among others?) to make layers visible/invisible at will, add the following command at the start of your file:<br />
<texcode><br />
\showlayoutcomponents<br />
</texcode><br />
<br />
* If you have a certain run of text that you want to keep together, you can test for the number of lines available on the current page with {{cmd|testpage|[''n'']}}, where ''n'' is the number of lines required. If there are not ''n'' lines available, a page break will be inserted at the location of the {{cmd|testpage}} command.<br />
<br />
* If you need absolute positioning of objects (text, pictures) on the page, but ad-hoc rather than systematic, the [[Layers]] mechanism is more suitable.<br />
<br />
* For layout from a [[Formatting Objects|XML/FO]] perspective, with some descriptive pictures, see At [http://getfo.sourceforge.net/context_xml/index.html Paul Tremblay's] [[XML]] ConTeXt site.<br />
<br />
== Table of Parameters ==<br />
<br />
The first colum is the name by which the variable is set in {{cmd|setuplayout}}. The second column is the name by which TeX stores the variable. This name is usually the same, but sometimes different; knowing it allows you to invoke it with code like <code>The paper's height is \the\paperheight.</code> Any remarks (usually a short description) are given in the third column.<br />
<br />
{| class=wikitable<br />
! \setuplayout[...] !! dimension !! Remarks<br />
|-<br />
| paperheight<br />
| {{cmd|paperheight}}<br />
| height of paper page<br />
|-<br />
| paperwidth<br />
| {{cmd|paperwidth}}<br />
| width of paper page<br />
|-<br />
| printpaperheight<br />
| {{cmd|printpaperheight}}<br />
| differs from paperheight when using [[Imposition]] (arranging)<br />
|-<br />
| printpaperwidth<br />
| {{cmd|printpaperwidth}}<br />
| differs from paperwidth when using [[Imposition]] (arranging)<br />
|-<br />
| topspace<br />
| {{cmd|topspace}}<br />
| above header: from top rim of paper to to top rim of header<br />
|-<br />
| backspace<br />
| {{cmd|backspace}}<br />
| from left rim of paper to left rim of main text area<br />
|-<br />
| height<br />
| {{cmd|makeupheight}}<br />
| sum of heights of text area, header and footer (plus distances)<br />
|-<br />
| width<br />
| {{cmd|makeupwidth}}<br />
| width of the main text area. {{cmd|makeupwidth}} is normally same as {{cmd|textwidth}}, but it can be different, for example in columns<br />
|-<br />
| top<br />
| {{cmd|topheight}}<br />
| height of the top area<br />
|-<br />
| topdistance<br />
| {{cmd|topdistance}}<br />
| between top and header<br />
|-<br />
| header<br />
| {{cmd|headerheight}}<br />
| height of header area<br />
|-<br />
| headerdistance<br />
| {{cmd|headerdistance}}<br />
| between header and text<br />
|-<br />
| textheight<br />
| {{cmd|textheight}}<br />
| height of text area<br />
|-<br />
| footerdistance<br />
| {{cmd|footerdistance}}<br />
| between text and footer<br />
|-<br />
| footer<br />
| {{cmd|footerheight}}<br />
| height of footer area<br />
|-<br />
| bottomdistance<br />
| {{cmd|bottomdistance}}<br />
| between footer and bottom<br />
|-<br />
| bottom<br />
| {{cmd|bottomheight}}<br />
| space below footer (but isn't calculated automatically)<br />
|-<br />
| bottomspace<br />
| {{cmd|bottomspace}}<br />
| space from bottom footer to bottom rim of paper<br />
|-<br />
| cutspace<br />
| {{cmd|cutspace}}<br />
| from right rim of paper to right rim of main text area<br />
|-<br />
| leftedge<br />
| {{cmd|leftedgewidth}}<br />
| from left rim of paper to left rim of left margin<br />
|-<br />
| leftedgedistance<br />
| {{cmd|leftedgedistance}}<br />
| between leftegde and left margin<br />
|-<br />
| leftmargin<br />
| {{cmd|leftmarginwidth}}<br />
| width of left margin (marginals space)<br />
|-<br />
| leftmargindistance<br />
| {{cmd|leftmargindistance}}<br />
| between left margin and text<br />
|-<br />
| textwidth<br />
| {{cmd|textwidth}}<br />
| width of text area. when columns are used, the value of {{cmd|textwidth}} can differ from {{cmd|makeupwidth}}<br />
|-<br />
| rightmargindistance<br />
| {{cmd|rightmargindistance}}<br />
| between text area and right margin<br />
|-<br />
| rightmargin<br />
| {{cmd|rightmarginwidth}}<br />
| width of right margin (marginals area)<br />
|-<br />
| rightedgedistance<br />
| {{cmd|rightedgedistance}}<br />
| between right margin and right edge<br />
|-<br />
| rightedge<br />
| {{cmd|rightedgewidth}}<br />
| from right margin to right rim of paper<br />
|-<br />
| horoffset<br />
| ?<br />
| bleed from left of paper<br />
|-<br />
| voroffset<br />
| ?<br />
| bleed from top of paper<br />
|}<br />
<br />
'''Note:'''<br />
<br />
*width=middle<br />
<code><br />
if cutspace == 0pt then<br />
cutspace = backspace<br />
end<br />
makeupwidth = paperwidth- backspace -cutspace<br />
</code><br />
*width=fit<br />
<code> <br />
if cutspace == 0pt then<br />
cutspace = backspace<br />
end<br />
makeupwidth = paperwidth-cutspace<br />
scratchdimen = backspace - leftedgewidth-leftedgedistance-leftmarginwidth-leftmargindistance<br />
if scratchdimen< 0pt then<br />
scratchdimen = 0pt<br />
end<br />
makeupwidth = makeupwidth - rightmargindistance-rightmarginwidth- rightedgedistance-rightedgewidth- scratchdimen<br />
</code><br />
* otherwise:<br />
<code><br />
makeupwidth=width<br />
if cutspace == 0pt then<br />
cutspace = paperwidth-makeupwidth-backspace<br />
else<br />
% A kind of inconsistent specification, but used<br />
% in for instance s-pre-19.tex; the cutspace is<br />
% used only for determining some kind of right<br />
% margin; don't use this in doublesided mode<br />
pass <br />
end<br />
</code><br />
(From {{src|page-lay.mkiv}}.)<br />
<br />
{{Getting started navbox}}<br />
<br />
[[Category:ConTeXt-Issues]]</div>Mæstrohttps://wiki.contextgarden.net/index.php?title=URL&diff=23699URL2017-12-24T23:14:29Z<p>Mæstro: small changes in example code</p>
<hr />
<div>== Overview ==<br />
URLs can be typeset in various ways. You may specify a URL for later reuse via {{cmd|useURL}}:<br />
<texcode><br />
\useURL[aurl] [http://xkcd.com/149/] [] [I prefer hot dogs.]<br />
</texcode><br />
where #1 is the identifier, #2 is the URL you want to point to, and #4 the text to be displayed where the URL is used. #3 can be used for the 'file path' portion of the URL, if you want. This dates back to when hyperlink support in <br />
DVI viewers required that split.<br />
<br />
Alternatively, you can use only two arguments and the URL will be used as its own text. <br />
<texcode><br />
\useURL[anotherurl] [http://xkcd.com/224/]<br />
</texcode><br />
(That way any character may appear inside the URL string without breaking things under certain circumstances, which can happen when you specify the URL itself as the fourth argument.)<br />
<br />
Now that you have defined some URLs you are ready to dereference them by their identifier wherever you please. Don't forget to enable interaction for clickable WWW-look-and-feel.<br />
<texcode><br />
\setupinteraction[state=start]<br />
\starttext<br />
\from[aurl] % typesets the URL description in color<br />
\from[anotherurl] % typesets the URL in color<br />
\stoptext<br />
</texcode><br />
<br />
<!--You can use<br />
<texcode><br />
\url[aurl]<br />
</texcode><br />
as well, which behaves like {{cmd|from}}[#1].<br />
--><br />
<br />
URL shortcuts defined by {{cmd|useURL}} can be used while {{cmd|url}} as well:<br />
<texcode><br />
\url[aurl]<br />
</texcode><br />
<br />
== How to Typeset URLs ==<br />
<br />
=== Example for Mailto #1 ===<br />
<context source=yes><br />
\setupinteraction[state=start]<br />
\useurl [mymail] [mailto:nobody@example.zzz] [][visible@mailaddress.zzz]<br />
<br />
Send your spam to \from[mymail]!<br />
</context><br />
<br />
=== Example for Mailto #2 ===<br />
<br />
<context source=yes><br />
\setupinteraction[state=start]<br />
<br />
Send your spam to \goto{visible@mailaddress.zzz}[url(mailto:nobody@example.zzz)]<br />
</context><br />
<br />
=== Example for WWW ({{cmd|goto}}) ===<br />
<br />
Another way of typesetting URLs is the {{cmd|goto}}: \goto{#1}[#2] command. This expects the description text as first argument and the actual URL as the second one; note that it has to be wrapped in url(#2) to create a clickable link:<br />
<texcode><br />
\goto{In Lua, array indices start from one.}[url(http://www.xkcd.com/163/)]<br />
</texcode><br />
<br />
=== Escaping of Special Characters ===<br />
<br />
You might be interested in [[URL#Avoid_Escaping_Characters|not escaping characters]].<br />
<br />
Note that special characters, eg hash sign, percent sign, must be escaped by backslash. <br />
Escaping means that the special character will be processed one step later and it prevents<br />
annoying error messages during compilation.<br />
<br />
The <code>#</code> sign will be replaced by <code>\#</code>,<br />
the <code>%</code> sign by <code>\%</code>, etc.<br />
<br />
<context source=yes><br />
\setupinteraction[state=start]<br />
\useurl [myurl] [www.example.zzz/\#999] [] [www.example.zzz/\#999]<br />
</context><br />
<br />
Another way of writing special characters is described below, with hyphenated URLs.<br />
<br />
== Hyphenated URLs ==<br />
<br />
URLs tend to become large monsters under many circumstances but you may have a good reason not to conceal them from the reader. <br />
This is where hyphenation comes in handy.<br />
ConTeXt provides a dedicated mechanism for chopping them into pieces:<br />
<context source=yes><br />
\hyphenatedurl{http://bits.blogs.nytimes.com/2010/03/05/a-former-book-designer-says-good-riddance-to-print/?hpw}<br />
</context><br />
<br />
=== Hyphenation Rules ===<br />
<br />
This has some characters predefined where Hans “likes” URLs to break (see the list at the beginning of [[source:lang-url.lua|lang-url.lua]], cf. [http://www.ntg.nl/pipermail/ntg-context/2008/032959.html a message on ntg-context]).<br />
If you prefer other characters you can add them via:<br />
<texcode><br />
\sethyphenatedurlnormal{:=?&}<br />
\sethyphenatedurlbefore{?&}<br />
\sethyphenatedurlafter {:=}<br />
</texcode><br />
<br />
URL hyphenation can, of course, be used wherever you need them.<br />
<texcode><br />
\useURL[yaurl] [http://xkcd.com/638/] [] [\hyphenatedurl{http://xkcd.com/638/}]<br />
\starttext<br />
\from[yaurl]<br />
\stoptext<br />
</texcode><br />
<br />
=== Escaping Special Characters ===<br />
<br />
The method for escaping of special characters described above does not work with command<br />
{{cmd|hyphenatedurl}} completely, unfortunately. Escaping backslash will undesirably appear on the output when percent sign is printed out. Similar problems bring hash sign and backslash.<br />
<br />
Therefore, these three characters must be rewritten to commands, see the following list:<br />
<table><br />
<tr><td><code>%</code></td><td> --> <code>{{cmd|letterpercent}}</code></td></tr><br />
<tr><td><code>#</code></td><td> --> <code>{{cmd|letterhash}}</code></td></tr><br />
<tr><td><code>\</code></td><td> --> <code>{{cmd|letterescape}} or {{cmd|letterbackslash}}</code></td></tr><br />
</table><br />
<br />
For other characters, similar commands have been predefined but it is not necessary to use them.<br />
<br />
<table><br />
<tr><td><code>&</code></td><td> --> <code>{{cmd|letterampersand}}</code></td></tr><br />
<tr><td><code><</code></td><td> --> <code>{{cmd|letterless}}</code></td></tr><br />
<tr><td><code>></code></td><td> --> <code>{{cmd|lettermore}}</code></td></tr><br />
<tr><td><code>"</code></td><td> --> <code>{{cmd|letterdoublequote}}</code></td></tr><br />
<tr><td><code>'</code></td><td> --> <code>{{cmd|lettersinglequote}}</code></td></tr><br />
<tr><td><code>$</code></td><td> --> <code>{{cmd|letterdollar}}</code></td></tr><br />
<tr><td><code>^</code></td><td> --> <code>{{cmd|letterhat}}</code></td></tr><br />
<tr><td><code>_</code></td><td> --> <code>{{cmd|letterunderscore}}</code></td></tr><br />
<tr><td><code>|</code></td><td> --> <code>{{cmd|letterbar}}</code></td></tr><br />
<tr><td><code>~</code></td><td> --> <code>{{cmd|lettertilde}}</code></td></tr><br />
<tr><td><code>/</code></td><td> --> <code>{{cmd|letterslash}}</code></td></tr><br />
<tr><td><code>?</code></td><td> --> <code>{{cmd|letterquestionmark}}</code></td></tr><br />
<tr><td><code>!</code></td><td> --> <code>{{cmd|letterexclamationmark}}</code></td></tr><br />
<tr><td><code>@</code></td><td> --> <code>{{cmd|letterat}}</code></td></tr><br />
<tr><td><code>:</code></td><td> --> <code>{{cmd|lettercolon}}</code></td></tr><br />
<tr><td><code>{</code></td><td> --> <code>{{cmd|letterbgroup}}</code> or <code>{{cmd|letteropenbrace}}</code> or <code>{{cmd|letterleftbrace}}</code></td></tr><br />
<tr><td><code>}</code></td><td> --> <code>{{cmd|letteregroup}}</code> or <code>{{cmd|letterclosebrace}}</code> or <code>{{cmd|letterrightbrace}}</code></td></tr><br />
</table><br />
<br />
A custom symbol can be inserted as well, eg in case of a linebreak:<br />
<texcode><br />
\def\hyphenatedurlseparator{↩}<br />
</texcode><br />
<br />
These special commands can be used in other cases, like {{cmd|useURL}}, too.<br />
<br />
<br />
== Setting Color and Style ==<br />
For {{cmd|url}}:<br />
<texcode><br />
\setupurl<br />
[color=blue,<br />
style=\tf]<br />
</texcode><br />
For {{cmd|goto}} and {{cmd|from}}:<br />
<texcode><br />
\setupinteraction<br />
[state=start,<br />
color=blue,<br />
style=\tf]<br />
</texcode><br />
<br />
== Tips and Tricks ==<br />
<br />
=== Many Different Hyperrefs ===<br />
If you need many hyperrefs in your document these definitions may be handy for you<br />
<context source=yes><br />
\def\href#1#2{\useURL[#2][{#2}][][{#1}]\goto{\url[#2]}[url(#1)]}<br />
\def\ahref#1{\color[linkcolor]{\ttx \href{#1}{<#1>}}}<br />
\def\fullahref#1{\color[linkcolor]{\ttx \href{#1}{http://#1}}}<br />
\def\mailto#1{\useURL[#1][mailto:#1][][#1]\from[{#1}]}<br />
\def\MailTo#1#2{\useURL[#1][mailto:#1][][#2]\from[{#1}]}<br />
<br />
Send mail to \MailTo{foo@bar.zzz}{Mr. Foo}<br />
</context><br />
<br />
=== Avoid Escaping Characters ===<br />
<br />
In case you don’t want to escape characters from your URLs, you might want to use the following command:<br />
<br />
<context source="yes"><br />
\setupinteraction[state=start]<br />
\setupnote[footnote][location=text]<br />
\setupnotation[footnote][alternative=serried, numbercommand=\tfx]<br />
\unexpanded\def\mypersonalurl#1{%<br />
\bgroup\tt\goto{\hyphenatedurl{#1}}[url(#1)]\egroup}<br />
<br />
\startasciimode<br />
\mypersonalurl{http://a.b?hpw%20h#pw}<br />
\stopasciimode<br />
\startasciimode<br />
\footnote{\mypersonalurl{http://a.b?hpw%20h#pw}}<br />
\stopasciimode<br />
\placenotes[footnote]<br />
</context><br />
<br />
But you have to consider one option to make it work:<br />
<br />
* Setting <cmd>asciimode</cmd> for the whole document.<p>Comments won’t work, because <code>%</code> will be considered a standard character.</p><br />
<br />
* Wrapping all URLs inside <cmd>startasciimode</cmd>...<cmd>stopasciimode</cmd>.<p>If you use URLs inside footnotes, it is the whole footnote which has to be inside the pair of commands.</p><p>Comments inside the mode won’t work.</p><br />
<br />
=== External Links ===<br />
Create a macro for external links in a colour that is distinct from other document links.<br />
<br />
<pre><br />
% Enable document colours<br />
\setupcolors[state=start,]<br />
<br />
% Internal link colours<br />
\setupinteraction[state=start,color=blue,]<br />
<br />
% External link colours<br />
\definecolor[steelblue][h=4682B4]<br />
\define[2]\href{%<br />
\begingroup<br />
\setupinteraction[<br />
style=normal,<br />
color=steelblue,<br />
]%<br />
\goto{#1}[url(#2)]%<br />
\endgroup%<br />
}<br />
<br />
% Set index colours<br />
\setupcombinedlist[content][<br />
interaction=all,<br />
color=red,<br />
]<br />
<br />
% Set the table of contents colours<br />
\setuplist[chapter][<br />
% Text colour<br />
color=darkcyan,<br />
% Page number colour<br />
pagecolor=darkgreen,<br />
]<br />
<br />
% Set up the index heading colour<br />
\setupregister[index][<br />
color=darkgray,<br />
balance=no,<br />
]<br />
<br />
\def\Google{G\color[red]{o}\color[orange]{o}g\color[green]{l}\color[red]{e}}<br />
<br />
\starttext<br />
\completecontent<br />
<br />
\startchapter[title=chapter]<br />
Search \index{source code}{source code} using \href{\Google{} Website}{http://google.com}! Read about<br />
\index{syntax}{syntax}.<br />
\stopchapter<br />
<br />
\placeindex<br />
<br />
\stoptext<br />
</pre></div>Mæstrohttps://wiki.contextgarden.net/index.php?title=URL&diff=23698URL2017-12-24T23:06:42Z<p>Mæstro: removed starttext/stoptext from preview</p>
<hr />
<div>== Overview ==<br />
URLs can be typeset in various ways. You may specify a URL for later reuse via {{cmd|useURL}}:<br />
<texcode><br />
\useURL[aurl] [http://xkcd.com/149/] [] [I prefer hot dogs.]<br />
</texcode><br />
where #1 is the identifier, #2 is the URL you want to point to, and #4 the text to be displayed where the URL is used. #3 can be used for the 'file path' portion of the URL, if you want. This dates back to when hyperlink support in <br />
DVI viewers required that split.<br />
<br />
Alternatively, you can use only two arguments and the URL will be used as its own text. <br />
<texcode><br />
\useURL[anotherurl] [http://xkcd.com/224/]<br />
</texcode><br />
(That way any character may appear inside the URL string without breaking things under certain circumstances, which can happen when you specify the URL itself as the fourth argument.)<br />
<br />
Now that you have defined some URLs you are ready to dereference them by their identifier wherever you please. Don't forget to enable interaction for clickable WWW-look-and-feel.<br />
<texcode><br />
\setupinteraction[state=start]<br />
\starttext<br />
\from[aurl] % typesets the URL description in color<br />
\from[anotherurl] % typesets the URL in color<br />
\stoptext<br />
</texcode><br />
<br />
<!--You can use<br />
<texcode><br />
\url[aurl]<br />
</texcode><br />
as well, which behaves like {{cmd|from}}[#1].<br />
--><br />
<br />
URL shortcuts defined by {{cmd|useURL}} can be used while {{cmd|url}} as well:<br />
<texcode><br />
\url[aurl]<br />
</texcode><br />
<br />
== How to Typeset URLs ==<br />
<br />
=== Example for Mailto #1 ===<br />
<context source=yes><br />
\setupinteraction[state=start]<br />
\useurl [mymail] [mailto:nobody@example.zzz] [][visible@mailaddress.zzz]<br />
<br />
Send your spam to \from[mymail]!<br />
</context><br />
<br />
=== Example for Mailto #2 ===<br />
<br />
<context source=yes><br />
\setupinteraction[state=start]<br />
Send your spam to \goto{visible@mailaddress.zzz}[url(mailto:nobody@example.zzz)]<br />
</context><br />
<br />
=== Example for WWW ({{cmd|goto}}) ===<br />
<br />
Another way of typesetting URLs is the {{cmd|goto}}: \goto{#1}[#2] command. This expects the description text as first argument and the actual URL as the second one; note that it has to be wrapped in url(#2) to create a clickable link:<br />
<texcode><br />
\goto{In Lua, array indices start from one.}[url(http://www.xkcd.com/163/)]<br />
</texcode><br />
<br />
=== Escaping of Special Characters ===<br />
<br />
You might be interested in [[URL#Avoid_Escaping_Characters|not escaping characters]].<br />
<br />
Note that special characters, eg hash sign, percent sign, must be escaped by backslash. <br />
Escaping means that the special character will be processed one step later and it prevents<br />
annoying error messages during compilation.<br />
<br />
The <code>#</code> sign will be replaced by <code>\#</code>,<br />
the <code>%</code> sign by <code>\%</code>, etc.<br />
<br />
<context source=yes><br />
\setupinteraction[state=start]<br />
\useurl [myurl] [www.example.zzz/\#999] []<br />
[www.example.zzz/\#999]<br />
</context><br />
<br />
Another way of writing special characters is described below, with hyphenated URLs.<br />
<br />
== Hyphenated URLs ==<br />
<br />
URLs tend to become large monsters under many circumstances but you may have a good reason not to conceal them from the reader. <br />
This is where hyphenation comes in handy.<br />
ConTeXt provides a dedicated mechanism for chopping them into pieces:<br />
<context source=yes><br />
\hyphenatedurl{http://bits.blogs.nytimes.com/2010/03/05/a-former-book-designer-says-good-riddance-to-print/?hpw}<br />
</context><br />
<br />
=== Hyphenation Rules ===<br />
<br />
This has some characters predefined where Hans “likes” URLs to break (see the list at the beginning of [[source:lang-url.lua|lang-url.lua]], cf. [http://www.ntg.nl/pipermail/ntg-context/2008/032959.html a message on ntg-context]).<br />
If you prefer other characters you can add them via:<br />
<texcode><br />
\sethyphenatedurlnormal{:=?&}<br />
\sethyphenatedurlbefore{?&}<br />
\sethyphenatedurlafter {:=}<br />
</texcode><br />
<br />
URL hyphenation can, of course, be used wherever you need them.<br />
<texcode><br />
\useURL[yaurl] [http://xkcd.com/638/] [] [\hyphenatedurl{http://xkcd.com/638/}]<br />
\starttext<br />
\from[yaurl]<br />
\stoptext<br />
</texcode><br />
<br />
=== Escaping Special Characters ===<br />
<br />
The method for escaping of special characters described above does not work with command<br />
{{cmd|hyphenatedurl}} completely, unfortunately. Escaping backslash will undesirably appear on the output when percent sign is printed out. Similar problems bring hash sign and backslash.<br />
<br />
Therefore, these three characters must be rewritten to commands, see the following list:<br />
<table><br />
<tr><td><code>%</code></td><td> --> <code>{{cmd|letterpercent}}</code></td></tr><br />
<tr><td><code>#</code></td><td> --> <code>{{cmd|letterhash}}</code></td></tr><br />
<tr><td><code>\</code></td><td> --> <code>{{cmd|letterescape}} or {{cmd|letterbackslash}}</code></td></tr><br />
</table><br />
<br />
For other characters, similar commands have been predefined but it is not necessary to use them.<br />
<br />
<table><br />
<tr><td><code>&</code></td><td> --> <code>{{cmd|letterampersand}}</code></td></tr><br />
<tr><td><code><</code></td><td> --> <code>{{cmd|letterless}}</code></td></tr><br />
<tr><td><code>></code></td><td> --> <code>{{cmd|lettermore}}</code></td></tr><br />
<tr><td><code>"</code></td><td> --> <code>{{cmd|letterdoublequote}}</code></td></tr><br />
<tr><td><code>'</code></td><td> --> <code>{{cmd|lettersinglequote}}</code></td></tr><br />
<tr><td><code>$</code></td><td> --> <code>{{cmd|letterdollar}}</code></td></tr><br />
<tr><td><code>^</code></td><td> --> <code>{{cmd|letterhat}}</code></td></tr><br />
<tr><td><code>_</code></td><td> --> <code>{{cmd|letterunderscore}}</code></td></tr><br />
<tr><td><code>|</code></td><td> --> <code>{{cmd|letterbar}}</code></td></tr><br />
<tr><td><code>~</code></td><td> --> <code>{{cmd|lettertilde}}</code></td></tr><br />
<tr><td><code>/</code></td><td> --> <code>{{cmd|letterslash}}</code></td></tr><br />
<tr><td><code>?</code></td><td> --> <code>{{cmd|letterquestionmark}}</code></td></tr><br />
<tr><td><code>!</code></td><td> --> <code>{{cmd|letterexclamationmark}}</code></td></tr><br />
<tr><td><code>@</code></td><td> --> <code>{{cmd|letterat}}</code></td></tr><br />
<tr><td><code>:</code></td><td> --> <code>{{cmd|lettercolon}}</code></td></tr><br />
<tr><td><code>{</code></td><td> --> <code>{{cmd|letterbgroup}}</code> or <code>{{cmd|letteropenbrace}}</code> or <code>{{cmd|letterleftbrace}}</code></td></tr><br />
<tr><td><code>}</code></td><td> --> <code>{{cmd|letteregroup}}</code> or <code>{{cmd|letterclosebrace}}</code> or <code>{{cmd|letterrightbrace}}</code></td></tr><br />
</table><br />
<br />
A custom symbol can be inserted as well, eg in case of a linebreak:<br />
<texcode><br />
\def\hyphenatedurlseparator{↩}<br />
</texcode><br />
<br />
These special commands can be used in other cases, like {{cmd|useURL}}, too.<br />
<br />
<br />
== Setting Color and Style ==<br />
For {{cmd|url}}:<br />
<texcode><br />
\setupurl<br />
[color=blue,<br />
style=\tf]<br />
</texcode><br />
For {{cmd|goto}} and {{cmd|from}}:<br />
<texcode><br />
\setupinteraction<br />
[state=start,<br />
color=blue,<br />
style=\tf]<br />
</texcode><br />
<br />
== Tips and Tricks ==<br />
<br />
=== Many Different Hyperrefs ===<br />
If you need many hyperrefs in your document these definitions may be handy for you<br />
<context source=yes><br />
\def\href#1#2{\useURL[#2][{#2}][][{#1}]\goto{\url[#2]}[url(#1)]}<br />
\def\ahref#1{\color[linkcolor]{\ttx \href{#1}{<#1>}}}<br />
\def\fullahref#1{\color[linkcolor]{\ttx \href{#1}{http://#1}}}<br />
\def\mailto#1{\useURL[#1][mailto:#1][][#1]\from[{#1}]}<br />
\def\MailTo#1#2{\useURL[#1][mailto:#1][][#2]\from[{#1}]}<br />
<br />
Send mail to \MailTo{foo@bar.zzz}{Mr. Foo}<br />
</context><br />
<br />
=== Avoid Escaping Characters ===<br />
<br />
In case you don’t want to escape characters from your URLs, you might want to use the following command:<br />
<br />
<context source="yes"><br />
\setupinteraction[state=start]<br />
\setupnote[footnote][location=text]<br />
\setupnotation[footnote][alternative=serried, numbercommand=\tfx]<br />
\unexpanded\def\mypersonalurl#1{%<br />
\bgroup\tt\goto{\hyphenatedurl{#1}}[url(#1)]\egroup}<br />
\starttext<br />
\startasciimode<br />
\mypersonalurl{http://a.b?hpw%20h#pw}<br />
\stopasciimode<br />
\startasciimode<br />
\footnote{\mypersonalurl{http://a.b?hpw%20h#pw}}<br />
\stopasciimode<br />
\placenotes[footnote]<br />
\stoptext<br />
</context><br />
<br />
But you have to consider one option to make it work:<br />
<br />
* Setting <cmd>asciimode</cmd> for the whole document.<p>Comments won’t work, because <code>%</code> will be considered a standard character.</p><br />
<br />
* Wrapping all URLs inside <cmd>startasciimode</cmd>...<cmd>stopasciimode</cmd>.<p>If you use URLs inside footnotes, it is the whole footnote which has to be inside the pair of commands.</p><p>Comments inside the mode won’t work.</p><br />
<br />
=== External Links ===<br />
Create a macro for external links in a colour that is distinct from other document links.<br />
<br />
<pre><br />
% Enable document colours<br />
\setupcolors[state=start,]<br />
<br />
% Internal link colours<br />
\setupinteraction[state=start,color=blue,]<br />
<br />
% External link colours<br />
\definecolor[steelblue][h=4682B4]<br />
\define[2]\href{%<br />
\begingroup<br />
\setupinteraction[<br />
style=normal,<br />
color=steelblue,<br />
]%<br />
\goto{#1}[url(#2)]%<br />
\endgroup%<br />
}<br />
<br />
% Set index colours<br />
\setupcombinedlist[content][<br />
interaction=all,<br />
color=red,<br />
]<br />
<br />
% Set the table of contents colours<br />
\setuplist[chapter][<br />
% Text colour<br />
color=darkcyan,<br />
% Page number colour<br />
pagecolor=darkgreen,<br />
]<br />
<br />
% Set up the index heading colour<br />
\setupregister[index][<br />
color=darkgray,<br />
balance=no,<br />
]<br />
<br />
\def\Google{G\color[red]{o}\color[orange]{o}g\color[green]{l}\color[red]{e}}<br />
<br />
\starttext<br />
\completecontent<br />
<br />
\startchapter[title=chapter]<br />
Search \index{source code}{source code} using \href{\Google{} Website}{http://google.com}! Read about<br />
\index{syntax}{syntax}.<br />
\stopchapter<br />
<br />
\placeindex<br />
<br />
\stoptext<br />
</pre></div>Mæstrohttps://wiki.contextgarden.net/index.php?title=URL&diff=23697URL2017-12-24T23:03:46Z<p>Mæstro: removed more whitespaces in context</p>
<hr />
<div>== Overview ==<br />
URLs can be typeset in various ways. You may specify a URL for later reuse via {{cmd|useURL}}:<br />
<texcode><br />
\useURL[aurl] [http://xkcd.com/149/] [] [I prefer hot dogs.]<br />
</texcode><br />
where #1 is the identifier, #2 is the URL you want to point to, and #4 the text to be displayed where the URL is used. #3 can be used for the 'file path' portion of the URL, if you want. This dates back to when hyperlink support in <br />
DVI viewers required that split.<br />
<br />
Alternatively, you can use only two arguments and the URL will be used as its own text. <br />
<texcode><br />
\useURL[anotherurl] [http://xkcd.com/224/]<br />
</texcode><br />
(That way any character may appear inside the URL string without breaking things under certain circumstances, which can happen when you specify the URL itself as the fourth argument.)<br />
<br />
Now that you have defined some URLs you are ready to dereference them by their identifier wherever you please. Don't forget to enable interaction for clickable WWW-look-and-feel.<br />
<texcode><br />
\setupinteraction[state=start]<br />
\starttext<br />
\from[aurl] % typesets the URL description in color<br />
\from[anotherurl] % typesets the URL in color<br />
\stoptext<br />
</texcode><br />
<br />
<!--You can use<br />
<texcode><br />
\url[aurl]<br />
</texcode><br />
as well, which behaves like {{cmd|from}}[#1].<br />
--><br />
<br />
URL shortcuts defined by {{cmd|useURL}} can be used while {{cmd|url}} as well:<br />
<texcode><br />
\url[aurl]<br />
</texcode><br />
<br />
== How to Typeset URLs ==<br />
<br />
=== Example for Mailto #1 ===<br />
<context source=yes><br />
\setupinteraction[state=start] <br />
\useurl [mymail] [mailto:nobody@example.zzz] [][visible@mailaddress.zzz]<br />
<br />
\starttext <br />
<br />
Send your spam to \from[mymail]! <br />
<br />
\stoptext <br />
</context><br />
<br />
=== Example for Mailto #2 ===<br />
<br />
<context source=yes><br />
\setupinteraction[state=start] <br />
\starttext <br />
Send your spam to \goto{visible@mailaddress.zzz}[url(mailto:nobody@example.zzz)] <br />
\stoptext <br />
</context><br />
<br />
=== Example for WWW ({{cmd|goto}}) ===<br />
<br />
Another way of typesetting URLs is the {{cmd|goto}}: \goto{#1}[#2] command. This expects the description text as first argument and the actual URL as the second one; note that it has to be wrapped in url(#2) to create a clickable link:<br />
<texcode><br />
\goto{In Lua, array indices start from one.}[url(http://www.xkcd.com/163/)]<br />
</texcode><br />
<br />
=== Escaping of Special Characters ===<br />
<br />
You might be interested in [[URL#Avoid_Escaping_Characters|not escaping characters]].<br />
<br />
Note that special characters, eg hash sign, percent sign, must be escaped by backslash. <br />
Escaping means that the special character will be processed one step later and it prevents<br />
annoying error messages during compilation.<br />
<br />
The <code>#</code> sign will be replaced by <code>\#</code>,<br />
the <code>%</code> sign by <code>\%</code>, etc.<br />
<br />
<context source=yes><br />
\setupinteraction[state=start]<br />
\useurl [myurl] [www.example.zzz/\#999] []<br />
[www.example.zzz/\#999]<br />
</context><br />
<br />
Another way of writing special characters is described below, with hyphenated URLs.<br />
<br />
== Hyphenated URLs ==<br />
<br />
URLs tend to become large monsters under many circumstances but you may have a good reason not to conceal them from the reader. <br />
This is where hyphenation comes in handy.<br />
ConTeXt provides a dedicated mechanism for chopping them into pieces:<br />
<context source=yes><br />
\hyphenatedurl{http://bits.blogs.nytimes.com/2010/03/05/a-former-book-designer-says-good-riddance-to-print/?hpw}<br />
</context><br />
<br />
=== Hyphenation Rules ===<br />
<br />
This has some characters predefined where Hans “likes” URLs to break (see the list at the beginning of [[source:lang-url.lua|lang-url.lua]], cf. [http://www.ntg.nl/pipermail/ntg-context/2008/032959.html a message on ntg-context]).<br />
If you prefer other characters you can add them via:<br />
<texcode><br />
\sethyphenatedurlnormal{:=?&}<br />
\sethyphenatedurlbefore{?&}<br />
\sethyphenatedurlafter {:=}<br />
</texcode><br />
<br />
URL hyphenation can, of course, be used wherever you need them.<br />
<texcode><br />
\useURL[yaurl] [http://xkcd.com/638/] [] [\hyphenatedurl{http://xkcd.com/638/}]<br />
\starttext<br />
\from[yaurl]<br />
\stoptext<br />
</texcode><br />
<br />
=== Escaping Special Characters ===<br />
<br />
The method for escaping of special characters described above does not work with command<br />
{{cmd|hyphenatedurl}} completely, unfortunately. Escaping backslash will undesirably appear on the output when percent sign is printed out. Similar problems bring hash sign and backslash.<br />
<br />
Therefore, these three characters must be rewritten to commands, see the following list:<br />
<table><br />
<tr><td><code>%</code></td><td> --> <code>{{cmd|letterpercent}}</code></td></tr><br />
<tr><td><code>#</code></td><td> --> <code>{{cmd|letterhash}}</code></td></tr><br />
<tr><td><code>\</code></td><td> --> <code>{{cmd|letterescape}} or {{cmd|letterbackslash}}</code></td></tr><br />
</table><br />
<br />
For other characters, similar commands have been predefined but it is not necessary to use them.<br />
<br />
<table><br />
<tr><td><code>&</code></td><td> --> <code>{{cmd|letterampersand}}</code></td></tr><br />
<tr><td><code><</code></td><td> --> <code>{{cmd|letterless}}</code></td></tr><br />
<tr><td><code>></code></td><td> --> <code>{{cmd|lettermore}}</code></td></tr><br />
<tr><td><code>"</code></td><td> --> <code>{{cmd|letterdoublequote}}</code></td></tr><br />
<tr><td><code>'</code></td><td> --> <code>{{cmd|lettersinglequote}}</code></td></tr><br />
<tr><td><code>$</code></td><td> --> <code>{{cmd|letterdollar}}</code></td></tr><br />
<tr><td><code>^</code></td><td> --> <code>{{cmd|letterhat}}</code></td></tr><br />
<tr><td><code>_</code></td><td> --> <code>{{cmd|letterunderscore}}</code></td></tr><br />
<tr><td><code>|</code></td><td> --> <code>{{cmd|letterbar}}</code></td></tr><br />
<tr><td><code>~</code></td><td> --> <code>{{cmd|lettertilde}}</code></td></tr><br />
<tr><td><code>/</code></td><td> --> <code>{{cmd|letterslash}}</code></td></tr><br />
<tr><td><code>?</code></td><td> --> <code>{{cmd|letterquestionmark}}</code></td></tr><br />
<tr><td><code>!</code></td><td> --> <code>{{cmd|letterexclamationmark}}</code></td></tr><br />
<tr><td><code>@</code></td><td> --> <code>{{cmd|letterat}}</code></td></tr><br />
<tr><td><code>:</code></td><td> --> <code>{{cmd|lettercolon}}</code></td></tr><br />
<tr><td><code>{</code></td><td> --> <code>{{cmd|letterbgroup}}</code> or <code>{{cmd|letteropenbrace}}</code> or <code>{{cmd|letterleftbrace}}</code></td></tr><br />
<tr><td><code>}</code></td><td> --> <code>{{cmd|letteregroup}}</code> or <code>{{cmd|letterclosebrace}}</code> or <code>{{cmd|letterrightbrace}}</code></td></tr><br />
</table><br />
<br />
A custom symbol can be inserted as well, eg in case of a linebreak:<br />
<texcode><br />
\def\hyphenatedurlseparator{↩}<br />
</texcode><br />
<br />
These special commands can be used in other cases, like {{cmd|useURL}}, too.<br />
<br />
<br />
== Setting Color and Style ==<br />
For {{cmd|url}}:<br />
<texcode><br />
\setupurl<br />
[color=blue,<br />
style=\tf]<br />
</texcode><br />
For {{cmd|goto}} and {{cmd|from}}:<br />
<texcode><br />
\setupinteraction<br />
[state=start,<br />
color=blue,<br />
style=\tf]<br />
</texcode><br />
<br />
== Tips and Tricks ==<br />
<br />
=== Many Different Hyperrefs ===<br />
If you need many hyperrefs in your document these definitions may be handy for you<br />
<context source=yes><br />
\def\href#1#2{\useURL[#2][{#2}][][{#1}]\goto{\url[#2]}[url(#1)]}<br />
\def\ahref#1{\color[linkcolor]{\ttx \href{#1}{<#1>}}}<br />
\def\fullahref#1{\color[linkcolor]{\ttx \href{#1}{http://#1}}}<br />
\def\mailto#1{\useURL[#1][mailto:#1][][#1]\from[{#1}]}<br />
\def\MailTo#1#2{\useURL[#1][mailto:#1][][#2]\from[{#1}]}<br />
<br />
Send mail to \MailTo{foo@bar.zzz}{Mr. Foo}<br />
</context><br />
<br />
=== Avoid Escaping Characters ===<br />
<br />
In case you don’t want to escape characters from your URLs, you might want to use the following command:<br />
<br />
<context source="yes"><br />
\setupinteraction[state=start]<br />
\setupnote[footnote][location=text]<br />
\setupnotation[footnote][alternative=serried, numbercommand=\tfx]<br />
\unexpanded\def\mypersonalurl#1{%<br />
\bgroup\tt\goto{\hyphenatedurl{#1}}[url(#1)]\egroup}<br />
\starttext<br />
\startasciimode<br />
\mypersonalurl{http://a.b?hpw%20h#pw}<br />
\stopasciimode<br />
\startasciimode<br />
\footnote{\mypersonalurl{http://a.b?hpw%20h#pw}}<br />
\stopasciimode<br />
\placenotes[footnote]<br />
\stoptext<br />
</context><br />
<br />
But you have to consider one option to make it work:<br />
<br />
* Setting <cmd>asciimode</cmd> for the whole document.<p>Comments won’t work, because <code>%</code> will be considered a standard character.</p><br />
<br />
* Wrapping all URLs inside <cmd>startasciimode</cmd>...<cmd>stopasciimode</cmd>.<p>If you use URLs inside footnotes, it is the whole footnote which has to be inside the pair of commands.</p><p>Comments inside the mode won’t work.</p><br />
<br />
=== External Links ===<br />
Create a macro for external links in a colour that is distinct from other document links.<br />
<br />
<pre><br />
% Enable document colours<br />
\setupcolors[state=start,]<br />
<br />
% Internal link colours<br />
\setupinteraction[state=start,color=blue,]<br />
<br />
% External link colours<br />
\definecolor[steelblue][h=4682B4]<br />
\define[2]\href{%<br />
\begingroup<br />
\setupinteraction[<br />
style=normal,<br />
color=steelblue,<br />
]%<br />
\goto{#1}[url(#2)]%<br />
\endgroup%<br />
}<br />
<br />
% Set index colours<br />
\setupcombinedlist[content][<br />
interaction=all,<br />
color=red,<br />
]<br />
<br />
% Set the table of contents colours<br />
\setuplist[chapter][<br />
% Text colour<br />
color=darkcyan,<br />
% Page number colour<br />
pagecolor=darkgreen,<br />
]<br />
<br />
% Set up the index heading colour<br />
\setupregister[index][<br />
color=darkgray,<br />
balance=no,<br />
]<br />
<br />
\def\Google{G\color[red]{o}\color[orange]{o}g\color[green]{l}\color[red]{e}}<br />
<br />
\starttext<br />
\completecontent<br />
<br />
\startchapter[title=chapter]<br />
Search \index{source code}{source code} using \href{\Google{} Website}{http://google.com}! Read about<br />
\index{syntax}{syntax}.<br />
\stopchapter<br />
<br />
\placeindex<br />
<br />
\stoptext<br />
</pre></div>Mæstrohttps://wiki.contextgarden.net/index.php?title=URL&diff=23696URL2017-12-24T22:59:25Z<p>Mæstro: removed whitespaces in context</p>
<hr />
<div>== Overview ==<br />
URLs can be typeset in various ways. You may specify a URL for later reuse via {{cmd|useURL}}:<br />
<texcode><br />
\useURL[aurl] [http://xkcd.com/149/] [] [I prefer hot dogs.]<br />
</texcode><br />
where #1 is the identifier, #2 is the URL you want to point to, and #4 the text to be displayed where the URL is used. #3 can be used for the 'file path' portion of the URL, if you want. This dates back to when hyperlink support in <br />
DVI viewers required that split.<br />
<br />
Alternatively, you can use only two arguments and the URL will be used as its own text. <br />
<texcode><br />
\useURL[anotherurl] [http://xkcd.com/224/]<br />
</texcode><br />
(That way any character may appear inside the URL string without breaking things under certain circumstances, which can happen when you specify the URL itself as the fourth argument.)<br />
<br />
Now that you have defined some URLs you are ready to dereference them by their identifier wherever you please. Don't forget to enable interaction for clickable WWW-look-and-feel.<br />
<texcode><br />
\setupinteraction[state=start]<br />
\starttext<br />
\from[aurl] % typesets the URL description in color<br />
\from[anotherurl] % typesets the URL in color<br />
\stoptext<br />
</texcode><br />
<br />
<!--You can use<br />
<texcode><br />
\url[aurl]<br />
</texcode><br />
as well, which behaves like {{cmd|from}}[#1].<br />
--><br />
<br />
URL shortcuts defined by {{cmd|useURL}} can be used while {{cmd|url}} as well:<br />
<texcode><br />
\url[aurl]<br />
</texcode><br />
<br />
== How to Typeset URLs ==<br />
<br />
=== Example for Mailto #1 ===<br />
<context source=yes><br />
\setupinteraction[state=start] <br />
\useurl [mymail] [mailto:nobody@example.zzz] [][visible@mailaddress.zzz]<br />
<br />
\starttext <br />
<br />
Send your spam to \from[mymail]! <br />
<br />
\stoptext <br />
</context><br />
<br />
=== Example for Mailto #2 ===<br />
<br />
<context source=yes><br />
\setupinteraction[state=start] <br />
\starttext <br />
Send your spam to \goto{visible@mailaddress.zzz}[url(mailto:nobody@example.zzz)] <br />
\stoptext <br />
</context><br />
<br />
=== Example for WWW ({{cmd|goto}}) ===<br />
<br />
Another way of typesetting URLs is the {{cmd|goto}}: \goto{#1}[#2] command. This expects the description text as first argument and the actual URL as the second one; note that it has to be wrapped in url(#2) to create a clickable link:<br />
<texcode><br />
\goto{In Lua, array indices start from one.}[url(http://www.xkcd.com/163/)]<br />
</texcode><br />
<br />
=== Escaping of Special Characters ===<br />
<br />
You might be interested in [[URL#Avoid_Escaping_Characters|not escaping characters]].<br />
<br />
Note that special characters, eg hash sign, percent sign, must be escaped by backslash. <br />
Escaping means that the special character will be processed one step later and it prevents<br />
annoying error messages during compilation.<br />
<br />
The <code>#</code> sign will be replaced by <code>\#</code>,<br />
the <code>%</code> sign by <code>\%</code>, etc.<br />
<br />
<context source=yes><br />
\setupinteraction[state=start]<br />
\useurl [myurl] [www.example.zzz/\#999] []<br />
[www.example.zzz/\#999]<br />
</context><br />
<br />
Another way of writing special characters is described below, with hyphenated URLs.<br />
<br />
== Hyphenated URLs ==<br />
<br />
URLs tend to become large monsters under many circumstances but you may have a good reason not to conceal them from the reader. <br />
This is where hyphenation comes in handy.<br />
ConTeXt provides a dedicated mechanism for chopping them into pieces:<br />
<context source=yes><br />
\hyphenatedurl{http://bits.blogs.nytimes.com/2010/03/05/a-former-book-designer-says-good-riddance-to-print/?hpw}<br />
</context><br />
<br />
=== Hyphenation Rules ===<br />
<br />
This has some characters predefined where Hans “likes” URLs to break (see the list at the beginning of [[source:lang-url.lua|lang-url.lua]], cf. [http://www.ntg.nl/pipermail/ntg-context/2008/032959.html a message on ntg-context]).<br />
If you prefer other characters you can add them via:<br />
<texcode><br />
\sethyphenatedurlnormal{:=?&}<br />
\sethyphenatedurlbefore{?&}<br />
\sethyphenatedurlafter {:=}<br />
</texcode><br />
<br />
URL hyphenation can, of course, be used wherever you need them.<br />
<texcode><br />
\useURL[yaurl] [http://xkcd.com/638/] [] [\hyphenatedurl{http://xkcd.com/638/}]<br />
\starttext<br />
\from[yaurl]<br />
\stoptext<br />
</texcode><br />
<br />
=== Escaping Special Characters ===<br />
<br />
The method for escaping of special characters described above does not work with command<br />
{{cmd|hyphenatedurl}} completely, unfortunately. Escaping backslash will undesirably appear on the output when percent sign is printed out. Similar problems bring hash sign and backslash.<br />
<br />
Therefore, these three characters must be rewritten to commands, see the following list:<br />
<table><br />
<tr><td><code>%</code></td><td> --> <code>{{cmd|letterpercent}}</code></td></tr><br />
<tr><td><code>#</code></td><td> --> <code>{{cmd|letterhash}}</code></td></tr><br />
<tr><td><code>\</code></td><td> --> <code>{{cmd|letterescape}} or {{cmd|letterbackslash}}</code></td></tr><br />
</table><br />
<br />
For other characters, similar commands have been predefined but it is not necessary to use them.<br />
<br />
<table><br />
<tr><td><code>&</code></td><td> --> <code>{{cmd|letterampersand}}</code></td></tr><br />
<tr><td><code><</code></td><td> --> <code>{{cmd|letterless}}</code></td></tr><br />
<tr><td><code>></code></td><td> --> <code>{{cmd|lettermore}}</code></td></tr><br />
<tr><td><code>"</code></td><td> --> <code>{{cmd|letterdoublequote}}</code></td></tr><br />
<tr><td><code>'</code></td><td> --> <code>{{cmd|lettersinglequote}}</code></td></tr><br />
<tr><td><code>$</code></td><td> --> <code>{{cmd|letterdollar}}</code></td></tr><br />
<tr><td><code>^</code></td><td> --> <code>{{cmd|letterhat}}</code></td></tr><br />
<tr><td><code>_</code></td><td> --> <code>{{cmd|letterunderscore}}</code></td></tr><br />
<tr><td><code>|</code></td><td> --> <code>{{cmd|letterbar}}</code></td></tr><br />
<tr><td><code>~</code></td><td> --> <code>{{cmd|lettertilde}}</code></td></tr><br />
<tr><td><code>/</code></td><td> --> <code>{{cmd|letterslash}}</code></td></tr><br />
<tr><td><code>?</code></td><td> --> <code>{{cmd|letterquestionmark}}</code></td></tr><br />
<tr><td><code>!</code></td><td> --> <code>{{cmd|letterexclamationmark}}</code></td></tr><br />
<tr><td><code>@</code></td><td> --> <code>{{cmd|letterat}}</code></td></tr><br />
<tr><td><code>:</code></td><td> --> <code>{{cmd|lettercolon}}</code></td></tr><br />
<tr><td><code>{</code></td><td> --> <code>{{cmd|letterbgroup}}</code> or <code>{{cmd|letteropenbrace}}</code> or <code>{{cmd|letterleftbrace}}</code></td></tr><br />
<tr><td><code>}</code></td><td> --> <code>{{cmd|letteregroup}}</code> or <code>{{cmd|letterclosebrace}}</code> or <code>{{cmd|letterrightbrace}}</code></td></tr><br />
</table><br />
<br />
A custom symbol can be inserted as well, eg in case of a linebreak:<br />
<texcode><br />
\def\hyphenatedurlseparator{↩}<br />
</texcode><br />
<br />
These special commands can be used in other cases, like {{cmd|useURL}}, too.<br />
<br />
<br />
== Setting Color and Style ==<br />
For {{cmd|url}}:<br />
<texcode><br />
\setupurl<br />
[color=blue,<br />
style=\tf]<br />
</texcode><br />
For {{cmd|goto}} and {{cmd|from}}:<br />
<texcode><br />
\setupinteraction<br />
[state=start,<br />
color=blue,<br />
style=\tf]<br />
</texcode><br />
<br />
== Tips and Tricks ==<br />
<br />
=== Many Different Hyperrefs ===<br />
If you need many hyperrefs in your document these definitions may be handy for you<br />
<context source=yes><br />
\def\href#1#2{\useURL[#2][{#2}][][{#1}]\goto{\url[#2]}[url(#1)]} <br />
\def\ahref#1{\color[linkcolor]{\ttx \href{#1}{<#1>}}} <br />
\def\fullahref#1{\color[linkcolor]{\ttx \href{#1}{http://#1}}} <br />
\def\mailto#1{\useURL[#1][mailto:#1][][#1]\from[{#1}]} <br />
\def\MailTo#1#2{\useURL[#1][mailto:#1][][#2]\from[{#1}]} <br />
<br />
Send mail to \MailTo{foo@bar.zzz}{Mr. Foo}<br />
</context><br />
<br />
=== Avoid Escaping Characters ===<br />
<br />
In case you don’t want to escape characters from your URLs, you might want to use the following command:<br />
<br />
<context source="yes"><br />
\setupinteraction[state=start]<br />
\setupnote[footnote][location=text]<br />
\setupnotation[footnote][alternative=serried, numbercommand=\tfx]<br />
\unexpanded\def\mypersonalurl#1{%<br />
\bgroup\tt\goto{\hyphenatedurl{#1}}[url(#1)]\egroup}<br />
\starttext<br />
\startasciimode<br />
\mypersonalurl{http://a.b?hpw%20h#pw}<br />
\stopasciimode<br />
\startasciimode<br />
\footnote{\mypersonalurl{http://a.b?hpw%20h#pw}}<br />
\stopasciimode<br />
\placenotes[footnote]<br />
\stoptext<br />
</context><br />
<br />
But you have to consider one option to make it work:<br />
<br />
* Setting <cmd>asciimode</cmd> for the whole document.<p>Comments won’t work, because <code>%</code> will be considered a standard character.</p><br />
<br />
* Wrapping all URLs inside <cmd>startasciimode</cmd>...<cmd>stopasciimode</cmd>.<p>If you use URLs inside footnotes, it is the whole footnote which has to be inside the pair of commands.</p><p>Comments inside the mode won’t work.</p><br />
<br />
=== External Links ===<br />
Create a macro for external links in a colour that is distinct from other document links.<br />
<br />
<pre><br />
% Enable document colours<br />
\setupcolors[state=start,]<br />
<br />
% Internal link colours<br />
\setupinteraction[state=start,color=blue,]<br />
<br />
% External link colours<br />
\definecolor[steelblue][h=4682B4]<br />
\define[2]\href{%<br />
\begingroup<br />
\setupinteraction[<br />
style=normal,<br />
color=steelblue,<br />
]%<br />
\goto{#1}[url(#2)]%<br />
\endgroup%<br />
}<br />
<br />
% Set index colours<br />
\setupcombinedlist[content][<br />
interaction=all,<br />
color=red,<br />
]<br />
<br />
% Set the table of contents colours<br />
\setuplist[chapter][<br />
% Text colour<br />
color=darkcyan,<br />
% Page number colour<br />
pagecolor=darkgreen,<br />
]<br />
<br />
% Set up the index heading colour<br />
\setupregister[index][<br />
color=darkgray,<br />
balance=no,<br />
]<br />
<br />
\def\Google{G\color[red]{o}\color[orange]{o}g\color[green]{l}\color[red]{e}}<br />
<br />
\starttext<br />
\completecontent<br />
<br />
\startchapter[title=chapter]<br />
Search \index{source code}{source code} using \href{\Google{} Website}{http://google.com}! Read about<br />
\index{syntax}{syntax}.<br />
\stopchapter<br />
<br />
\placeindex<br />
<br />
\stoptext<br />
</pre></div>Mæstrohttps://wiki.contextgarden.net/index.php?title=URL&diff=23695URL2017-12-24T22:58:13Z<p>Mæstro: removed whitespaces in texcode</p>
<hr />
<div>== Overview ==<br />
URLs can be typeset in various ways. You may specify a URL for later reuse via {{cmd|useURL}}:<br />
<texcode><br />
\useURL[aurl] [http://xkcd.com/149/] [] [I prefer hot dogs.]<br />
</texcode><br />
where #1 is the identifier, #2 is the URL you want to point to, and #4 the text to be displayed where the URL is used. #3 can be used for the 'file path' portion of the URL, if you want. This dates back to when hyperlink support in <br />
DVI viewers required that split.<br />
<br />
Alternatively, you can use only two arguments and the URL will be used as its own text. <br />
<texcode><br />
\useURL[anotherurl] [http://xkcd.com/224/]<br />
</texcode><br />
(That way any character may appear inside the URL string without breaking things under certain circumstances, which can happen when you specify the URL itself as the fourth argument.)<br />
<br />
Now that you have defined some URLs you are ready to dereference them by their identifier wherever you please. Don't forget to enable interaction for clickable WWW-look-and-feel.<br />
<texcode><br />
\setupinteraction[state=start]<br />
\starttext<br />
\from[aurl] % typesets the URL description in color<br />
\from[anotherurl] % typesets the URL in color<br />
\stoptext<br />
</texcode><br />
<br />
<!--You can use<br />
<texcode><br />
\url[aurl]<br />
</texcode><br />
as well, which behaves like {{cmd|from}}[#1].<br />
--><br />
<br />
URL shortcuts defined by {{cmd|useURL}} can be used while {{cmd|url}} as well:<br />
<texcode><br />
\url[aurl]<br />
</texcode><br />
<br />
== How to Typeset URLs ==<br />
<br />
=== Example for Mailto #1 ===<br />
<context source=yes><br />
\setupinteraction[state=start] <br />
\useurl [mymail] [mailto:nobody@example.zzz] [][visible@mailaddress.zzz]<br />
<br />
\starttext <br />
<br />
Send your spam to \from[mymail]! <br />
<br />
\stoptext <br />
</context><br />
<br />
=== Example for Mailto #2 ===<br />
<br />
<context source=yes><br />
\setupinteraction[state=start] <br />
\starttext <br />
Send your spam to \goto{visible@mailaddress.zzz}[url(mailto:nobody@example.zzz)] <br />
\stoptext <br />
</context><br />
<br />
=== Example for WWW ({{cmd|goto}}) ===<br />
<br />
Another way of typesetting URLs is the {{cmd|goto}}: \goto{#1}[#2] command. This expects the description text as first argument and the actual URL as the second one; note that it has to be wrapped in url(#2) to create a clickable link:<br />
<texcode><br />
\goto{In Lua, array indices start from one.}[url(http://www.xkcd.com/163/)]<br />
</texcode><br />
<br />
=== Escaping of Special Characters ===<br />
<br />
You might be interested in [[URL#Avoid_Escaping_Characters|not escaping characters]].<br />
<br />
Note that special characters, eg hash sign, percent sign, must be escaped by backslash. <br />
Escaping means that the special character will be processed one step later and it prevents<br />
annoying error messages during compilation.<br />
<br />
The <code>#</code> sign will be replaced by <code>\#</code>,<br />
the <code>%</code> sign by <code>\%</code>, etc.<br />
<br />
<context source=yes><br />
\setupinteraction[state=start] <br />
\useurl [myurl] [www.example.zzz/\#999] []<br />
[www.example.zzz/\#999] <br />
</context><br />
<br />
Another way of writing special characters is described below, with hyphenated URLs.<br />
<br />
== Hyphenated URLs ==<br />
<br />
URLs tend to become large monsters under many circumstances but you may have a good reason not to conceal them from the reader. <br />
This is where hyphenation comes in handy.<br />
ConTeXt provides a dedicated mechanism for chopping them into pieces:<br />
<context source=yes><br />
\hyphenatedurl{http://bits.blogs.nytimes.com/2010/03/05/a-former-book-designer-says-good-riddance-to-print/?hpw}<br />
</context><br />
<br />
=== Hyphenation Rules ===<br />
<br />
This has some characters predefined where Hans “likes” URLs to break (see the list at the beginning of [[source:lang-url.lua|lang-url.lua]], cf. [http://www.ntg.nl/pipermail/ntg-context/2008/032959.html a message on ntg-context]).<br />
If you prefer other characters you can add them via:<br />
<texcode><br />
\sethyphenatedurlnormal{:=?&}<br />
\sethyphenatedurlbefore{?&}<br />
\sethyphenatedurlafter {:=}<br />
</texcode><br />
<br />
URL hyphenation can, of course, be used wherever you need them.<br />
<texcode><br />
\useURL[yaurl] [http://xkcd.com/638/] [] [\hyphenatedurl{http://xkcd.com/638/}]<br />
\starttext<br />
\from[yaurl]<br />
\stoptext<br />
</texcode><br />
<br />
=== Escaping Special Characters ===<br />
<br />
The method for escaping of special characters described above does not work with command<br />
{{cmd|hyphenatedurl}} completely, unfortunately. Escaping backslash will undesirably appear on the output when percent sign is printed out. Similar problems bring hash sign and backslash.<br />
<br />
Therefore, these three characters must be rewritten to commands, see the following list:<br />
<table><br />
<tr><td><code>%</code></td><td> --> <code>{{cmd|letterpercent}}</code></td></tr><br />
<tr><td><code>#</code></td><td> --> <code>{{cmd|letterhash}}</code></td></tr><br />
<tr><td><code>\</code></td><td> --> <code>{{cmd|letterescape}} or {{cmd|letterbackslash}}</code></td></tr><br />
</table><br />
<br />
For other characters, similar commands have been predefined but it is not necessary to use them.<br />
<br />
<table><br />
<tr><td><code>&</code></td><td> --> <code>{{cmd|letterampersand}}</code></td></tr><br />
<tr><td><code><</code></td><td> --> <code>{{cmd|letterless}}</code></td></tr><br />
<tr><td><code>></code></td><td> --> <code>{{cmd|lettermore}}</code></td></tr><br />
<tr><td><code>"</code></td><td> --> <code>{{cmd|letterdoublequote}}</code></td></tr><br />
<tr><td><code>'</code></td><td> --> <code>{{cmd|lettersinglequote}}</code></td></tr><br />
<tr><td><code>$</code></td><td> --> <code>{{cmd|letterdollar}}</code></td></tr><br />
<tr><td><code>^</code></td><td> --> <code>{{cmd|letterhat}}</code></td></tr><br />
<tr><td><code>_</code></td><td> --> <code>{{cmd|letterunderscore}}</code></td></tr><br />
<tr><td><code>|</code></td><td> --> <code>{{cmd|letterbar}}</code></td></tr><br />
<tr><td><code>~</code></td><td> --> <code>{{cmd|lettertilde}}</code></td></tr><br />
<tr><td><code>/</code></td><td> --> <code>{{cmd|letterslash}}</code></td></tr><br />
<tr><td><code>?</code></td><td> --> <code>{{cmd|letterquestionmark}}</code></td></tr><br />
<tr><td><code>!</code></td><td> --> <code>{{cmd|letterexclamationmark}}</code></td></tr><br />
<tr><td><code>@</code></td><td> --> <code>{{cmd|letterat}}</code></td></tr><br />
<tr><td><code>:</code></td><td> --> <code>{{cmd|lettercolon}}</code></td></tr><br />
<tr><td><code>{</code></td><td> --> <code>{{cmd|letterbgroup}}</code> or <code>{{cmd|letteropenbrace}}</code> or <code>{{cmd|letterleftbrace}}</code></td></tr><br />
<tr><td><code>}</code></td><td> --> <code>{{cmd|letteregroup}}</code> or <code>{{cmd|letterclosebrace}}</code> or <code>{{cmd|letterrightbrace}}</code></td></tr><br />
</table><br />
<br />
A custom symbol can be inserted as well, eg in case of a linebreak:<br />
<texcode><br />
\def\hyphenatedurlseparator{↩}<br />
</texcode><br />
<br />
These special commands can be used in other cases, like {{cmd|useURL}}, too.<br />
<br />
<br />
== Setting Color and Style ==<br />
For {{cmd|url}}:<br />
<texcode><br />
\setupurl<br />
[color=blue,<br />
style=\tf]<br />
</texcode><br />
For {{cmd|goto}} and {{cmd|from}}:<br />
<texcode><br />
\setupinteraction<br />
[state=start,<br />
color=blue,<br />
style=\tf]<br />
</texcode><br />
<br />
== Tips and Tricks ==<br />
<br />
=== Many Different Hyperrefs ===<br />
If you need many hyperrefs in your document these definitions may be handy for you<br />
<context source=yes><br />
\def\href#1#2{\useURL[#2][{#2}][][{#1}]\goto{\url[#2]}[url(#1)]} <br />
\def\ahref#1{\color[linkcolor]{\ttx \href{#1}{<#1>}}} <br />
\def\fullahref#1{\color[linkcolor]{\ttx \href{#1}{http://#1}}} <br />
\def\mailto#1{\useURL[#1][mailto:#1][][#1]\from[{#1}]} <br />
\def\MailTo#1#2{\useURL[#1][mailto:#1][][#2]\from[{#1}]} <br />
<br />
Send mail to \MailTo{foo@bar.zzz}{Mr. Foo}<br />
</context><br />
<br />
=== Avoid Escaping Characters ===<br />
<br />
In case you don’t want to escape characters from your URLs, you might want to use the following command:<br />
<br />
<context source="yes"><br />
\setupinteraction[state=start]<br />
\setupnote[footnote][location=text]<br />
\setupnotation[footnote][alternative=serried, numbercommand=\tfx]<br />
\unexpanded\def\mypersonalurl#1{%<br />
\bgroup\tt\goto{\hyphenatedurl{#1}}[url(#1)]\egroup}<br />
\starttext<br />
\startasciimode<br />
\mypersonalurl{http://a.b?hpw%20h#pw}<br />
\stopasciimode<br />
\startasciimode<br />
\footnote{\mypersonalurl{http://a.b?hpw%20h#pw}}<br />
\stopasciimode<br />
\placenotes[footnote]<br />
\stoptext<br />
</context><br />
<br />
But you have to consider one option to make it work:<br />
<br />
* Setting <cmd>asciimode</cmd> for the whole document.<p>Comments won’t work, because <code>%</code> will be considered a standard character.</p><br />
<br />
* Wrapping all URLs inside <cmd>startasciimode</cmd>...<cmd>stopasciimode</cmd>.<p>If you use URLs inside footnotes, it is the whole footnote which has to be inside the pair of commands.</p><p>Comments inside the mode won’t work.</p><br />
<br />
=== External Links ===<br />
Create a macro for external links in a colour that is distinct from other document links.<br />
<br />
<pre><br />
% Enable document colours<br />
\setupcolors[state=start,]<br />
<br />
% Internal link colours<br />
\setupinteraction[state=start,color=blue,]<br />
<br />
% External link colours<br />
\definecolor[steelblue][h=4682B4]<br />
\define[2]\href{%<br />
\begingroup<br />
\setupinteraction[<br />
style=normal,<br />
color=steelblue,<br />
]%<br />
\goto{#1}[url(#2)]%<br />
\endgroup%<br />
}<br />
<br />
% Set index colours<br />
\setupcombinedlist[content][<br />
interaction=all,<br />
color=red,<br />
]<br />
<br />
% Set the table of contents colours<br />
\setuplist[chapter][<br />
% Text colour<br />
color=darkcyan,<br />
% Page number colour<br />
pagecolor=darkgreen,<br />
]<br />
<br />
% Set up the index heading colour<br />
\setupregister[index][<br />
color=darkgray,<br />
balance=no,<br />
]<br />
<br />
\def\Google{G\color[red]{o}\color[orange]{o}g\color[green]{l}\color[red]{e}}<br />
<br />
\starttext<br />
\completecontent<br />
<br />
\startchapter[title=chapter]<br />
Search \index{source code}{source code} using \href{\Google{} Website}{http://google.com}! Read about<br />
\index{syntax}{syntax}.<br />
\stopchapter<br />
<br />
\placeindex<br />
<br />
\stoptext<br />
</pre></div>Mæstro