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.
Asked
Active
Viewed 166 times
1
-
1https://tex.stackexchange.com/questions/314041/hyperlinks-in-plain-tex – samcarter_is_at_topanswers.xyz Mar 03 '22 at 12:52
-
1Can you clarify if you are using plain tex or latex? Your title and tags says one thing, the text of your question another.... – samcarter_is_at_topanswers.xyz Mar 03 '22 at 12:55
-
right, I'll update it – dallonsi Mar 03 '22 at 13:24
1 Answers
1
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 it injects some pdf code because links are not natively supported by TeX (even when using 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}!
The macro \url
works also when the document is not compiled with pdftex
. In this case the conditional ifpdfmode
will be set to false
by the compiler and a simple text formatted with the \tt
font will be rendered instead.
You can find a "live" example here: https://github.com/madrisan/cv

Davide Madrisan
- 1,969
- 2
- 14
- 22
-
the links in your CV are not clickable when opening the file in github (https://github.com/madrisan/cv/blob/master/dmadrisan_cv_en.pdf), shame on github :p – dallonsi Mar 03 '22 at 16:55
-
-
1It injects some postscript code that make the parameter #1 of the macro `\url` a clickable URL. I forgot to say that a prefix `https://` is added. This should be not an issue nowadays. If you want to support `http://` links you can easily modify the macro. – Davide Madrisan Mar 03 '22 at 17:57