1

This question already has an answer here:

I am new to VTEX. How can i solve this??

\documentclass{article}
\begin{document}
\the\hsize
\end{document}

Output: 345.0 pt

but i have to write a macro to calculate hsize in mm example: \printdimen[mm]\hsize and if i take hsize 6.5in then what will be output in mm?

marked as duplicate by Werner, Svend Tveskæg, Przemysław Scherwentke, Malipivo, user31729 Apr 21 '15 at 16:54

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1
% arara: pdflatex

\documentclass[a4paper]{article}
\usepackage{xparse}
\usepackage{siunitx}
\usepackage{pgf}
\usepackage{mathtools}
\makeatletter
\def\convertto#1#2{\strip@pt\dimexpr #2*65536/\number\dimexpr 1#1}
\makeatother
\newcommand*{\getlength}[3]{%
    \pgfmathsetmacro#1{#3*#2}
}
\DeclareDocumentCommand\printdimen { o m }{%
    \getlength{\tmp}{\convertto{#1}{1pt}}{#2}\SI{\tmp}{#1}
}


\begin{document}  
\begin{align*}  
    \text{\the\hsize} &\equiv \printdimen[mm]\hsize \\
                      &\equiv \printdimen[cm]\hsize \\
                      &\equiv \printdimen[ex]\hsize \\                    
                      &\equiv \printdimen[em]\hsize \\      
                      &\equiv \printdimen[bp]\hsize \\
                      &\equiv \printdimen[dd]\hsize \\                    
                      &\equiv \printdimen[pc]\hsize \\  
                      &\equiv \printdimen[in]\hsize                                    
\end{align*}
\end{document}

enter image description here

  • For VTeX...........? – jon Apr 21 '15 at 14:49
  • @jon no idea, what that is. Sorry. – LaRiFaRi Apr 21 '15 at 14:50
  • No e-TeX extensions. – jon Apr 21 '15 at 14:53
  • @LaRiFaRi i want to show output only 121.25221 mm. In that case what i have to do? whenever i use \printdimen[mm]\hsize then output ll be only 21.25221 mm "Thanks" – enadul shaheen Apr 21 '15 at 16:12
  • @enadulshaheen you get 21... when compiling my MWE? – LaRiFaRi Apr 21 '15 at 16:17
4

Like this?

\documentclass{article}
\usepackage{printlen}
\begin{document}
\uselengthunit{mm}\printlength{\hsize}
\end{document}
  • like that \printdimen[mm]\hsize – enadul shaheen Apr 21 '15 at 14:21

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