I have a bunch of links which are individually stored in text files. I would like to create a LaTeX document in which those files are accessed using relative paths and the link included into the final PDF. The reason is that later in the future I might want to change the links in the files and the generated PDF should update accordingly.
This is what I have tried:
\usepackage{verbatim}
\href{\verbatiminput{./links/1.txt}}
but I get the error:
TeX capacity exceeded, sorry [input stack size=5000].
Here is a minimum working example:
Create File: 1.txt
1.1. Input https://www.youtube.com/
1.2. Close file
Latex Code without pulling from text file
% !TeX program = lualatex
\documentclass{article}%
\usepackage{graphicx}
\usepackage{hyperref}% for the links
\usepackage{verbatim}% for the input
\begin{document}%
\href{https://www.youtube.com}{\includegraphics[width=\linewidth]{example-image}}
\end{document}%
works great !
now with pulling from text file
% !TeX program = lualatex
\documentclass{article}%
\usepackage{graphicx}
\usepackage{hyperref}% for the links
\usepackage{verbatim}% for the input
\begin{document}%
\href{\include{1.txt}}{\includegraphics[width=\linewidth]{example-image}}
\end{document}%
I get the errors:
line 10: Argument of @include has an extra }. \href{\include{1.txt}}
line 10: Paragraph ended before @include was complete.
\href{\include{1.txt}} line 10: Paragraph ended before \href@ was
complete. \href{\include{1.txt}} line 10: Extra }, or forgotten
\endgroup. \href{\include{1.txt}} line 10: Overfull \hbox (15.0pt too
wide) in paragraph
EDIT:
based on @Ulrike Fischer, I tried
% !TeX program = lualatex
\documentclass{article}%
\usepackage{graphicx}
\usepackage{hyperref,catchfile}% for the links
\usepackage{verbatim}% for the input
\begin{document}%
\CatchFileDef\myurl{1.txt}{}
\href{\myurl}{\includegraphics[width=\linewidth]{example-image}}
\end{document}%
but I got:
Package catchfile Error: File `1.txt' not found. \CatchFileDef\myurl{1.txt}{} Suppressing link with empty target Overfull \hbox (15.0pt too wide) in paragraph
EDIT 2:
Also tried to create a new command, but did not work: http://www.emerson.emory.edu/services/latex/latex_19.html
\newcommand\urlFromFile[1]{\CatchFileDef{#1}{}}
EDIT 3:
% !TeX program = lualatex
\documentclass{article}%
\usepackage{graphicx}
\usepackage{hyperref,catchfile}% for the links
\usepackage{verbatim}% for the input
\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}}