# Latex long calculation error: “Missing number, treated as zero”

Why do I get the error "Missing number, treated as zero." for case A, while other cases are working? And how to avoid it?

\documentclass{report}
\begin{document}
\newlength\newLen

% Case A (error)
\setlength\newLen{\columnwidth-\tabcolsep-\doublerulesep-\arrayrulewidth}

% Case B (no error)
%\setlength\newLen{\columnwidth-\tabcolsep-\doublerulesep}

% Case C (no error)
%\setlength\newLen{\columnwidth-\tabcolsep-\arrayrulewidth}

% Case D (no error)
%\setlength\newLen{\columnwidth-\doublerulesep-\arrayrulewidth}

% Case E (no error)
%\setlength\newLen{\tabcolsep-\doublerulesep-\arrayrulewidth}

\end{document}


• You are missing \usepackage{calc}. – campa Jan 18 at 15:04
• Thanks, that is helping. But why are the other cases working? – user233236 Jan 18 at 15:06
• they are all in error, you can not by default have expressions in \setlength – David Carlisle Jan 18 at 16:22
• actually, there is no error message for cases B to E. See explanation by Phelype Oleinik. – user233236 Jan 18 at 17:28

\setlength is defined as:

\def\setlength#1#2{#1 #2\relax}


so it uses TeX's plain assignment \register1=\register2, omitting the optional = sign.

Your code then does, after the expansion of \setlength:

\newLen \columnwidth-\tabcolsep-\doublerulesep-\arrayrulewidth


which, newlines added for clarity, is the same as:

\newLen=\columnwidth
-
\tabcolsep=-\doublerulesep
-
\arrayrulewidth=\relax % error


and the final \arrayrulewidth errors because it's misused there, and if you look at the PDF you'll see two - typeset. The other versions don't actually work: they just don't throw errors, but still typeset spurious -. They don't error because the number of registers is even, so none is misused.

The right way would be to tell TeX that is a dimension expression with \dimexpr:

\setlength\newLen{\dimexpr\columnwidth-\tabcolsep-\doublerulesep-\arrayrulewidth}


or \usepackage{calc}, as campa said in the comment, which redefines \setlength to understand expressions and some other goodies not available with \dimexpr only (check out the documentation).

By the way, expl3's equivalent \dim_set:Nn already does \dimexpr on the argument (though it doesn't add the calc syntax):

\ExplSyntaxOn
\dim_set:Nn \newLen {\columnwidth-\tabcolsep-\doublerulesep-\arrayrulewidth}
\ExplSyntaxOff

• @campa sorry :) – Phelype Oleinik Jan 18 at 15:18
• It happens :-) – campa Jan 18 at 15:20