Consider the following snippet from etoolbox:


Maybe I do not understand the differences between \numexpr, \dimexpr, \glueexpr and \muglueexpr (e-TeX expressions), but I suspected the use of \dimexpr in the definition of \deflength just like \numexpr is used in the definition of \defcounter Can someone explain the difference?

  • 1
    latex lengths are skips (glue) not dimens. – David Carlisle Apr 14 '15 at 7:24

The following should answer the question:


\mylenA=5pt plus 2pt
\showthe\mylenA % \mylenA = 5pt plus 2pt

\showthe\mylenB % \mylenB = 5pt plus 2pt

\showthe\mylenB % \mylenB = 5pt (no glue)

\showthe\mylenB % \mylenB = 5pt plus 2pt


The .log outputs:

> 5.0pt plus 2.0pt.
l.7 \showthe\mylenA

> 5.0pt plus 2.0pt.
l.10 \showthe\mylenB

> 5.0pt.
l.13 \showthe\mylenB

> 5.0pt plus 2.0pt.
l.16 \showthe\mylenB

If you set a length using \dimexpr<len> you lose any glue. Using \glueexpr<len> the glue is kept.

| improve this answer | |
  • By <len> I refer to a length macro, not an actual length. – Werner Apr 14 '15 at 6:00
  • 1
    The important thing you don't mention is that latex's \newlength defines a skip register not a dimen register. that is it is based on \newskip not \newdimen – David Carlisle Apr 14 '15 at 7:21
  • @DavidCarlisle I see. As you mentioned, the main reason must be that \newlength defines a skip instead of a dimen. – Pieter Stroobants Apr 15 '15 at 1:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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