# How to make interactive PDF documents with TeX?

Is it possible to have an interactive PDF Document using LaTeX? For example, I want to make a PDF document (math exercise sheets) such that:

• The user could fold/unfold parts of the document (i.e., the user could press a plus to see the answers)
• The user could tick some field to submit an answer and see his/her score
• Print the resulting PDF document or save it
-
Welcome to TeX.sx! Usually, we don't put a greeting or a "thank you" in our posts. While this might seem strange at first, it is not a sign of lack of politeness, but rather part of our trying to keep everything very concise. Upvoting is the preferred way here to say "thank you" to users who helped you. – Andrey Vihrov Feb 20 '12 at 9:22
related question/partial duplicate: tex.stackexchange.com/questions/19673/… – doncherry Feb 20 '12 at 9:29
This would be limited to acrobat and acrobat reader. Some of this is probably not yet possible even so. Documents with this amount of dynamic content are better suited to web pages with javascript. This would be better for the submission process as well, if you use a dose of CGI. – qubyte Feb 20 '12 at 9:36
tex.stackexchange.com/questions/8918/hello-world-in-pdflatex (talking pdf!) and interactive tex.stackexchange.com/questions/7869/…. Only work with acrobat. – Yiannis Lazarides Feb 20 '12 at 12:22
I like this animated Tikz texample of a Wankel motor: texample.net/tikz/examples/wankel-motor – matth Mar 19 '12 at 14:39

It is possible to have an interactive PDF document, but will only probably work in Acrobat Reader. Some examples can be found at Hello World in pdfLaTeX and How do you say Happy New Year with LaTeX?.

There are a number of ways to create them but the simpler so far is to use the insdljs package from the AcroTeX Education Bundle.

To create the interactive part one needs to use PFD Forms and to insert the appropriate JavaScript code, which like in web pages is used to script the interactive part.

The insdljs package provides an environment, similar to file contents for writing a JavaScript file. In the minimal it defines a function to calculate the area and diameter of a circle given its radius.

function doCalculation()
{
}


The Textfields and push button are also defined accordingly. The MWE illustrates the application. Please view it with a compatible reader.

\documentclass{scrartcl}
\usepackage[T1]{fontenc}
\usepackage{mathptmx}
\usepackage[scaled =.92]{helvet}
\setlength{\paperwidth}{5.2075in}
\setlength{\paperheight}{4.90in}
\renewcommand*{\familydefault}{phv}
\usepackage[pdftex,margin=0.5in]{geometry}
\usepackage{fancyhdr}
\lfoot{}\cfoot{}\rfoot{}
\pagestyle{fancy}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage[pdftex,pdfpagelayout=SinglePage,
pdftitle={Wishing you a happy year},pdfsubject={Invest your new year improving your TeX skills}%
]{hyperref}
\setlength{\parindent}{0.0cm}
\usepackage[pdftex]{insdljs}

\begin{insDLJS}[test]{test}{JavaScript}
function doCalculation()
{
}
\end{insDLJS}

%% Short hand commands
\newcommand{\textforlabel}[2]{%
\TextField[name={#1}, value={#2}, width=9em,align=2,%
bordercolor={0.990 .980 .85},%
}

\begin{document}
\begin{center}
\textbf{\Huge Calculations\\ with JavaScript\\*[4pt] and pdfLateX!}
\end{center}

\newpage

\begin{Form}

%%

~m\\

%% Push button is defined here
\textforlabel{l02}{Press to calculate}
\PushButton[name=start,onclick={doCalculation();},bordercolor={0.650 .790 .94}%
]{Calculate}\\

%% RESULTS
%% Diameter
\textforlabel{name=l04}{%
Diameter :} \TextField[name=diameter,width=10em,bordercolor={0.650 .790 .94},%

\textforlabel{name=l05}{Area:}
\TextField[name=areacircle,width=10em,%
bordercolor={0.650 .790 .94},readonly=true]{}~m$^2$\\*[-0.8em]
\end{Form}
\end{document}


The AcroTeX Education Bundle provides numerous other functions, which can be useful in an Academic environment for quizzes and tutorials.

Personally I am not very convinced, as such facilities can better be provided in web pages with better interactivity and opening other opportunities.

-
Several viewers support enough of the Adobe object model to support Interactive PDF, including Apple's Preview application and Safari browser. Interactive PDFs are quite useful for adding navigation support to documents, e.g. having pop-ups in the index that show the context of the references listed for each entry. – Charles Stewart Feb 25 '13 at 10:23
@CharlesStewart Very true. – Yiannis Lazarides Feb 25 '13 at 13:07
– Hi I'm Frogatto Nov 1 '15 at 11:21