# Missing number treated as zero error

I have read several posts with a similar error, but cannot find where mine is.

I have the following code to put in comments next to sequential inequalities in an alignat* environment. Unfortunately, every time I use my \cm command latex gives an error stating that a missing number is treated as zero. I figure I'm probably missing some argument in one of my length commands, but I can't figure out where. Thanks in advance.

\newlength{\argwidth}
\newlength{\whatsleft}
\newcommand{\measureremainder}[1]{%
\begin{tikzpicture}[overlay,remember picture]
\path (current page.north west) ++(\hoffset, -\voffset)
node[anchor=north west, shape=rectangle, inner sep=0, minimum             width=\paperwidth, minimum height=\paperheight]
(pagearea) {};
node[anchor=north west, shape=rectangle, inner sep=0, minimum width=\textwidth, minimum height=\textheight]
(textarea) {};
\path let \p0 = (0,0), \p1 = (textarea.east) in
[/utils/exec={\pgfmathsetlength#1{\x1-\x0}\global#1=#1}];
\end{tikzpicture}%
}

\newcommand{\cm}[1]{&\quad&\hspace{1.3mm}\measureremainder{\whatsleft}\settowidth{\argwidth}{#1}\ifthenelse{\lengthtest{\argwidth < \whatsleft}}{\text{{#1}}}{\begin{minipage}[c]{\whatsleft} \raggedright {#1} \vspace{2mm}\end{minipage}}}


For example, I would use it as follows:

\documentclass[12pt]{report}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage[margins = 1.0in]{geometry}
\usepackage{MnSymbol}
\usepackage{tikz}
\usepackage{mathtools}
\usepackage{calc}
\usepackage{tkz-fct}
\usepackage{ifthen}
\usepackage{xifthen}

\newlength{\whatsleft}
\newlength{\argwidth}
\newcommand{\measureremainder}[1]{%
\begin{tikzpicture}[overlay,remember picture]
\path (current page.north west) ++(\hoffset, -\voffset)
node[anchor=north west, shape=rectangle, inner sep=0, minimum width=\paperwidth, minimum height=\paperheight]
(pagearea) {};
node[anchor=north west, shape=rectangle, inner sep=0, minimum width=\textwidth, minimum height=\textheight]
(textarea) {};
\path let \p0 = (0,0), \p1 = (textarea.east) in
[/utils/exec={\pgfmathsetlength#1{\x1-\x0}\global#1=#1}];
\end{tikzpicture}%
}

\newcommand{\cm}[1]{&\quad &\hspace{1.3mm}\measureremainder{\whatsleft}\settowidth{\argwidth}{#1}\ifthenelse{\lengthtest{\argwidth < \whatsleft}}{\text{{#1} }}{\begin{minipage}[c]{\whatsleft} \raggedright {#1} \vspace{2mm}\end{minipage}}}

\begin{document}

\begin{alignat*}{2}
\lim_{x \to 3} x^2 - 4x + 3 &= \lim_{x \to 3} x^2 - \lim_{x \to 3} 4x + \lim_{x \to 3} 3 \cm{Using the sum rule} \\
&= \left(\lim_{x \to 3} x\right)\left(\lim_{x \to 3} x\right) - \left(4\lim_{x \to 3} x\right) + \lim_{x \to 3} 3 \cm{Using the product rule} \\
&= 3 \cdot 3 - 4 \cdot 3 + 3 \\
&= 0 \end{alignat*}

\end{document}


Thanks in advance for any help.

• Please edit your question so it has a single code example, a complete document that demonstrates the error, so people can debug it – David Carlisle Apr 10 '15 at 18:28

The error occurs at the first \lim right after \begin{alignat*}. This environment expects an argument, the number of "equation columns". Since \lim is not a number, TeX throws the error.

Unless you have redefined $$ and $$, they will cause further trouble, because they are usually used for inline math mode. Therefore I have replaced them by normal parentheses. I do not think, that \left and \right are needed here despite the index of the limes. The normal parentheses look better here IMHO.

Full example (two LaTeX runs are needed):

\documentclass{article}
\usepackage{ifthen}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{calc}

\newlength{\currentsidemargin}
\newlength{\argwidth}
\newlength{\whatsleft}
\newcommand{\measureremainder}[1]{%
\begin{tikzpicture}[overlay,remember picture]
\path
(current page.north west) ++(\hoffset, -\voffset)
node[
anchor=north west,
shape=rectangle,
inner sep=0,
minimum width=\paperwidth,
minimum height=\paperheight
] (pagearea) {}
;
\path
(pagearea.north west)
node[
anchor=north west,
shape=rectangle,
inner sep=0,
minimum width=\textwidth,
minimum height=\textheight
] (textarea) {}
;
\path
let \p0 = (0,0),
\p1 = (textarea.east)
in
[/utils/exec={\pgfmathsetlength#1{\x1-\x0}\global#1=#1}]
;
\end{tikzpicture}%
}

\newcommand{\cm}[1]{%
&\hspace{1.3mm}%
\measureremainder{\whatsleft}%
\settowidth{\argwidth}{#1}%
\ifthenelse{\lengthtest{\argwidth < \whatsleft}}{%
\text{#1}
}{%
\begin{minipage}[c]{\whatsleft}
\raggedright
#1\par
\vspace{2mm}%
\end{minipage}%
}%
}

\begin{document}
\begin{alignat*}{2}
\lim_{x \to 3} (x^2 - 4x + 3) &= \lim_{x \to 3} x^2 - \lim_{x \to 3} 4x +
\lim_{x \to 3} 3 \cm{Using the sum rule} \\
&= (\lim_{x \to 3} x)
(\lim_{x \to 3} x)
- 4(\lim_{x \to 3} x) +
\lim_{x \to 3} 3 \cm{Using the product rule} \\
&= 3 \cdot 3 - 4 \cdot 3 + 3 \\
&= 0
\end{alignat*}
\end{document}