[Dev-luatex] dimension helper

David Kastrup dak at gnu.org
Sat Feb 20 15:42:16 CET 2010


Hans Hagen <pragma at wxs.nl> writes:

> On 20-2-2010 14:02, Paweł Jackowski wrote:
>> Dear Team,
>>
>> it is a common convention in luatex that dimensions are specified either
>> as a number (in scaled points) or a string with unit included. But
>> unless I'm blind, there is no helper function that converts string
>> dimension to a number. Seems that there is a standard dimen_to_number()
>> function for that purpose. Would be convenient to have such on aboard.
>> If I make such a helper, will you consider adding it to a repo? I'm
>> thinking of
>>
>> tex.sp'1in' -> 4736286
>> tex.sp() -> error argument must be a string
>>
>> or more general
>>
>> tex.unit('1in', 'cm') -> 2.54
>>
>> wdyt?
>
> luatex is consistently scaled points and a helper can be written in
> luq quite easily
>
> also, keep in mind that performance wise it's best to do it in lua
> anyway; it's actually just a matter of multiplication (which saves a
> function call too)

No, it isn't.  It is a matter of multiplication, division and
truncation.

It is a little-know fact that 2.54cm are 72.2698pt in TeX, 1in is
72.26999pt, and both are different from 72.27pt, while 254cm and 100in
perfectly well are 7227.0pt.

So no, you can't substitute a unit in TeX with a constant.  Units are
_fractions_ of sp, and applying a "multiplier" to them does not work
like one would think.

-- 
David Kastrup


More information about the dev-luatex mailing list