Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Tried the printlen package, but it seems to not understand what 2.5in means:

\documentclass{minimal} 
\usepackage{printlen} 
\uselengthunit{in} 
\begin{document} 
\newlength{\advertwidth} 
\setlength{\advertwidth}{2.5in} 
\printlength{\advertwidth} 
\end{document} 

Typesetting the above yields 2.50049 in --- is there something better?

NB - in addition to the above, the project in question needs the packages:

\usepackage{calc,geometry,xcolor,graphicx,csvsimple}

the last in particular, conflicts w/ the answers initially provided.

share|improve this question

3 Answers 3

up vote 10 down vote accepted
\documentclass[preview,border=12pt,varwidth]{standalone}
\usepackage[nomessages]{fp}
\usepackage{printlen}
\makeatletter
\newcommand{\printer}[3][in]{%
    \FPeval\temp{round(\expandafter\strip@pt\csname#2\endcsname/72.27:#3)}%
    \temp#1}
\makeatother

\newlength\xxx
\setlength{\xxx}{2.5in}    
\parindent=0pt


\begin{document}    

\printer{xxx}{1}

\printer{xxx}{2}

\printer{xxx}{7}

\end{document}

enter image description here

share|improve this answer

The recently uploaded lengthconvert package seems to be what you're looking for:

\documentclass{article}
\usepackage{lengthconvert}
\Convertsetup{unit=in}
\begin{document}

\newlength{\advertwidth}
\setlength{\advertwidth}{2.5in}

\Convert{\advertwidth}

\Convert{72.27pt}

\end{document}

enter image description here

share|improve this answer
    
Unfortunately, it clashes with csvsimple --- I've emailed the two package authors, so hopefully this will get worked out. –  WillAdams Jul 9 '13 at 16:26
4  
The macro \TrimSpaces in csvsimple should have an @ name, since it's an internal of the package. The clash is with xparse, rather than lengthconvert –  egreg Jul 9 '13 at 16:30
    
Prof. Sturm, the author of csvsimple pointed out in a private e-mail that re-ordering the packages would've been sufficient to fix this, but has indicated that he will change the relevant macro name in his next update. Thanks! –  WillAdams Jul 10 '13 at 16:31
1  
@WillAdams No, it wouldn't be sufficient; loading csvsimple after xparse would avoid raising the error in this particular case, but would break xparse. –  egreg Jul 10 '13 at 16:33
    
Okay, next version then. –  WillAdams Jul 10 '13 at 16:48

The obligatory expl3 solution:

\documentclass{minimal} 
\usepackage{expl3,xparse}
\ExplSyntaxOn
\NewDocumentCommand { \printlengthas } { m m }
  { \dim_to_unit:nn {#1} { 1 #2 } #2 }
\ExplSyntaxOff 
\begin{document} 
\newlength{\advertwidth} 
\setlength{\advertwidth}{2.5in} 
\printlengthas{\advertwidth}{in}
\end{document} 

(\dim_to_unit:nn is currently experimental, but the idea is bound to stay: just a question of the name.)

Note: this currently requires the latest release of expl3: \dim_to_unit:nn was added to the CTAN version on 2013-07-11.

share|improve this answer
    
I see egreg's solution also uses expl3 internally: mine is a wrapper around basic TeX arithmetic only (lenghtconvert uses the L3 FPU). –  Joseph Wright Jul 9 '13 at 15:22
    
Unfortunately, this doesn't play well w/ csvsimple either. –  WillAdams Jul 9 '13 at 16:28
    
@WillAdams I think that should be asked as a separate question ('How to use csvsimple and xparse: clash over \TrimSpaces'). A solution is I think easy, as csvsimple uses \TrimSpaces only internally and only in one place, and this can be fixed using an alternative version from expl3. (This is separate from the question posed here, so two separate but linked questions would be better than one with two entirely separate parts.) –  Joseph Wright Jul 9 '13 at 16:38
    
dim_to_unit isn't documented :-( –  Marco Daniel Jul 9 '13 at 17:05
1  
@WillAdams The fixed version of csvsimple has been uploaded on CTAN (and included in TeX Live) –  egreg Sep 27 '13 at 11:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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