Let's build it up by pieces. First, as @rbernabe suggests, use the start-of-word and end-of-word patterns to find "t" as an entire word:
/\<t\>
Next, to replace all such on the current line, use
:s/\<t\>/s/g
Now, position the cursor on a \begin{equation}
line. The range .,/\\end{equation}/
specifies all lines up to and including the end of the equation environment, so
:.,/\\end{equation}/s/\<t\>/s/g
will replace all the single-word "t"s with "s" in that range. In order to repeat this command for all equation environments in the file, use :g/\\begin{equation}/{command}
:
:g/\\begin{equation}/.,/\\end{equation}/s/\<t\>/s/g
If you want to play vimgolf, then the . is optional. Finally, if you want to handle multiple environments, I am afraid there is no way to tie the variable environment name in the \begin{...}
to the closing \end{...}
. If none of your equation-like environments is nested, then you can use
:g/\\begin{\(equation\|align\|eqnarray\|multline\)}/.,/\\end{\(equation\|align\|eqnarray\|multline\)}/s/\<t\>/s/g
You can also use an explicit loop, which might help if there are nested environments:
:let envs = ['equation', 'align', 'eqnarray', 'multline']
:for env in envs
: execute 'g/\\begin{' . env . '}/.,/\\end{' . env . '}/s/\<t\>/s/g'
:endfor
Of course, regular expressions are not a substitute for real parsing. As long as your actual LaTeX code is similar to your sample, this should work, but you will run into trouble if you ever have something like
\end{equation} This is ordinary text with a t in it.