From Wiki
Revision as of 21:09, 22 April 2013 by Jannis (talk | contribs)
Jump to navigation Jump to search

ConTeXt allows different methods to initialize variables and to calculate with dimension units.




C \measure{ColumnC}

D \measure{ColumnD}

CD \measure{ColumnCD}




\defineexpandable\ColumnA    {30mm}
\defineexpandable\ColumnB    {40mm}
\defineexpandable\ColumnAB    {\the\dimexpr(\ColumnA + \ColumnB)\relax}

A  \ColumnA

B  \ColumnB

AB: \ColumnAB


The behavior of \define has changed. At first the default was expanded, now it is unexpanded. If "unexpanded" is wished some extracommands are neccesary:

same as the lowlevel-TeX-Macro \def\...
same as the low-level-textmacro \unexpanded\def\... 



\defineexpandable\ColumnA    {30mm}
\defineexpandable\ColumnB    {40mm}
\newdimen\ColumnAB \ColumnAB=\dimexpr(\ColumnA + \ColumnB)

A  \ColumnA

B  \ColumnB

ColumnAB: \the\ColumnAB


\externalfigure ist also working without "\the".



\defineexpandable\ColumnA    {30mm}
\defineexpandable\ColumnB    {40mm}

\defineexpandable\ColumnABii   {\ctxlua{context([==[\ColumnA + \ColumnB]==])}}

ColumnABii: \the\dimexpr \ColumnABii\relax


Important to understand

This points have to be explained.


\the: what is it? 


expanding of variables: What does this mean?


With \relax the termination of a calculation is garantied. If there is one too much ... no problem, then it is ignored.

"add a \relax after code definitions to prevent the scanner from reading too much"

\the\dimexpr... will look ahead till there's something nonexpandable, and contrary to what one expects


will not stop at the ) so, although with measures it normally goes okay, personally I always use \relax as terminator; the \relax will be eaten up so there is no interference but it guarantees to stop scanning.

\definemeasure[ColumnC][30mm] \definemeasure[ColumnD][40mm] \definemeasure[ColumnCDi][\the\dimexpr(\measure{ColumnC}+\measure{ColumnD})\relax]

Further examples

\footnote{\input tufte \relax} \par \definepapersize[bigsheet][width=\dimexpr\paperwidth+6mm\relax,height=\dimexpr\paperheight+6mm\relax] \setupTABLE[c][3][width={\dimexpr(\textwidth-2cm)* 2 / 3\relax}] \definemeasure[topspace] [\dimexpr(210mm-31mm*5)/2\relax]