Expressions

From Wiki
Revision as of 18:20, 2 February 2009 by Taco (talk | contribs) (→‎Expressions: I removed the "optional" for \relax. It actually isn't, except in a controlled environment)
Jump to navigation Jump to search

< Main Page | Inside ConTeXt >

ConTeXt implements extensions from eTeX including the evaluation of expressions (quoted from the [eTeX manual]):

Expressions

eTeX introduces the notion of expressions of type number, dimen, glue, or muglue, that can be used whenever a quantity of that type is needed. Such expressions are evaluated by eTeX's scanning mechanism; they are initiated by one of the commands \numexpr, \dimexpr, \glueexpr, or \muexpr (determining the type t) and terminated by \relax (which will be absorbed by the scanning mechanism). An expression consists of one or more terms of the same type to be added or subtracted; a term of type t consists of a factor of that type, optionally multiplied and/or divided by numeric factors; finally a factor of type t is either a parenthesized subexpression or a quantity (number, etc.) of that type.

Examples

It has been pointed out that the only important thing for \dimexpr is to write the dimen value as first value after the \dimexpr command and then the numeric values. Notice that the following expression is also valid:

\placesidebyside {\externalfigure[cow][width=.4\textwidth]}
 {\framed[width=.4\textwidth,height=\dimexpr.4\textwidth*200/275\relax]
  {\vbox{this is a box}}}


TODO: Add more illustrative examples. (See: To-Do List)