1

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.

\begin{equation}
  r_s^{\WPT} &= 100.00
\end{equation}

\end{document}

Thanks in advance for your help.

  • 2
    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 at 12:12
  • 1
    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 at 14:21
1

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 $$.
<to be read again> 
                   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.

\begin{equation}
  r_s^{\WPT} = 100.00
\end{equation}

\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.

\begin{equation}
  r_s^{\WPT} = 100.00
\end{equation}

\end{document}

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.