Is there an easy way to add hover text to all incidents of math mode where the hover text would contain the LaTeX code?

The fancytooltip package provides a bit more advanced capabilities than does the cooltooltips package. As an example, the second paragraph of the package documentation shows the inclusion of regular (fixed) tooltip text, as well as animated tooltip text on mouseover.

The documentation states that it is limited to the (free) Adobe Reader or Adobe Acrobat suite. This restriction may be prohibitive, but Adobe's integration with web browsers counts towards it's abundant usage. Additionally, since the tooltips may be "fancy", they are typically created in a separate document from your source.

Another alternative would be to use the pdfcomment package that provides similar functionality within your source document. Here is a minimal example of how it may be used within an align environment of amsmath:

enter image description here

\documentclass{article}
\usepackage{pdfcomment}% http://ctan.org/pkg/pdfcomment
\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\usepackage{mathtools}% http://ctan.org/pkg/mathtools
\begin{document}
% \pdftooltip{<text>}{<tooltip>}
\begin{align*}
  \mathrlap{\pdftooltip[mathstyle=\displaystyle]{\phantom{\sum_{i=1}^n i=\frac{n}{2}(n+1)}}{sum\string_\{i=1\}\string^n i=tfrac\{n\}\{2\}(n+1)}}%
  \sum_{i=1}^n i &= \tfrac{n}{2}(n+1) \\
  \mathrlap{\pdftooltip[mathstyle=\displaystyle]{\phantom{E=mc^2}}{E=mc\textasciicircum 2}}%
  E &= mc^2
\end{align*}
\end{document}

Since the internal align structure cannot be broken across & within the \pdfcomment, it is possible to use some mathtools overlap magic (via \mathrlap).


For completeness, here is an elaboration on the functionality provided by the cooltooltips package, since it may be useful to others. It provides

\cooltooltip[<popup color>][<link color>]{<subject>}{<message>}{<url>}{<tooltip>}{<text>}

that prints a box of colour <link color> around <text>. Additionally, a popup of colour <popup color> is displayed with a title <subject> and text <message> Hovering over <text> also brings up the tooltip <tooltip> and clicking the link takes you to <url>. Here's a very minimal example illustrating this:

enter image description here

\documentclass{article}
\usepackage{cooltooltips}% http://ctan.org/pkg/cooltooltips
\begin{document}
\section{Introduction}
Have you ever wondered what is \cooltooltip[0 0 1]{Einstein}{E=mc^2}%
{http://en.wikipedia.org/wiki/Albert_Einstein}{Einstein on the web}{$E=mc^2$}?
\end{document}

The implementation of cooltooltips is fairly limited and fragile. For example, movement of the popup is not possible since it is activated/deactivated by means of the hover. Also, depending on the resolution of view, it may actually impede viewing. Popups can be disabled by the viewer by incorporating a "toggle button" (say <text>)in the document by using

\cooltooltiptoggle{<text>}

Pressing <text> suppresses all popups in the document. Pressing it again re-enables popups. Some control over the display of border in the actual text is possible by setting the lengths \fboxrule and \fboxsep via a \setlength command.


This does not directly answer your question, but it is a possible (partial) solution of the accessibility problem that you list as one of your reasons for wanting tooltips.

I simply provide two versions of each document: I run pdflatex on my document to produce a pdf version, and htlatex to produce an xhtml version with mathml mathematics. As far as I know, screen readers should be able to handle the xhtml+mathml version. For the students whose browser does not support the mathml, or who do not have the appropriate math fonts installed on their system, I provide link to the pdf file using the following macro:

\newcommand{\pdflink}[1][Printable version of this document]{%
\ifpdf\relax\else\HCode{<a href="\jobname.pdf">#1</a>}\fi}

Then on the top of the document I put \pdflink. When processed by pdflatex, this will be ignored, but it will include a link to the pdf version when processed by htlatex.