2

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?

1
  • 1
    latex lengths are skips (glue) not dimens. Apr 14, 2015 at 7:24

1 Answer 1

4

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.

3
  • By <len> I refer to a length macro, not an actual length.
    – Werner
    Apr 14, 2015 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 Apr 14, 2015 at 7:21
  • @DavidCarlisle I see. As you mentioned, the main reason must be that \newlength defines a skip instead of a dimen. Apr 15, 2015 at 1:52

You must log in to answer this question.

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