I'd go with
\newcommand{\Zp}[1]{\mathbb{Z}/p^{#1}\mathbb{Z}}
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
\newcommand{\Zp}[2][p]{\mathbb{Z}/#1^{#2}\mathbb{Z}}
so, for the case where you want to use a different prime you can type
\Zp[q]{a}
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
\newcommand{\Z}{\mathbb{Z}}
it's better doing
\newcommand{\Zp}[2][p]{\Z/#1^{#2}\Z}
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
\newcommand{\numberset}[1]{\mathbb{#1}}
\newcommand{\Z}{\numberset{Z}}
\newcommand{\Q}{\numberset{Q}}
% ... other possible number sets ...
\newcommand{\Zp}[2][p]{\Z/#1^{#2}\Z}
so uniformity is ensured for all alike symbols.
\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 nameZ_p
, which contains two letter-class characters and one nonletter-class character -- is not valid under TeX's syntax rules.