Changes

Jump to navigation Jump to search
3,532 bytes added ,  14:22, 12 December 2012
→‎Syntax: add caveat on dimensions and font size
What’s the status of this?
-->
 
== Treacherous Dimensions ==
 
At some places dimension-lookalikes are expected but they do not behave
exactly as in TEX per se because they are evaluated differently.
A very common example is the command {{cmd|setupbodyfont}} that is
possibly called, albeit implicitly, in every production document.
Its argument, the ''font size'', although it may look like an ordinary
dimension expression, will not have the same result if it has zeros
prepended or decimal places are specified.
 
Suppose you want to set the main font to a very large size:
 
<texcode>
\setupbodyfont[42pt]
\starttext foobar \stoptext
</texcode>
 
this works out well as long as you do not mistake the expression
''42pt'' to be a real dimension.
 
In TEX dimensions (which are really just integers) are treated the same
irrespective of leading or trailing zeros used in the variable
assignment.
Thus the following are all equivalent:
 
<texcode>
\newdimen\fortytwo\fortytwo=42pt
\newdimen\fortytoo\fortytoo=042pt
\newdimen\fortytww\fortytww=42.00pt
 
\starttext
\the\fortytwo\ \ifnum\fortytwo=\fortytoo\m{\top}\else\m{\bot}\fi\par
\the\fortytoo\ \ifnum\fortytwo=\fortytww\m{\top}\else\m{\bot}\fi\par
\the\fortytww\ \ifnum\fortytoo=\fortytww\m{\top}\else\m{\bot}\fi\par
\stoptext
</texcode>
 
However, this does not hold for the Context commands
{{cmd|setupbodyfont}} and {{cmd|switchtobodyfont}}.
With the latter macros, only the ''pure-integer'' specification
(<code>42pt</code>) can be used reliably, everything else, even though it
denotates the same TEX dimension, will result in a warning:
 
<pre>
fonts > bodyfont 42.0pt is defined (can better be done global)
</pre>
 
Additionally, if the code in question relies on font switching a lot
(e.&nbsp;g. Lua snippets that calculcate font sizes from floating point
numbers), there will be a ''huge'' perfomance penalty because everytime
a font switch occurs, the font will be reloaded entirely.
The reason for this is that the process of defining a font for the main
text is accompanied by a myriad of secondary definitions for different
relative font sizes ({{cmd|tfx|link=no}}, {{cmd|tfa|link=no}}
[[Font_Switching#Font_sizes|and the likes]]) and shapes &ndash; the
creation of the ''body font environment''.
If the “size” requested by {{cmd|setupbodyfont}} cannot be found in the
internal table, this environment will be rebuilt on the spot.
 
''It is also not possible to catch these cases by predefining the corresponding bodyfont environments''
by placing {{cmd|definebodyfontenvironment}} statements in the preamble.
So if you have, say:
 
<texcode>
\definebodyfontenvironment[42.0pt]
\definebodyfontenvironment[042pt]
\definebodyfontenvironment[042.0pt]
\starttext
\setupbodyfont[42.0pt] foo bar
\setupbodyfont[042pt] foo bar
\setupbodyfont[042.0pt] foo bar
\stoptext
</texcode>
 
the warning and slowdown will occur regardless.
The only real option is to serve {{cmd|setupbodyfont}} and the likes
natural integers only.
 
Alternatively you can always employ raw font definitions, if there
isn’t any need for the environment in the first place:
<texcode>
\starttext
\definedfont[file:iwona-regular.otf at 42.0pt] foo bar
\definedfont[file:iwona-regular.otf at 042pt] foo bar
\definedfont[file:iwona-regular.otf at 042.0pt] foo bar
\stoptext
</texcode>
Here the dimensions are ''real''.
 
For further information see
[http://www.ntg.nl/pipermail/ntg-context/2012/067324.html this] and
[http://www.ntg.nl/pipermail/ntg-context/2012/066940.html this]
thread on the mailing list.
188

edits

Navigation menu