3

From the layouts package manual (page 3 and 4):

The textwidth is \printinunitsof{pt}\prntlen{\textwidth} which is also \printinunitsof{in}\prntlen{\textwidth} or \printinunitsof{mm}\prntlen{\textwidth}.
prints out:
The textwidth is 433.62pt which is also 6.00117in or 152.39821mm.

But 1 inch = 25.4 mm, so 6.00117in should equal 152.429718mm. I noticed this type of inaccuracy also in a document I am currently preparing.
The number of decimals provided in the manual example seems to imply a high accuracy, but practice seems to show otherwise.
Am I seeing/doing something wrong?
If not, how accurate are the printed lengths?

  • 1
    Rounding errors. – egreg Nov 5 '18 at 15:09
  • How accurate are the printed lengths then? N.B.: the manual is treacherous then with its many decimals. – Bart Nov 5 '18 at 15:15
2

Floating point calculations in layouts are based on dimension arithmetic of TeX, which is not really accurate.

You get better results with the floating point module of expl3. Still not accurate to five decimals, but much more than the coarser result by layouts.

\documentclass{article}
\usepackage{layouts}

\usepackage{xparse}
\ExplSyntaxOn
\RenewDocumentCommand{\prntlen}{m}
 {
  \dim_to_decimal_in_unit:nn { #1 } { 1\use:c {l@yunits} } \, \use:c{l@yunits}
 }
\ExplSyntaxOff

\setlength{\textwidth}{6in}

\begin{document}

The textwidth is \printinunitsof{pt}\prntlen{\textwidth}
which is also \printinunitsof{in}\prntlen{\textwidth} or
\printinunitsof{mm}\prntlen{\textwidth}.

\end{document}

enter image description here

  • Thanks a lot! It is sufficient precise now for my purposes. Within my view, your answer would be a good improvement for a new version of the layouts package. – Bart Nov 5 '18 at 18:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.