blob: bd6daf7d42cd7f6f072546e85c1941531873f86f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
% !TeX root = ../easyfloats.tex
% Copyright © 2020 E. Zöllner
% Alternatively to the terms of the LPPL, at your choice,
% you can redistribute and/or modify this file under the
% terms of the Do What The Fuck You Want To Public License, Version 2,
% as published by Sam Hocevar. See http://www.wtfpl.net/about/.
% Adds an abstraction layer above hyperref's \href and \hyperref commands.
% Links are defined with:
% \newurllink{<name>}{<url>}
% \newlabellink{<name>}{<label>}
% A text is turned into a link with
% \link[<name>]{<text>}
% Like in markdown the name of the link is optional.
% If it is omitted <text> is used instead.
% This has the advantage that all links can be declared in one place
% and URLs don't need to be repeated.
% Changing an external link to an internal link is easy.
\makeatletter
\newcommand{\link@csname}[1]{link@cs@#1}
\newcommand\newurllink{%
\begingroup
\let\do=\@makeother
\dospecials
\catcode`{=1
\catcode`}=2
\newurllink@do
}
\newcommand\newurllink@do[2]{% #1: name, #2: url
\endgroup
\expandafter \newcommand \csname\link@csname{#1}\endcsname{\href{#2}}%
}
\newcommand\newlabellink[2]{% #1: name, #2: label
\expandafter \newcommand \csname\link@csname{#1}\endcsname{\hyperref[#2]}%
}
\newcommand\link{% [#1: name], #2: displayed text
\@ifnextchar [
{\link@do}
{\@dblarg\link@do}%
}
\def\link@do[#1]#2{%
\ifcsname\link@csname{#1}\endcsname
\csname\link@csname{#1}\endcsname{#2}%
\else
\PackageError{link}{link name `#1' undefined}{}%
\fi
}
\makeatother
|