I want to convert a length in cm (centimeter) to bp (big point). Is there a command to convert cm to bp?


You can store the cm in a register, which converts it into the internal pt format and then convert pt to bp using a 72/72.27 factor (graphic/x uses .99626).

You can use the eTeX macro \dimexpr for this. Then it is even expandable:

\def\converttobp#1{\the\dimexpr .99626\dimexpr #1\relax\relax}

This takes a cm or any other dimension and converts it to bp but return it without the bp unit attached. However the two conversions (cm->pt->bp) will add rounding errors.

You can avoid one of them by stripping the cm off and replacing it with pt to make TeX take in points instead, then convert it with the cm-to-bp factor of 28.3464567:

\def\cmtobp#1{\strip@pt\dimexpr 28.3464567\dimexpr\strip@cm #1 pt\relax\relax}
% Usage: \cmtobp{1cm} (returns value in bp without trailing unit)

If you want to use the cm value without unit and get a dimension with bp unit use:

\def\cmtobp#1{\strip@pt\dimexpr 28.3464567\dimexpr #1 pt\relax\relax bp}
  • there is a rounding error.
    – xport
    Jul 10 '11 at 11:29
  • 1
    @xport: Yes, sure there is. TeX numeric accuracy isn't overwhelming. You can try a more accurate factor like 0.99626401 but I get the same result for e.g. 1cm. There should be reason why graphics/x uses it. If you want more accurate results I would convert it using an external script.
    – Martin Scharrer
    Jul 10 '11 at 11:36
  • 2
    @xport: No offense, but isn't this the kind of +1-comments we agreed on not to post?
    – doncherry
    Jul 10 '11 at 17:05
  • @Martin: how to add a trailing bp and remove cm when invoking \cmtobp. It means when I invoke \cmtobp{2.54}, I will get 72bp.
    – xport
    Jul 11 '11 at 8:06
  • @xport: I now updated my question to include this version.
    – Martin Scharrer
    Jul 11 '11 at 8:17

And if you need to "ceil" the result:

  \the\dimexpr 28.3464567\dimexpr\strip@cm #1 pt\relax\relax}

\begingroup\catcode`P=12 \catcode`T=12
  \def\@ceil#1.#2PT{\number\numexpr#1+0\ifnum#2>\z@ 1\fi\relax}}

\cmtobp{3cm} % -> 86
\cmtobp{2.54cm} % -> 72
\cmtobp{2.541cm} % -> 73

This uses the fact that \the<dimen> has always at least one decimal digit (possibly 0).

The following version has different input and output, as per request:

  \the\dimexpr 28.3464567\dimexpr #1pt\relax\relax}

\begingroup\catcode`P=12 \catcode`T=12
  \def\@ceil#1.#2PT{\number\numexpr#1+0\ifnum#2>\z@ 1\fi\relax bp}}

\cmtobp{3}     % -> 86bp
\cmtobp{2.54}  % -> 72bp
\cmtobp{2.541} % -> 73bp

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.