# Subtract a counter from another in plain tex

I'm sure this is very easy, but searching the internet I came up with nothing, and reading the TeXbook, I learned so much other stuff that I forgot what I was originally looking for ;-)

So, I just want to set the value of a counter to the difference of the values of two other counters in plain TeX, like this:

\newcount\countOne%
\newcount\countTwo%
\newcount\diff%
\diff=\countOne-\countTwo\relax%


Only, this doesn't work, ending up with "missing number, treated as zero"...

\diff=\countOne

• That was extremely fast!! I knew it was easy... Thanks! Sorry, can't upvote due to low reputation.
– Duke
Dec 19 '16 at 11:59

That would be

\diff=\countOne

• I'll accept David Carlisle's answer as it was a little faster, but thanks anyway!
– Duke
Dec 19 '16 at 12:00

For the case that e-TeX is available (\numexpr):

\newcount\countOne
\newcount\countTwo
\newcount\diff
\diff=\numexpr\countOne-\countTwo\relax


Since the examples given here are no MWE, I wasn't really able to test them. So, here is another code (but a MWE) that works as well:

\documentclass{article}

\begin{document}

\newcounter{FirstCounter}
\setcounter{FirstCounter}{42}
\newcounter{SecondCounter}
\setcounter{SecondCounter}{23}

\newcounter{FirstMinusSecondCounter}
\setcounter{FirstMinusSecondCounter}{%
\numexpr\value{FirstCounter}-\value{SecondCounter}%
}

\noindent %just for a nicer output...
1st Counter: \theFirstCounter\\
2nd Counter: \theSecondCounter\\
1st minus 2nd: \theFirstMinusSecondCounter

\end{document}