I would like to incorporate a link into a picture using \href. The links are stored in text files. The .tex file should be able to read form those text files (i.e. 1.text) and generate that clickable image.
I already got quite a good answer in this question How to add externally stored link text into a hyperlink?
...but I still have a problem:
% !TeX program = lualatex
\documentclass{article}%
\usepackage{graphicx}
\usepackage{hyperref,catchfile}% for the links
\usepackage{verbatim}% for the input
%To generate a text file for demonstration
\begin{filecontents*}{1.txt}
https://www.youtube.com/
\end{filecontents*}
\usepackage{hyperref,catchfile}
\newcommand\urlFromFile[1]{%
\CatchFileDef\myurl{#1}{\catcode`\#=12\catcode`\%=12}%
\expandafter\url\expandafter{\myurl}}
\begin{document}
\href{\urlFromFile{1.txt}}{\includegraphics[width=\linewidth]{example-image}}
\end{document}
%
I get:
line 16: TeX capacity exceeded, sorry [parameter stack size=10000]. \href{\urlFromFile{1.txt}}