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?
[Tex/LaTex] A button that runs an external program from a Beamer PDF presentation
beamerhyperrefpdf
Related Solutions
To import a slide from another beamer
presentation as a "picture", you can use pdfpages
. You'll have to \setbeamercolor{background canvas}{bg=}
as explained in this answer because only a white frame will be shown otherwise:
\documentclass{beamer}
\usepackage{pdfpages}
\begin{document}
\begin{frame}
Content
\end{frame}
{
\setbeamercolor{background canvas}{bg=}
\includepdf[pages=3]{filea.pdf}
}
\end{document}
However, if you use head- or footlines or even a different theme in your existing presentation, this will probably not fit snugly. In this case, a better solution would be to actually import the source code of the existing presentation, which can be done using the docmute
package in combination with the \againframe
command:
Suppose this is your existing presentation filea.tex
: You need to give the slides you want to import a name using the label
option of the frame environment, like this:
\documentclass{beamer}
\begin{document}
\begin{frame}[label=myframe]
Frame to be included
\end{frame}
\end{document}
Then you can use this code in your new presentation:
\documentclass{beamer}
\usepackage{docmute}
\makeatletter
\newcommand*{\loadpresentation}[1]{{\beamer@inlecturefalse\input{#1}}}
\makeatother
\begin{document}
\loadpresentation{filea.tex}
\begin{frame}
The new presentation
\end{frame}
\againframe{myframe}
\end{document}
Issuing \loadpresentation{filea.tex}
imports the frames from your existing presentation without displaying them. You can insert them wherever needed using \againframe
with the label you chose in filea.tex
. The command \loadpresentation
should be used someplace after \begin{document}
(but before you actually include a frame from this presentation, of course).
This works roughly the same as if you'd actually copy the source code of the frame from the existing presentation, so things like overlays etc. are taken over.
Doing this in combination with listings
gives you a pretty nice solution:
\documentclass{article}
\usepackage{filecontents,hyperref,listings}
\begin{filecontents*}{script.bat}
@echo off
echo "Hello, World!"
pause
\end{filecontents*}
\begin{document}
\lstinputlisting[language=csh,float,caption={A Windows batch file}]{script.bat}
Click \href{run:script.bat}{here} to run the script.
\end{document}
This should also work with Beamer.
Edit
If you're working with a UNIX system, note that bat
is Windows-only, since Windows doesn't use a 'real' shell. With UNIX, give it a .sh
extension (if you want to give it one at all). You might also need to do a few more things:
- Make sure the file is executable: run
chmod +x myscript.sh
- Give the file a shebang line:
script.sh
:
#!/usr/bin/env sh
echo "Oh, the wonderful possibilities of UNIX shells."
Please note that, as of now, this solution may not always work on Windows.
Note also that the handling of run:
protocols can vary from viewer to viewer.
Some may not support it at all due to security risks, but it has been confirmed that Evince and Skim support it.
Best Answer
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:
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.