# Annotation on mathematical symbol

Is it possible to annotate the equal-symbol like in the picture below? \begin{equation}
E[|A\cup B|]=E[|A|+|B|-|A\cap B|]=E[|A|]+E[|B|]-E[|A\cap B|]
\end{equation}

• Please do not do this in general. Might work fine with pen and paper or on a black board. But it should not be used in typeset text. – daleif Feb 3 '16 at 19:48
• @daleif Nonsense; it might not be appropriate in an academic paper, but there are plenty of contexts (textbooks, lecture notes, presentation slides) where annotating a mathematical expression is by far the clearest way to explain what's going on. – dbmag9 Feb 3 '16 at 20:24
• @dbmag9 I beg to differ, good typographic manners should be used no matter if it is an academic paper or not. How else are people going to learn propper typography if some rules only apply to certain types of documents. – daleif Feb 3 '16 at 20:34
• @daleif To take a simple example, if I am writing a textbook explaining the terms 'numerator' and 'denominator', by far the clearest way to explain them is by labelling the two on a fraction. We might also explain in words below, but for many the intellectual effort of reading a label and cross-referencing with what is above can make that far more difficult to follow. There are plenty of things appropriate in some contexts but not others. – dbmag9 Feb 3 '16 at 20:43

You could use the \overset macro, which is provided by the amsmath package: \documentclass{article}
\usepackage{amsmath} % for \overset and \text macros
\begin{document}

\begin{equation}
E[|A\cup B|]=E[|A|+|B|-|A\cap B|]
\overset{\text{linearity}}{=}
E[|A|]+E[|B|]-E[|A\cap B|]
\end{equation}\

\end{document}


Addendum: If you also need the vertical arrow below "linearity", just replace

\overset{\text{linearity}}{=}


with

\overset{\substack{\text{linearity} \\ \downarrow}}{=}


The \substack macro is also provided by the amsmath package.

You can use \overset and \substack, with a trick for making the annotation to have zero width:

\documentclass{article}
\usepackage{amsmath}

\newcommand{\annoterel}{%
\overset{%
\substack{\hidewidth\text{#1}\hidewidth\\\downarrow}%
}{#2}%
}

\begin{document}

\begin{equation}
E[|A\cup B|] = E[|A|+|B|-|A\cap B|]
\annoterel{linearity}{=} E[|A|]+E[|B|]-E[|A\cap B|]
\end{equation}

\end{document} A slight modification if you need the arrow to be taller, maybe for accommodating fractions or other big symbols:

\newcommand{\annoterel}[]{%
\overset{%
\substack{\hidewidth\text{#2}\hidewidth\\#1\downarrow}%
}{#3}%
}


Now the macro \annoterel has an optional argument that should be one of \big, \Big, \bigg or \Bigg; for instance

\begin{equation}
E[|A\cup B|] = E[|A|+|B|-|A\cap B|]
\annoterel[\Big]{linearity}{=} E[|A|]+E[|B|]-E[|A\cap B|]
\end{equation}


would produce 