# Avoid “Illegal unit of measure (pt inserted)” when dealing with LaTeX lengths

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{
% 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,
}
\tikz{
\node (previewimage)
}
}

\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}
\end{center}
\end{frame}
\end{document}

• Try \fontsize{0.4\dimexpr\vlinkwidth}... – Ulrike Fischer Nov 11 '19 at 10:19

\vlinkWidth, is a macro not a length register, you would see the same if you went \def\zzz{100.5pt} then used 0.4\zzz as a length.
The macro would expand and give you 0.4100.5pt with two . and the error that you show.
As Ulrike commented you can use \dimexpr which is essentially an anonymous length register so 0.4\dimexpr\zzz\relax is again a valid length or in your case 0.4\dimexpr\vlinkwidth\relax
• Thank you very much @UlrikeFischer and @DavidCarlisle for providing a solution and also the background information to use an anonymous length register using \dimexpr. – Schwefelsaeure Nov 12 '19 at 10:26