Changes

Jump to navigation Jump to search
463 bytes added ,  08:05, 18 May 2011
m
added categories
as first value after the <code>\dimexpr</code> command and then the numeric values.
Notice that the following expression is also valid:
<texcode>
\placesidebyside {\externalfigure[cow][width=.4\textwidth]}
{\framed[width=.4\textwidth,height=\dimexpr.4\textwidth*200/275\relax]
{\vbox{this is a box}}}
</texcode>
<contextsource="yes">
\setupexternalfigures[location={local,default}]
\placesidebyside{\externalfigure[cow][width=.4\textwidth]}
<context source="yes">
\dimen0=15pt
\dimen1dimen2=20pt
\number\dimexpr\dimen0/\dimen2\relax
</context>
{{todo|Fix me!}}
''The result of the integer division is 1 (rather than the decimal 0.75); This illustrates that the result of dividing two numbers that are nearly equal within TeX is not very useful. We can get around this by multiplying the numerators by some large factor, assuring that the evaluated fractions remain integer:''
\fi
</context>
 
The important point to keep in mind is that TeX performs '''integer''' arithmetic in units of scaled points.
Therefore, one must be careful, especially when using divisions that may lead to integer rounding.
== LuaTeX ==
''Alternatively, we can use luaTeX to reliably get the correct result. The <code>\type{tex.dimen}</code> command allows us to access the <code>\dimen</code> register from TeX in Lua.''
<context source="yes"texcode>
\dimen0=15pt
\dimen2=20pt
end
\stopluacode
</texcode>
 
<context>
\dimen0=15pt
\dimen2=20pt
\dimen4=15pt
\dimen6=30pt
 
\ifdim\dimexpr100\dimen0/\dimen2\relax<\dimexpr100\dimen4/\dimen6\relax
The second fraction is greater.
\else
The first fraction is greater.
\fi
</context>
{{todo|I guess that the online conTeXt doesn't do luacode...}}
''and''
<context source="yes"texcode>
\dimen0=15pt
\dimen2=20pt
end
\stopluacode
</texcode>
 
<context>
\dimen0=15pt
\dimen2=20pt
\dimen4=15pt
\dimen6=15pt
 
\ifdim\dimexpr100\dimen0/\dimen2\relax<\dimexpr100\dimen4/\dimen6\relax
The second fraction is now greater.
\else
The first fraction is still greater.
\fi
</context>
''The output is now correct in both cases without making use of any tricks.''
 
 
[[Category:Inside ConTeXt]]
[[Category:ConTeXt programming]]

Navigation menu