[NTG-context] xml and lua again

Thomas A. Schmitz thomas.schmitz at uni-bonn.de
Fri Oct 28 08:55:18 CEST 2011


On 10/28/11 08:44, Patrick Gundlach wrote:
>
>
>>>>>
>>>>> context.blackrule{ width = number.topoints(tex.dimen["textwidth"]/2) }
>>>
>>> or just tex.dimen["textwidth"]/2 .. "sp"
>>
>> Wait, just so I understand: your solution would imply that tex.dimen["textwidth"] holds a number, not a dimension, right? (Because you simply concatenate it with a dimension unit). Which makes sense when I think of it because lua has no concept of dimensions, only of strings, functions, tables, numbers... Whereas the Wolfgang implies that the result is already in sp. So who's right?
>
> both :)
>
> tex.dimen holds a number, that is the size in points, multiplied by 65536/1pt, so for example 3pt becomes
>
> 3pt * 65536
> -----------  = 3 * 65536 = 196608
>        1pt
>
>
> This number is also known "sp". So if you store the number 3*65536 in tex.dimen[...], you can say:
>
> my width is \directlua{ tex.dimen[...] / 2}sp (results to "my width is 196608sp", which you can use as an argument to whatever needs a length)
>
> or
>
> my width is \directlua{  number_to_points(tex.dimen[...]) } where number_to_points is something like
>
> number_to_points = function (amount_in_sp)
>    in_pt = tostring(amount_in_sp / 65536)
>    return in_pt .. "pt"
> end
>
> which gives "3pt".
>
> Patrick
>

Luigi, Patrick,

thanks for your explanations! The point of my question was: can I feed 
the content of tex.dimen["textwidth"] directly back to TeX, and the 
answer to this appears to be "no"; you need to add some unit to it 
(otherwise, you get an error message). Which was a bit confusing to me 
at first, because the name tex.dimen implies that it holds a "real" 
dimension, like \newdim does.

Thomas


More information about the ntg-context mailing list