14

(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?

jub0bs
  • 58,916
  • Have a look here: http://tex.stackexchange.com/questions/8260/what-are-the-various-units-ex-em-in-pt-bp-dd-pc-expressed-in-mm – DG' Apr 19 '15 at 18:36

1 Answers1

12

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

DG'
  • 21,727
  • Actually i am using VTEX (visual text) but its giving me Undefined control sequence error. – enadul shaheen Apr 19 '15 at 18:57
  • This one: http://www.micropress-inc.com/texdocs/edmain.htm ? – DG' Apr 19 '15 at 19:02
  • I have some confusion from above answer that is why i multiplied 1in with 65536 (#2*65536), what is the reason to used 65536 and why i divide / \number (/\number\dimexpr 1#1),what is the reason to use \number . And why i used 1#1(1#cm) \dimexpr 1#1. It would be very helpful if you briefly explain me . Thanks in advance – enadul shaheen Apr 23 '15 at 14:27
  • Everything is explained here: http://groups.google.com/group/comp.text.tex/msg/7e812e5d6e67fcc5 and here: http://tex.stackexchange.com/questions/8260/what-are-the-various-units-ex-em-in-pt-bp-dd-pc-expressed-in-mm/8337#8337 – DG' Apr 23 '15 at 18:47
  • Can you explain only one thing that is why we used 65536? I need Clear idea about that. Thanks for helping me. – enadul shaheen Apr 25 '15 at 04:43
  • Internally TeX uses scaled points (sp) and 1 pt = 65536 sp. – DG' Apr 25 '15 at 11:23
  • I have one confusion that is why we used \number? Need to clear idea about that. Thanks man you are helping me lot. – enadul shaheen Apr 28 '15 at 14:25
  • This question has been closed as a duplicate of http://tex.stackexchange.com/questions/8260/what-are-the-various-units-ex-em-in-pt-bp-dd-pc-expressed-in-mm you should ask a new question with a MWE if there are any other issues. – DG' Apr 28 '15 at 18:08