summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/issuulinks/issuulinks.dtx
blob: 5204aba772e543af2bd71352a1abef66d30308c4 (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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
% \iffalse
% $Id: issuulinks.dtx,v 1.6 2012-03-22 22:54:19 boris Exp $
%
% Copyright 2012, Boris Veytsman <borisv@lk.net>
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either
% version 1.3 of this license or (at your option) any 
% later version.
% The latest version of the license is in
%    http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of
% LaTeX version 2003/06/01 or later.
%
% This work has the LPPL maintenance status `maintained'.
%
% The Current Maintainer of this work is Boris Veytsman
%
% This work consists of the file issuulinks.dtx and the
% derived files issuulinks.sty, issuulinks.dtx. 
%
% \fi 
% \CheckSum{106}
%
%
%% \CharacterTable
%%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%%   Digits        \0\1\2\3\4\5\6\7\8\9
%%   Exclamation   \!     Double quote  \"     Hash (number) \#
%%   Dollar        \$     Percent       \%     Ampersand     \&
%%   Acute accent  \'     Left paren    \(     Right paren   \)
%%   Asterisk      \*     Plus          \+     Comma         \,
%%   Minus         \-     Point         \.     Solidus       \/
%%   Colon         \:     Semicolon     \;     Less than     \<
%%   Equals        \=     Greater than  \>     Question mark \?
%%   Commercial at \@     Left bracket  \[     Backslash     \\
%%   Right bracket \]     Circumflex    \^     Underscore    \_
%%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%%   Right brace   \}     Tilde         \~} 
%
% \MakeShortVerb{|}
%
%\GetFileInfo{issuulinks.dtx}
% \title{Produce External Links Instead of Internal
% Ones\thanks{\copyright Boris Veytsman, 2012}}  
% \author{Boris Veytsman\thanks{This work was partially supported by
% The Food and Agriculture Organization of the United Nations}}
% \date{\filedate, \fileversion}
% \maketitle
%
% \begin{abstract}
%   A package to change automatic internal links in a document into
%   external ones in the form
%   \path{http://issue.com/action/page=PAGENUMBER} as required by
%   \url{http://issuu.com}.
% \end{abstract}
%
% \tableofcontents
%
% \clearpage
%
%\section{Introduction}
%\label{sec:intro}
%
% PDF visualizer ISSUU (\url{http://issuu.com}) is a popular service
% allowing to show PDF documents ``one page a time''.  Due to the way
% it is implemented, internal links in these documents are not
% allowed.  Instead, they must be converted to external ones in the
% form \path{http://issuu.com/action/page?page=PAGENUMBER}.  
%
% This package patches \textsf{hyperref} to produce external links in
% the required form instead of internal links created by |\ref|,
% |\cite| and other commands.
%
% Since the package redefines the internals of \textsf{hyperref}, you
% need to call it \emph{after} \textsf{hyperref}.
% 
% The author is grateful to FAO UN which partially funded this work
% and to Matthieu Stigler, Adam Prakash \& Filippo Gheri for
% suggesting and testing this package.
% 
%\section{Usage}
%\label{sec:usage}
%
%  To use this package just add |\usepackage{issuulinks}| \emph{after}
%  calling \textsf{hyperref}.  By default all links will be converted
%  into the form required by ISSUU.
%
% \DescribeMacro{\issuusetup}
% The command |\issuusetup|\marg{setup commands} might be used to
% customize the behavior of the package.  At present the only
% customizable command is |prefix|, that sets the part of the link
% before |PAGENUMBER|by default 
% |http://issuu.com/action/page?page=|.  You can change it, for example,
% \begin{verbatim}
% \issuusetup{prefix={http://www.issuu.com/action/page?page=}}
% \end{verbatim}
%
% Otherwise the work of the package should be transparent for the
% user.   
%
%\StopEventually{}
%
% \clearpage
% 
% \section{Implementation}
% \label{sec:implementation}
% 
%
%\subsection{Algorithm}
%\label{sec:alg}
%
% The idea is following.  Whenever \textsf{hyperref} creates an
% internal anchor \marg{name}, we write to the aux file the command
% \cmd{\newISSUUlink}\marg{name}\marg{abspage}, where \marg{abspage}
% is the absolute page number (as different from the displayed page
% number).  Then when \textsf{hyperref} creates an internal link to
% \marg{name}, we substitute this to a call to \url{http://issuu.com}
% with the corresponding page number. 
%
%\subsection{Declarations}
%\label{sec:decl}
% 
%  We start with declaration, who we are:
%
% \changes{v1.0}{2012/02/27}{First released version}
%    \begin{macrocode}
%<style>\NeedsTeXFormat{LaTeX2e}
%<*gobble>
\ProvidesFile{issuulinks.dtx}
%</gobble>
%<style>\ProvidesPackage{issuulinks}
[2012/03/22 v1.1 Links in ISSUU style]
%    \end{macrocode}
%
%    \begin{macrocode}
%<*gobble>
\documentclass{ltxdoc}
\usepackage{hypdoc}
\usepackage{url}
\CodelineIndex
\RecordChanges
\EnableCrossrefs
\begin{document}
  \DocInput{issuulinks.dtx}
\end{document}
%</gobble> 
%<*style>
%    \end{macrocode}
%
%
%\subsection{Parameters}
%\label{sec:params}
%
% We use \textsf{keyval} to process options:
%    \begin{macrocode}
\RequirePackage{xkeyval}
%    \end{macrocode}
% 
% \begin{macro}{\issuusetup}
%   The shorthand for setting options:
%    \begin{macrocode}
\def\issuusetup#1{\setkeys{ISL}{#1}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ISL@prefix}
%   The |prefix| macro:
%    \begin{macrocode}
\define@key{ISL}{prefix}{\def\ISL@prefix{#1}}
\issuusetup{prefix={http://issuu.com/action/page?page=}}
%    \end{macrocode}
%   
% \end{macro}
%
%
%\subsection{Working with Aux File}
%\label{sec:file}
%
%
% \begin{macro}{\newISSUUlink}
% \changes{v1.1}{2012/03/22}{Added check for undefined/changed references} 
% The page numbers in |\Hy@abspage| start from zero, so we need to
% increment them:
%    \begin{macrocode}
\def\newISSUUlink#1#2{\@tempcnta=#2\relax\advance\@tempcnta by1\relax
  \expandafter\xdef\csname ISL@link#1\endcsname{\the\@tempcnta}}
%    \end{macrocode}
% Someone can use an aux file from the previous run, so we provide a
% safety valve:
%    \begin{macrocode}
\AtBeginDocument{%
  \if@filesw
  \immediate\write\@mainaux{\string\providecommand\string\newISSUUlink[2]{}}%
  \fi}
%    \end{macrocode}   
% At the end of document \LaTeX{} checks whether references might
% been changed or undefined.  Here we plug in into this mechanism:
%    \begin{macrocode}
\AtEndDocument{\let\newISSUUlink\@testISSUUlink}
%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\@testISSUUlink}
% \changes{v1.1}{2012/03/22}{Added macro} 
%   Test whether this link is defined.  If not, set |\@tempswa| to
%   true---this will cause \LaTeX{} to issue a warning:
%    \begin{macrocode}
\def\@testISSUUlink#1#2{\@tempcnta=#2\relax\advance\@tempcnta by1\relax
  \edef\reserved@a{\the\@tempcnta}%
  \expandafter\ifx\csname ISL@link#1\endcsname\reserved@a\else
     \@tempswatrue
  \fi}
%    \end{macrocode}
%   
% \end{macro}
%
% 
%
%\subsection{Writing the Internal Link Information}
%\label{sec:writing}
%
% \begin{macro}{\new@pdflink}
%   We patch |\new@pdflink| to write its argument into the aux file.
%   Note that the counter |\Hy@abspage| stores the absolute page
%   position in \textsl{hyperref}.  We do not prevent writing the
%   internal anchor in the catalog---probably a waste of time and
%   bits, but somebody might rely on this for some other
%   purpose\footnote{Actually I am too lazy to do otherwise\dots}.
%    \begin{macrocode}
\let\new@pdflink@ISLorig=\new@pdflink
\def\new@pdflink#1{%
  \@bsphack
  \protected@write\@mainaux{}%
         {\string\newISSUUlink{#1}{\the\Hy@abspage}}%
  \@esphack
  \new@pdflink@ISLorig{#1}}
%    \end{macrocode}   
% \end{macro}
%
%
%\subsection{Patching Internal Links}
%\label{sec:patching}
% 
%
% \begin{macro}{\Hy@StartlinkName}
%   The standard |\Hy@StartlinkName| is defined like this:
% \begin{verbatim}
% \def\Hy@StartlinkName#1#2{%
%   \pdfstartlink attr{#1}goto name{#2}\relax
% }
% \end{verbatim}
% Here we are patching it.  Note that we can have bad links if we use
% `old' aux file
%    \begin{macrocode}
\def\Hy@StartlinkName#1#2{%
  \expandafter\ifx\csname ISL@link#2\endcsname\relax
    \PackageWarning{issuulinks}{The page number for an external link
      is not defined.  Setting it to 1.  You need to rerun LaTeX to
      get the page numbers right.}%
    \expandafter\def\csname ISL@link#2\endcsname{1}\fi
  \edef\Hy@pstringURI{\ISL@prefix\csname ISL@link#2\endcsname}%
  \pdfstartlink attr{#1}%
  user{%
       /Subtype/Link%
       \ifHy@pdfa /F 4\fi
       /A<<%
         /Type/Action%
         /S/URI%
         /URI(\Hy@pstringURI)%
         \ifHy@href@ismap
           /IsMap true%
         \fi
         \Hy@href@nextactionraw
       >>%
      }%
      \relax
}
%    \end{macrocode}
% 
%
%  
% \end{macro}
%
%
%
%    \begin{macrocode}
%</style>
%    \end{macrocode}
%\Finale
%\clearpage
%
%\PrintChanges
%\clearpage
%\PrintIndex
%
\endinput