3

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.

  • 5
    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
  • 1
    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
4

This solution uses plain TeX I/O commands.

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

\newread\fid

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

\begin{document}
\readfile{address.txt}
\href{mailto:\filetext}{\filetext}
\end{document}
6

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}
\usepackage[colorlinks]{hyperref}

\CatchFileDef\TheMailAddress{address.txt}{\endlinechar=-1}
% \endlinechar=-1 suppresses spaces by line ends

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

Result

  • Just for curiosity: how do you make the screenshots with transparent background? – user36296 Jul 4 '17 at 18:46
  • @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
  • @samcarter I guess that it's not a screnshot. Rather a pdf that was converted into a gif or png. – Dr. Manuel Kuehner Jul 4 '17 at 18:54
  • Sorry. Wasn't reading it accurate enough. The question wasn't of course not for me :). Still, have a look at en.m.wikipedia.org/wiki/ImageMagick. I use the convert command from the windows command window or in a batch file for that kind of tasks. – Dr. Manuel Kuehner Jul 4 '17 at 18:55
  • 1
    @Dr.ManuelKuehner :) The more people to answer the better :) – user36296 Jul 4 '17 at 19:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.