11

(I am a new to LaTeX.) I'm trying to print a length in centimeters. Here is my code:

\documentclass{article}
\begin{document}
\newdimen\mylength
\mylength=1in 
\the\mylength
\end{document}

And here is the resulting output:

72.27 pt

However, I want to show output in centimeters: Example: \the dimen [cm]\mylength. How can I do that?

8

You can use the \convertto macro from Philippe Goutet's post:

\documentclass{article}

\makeatletter
\def\convertto#1#2{\strip@pt\dimexpr #2*65536/\number\dimexpr 1#1}
\makeatother

\begin{document}
\newdimen\mylength
\mylength=1in
\convertto{cm}{\the\mylength} cm
\end{document}

Output:

2.54cm

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