My goal is to link to external video files in beamer presentations rather then embedding them directly into the PDF (e.g., with media9 package) to keep the size as small as possible.
I use the hyperref package to create a clickable area (a link) which contains a preview image of the video and TikZ to create a small play button as overlay to attract presenter's attention. The final result looks like this:
I wrapped the hyperref and TikZ commands in an own command \vlink[options]{name_of_video_file}
and I use the pgfkeys package so that my command can accept key-value pairs as options.
The vlink
command runs fine when using \textwidth
or integer dimensions like 2cm
(e.g., \vlink[width=\textwidth]{my_video_file.mp4}
). But, when invoking with width=0.5\textwidth
or width=2.5cm
, I get an Illegal unit of measure (pt inserted)
error because my TikZ command uses \fontsize{0.40\vlinkWidth}...
to set the overlay dimensions. Obviously, LaTeX expands 0.5\texwidth
to something strange which I don't understand (the LaTeX Wikibook states it should be a length).
So, what is the correct way to handle the passed width here?
Any help is appreciated. :)
A minimal working example is attached below (please add a dummy picture named BigBugBunny.mp4.preview.png
to avoid compilation errors):
\documentclass{beamer}
\usepackage[utf8x]{inputenc}
\usepackage{fontawesome}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{pgfkeys}
\usepackage{tikz}
\pgfkeys{
/vlink/.is family,
/vlink,
% Here are the options that a user can pass
default/.style =
{width = \textwidth, color=black, opacity=0.25},
width/.estore in = \vlinkWidth,
color/.estore in = \vlinkColor,
opacity/.estore in = \vlinkOpacity,
}
\newcommand\vlink[2][]{%
\pgfkeys{/vlink, default, #1}%
\tikz{
\node (previewimage)
{\href{run:#2}{\includegraphics[width=\vlinkWidth]{{{#2.preview}}}}};
\node [align=center,color=\vlinkColor,opacity=\vlinkOpacity,text width=\vlinkWidth] at
(previewimage.center){\fontsize{0.40\vlinkWidth}{\vlinkWidth}\selectfont\faPlayCircleO};
}
}
\begin{document}
\begin{frame}{Test `vlink' Command}
\begin{itemize}
\item Use `vlink' to create a link to a video file.
\item I.e., the video file is not embedded into the final PDF.
\item Instead, the default video player is launched when clicking the link.
\item The link area is a preview image of the embedded video.
\end{itemize}
\begin{center}
\vlink[color=white,opacity=0.6,width=\textwidth]{BigBuckBunny.mp4}
\end{center}
\end{frame}
\end{document}
\fontsize{0.4\dimexpr\vlinkwidth}...
– Ulrike Fischer Nov 11 '19 at 10:19