Hover text for images in LaTeX using pdfLaTeX

How to put a hovering title text for images (like the title attribute in HTML <img> tags) in LaTeX file using pdfLaTeX?

-
You want to mimic <img> HTML tag? – xport Jan 6 '11 at 10:25
What are you hoping to achieve? A tooltip that shows up when the mouse hovers over it? Or something that happens when you compile the document without the files being there? – frabjous Jan 6 '11 at 16:52
yes when the mouse hovers over it. But not using tooltip – S. Murugan Jan 7 '11 at 6:22
@S. Murugan: you’re confusing the alt and the title attribute. alt is displayed if the browser cannot display the image. It is not displayed (except in Internet Explorer) when the mouse hovers over the image. That’s the title tag. – Konrad Rudolph Jan 7 '11 at 17:13

PDF viewers are not web browsers. There is no builtin reaction to a mouse hovering over an image, or a special tag or code to insert what it should show when it does.

Heck, even web browsers aren't required to exhibit this behavior. ALT text derives from the early days on the web when some web browsers couldn't show graphics, or people on slow connections turned them off; it put something in place of the images. It is retained, I think, mainly for visually impaired people who use text to speech technology to get information from webpages. The tooltip behavior is just a convention certain browsers adopted to make this text available even when graphics were possible. The w3's spec of the alt text attribute says nothing about tooltips.

If you want to replicate this behavior, you'll have to use a tooltip package like fancytooltips or cooltooltips. However, because the behavior is replicated using JavaScript, it'll only work in PDF viewers which suppport JavaScript, like Adobe Reader and Acrobat. (Even some users of these problems turn off JavaScript for security reasons.)

If instead you're aiming at a visually impaired audience, I would just put a text caption on the image.

-
Note my answer makes less sense now that the question has changed to discuss title= rather than alt=. :-( – frabjous Jan 7 '11 at 20:12

You may use a hack with hyperref.

\href{alt-text}{\includegraphics{...}}

How it works: Some PDF-Viewers, including Adobe, render the exact URL as tooltip over links. Other PDF Viewers like Skim do the same, but some don't: Apple's Preview app. But beware, that the alt-text should not be a valid link. Don't forget to disable this hack when delivering the PDF, as the users might be confused on links which seem clickable, but do not work :)

Background: I have had the same problem. When I visually inspected the result PDF I found some pictures which need enhancements. Then I always wondered: What was the specific file name for that image? A alt-text would be desirable...

-