summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/easyfloats/doc/preamble/link.tex
diff options
context:
space:
mode:
Diffstat (limited to 'macros/latex/contrib/easyfloats/doc/preamble/link.tex')
-rw-r--r--macros/latex/contrib/easyfloats/doc/preamble/link.tex53
1 files changed, 53 insertions, 0 deletions
diff --git a/macros/latex/contrib/easyfloats/doc/preamble/link.tex b/macros/latex/contrib/easyfloats/doc/preamble/link.tex
new file mode 100644
index 0000000000..bd6daf7d42
--- /dev/null
+++ b/macros/latex/contrib/easyfloats/doc/preamble/link.tex
@@ -0,0 +1,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