[Tex/LaTex] n easy way to add hover text to all incidents of math mode where the hover text would contain the LaTeX code

accessibilitymath-modeteaching

Adding hover text (I believe the technical term is a tooltip) to any part of any LaTeX document can be accomplished using cooltooltips.sty, as I have recently learned.

I would like to do something a little more large scale. I would like to compile my documents so that every instance of math mode or math display mode automatically puts the defining LaTeX code as a tooltip (text hovering over it). So for example, my nicely typeset $\frac{a}{b}$ can also show the user that very same code: "\frac{a}{b}".

Ideally, I'd also like this to apply to math mode environments like align.

I have two reasons for wanting to do this:

  1. Math accessibility to the visually impaired is becoming a big issue. Some universities have been sued in the last few years for not complying with the Americans with Disabilities act because visually impaired students have little or no way to read math – be it LaTeX, MathML, MS Equation Editor, or whatever. Rather than wait 20 years for a screen reader that can accurately verbalize math on a pdf, I want to let screen readers verbalize the LaTeX code and let the visually disabled student interpret that code. It is an effective way to communicate math to sight-affected students as long as we're not talking about something intense like nested fractions.
  2. For teaching others what code was used to typeset something, this would be a nice tool to have.

It doesn't look like there is a package for doing this after a search on CTAN. Does anyone have any ideas?

Best Answer

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.

Related Question