%\documentclass{article}
\documentclass[envcountsect,t,10pt]{beamer}

%\usetheme{Ilmenau}
%\usetheme{Marburg}
\usetheme{PaloAlto}

\setbeamertemplate{theorems}[numbered]
\usepackage{amsthm,amsmath,graphicx,color}

\usepackage{tikz}
\PassOptionsToPackage{naturalnames}{hyperref}

\usepackage[inactive]{fancytooltips}

\newtheorem{remark}{Remark}
\def\dx{{\mathrm d}x}
\definecolor{darkgreen}{rgb}{0,0.6,0}

\begin{document}

\FancyHook

\title{Fantytooltips demo}
\author{Robert Ma\v{r}\'ik}

\maketitle
\section{Introduction}

\begin{frame}{Content}
  \tableofcontents
\end{frame}
\begin{frame}
  \frametitle{What can you find in this file?}
  \begin{itemize}
  \item Demo (math fiction) which shows how the cooperation between
    preview and fancytooltips package can be used to insert popup
    previews for equations, theorems and definitions into a
    presentation -- see for example Figure \ref{pic:sine} (move the
    mouse to the blue mark).
  \item Explanation how we achieved this behaviour.
  \item Simple howto.
  \end{itemize}
\end{frame}

\section{Math text example}

\begin{frame}{Demo: Definitions}
  \begin{definition}[Excellent number]
    Let $n$ be positive integer. The number $n$ is said to be
    \textit{excellent}, if the last digit of the number $\alpha$
    defined by the relation
    \begin{equation}
      \label{eq:excel}
      \alpha = n^2 +\int_0^{2\pi}\sin x\dx
    \end{equation}
    equals $1$.\label{def:excellent-number}
  \end{definition}

  (Note that from \eqref{eq:excel} it follows that $\alpha$ is
  integer, see \ref{eq:sin}.)

\begin{definition}[Happy number]
  Let $n$ be positive integer. The number $n$ is said to be
  \textit{happy}, if the last digit of the number $n$ equals $1$.
  \label{def:happy-number}
\end{definition}
\end{frame}

\begin{frame}{Demo: Example and comments}
\begin{example}
  The number $1$ is both happy and excellent. The number $129$ is
  excellent but not happy. This follows immediately from the
  Definitions \ref{def:excellent-number} and \ref{def:happy-number}.
\end{example}
\begin{alertblock}{Fancytooltips comment}
  Put the mouse pointer to the graphical symbol following definitions
  numbers. You will see the definitions again. We can also refer to
  equation, like this: \eqref{eq:excel} (note that you see the whole
  enclosing definition, not only the equation). Note that the same
  reference has been used on previous slide and the tooltip has not
  been attached, since the reference to \eqref{eq:excel} on the
  previous page is at the same page as its target.
\end{alertblock}
\end{frame}


\begin{frame}{Demo: A picture}
  \begin{figure}
    \centering
\begin{tikzpicture}[domain=0:6.28]
    \draw[->] (0,0) -- (7,0) node[right] {$x$};
    \draw[->] (0,-1.2) -- (0,1.2) node[above] {$f(x)$};
    \shadedraw[color=black,top color=blue,bottom color=red] 
       plot[id=sin] function{sin(x)};
\end{tikzpicture}
    \caption{Sine curve}
    \label{pic:sine}
  \end{figure}

  On one of the previous slides (in Definition \ref{def:excellent-number}) 
  we defined \textit{excellent} number in terms of the number $\alpha$
  defined by relation \eqref{eq:excel}. Below we introduce a simple
  characterization in Theorem \ref{theorem}.
\end{frame}

\begin{frame}{Demo: Newton--Leibniz theorem}
  
  \begin{theorem}
    Let $f(x)$ be integrable in the sense of Riemann on $[a,b]$. Let
    $F(x)$ be a function continuous on $[a,b]$ which is an
    antiderivative of the function $f$ on the interval $(a,b)$. Then
    \begin{equation*}
      \int_a^bf(x)\dx=[F(x)]_a^b=F(b)-F(a)
    \end{equation*}
    holds.\label{th:NL}
  \end{theorem}
\end{frame}

\begin{frame}{Demo: Integral term equals zero}
  \begin{remark}
    It is easy to see that
    \begin{equation}
      \label{eq:sin}
      \int_0^{2\pi}\sin x\dx=0.
    \end{equation}
    Really, direct computation based on Newton-Leibniz Theorem
    \ref{th:NL} shows
    \begin{align*}
      \int_0^{2\pi}\sin x\dx&=[\cos x]_0^{2\pi}\\
      &=\cos(2\pi)-\cos 0\\
      &=0.
    \end{align*}
    (see also Figure \ref{pic:sine})
  \end{remark}
\end{frame}

\begin{frame}
  \frametitle{Demo:  Main result}
  \begin{theorem}[Characterization of excellent numbers]
    The positive integer $n$ is
    \tooltip{excellent}{def:excellent-number} if and only if the last
    digit of the number $n$ is either $1$ or $9$.
    \label{theorem}
  \end{theorem}

\begin{alertblock}{Fancytooltips comment}
  Since we used {\color{red}\texttt{\textbackslash
      label\{def:excellent-number\}}} in the Definition
  \ref{def:excellent-number}, we can insert a tooltip to the word
  excellent by using command{\color{red} \texttt{\textbackslash
      tooltip\{excellent\}\{def:excellent-number\}}}. In this case the
  tooltip is activated by hovering the text, not the soap. This is the
  default behavior of fancytooltips.
\end{alertblock}

\end{frame}

\begin{frame}
  \frametitle{Demo:  Corollary}
  \begin{theorem}[Relationship between happy and excellent numbers]
    Each \tooltip*{happy}{def:happy-number} number is
    \tooltip{excellent}{def:excellent-number}.
  \end{theorem}

\begin{alertblock}{Fancytooltips comment}
  The ``happy'' tooltip is created by
  \texttt{\color{red}\textbackslash
    tooltip*\{happy\}\{def:happy-number\}}. The starred version causes
  that the active button is not attached to the text, but is attached
  to the mark. The ``excellent'' tooltip is created by
  \texttt{\color{red}\textbackslash
    tooltip\{excellent\}\{def:excellent-number\}} and hence, the blue soap is
  inactive and the text active.
\end{alertblock}
\end{frame}

\section{How it works}
\begin{frame}
  \frametitle{How it works}
  \begin{itemize}
  \item We compile the presentation in an ordinary way to get correct
    labels and references.
  \item We compile the presentation with preview package and extract
    displayed equations, theorems, definitions and floats (tables and
    figures).
  \item We create a new document which contains those parts extracted
    in the previous step, which have a label inside.
  \item We compile the presentation again with redefined \texttt{ref}
    macro. This macro inserts the popup using fancytooltips package.
  \end{itemize}
\end{frame}

 \section{Short howto}
 \begin{frame}
   \frametitle{How to create a presentation with pdf\LaTeX}
   Creating tooltips is easy. Simply follow these steps.
   \begin{itemize}
   \item Create presentation with your favorit presentation package,
     such as
     \href{http://www.ctan.org/tex-archive/help/Catalogue/entries/acrotex-web.html}{\color{blue}web},
     \href{http://www.ctan.org/tex-archive/macros/latex/contrib/pdfscreen/}{\color{blue}pdfscreen}
     or
     \href{http://www.ctan.org/tex-archive/help/Catalogue/entries/beamer.html}{\color{blue}beamer}.
   \item Insert
     \begin{quote}\upshape\color{red}
       \texttt{\textbackslash usepackage[inactive]\{fancytooltips\}}
     \end{quote}
     before \texttt{\textbackslash begin\{document\}} and
     \begin{quote}\upshape\color{red}
       \texttt{\textbackslash FancyHook}
     \end{quote}
     after \texttt{\textbackslash begin\{document\}}.
   \item Use the script \texttt{fancy-preview} to compile the
     presentation again, i.e. if your file is filename.tex run
     \begin{quote}\upshape\color{darkgreen}
       \texttt{bash fancy-preview filename}
     \end{quote}
     either in Linux terminal or inside
     \href{http://www.mingw.org/wiki/MSYS}{\color{blue}MSYS} on
     Windows.
   \item You may want to customize the script \texttt{fancy-preview}
     (colors, options for fancytooltips, etc.)
   \end{itemize}
 \end{frame}

 \begin{frame}
   \frametitle{How to create a presentation with dvips}
   \begin{itemize}
   \item This work-flow should still work with dvips, but has been not 
     tested, since it
     requires Acrobat Professional which is not available on author's
     platform (\texttt{Linux}). Moreover, the compilation cannot be
     done automatically, due to the post-processing in Acrobat. You
     are encouraged to try it by yourselves. Report success of problems 
     to the authors email, please.
   \item Basically follow the instructions for pdf\LaTeX{} users.
   \item You have to customize the script \texttt{fancy-preview}
     \begin{itemize}
     \item Replace \texttt{pdflatex} by \texttt{latex}
     \item Add commands which convert \texttt{minimal.ps} into
       \texttt{minimal.pdf}
     \item Extract the number of pages of the file
       \texttt{minimal.pdf} and pass it as an argument to the
       fancytooltips package. (You may use \texttt{pdftk} or
       \texttt{pdflatex} for this task.)
     \end{itemize}
     \item Remember that you have post-process the resulting
       \texttt{ps} file as described in manual for fancytooltips
       package.
   \end{itemize}
 \end{frame}
 

\begin{frame}
  \frametitle{That's all. }
  Any problem? Send a \textit{minimal example} to the author of the
  package.
\end{frame}

\end{document}

