\documentclass{article}
\usepackage{amsmath,amssymb}
\usepackage{color,soul}
\begin{document}
blah \hl{blah} blah \hl{$x=x$}
\hl{
\begin{gather}
x=y
\end{gather}
}
\end{document}
If I remove \hl{ before \begin{gather} and } after \end{gather} I get
yellow highlighting for both the plain text blah and the in-line
equation $x=x$ but if I don't, the error message is
! LaTeX Error: Environment {gather} undefined.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.10 }
What should I do instead?
-- John Harper
You could use the shaded environment from the framed package (http://
www.ctan.org/pkg/framed):
\documentclass{article}
\usepackage{amsmath,amssymb}
\usepackage{xcolor,soul,framed,caption}
\colorlet{shadecolor}{yellow}
\begin{document}
blah \hl{blah} blah \hl{$x=x$}
\begin{shaded}
\begin{gather}
x=y
\end{gather}
\end{shaded}
\begin{shaded}
\centering
\rule{4cm}{2cm} % just to simulate an actual figure
\captionof{figure}{Test figure}
\end{shaded}
\end{document}
you cannot use floats inside shaded, but you could use the \captionof
command from the caption package, as the example shows.