summaryrefslogtreecommitdiff
path: root/usergrps/dante/dtk/dtk-url.sty
blob: 3387c2807974b47bab5da7fd18959575d34bd5a5 (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
%% This is file `dtk-url.sty',
%%
%% LaTeX Class for ``Die TeXnische Komoedie''.
%%
%% Copyright (C) 2015-2024
%% Rolf Niepraschk, Herbert Voss
%%
%% It may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3c
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%%    http://www.latex-project.org/lppl.txt
%% and version 1.3c or later is part of all distributions of LaTeX
%% version 2005/12/01 or later.

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{dtk-url}[2024/06/26 v1.9 Urls (qrcode) for DTK (HO,hv,rn)]

\RequirePackage{url}[2006/04/12]
\RequirePackage{xcolor}
\RequirePackage{xkeyval}
%\RequirePackage{hvqrurl}

% Konfiguration:
\newcommand*{\DTK@UrlSetup}{\urlstyle{tt}}
\newcommand*{\DTK@UrlCtanSetup}{}
\newcommand*{\DTK@UrlEmailSetup}{}
\newcommand*{\DTK@UrlCtanPrefix}{CTAN:}
\newcommand*{\DTK@UrlCtanServerPrefix}{https://mirror.ctan.org/}
\newcommand*{\DTK@UrlFile}{\jobname.urls}

% Schalter \ifDTK@Url@ legt fest, wann die URLs aktiv sein sollen
\newif\ifDTK@Url@
\ifDTK@korr@\DTK@Url@true\fi

% Markup-Befehle:
\DeclareRobustCommand*{\url}{\DTK@Url}
\DeclareRobustCommand*{\ctanurl}{\DTK@CtanUrl}
\DeclareRobustCommand*{\Email}{\DTK@Email}
\let\URL\url
\let\CTANurl\ctanurl

\DeclareUrlCommand\File{\urlstyle{tt}}

\DeclareUrlCommand\DTK@Url{%
  \DTK@UrlSetup
  \def\UrlLeft{}%
  \def\UrlRight{}%
  \def\DTK@UrlType{url}%
}
\DeclareUrlCommand\DTK@CtanUrl{%
  \DTK@UrlSetup
  \DTK@UrlCtanSetup
  \let\UrlLeft\DTK@UrlCtanPrefix
  \def\UrlRight{}%
  \let\DTK@UrlLinkPrefix\DTK@UrlCtanServerPrefix
  \def\DTK@UrlType{ctanurl}%
}
\DeclareUrlCommand\DTK@Email{%
  \DTK@UrlSetup
  \DTK@UrlEmailSetup
  \def\UrlLeft{}%
  \def\UrlRight{}%
  \def\DTK@UrlLinkPrefix{mailto:}%
  \def\DTK@UrlType{email}%
}
\def\DTK@UrlType{unknown}

% Implementierung

\RequirePackage{pdfescape}

% Currently only pdfTeX/LuaTeX in PDF mode are supported
\RequirePackage{ifpdf}
\ifpdf
\else
  % Other engines then pdfTeX and LuaTeX in PDF mode
  % are not supported
  \DTK@Url@false
\fi

% Ensure that the needed primitives are enabled in LuaTeX
%% No more needed, we use the new macros hv 2016-04-23
%\RequirePackage{ifluatex}
%\ifluatex
%  \directlua{tex.enableprimitives('',{'pdfstartlink','pdfendlink'})}%
%\fi

\let\DTK@UrlLinkPrefix\@empty
\ifDTK@Url@
  \def\Url@HyperHook#1{%
    \begingroup
      \DTK@UrlPercent
      \edef\#{\string##}%
      \edef\DTK@Temp{\DTK@UrlLinkPrefix\Url@String\@empty}%
      \@onelevel@sanitize\DTK@Temp
      \edef\DTK@UrlRaw{\Url@String\@empty}%
      \@onelevel@sanitize\DTK@UrlRaw
      \edef\x{\endgroup
        \noexpand\EdefEscapeString\noexpand\DTK@Temp{\DTK@Temp}%
        \def\noexpand\DTK@Raw{\DTK@UrlRaw}%
      }%
    \x
    \DTK@UrlWrite{\DTK@UrlType}{\DTK@Raw}%
    \pdfextension startlink attr{%
      /H/I%
      /C[1 0 0]% red
      /Border[1 0 0]%
      /BS<</S/U/W 1>>%
    }%
    user{%
      /Subtype/Link
      /A<<%
        /Type/Action%
        /S/URI%
        /URI(\DTK@Temp)%
      >>%
    }%
    #1%
    \pdfextension endlink%
  }%
  % Implement writing of file \DTK@UrlFile
  \if@filesw
    \RequirePackage{atveryend}%
    \RequirePackage{embedfile}%
    \newwrite\DTK@UrlHandle
    \openout\DTK@UrlHandle=\DTK@UrlFile\relax
    \begingroup
      \count@\time
      \divide\count@ by 60 %
      \count2=-\count@
      \multiply\count2 by 60 %
      \advance\count2 \time
      \edef\x{\endgroup
        \write\DTK@UrlHandle{%
          \@percentchar\space
          \the\year-\two@digits\month-\two@digits\day
          \space\two@digits\count@:\two@digits{\count2 }, %
          format: <page> <type> <data>%
        }%
      }%
    \x
    \def\DTK@UrlWrite#1#2{%
      \protected@write\DTK@UrlHandle{}{%
        \thepage\space#1 #2%
      }%
    }%
    \let\DTK@embedfilefinish\embedfilefinish
    \let\embedfilefinish\relax
    \AfterLastShipout{%
      \immediate\closeout\DTK@UrlHandle
      \IfFileExists{\DTK@UrlFile}{%
        \embedfile[%
          mimetype=text/plain,%
          stringmethod=escape,%
          desc={%
            List of URLs found in %
            \@backslashchar url and \@backslashchar ctanurl%
          },%
        ]{\DTK@UrlFile}%
        \DTK@embedfilefinish
      }{}
    }%
  \else
    \let\DTK@UrlWrite\@gobbletwo
  \fi
\fi

\begingroup
  \lccode`\~=`\%
\lowercase{\endgroup
  \def\DTK@UrlPercent{\let~\DTK@UrlPercentCR}%
}
\begingroup
  \lccode`\0=`\^^M
\lowercase{\endgroup
  \def\DTK@UrlPercentCR#1{%
    \ifx0#1\@empty
      \expandafter\@gobble
    \else
      \expandafter\@firstofone
    \fi
    {\@percentchar#1}%
  }%
}

\endinput