TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to add a "run demo" button to a Beamer presentation (PDF file) that will launch an external Java application. Can this be done somehow - Embed an "exec" command inside a PDF using LaTeX/Beamer?

share|improve this question
Have a look on \href of the hyperref package. – Martin Scharrer Jul 13 '11 at 10:57
Maybe \url{run:<something>}. – xport Jul 13 '11 at 11:20
@xport: More like \href{run:/path/to/program}{Text Or Button image/diagram}. – Martin Scharrer Jul 13 '11 at 11:36
Using URLs requires a protocol handler for "run", which is not found on my system, and frankly, I think it is because of serious security issues. Does anyone knows of a tried-and-tested way to do this? – Little Bobby Tables Jul 13 '11 at 12:18
I would suggest you use a 'localhost' and execute it via a brower link. For example you could use WAMP and php. Your link then points to a php file that uses exec to execute an external command. Similar solutions exist for other languages. If you familiar with the above I can post a snippet. (My preference for this, is that you are not fiddling with the pdf security model). – Yiannis Lazarides Jul 13 '11 at 15:54

With Textworks on a Windows, MikTeX installation a simple link to the command amazingly will enable you to execute it, in the TeXWorks pdf reader. The following minimal will bring up the calculator program, provided "windows/system32" is in your path.


This will not work with the Adobe pdf reader, although I am sure there is a way to bypass the security features of Adobe.

As I mentioned in the comments another way is to provide a link that activates a php script through localhost. A simple function to do this is shown below:

function pdflatex($data=''){
        if (!empty($_POST)){
        //$res = file_put_contents('C:/latex-samples/'.$f, trim($code));
        $t='pdflatex.exe  c:/latex-samples/ZZZ.tex 2>&1';
        echo '<pre>'.shell_exec($t).'<pre>';

In the sample I invoke the pdflatex.exe and redirect the output to the screen, so that you can see the output. I use scripts like this normally to run, language scripts through a textarea in the browser (hence the commented lines). In this case the script is captured and send as POST and saved in a file (ZZZ.tex), which you can then let pdflatex to handle.

I normally use WAMP or IndigoStar to install the web stack. The latter at http://www.indigostar.com/indigoperl.php will set Apache for Perl and PHP. Both Perl as well as Python have similar commands to php's shell_exec, as well as variations to this command.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.