[pdftex] 1px is not 1bp which seems to contradict the pdftex manual

jfbu jfbu at free.fr
Sun Mar 26 14:24:04 CEST 2023


Hi,

The problem is only one of appropriate documentation:

1) perhaps the user should be informed that in the default 72px is not 1in

2) perhaps the user should be informed that using \pdfpxdimen 1bp creates
a situation which is not the default one.

Regarding engines: 

1) applies to both pdfTeX and luaTeX

2) applies only to pdfTeX.  In fact with luatex, \pxdimen 1bp is the same as
the default situation.  With pdfTeX it is not.  If doing if with pdfTeX, then
the px unit dimension will behave as in default luaTeX

off-topic:
Perhaps multi-engine formats such as LaTeX should unify behaviors?
i.e. for example set the px dimension as if user had done \pdfpxdimen 1bp
in pdftex ?


I did not look at respective sources, and I am fairly confident after some experimenting
with random inputs and the formulae given near end of this message (using xintexpr)
that the underlying mechanism is the following

* when user does "\(pdf)pxdimen <dimspec>", the engine uses the TeX input parsing
of dimensions to convert this into an integer N (representing a multiple of "sp" unit)

* then the "px" dimension is handled like all other TeX units, i.e. via a certain DK algorithm
which uses a ratio. This ratio is (for lack of any obvious better choice) N/65536 where
N was found in the previous step.

If one wants the "px" unit to be a user-customizable configuration via a \(pdf)pxdimen 
interface
there seems indeed to be no other reasonable way than the above.

I thus imagine (having only briefly) tested that using \pdfpxdimen in pdfTeX or
\pxdimen in LuaTeX will cause the "px" unit to behave exactly identical in both.

But:

- When pdftex starts, it is configured to handle "px" as associated with ratio 65782/65536.

- When luatex starts, it is configured to handle "px" as associated with ratio 65781/65536.

The luatex choice means that if a user does \pxdimen 1bp, the default is not modified.

With pdftex a user doing \pdfpxdimen 1bp will modify pdfTeX handling of px unit into
the one of LuaTeX.

For a pdftex user  to revert to pdfTeX default after a change to "px" unit, the input
"\pdfpxdimen 1.00001bp" will let "px" behave as initially.

Whether with pdftex or luatex starting point, it is simply impossible to have a choice of "px"
which will make "72px = 1in" for TeX.

Indeed pdfTeX makes the choice of ratio 65782/65536 (one can simplify by a factor of 2)
and with this choice one ends up with 72px being represented by 4736304sp

LuaTeX chooses the ratio 65781/65536 and this ends up with 72px being represented
by 4736232sp.

But TeX represents 1in by 4736286sp which is in-between.  There is no N/65536 ratio
which will work.

As per the gory details the math formulae for conversion of (positive) inputs in "px" unit
into integer multiple of "sp" unit are

- pdfTeX: trunc(round(x*65536)*65782/65536);
- luaTeX: trunc(round(x*65536)*65781/65536);

where round is rounding away from zero.

Sorry for being perhaps a bit verbose, but I believe documentation should try
to say something like this

- 72px is initially very close to 1in for (pdf,lua]TeX but not exactly equal to it,
- the default of pdfTeX is *not* the same as \pdfpxdimen 1bp but is the same
as \pdfpxdimen 1.00001bp

(I did try "texdoc pdftex" and "texdoc luatex" and searched in the respectives files for 
any provided information on "pxdimen"; apologies if I missed something)

Regards,

Jean-François







More information about the pdftex mailing list.