9

I´m wondering if you can include an email hyperlink in a PDF, that will not only open my mail application with the specified mail address, but also insert a subject, which I specified in LaTeX?

I found something, that hints in the right direction, however, I seem to be unable to make it work. There is the "pracjourn" class, which is supposed to have this implemented in the following macro from http://ctan.uib.no/macros/latex/contrib/pracjourn/pracjourn.pdf (p.15):

This macro takes three arguments to typeset a mailto email hyperlink. The #1 takes the email address, #2 takes the default subject of the email, and #3 is the text to appear in the output as the hyperlink.

230 \newcommand\tpj@compose@mailto[3]{%
231 \edef\@tempa{mailto:#1?subject=#2 }%
232 \edef\@tempb{\expandafter\html@spaces\@tempa\@empty}%
233 \href{\@tempb}{#3}}

I don´t really know what to do with that macro... Even using the pracjourn class doesn´t support this command, which is obviously due to the @ in the command name and I can only guess, that this is not meant for LaTeX, but TeX?!

10

Your copied piece of code is not complete. If you look into the pdf you will find a few more lines.

I put all together to a compiling MWE:

\documentclass{report} 

\usepackage{etoolbox}
\makeatletter
\newcommand\myemail[3]{%                %\newcommand\tpj@compose@mailto[3]{%
\edef\@tempa{mailto:#1?subject=#2 }%
\edef\@tempb{\expandafter\html@spaces\@tempa\@empty}%
\href{\@tempb}{#3}}

\catcode\%=11
\def\html@spaces#1 #2{#1%20\ifx#2\@empty\else\expandafter\html@spaces\fi#2}
\catcode\%=14
\makeatother

\usepackage{hyperref}


\begin{document}
\section{Test Email}

An email adress: \myemail{john.doe@doe.ab}{Subjekt}{Text in pdf}

\end{document}

I renamed the macro to \myemail and it needs tree arguments, the email adress to send to (john.doe@doe.ab), the subject (Subjekt) and an text (Text in pdf) to be showed in the resulting pdf for the link (could be the email adress, if you want). The macro \html@space changes the blanks to %20.

  • is it correct that the part of code after \def\html@spaces#1 #2{#1 seems to be commented because of %? – Vladimir Parkhomenko Nov 14 '17 at 8:53

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.