For playing the following example adds a \fbox around inline math:
\documentclass{article}
\newsavebox{\mymathbox}
\everymath{%
\mathsurround=0pt$%
\begin{lrbox}{\mymathbox}\everymath{}$%
\aftergroup\mathboxend
}
\newcommand*{\mathboxend}{%
\end{lrbox}%
\fbox{\usebox{\mymathbox}}%
}
\begin{document}
$abc$ Hello\textsuperscript{World}
\begin{tabular}{l}Hello\\World\end{tabular}
\begin{minipage}{4em}Hello\\World\end{minipage}
\begin{minipage}[t]{4em}Hello\\World\end{minipage}
\end{document}
Update: Explanation and \mathsurround=0pt added.
The goal is to have something like
\fbox{$...$}
If \everymath is called, we are already in math mode. Therefore the first $ ends the math mode. The space, given by \mathsurround would be set around the empty formula,
therefore it is set to zero.
Then a horizontal box is opened (lrbox) and we switch in math mode again, but with
empty \everymath. Via \aftergroup we get to the point right after the closing $ and we can close the box and set the box with \fbox.
Variation added.
Also we could let the math group in place and put the lrbox inside:
\everymath{%
\begin{lrbox}{\mymathbox}%
\everymath{}$\mathsurround=0pt\relax
\aftergroup\mathboxend
}
\newcommand*{\mathboxend}{%
\end{lrbox}%
\fbox{\usebox{\mymathbox}}%
$%
}
The difference of these methods is the handling of \mathsurround, if it is not zero.
In the first case the space is put inside the box, in the second case, the space is outside.
However, there is a serious drawback of this general method via \everymath.
Inline math is used at many different places, thus the example also shows boxes at places where inline math is not expected.

\everymathand\everydisplaycan be used only to insert something "in front of" the math material. For boxing, you at the very least have to insert something on both sides, even better to "grab" the math material so it can be boxed. Furthermore, for displayed math, additional questions about what should happen with numbers or page breaks arise. In the end, this will get really complicated with lots of special cases needing to be handeled. If you're lucky, you'll find some package doing a similar thing which can be used as a specimen. – Stephan Lehmke Aug 25 '12 at 5:04\aftergroupcould help? I tried something with that and did not succeed, but maybe there are other who know what to do... – tohecz Aug 25 '12 at 5:52\textsuperscript) so this will turn into an odyssey. – Stephan Lehmke Aug 25 '12 at 6:02