Is it possible to define clickable links in a plainTeX document when compiled with pdftex? As far as I can see there is no support in plainTeX for this feature.
CodePudding user response:
For creating clickable links in pdf documents generated from a TeX
(plainTex
) document you can use this code:
\newif\ifpdfmode
\ifx\pdfoutput\undefined
\else
\ifnum\pdfoutput>0 \pdfmodetrue\fi
\fi
\def\url#1{%
% turn off the special meaning of ~ inside \url{}.
\begingroup\catcode`\~=12\catcode`\_=12\relax
\ifpdfmode
\pdfstartlink user{
/Subtype /Link
% w/o this you get an ugly box around the URL.
/Border [ 0 0 0 ] % radius, radius, line thickness
/A <<
/Type /Action
/S /URI
/URI (https://#1)
>>
}%
{\tt#1}%
\pdfendlink{}%
\else
%{\tt https\negthinspace:\negthinspace/\negthinspace/#1}%
{\tt#1}%
\fi
\endgroup}
that you can save in a file named lib/url.sty
.
Note that you need to inject some pdf code because links are not natively supported by TeX (even if you compile your document with the pdftex
compiler).
Once done it's just a question of using the macro url
in your TeX
code:
\input lib/url.sty
My preferred site is \url{stackoverflow.com}!
Note also that this macro works also when the document is not compiled with pdftex
. In this case the conditional ifpdfmode
will be set to false
and a plain text formatted with the \tt
font will be inserted in the output.
You can find a "live" example here: https://github.com/madrisan/cv