TeX stores dimensions internally in scaled points but operation \the expands to the corresponding value in points. Can we avoid the conversion and get the more precise, "original" value instead?

$ tex \\relax
This is TeX, Version 3.14159265 (TeX Live 2014) (preloaded format=tex)

(Please type a command or say `\end')

> 252.94499pt.
<*> \showthe\dimen0



> 16577003.
<*> \showthe\count0

dimen values are just integer values interpreted as sp so you can do the above (although actually there is no loss of precision I think in the fractional pt value tex shows, it always shows enough decimal places to determine the exact value in sp)

  • 2
    If e-TeX is available, \showtokens\expandafter{\number\dimen0} avoids assigning the value to a count register. In general \number\dimen0 will expand the dimension in scaled points (with possible number termination problems, of course). – egreg Oct 23 '14 at 8:58
  • This was an easy question :-) But how about dimension values in the output file? Can we have them in scaled points, too? – SJU Oct 23 '14 at 11:45
  • @egreg What are number termination problems? – SJU Oct 23 '14 at 11:47
  • @AngelTsankov Don't worry: leave a space after \dimen0 and you'll be OK. – egreg Oct 23 '14 at 11:53
  • @egreg so modern, as always, I forget the 1980's have finished. – David Carlisle Oct 23 '14 at 11:57

For printing a length in sp units, define

\newcommand\lengthinsp[1]{\number\dimexpr#1\relax sp}

This will accept \lengthinsp{\parindent} (with a register) or even \lengthinsp{3.5in}.



\newcommand\lengthinsp[1]{\number\dimexpr#1\relax sp}





enter image description here

This is fully expandable. If you don't want to depend on e-TeX, a non-expandable version is needed:

  \number\dimen@ sp%

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.