[Tex/LaTex] Flash animation and beamer


I want to have a flash file (.swf) in my beamer document on a Linux machine, using pdfLaTeX and Evince.

Is there a way to make a link to that file which runs an external player or even better, is it possible to embed it into my presentation?

For the first option I tried

\href{run:/usr/bin/gnash /tmp/test.swf}{test}

which gives me the error

Failed to open "/usr/bin/gnash /tmp/test.swf"
Error stating file '/usr/bin/gnash /tmp/test.swf': No such file or directory.

(however \href{run:/usr/bin/gnash}{test} starts just gnash).

For the second I know the flashmovie package. However I want use Evince as PDF viewer and not Adobe Reader.


Finally I just used \href{run:/tmp/test.swf}. I think if you open this by Evince the correct application to open the .swf file is chosen by gnome-open. If you use okular I guess it is kde-open. To avoid possible configuration problems with those openers and to have more control, I think it would be much better to have a way to specify the application which should open my file (in my case gnash) as I tried in my question above. So if there are any ideas …

Best Answer

This is actually to do with the PDF renderer, not TeX. I don't have gnash installed, nor any flash files to hand, but I tested with the following file:


\href{run:firefox http://www.math.ntnu.no/}{launch}

With evince then the second link opened my department homepage, as expected, but the first produced the error:

Error stating file `/path/to/directory/where/I/launched/evince/firefox http:/www.math.ntnu.no': No such file or directory

So clearly evince is trying to launch a program in its current directory called firefox http://www.math.ntnu.no/ (well, modulo disappearing slashes).

However, when I try this with xpdf, my usual PDF reader, then when I click on the link it says:

About to execute the command: firefox http://www.math.ntnu.no/ &

and asks me if I really want to do this. If I click "OK" then I get what I expect. This experiment suggests that there is some latitude in what the viewer gets to do.

Looking at the resulting PDF file, I see the following:

4 0 obj
<</Border[0 0 1]/Subtype/Link/C[0 .7 .7]/A<</F(firefox http://www.math.ntnu.no/)/S/Launch>>/Type/Annot/Rect[147.716 656.239 178.213 665.15]/H/I>>
5 0 obj
<</Border[0 0 1]/Subtype/Link/C[0 1 1]/A<</URI(http://www.math.ntnu.no/)/Type/Action/S/URI>>/Type/Annot/Rect[179.541 656.239 210.038 665.15]/H/I>>

(Note that the slashes are as they should be). So a run: directive gets converted to a Launch action, and an http: directive to a URI action.

Looking at the PDF specs (or at least, Adobe's free copy thereof) I learnt more than I wanted to about the internals of PDFs, including launch actions. These are detailed in Section (p422, internal numbering, p430, external). What is interesting is that some parts of this have the tag "not yet defined". Whilst I don't think that these are relevant here (as they refer to OS-specific features and these aren't used), I think that this implies that the specification here might be subject to revision as unusual use-cases appear. (Seeing this just after reading about Windows behaviour with spaces in program names is an interesting juxtaposition.)

So my inference (and it is nothing more) is that exactly what a PDF viewer does when it encounters a "Launch" action is pretty much up to that viewer. Unfortunately, this includes whether to regard the string as a single command name or to break it up. Actually, I suspect that the question is whether to pass it to the relevant open command (or maybe the shell) as a quoted string or not.

To avoid this, I recommend writing a small script that calls the flash viewer on your program. Something like:

!# /bin/sh
/usr/bin/gnash test.swf

and then call that from within your file.

With a bit of \write trickery, you could even get tex to create that file itself.