# Why is \glueexpr used in etoolbox's \deflength instead of \dimexpr

Consider the following snippet from etoolbox:

\newrobustcmd*{\deflength}[2]{%
\ifundef{#1}
{\etb@noglobal\etb@err@nolen{#1}}%
{#1\glueexpr#2\relax}}


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?

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

The following should answer the question:

\documentclass{article}
\newlength{\mylenA}
\newlength{\mylenB}
\begin{document}

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

\setlength{\mylenB}{\mylenA}
\showthe\mylenB % \mylenB = 5pt plus 2pt

\setlength{\mylenB}{\dimexpr\mylenA}
\showthe\mylenB % \mylenB = 5pt (no glue)

\setlength{\mylenB}{\glueexpr\mylenA}
\showthe\mylenB % \mylenB = 5pt plus 2pt

\end{document}


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.

• By <len> I refer to a length macro, not an actual length. – Werner Apr 14 '15 at 6:00
• 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