# What command should I use to be warned of this collision beforehand?

After a hunt through several subfiles, I've narrowed down what I thought was a bug down to this MWE

\documentclass{article}
\usepackage{amsmath, amssymb}
\newcommand{\R}{\mathbb{R}}
\begin{document}
$\R$
\newdimen\R
\R=.4cm
$\R$
\end{document}


Clearly user error. Although this is what I get for copy and pasting code without paying too close attention to the variables they use. What commands should I use to be warned of this collision in compiling instead of getting the error ! Missing number... and having to scour several files for what this could be?

I feel like this is along the lines of \def versus \newcommand.

• Use LaTeX's \newlength instead of \newdimen. Dec 19, 2018 at 5:30
• by the way, use \the\R instead of \R if it is a dimen register and you want to typeset its value (in pt units)
– user4686
Dec 19, 2018 at 8:06

You should use LaTeX's \newlength and \setlength instead of \newdimen and = assignment.

\documentclass{article}
\usepackage{amsmath, amssymb}
\newcommand{\R}{\mathbb{R}}
\begin{document}
$\R$
\newlength\R
\setlength\R{.4cm}
$\R$
\end{document}


Yes, it's the same as the problem with \def.

The \newdimen macro comes from plain TeX and it's in LaTeX for historical reasons: in order to ease transition from plain TeX, LaTeX was loaded with a copy of plain TeX, barring a few commands that were reused (\line, for instance).

The only difference between plain TeX's and LaTeX's \newdimen is that the former is \outer and the latter isn't.

\outer\def\newdimen{\alloc@1\dimen\dimendef\insc@unt}  %% <-- plain TeX

\def\newdimen{\alloc@1\dimen\dimendef\insc@unt} %% <--- LaTeX (up to 2015)


The LaTeX definition has slightly changed in 2015, because a different set of allocation macros was introduced to cope with the extended range of registers afforded by e-TeX.

The \alloc@ macro in LaTeX was (and its current variant is) essentially the same as in plain; the \dimendef primitive (the ultimate responsible for assigning the desired meaning to \foo in \newdimen\foo) does no check for definedness of the control sequence.

The LaTeX commands that do definitions and allocations and are documented in the manual all do a check.


\newdimension{\mydim}
\mydim=.4cm
\showthe\mydim
\end{document}

• That'll work. If there's not a native command, I'll accept this.
– user45054
Dec 19, 2018 at 5:25
• As far as I know there is none, sorry... Dec 19, 2018 at 5:28
• @AndiW Yes, there is, see my answer. Dec 19, 2018 at 5:34
• Arrgghh... sometimes you don't think about the most basic things... I'll take the blame... Dec 19, 2018 at 5:36