# Missing characters inserted when using new commands in equations

I'm having a problem that I can't seem to fix. I would like to define a math symbol, and shown in the code snippet, which I use frequently throughout the text. When I want to include this same symbol inside an equation, I get a lot of "missing character inserted" errors and the formatting is wrong at the other side.

\documentclass[12pt]{article}
\usepackage{amsmath,amssymb}

\newcommand{\WPT}{$p_{\text{T}}^W$}

\begin{document}
The result for \WPT is shown below.

$$r_s^{\WPT} &= 100.00$$

\end{document}


• Welcome to TeX.SX! You are entering math-mode twice (and getting an error somewhere). Use \newcommand{\WPT}{\ensuremath{p_{\text{T}}^W}} instead. – Phelype Oleinik Feb 26 '19 at 12:12
• In addition to the problem with \WPT as mentioned in the answer, the equation environment does not support the use of &. – barbara beeton Feb 26 '19 at 14:21

If I run the code you posted I get the error:

! Missing } inserted.
<inserted text>
}
l.10   r_s^{\WPT
} = 100.00
?


this error happens because when your command expands you have (up to the point where the error happens) basically:

$$r_s^{   which is not a valid TeX construct. You start display math, you start a group, then you end an inline math. Later on TeX would say that: ! Display math should end with$$.
p
l.13   r_s^{$p _{\text{T}}^W$} = 100
?


and would get even more confused trying to fix all that.

You can use \ensuremath which, as the name says, ensures that its contents are typeset in math-mode (notice the extra {} after \WPT in the text here):

\documentclass[12pt]{article}
\usepackage{amsmath,amssymb}

\newcommand{\WPT}{\ensuremath{p_{\text{T}}^W}}

\begin{document}
The result for \WPT{} is shown below.

$$r_s^{\WPT} = 100.00$$

\end{document}


but, since \WPT is essentially math content, I'd go for the proper markup and wrap \WPT in $...$ in the text:

\documentclass[12pt]{article}
\usepackage{amsmath,amssymb}

\newcommand{\WPT}{p_{\text{T}}^W}

\begin{document}
The result for $\WPT$ is shown below.

$$r_s^{\WPT} = 100.00$$

\end{document}