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:


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


4 Answers 4

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

That would be

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

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


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:





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


(based upon an answer to this related question about adding numbers)

  • 1
    The question was about plain TeX, not LaTeX. Jan 26, 2019 at 23:05
  • O, yeah, now that you mention it... I guess I didn't realize this since I was focusing too much on solving my problem (with LaTeX)...
    – Prof.Chaos
    Jan 26, 2019 at 23:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.