I would like to have a command which executes a simple division of numbers. This \newcommand{\mylen}[1]{1.0 / #1} just prints 1.0 / 3 when invoked as \mylen{3} and not the desired 0.33333. What do I have to do?

Edit: The result should be usable in an expression like \includegraphics[width=\mylen{3}\textwidth]{a}

  • For the simple usage using \dimexpr is OK. For something more complicated, you might want to use `luatex. See the section on Arithmetic without using abacus on the ConTeXt wiki.
    – Aditya
    Commented Aug 18, 2013 at 21:57

1 Answer 1


If you want this for lengths then it is easy,

\the\dimexpr 1pt/3\relax

produces 0.33333pt. If you don't want the explicit units then the simplest way is to first add pt then remove it from the result.

Or there are several packages that do more exact floating point arithmetic, notably pgf or fp or l3fp

  • I would like to use the result in an expression like \includegraphics[width=\mylen{3}]{...} or actually with \setkeys{Gin}{width=\mylen{3}\textwidth} :)
    – Danvil
    Commented Aug 18, 2013 at 20:23
  • [width=\dimexpr\textwidth/3] is all you need in that case Commented Aug 18, 2013 at 20:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .