# \input inside \href

I have a number of papers that include my email on the cover of the paper, and need to find a solution to \input my email address using \href. This way I will be able to edit my email once, and then get the most updated email address in all my papers every time I compile the file.

Is it possible to do something like this?

\href{mailto:{\input{/Path/to/my/file/with/my/email/address.txt}\unskip}}{{\input{/Path/to/my/file/with/my/email/address.txt}\unskip}}


Thanks guys.

• you could but why make it so complicated, rather than \href{mailto:\myemail}{\myemail} together with a myemail.sty that you can put in your input path with just one line: \def\myemail{foo@example.com} – David Carlisle Jul 4 '17 at 16:29
• If you are trying to remove the space that TeX adds after the sheer contents of your file (because it adds an end-of-line marker), \unskip cannot be used for this purpose in the first argument of \href. In principle, the problem could be cured by setting \endlinechar = -1, but it is much more simple to act as @DavidCarlisle suggests (but replacing \def with \newcommand*, I’d say…). – GuM Jul 4 '17 at 16:34

This solution uses plain TeX I/O commands.

\begin{filecontents}{address.txt}
jkormylo@elfsoft2000.com
\end{filecontents}
%
\documentclass{article}
\usepackage{hyperref}

\newcommand{\readfile}[1]% #1 = filename
{\bgroup
\endlinechar=-1
\openin\fid=#1
\loop\ifx\empty\filetext\relax% skip over comments
\repeat
\closein\fid
\global\let\filetext=\filetext
\egroup}

\begin{document}
\href{mailto:\filetext}{\filetext}
\end{document}


Solution that fetches the mail address from a file to a macro via package catchfile:

\begin{filecontents}{address.txt}
john.doe@example.org
\end{filecontents}

\documentclass{article}
\usepackage{catchfile}

\href{mailto:\TheMailAddress}{John Doe $\langle$\TheMailAddress$\rangle$}

• @samcarter Usually, I convert to PDF, crop it, and run it through ghostscript's device pngalpha. Here, I have used the device png16m and used Gimp's "Colorize to alpha", because the current installed ghostscript (9.19) creates ugly artefacts at the edges. – Heiko Oberdiek Jul 4 '17 at 18:54