I am using \mathbb{Z}/p^{a}\mathbb{Z} many times in my work with variable a, I was thinking can I define a macro like \Z_p^{a} which will give the above result. I tried


but LaTeX did not like it.

  • 1
    Names of TeX macros defined via \def or \newcommand must consist of either one or more "letter"-class characters (A-Z and a-z) or exactly one non-letter character. The macro name Z_p, which contains two letter-class characters and one nonletter-class character -- is not valid under TeX's syntax rules.
    – Mico
    Mar 28, 2015 at 14:58

2 Answers 2


I'd go with


and $\Zp{a}$ will do what you want. It's not possible to have _ in the name of a macro (unless playing nasty and fragile tricks).

Maybe I'd do


so, for the case where you want to use a different prime you can type


Why not \ensuremath? Because it serves little purpose; I find it much better to segregate math in the proper way, that is, between $ symbols or inside \(...\).

If you already have


it's better doing


so a change of formatting for the integers will automatically produce the same change in \Zp. Better yet, I usually advice to do something like

% ... other possible number sets ...


so uniformity is ensured for all alike symbols.

  • Why is changing the catcode of _ fragile?
    – 1010011010
    Mar 28, 2015 at 15:29
  • @1010011010 Would you like being also able to use subscripts in math? Yes, it can be done, I know, but I classify this as a nasty and fragile trick, as some packages may expect _ has its normal category code.
    – egreg
    Mar 28, 2015 at 15:31
  • @egreg Wouldn't that also lead to incompatibilities with LaTeX3?
    – 1010011010
    Mar 28, 2015 at 15:36
  • @1010011010 Not necessarily.
    – egreg
    Mar 28, 2015 at 15:36

With Plain TeX syntax you can do it:




\Z_p {137}% or Z_p{137}, it's all up to you


Notice that this overwrites a previous command \Z if it exists, but by default none exist. To be extra sure with other packages loaded, insert


before the \def to give a chance to LaTeX to protest.

enter image description here

  • I would bet that the OP has \newcommand{\Z}{\mathbb{Z}}
    – egreg
    Mar 28, 2015 at 16:41
  • @egreg perhaps but why didn't he use \Z in his/her ensuremath then? and I recommend \ZZ...
    – user4686
    Mar 28, 2015 at 16:42

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.