TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The integers modulo n, given by


is cumbersome to write. Accordingly, I would like to set up a new command that allows me to specify an input 'n'. Something like


But the above code is not right. Does anyone have any idea how this might be done?

share|improve this question
This might be a little grumpy of me, but if you google "latex newcommand" you get all manner of links describing how it works, including this feature. The LaTeX wikibook (the first result) is a good source, by the way. – Ryan Reich Nov 4 '11 at 4:06

If you want it to work in normal text mode too, i.e. without dollar signs:

share|improve this answer
Eek, sorry. This is nearly a duplicate of Leo's. That'll learn me to refresh... – qubyte Nov 4 '11 at 2:57
It's fine. This question is trivial for all experienced LaTeX users, but fewer ones know \ensuremath. – Leo Liu Nov 4 '11 at 3:10
share|improve this answer
And use it as $\Z{n}$. – Leo Liu Nov 4 '11 at 2:26

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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