# Why \newlength is not profiled as \newcommand?

While commands are defined and set in one step with \newcommand, lengths need two steps for this: \newlength and then \setlength. Because

\newlength{\foo}{1cm}


would be easier than

\newlength{\foo}
\setlength{\foo}{1cm}


I wonder if there is a special reason for \newlength to not have been profiled as \newcommand.

• In general you want to give commands always a definition, while it often happens that you only reserve lengths for later uses. expl3 offers \tl_new:N and \tl_set:Nn for commands. And there is \dim_const:Nn to set a dimension directly (the "const" in the name makes it a bit awkward to use for dimension you want to change later). – Ulrike Fischer Nov 14 '14 at 8:23
• @UlrikeFischer If you do \tl_const:Nn, then the variable should not change its value (across a LaTeX run); similarly for \dim_const:Nn and the other similar functions. Exemplary is \int_const:Nn \c_x_int: you can't even say \int_incr:N \c_x_int. The fact that changing the value of a constant dimension is possible with, say, \dim_add:Nn is just implementation dependent and shouldn't be relied on. – egreg Nov 14 '14 at 9:42
• In my experience, the cases where one allocates a length register and wants to set the value immediately are a small minority. – egreg Nov 14 '14 at 9:45
• @egreg: Yes I wouldn't \dim_const:Nn etc for register I want to change a lot (a \dim_new:Nn would be better to declare and set in one go). Would you use a constant for a value that is changed once? First a default is set and at the begin of the document it is perhaps changed? (An example is the font size of a document). – Ulrike Fischer Nov 14 '14 at 10:04
• @UlrikeFischer Once set, a constant should not change. – egreg Nov 14 '14 at 10:10

• I think this doesn't answer the “Why not \newlength\foo{2cm}”; one could make a macro that automatically does that, why hasn't it been done? – Manuel Nov 14 '14 at 11:20
• @DavidCarlisle Making use of \newsetlength defined by \newcommand{\newsetlength}[2]{\newlength{#1}\setlength{#1}{#2}} wouldn't be worse than making use of usual \newlength, isn't it? – Denis Bitouzé Nov 14 '14 at 13:15
• @DenisBitouzé It would be used instead of \setlength and that would be much worse. (If it is just used once per length to allocate and set then obviously it is not bad) – David Carlisle Nov 14 '14 at 13:16
\newlength is defined as a \skip, i.e. register provided also to calculations (\newlength reserves a new skip, \setlength sets its value), while \newcommand in this case would be only a string.