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