summaryrefslogtreecommitdiff
path: root/obsolete/usergrps/dante/dtk-1.32/dtk-url.sty
blob: 032bd233badd1e7ddc899888af7da0300be1d99c (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
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{dtk-url}[2011/10/23 v1.0 Urls for DTK (HO)]

\RequirePackage{url}[2006/04/12]

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

% Schalter \ifDTK@Url@ legt fest, wann die URLs aktiv sein sollen
\newif\ifDTK@Url@
\ifDTK@Draft@
  \DTK@Url@true
\fi
\ifDTK@lineno@
  \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\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
\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}%
    \pdfstartlink 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%
    \pdfendlink
  }%

  % 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
      \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