summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/flippdf/flippdf.dtx
blob: f9cd023d867e3464452934fb22dc723d0352b04d (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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
% \iffalse meta-comment
%
% Copyright 2006, 2020
% Sergio Callegari <sergio.callegari@gmail.com>
%
% ---------------------------------------------
% This file is part of the flippdf package,
% a contribution to the LaTeX2e system.
% ---------------------------------------------
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, version 1.3c.
% This license is in
%   https://www.latex-project.org/lppl/lppl-1-3c/
% and is part of all distributions of LaTeX later than
% 2008-05-04.
% 
% This work has the LPPL maintenance status "maintained".
%
% This program consists of the files listed in the README.md file
% included in the package.
%
%<*driver>
\documentclass{ltxdoc}
\usepackage{mathptmx}
\usepackage[scaled=0.92]{helvet}
\usepackage{hologo}
\usepackage[T1]{fontenc}
\usepackage{hypdoc}
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\begin{document}
  \DocInput{flippdf.dtx}
\end{document}
%</driver>
%
% \fi
%
% \DoNotIndex{\NeedsTeXFormat, \documentclass}
% \DoNotIndex{\begin, \end}
% \DoNotIndex{\def, \gdef, \let, \newcommand}
% \DoNotIndex{\ProvidesPackage, \RequirePackage, \usepackage, \PackageError}
% \DoNotIndex{\DeclareOption, \ProcessOptions}
% \DoNotIndex{\ifx, \fi, \newif, \else}
% \DoNotIndex{\paperwidth, \space, \strip@pt}
% \DoNotIndex{\maketitle, \title, \lipsum}
% \DoNotIndex{\thispagestyle, \relax, \setcounter, \Large, \clearpage, \bigskip}
% \DoNotIndex{\@ifundefined, \AtBeginDocument, \endinput, \MessageBreak}
% \DoNotIndex{\PackageWarningNoLine}

% \CheckSum{86}
%
% \def\filename{flippdf.dtx}
% \def\fileversion{2.0b}
% \def\filedate{2020/10/27}
% \def\docdate{2020/10/27}
%
% \newcommand*{\Lpack}[1]{\textsf {#1}}           ^^A typeset a package
% \newcommand*{\Lopt}[1]{\textsf {#1}}            ^^A typeset an option
% \newcommand*{\file}[1]{\texttt {#1}}            ^^A typeset a file
% \newcommand*{\Lcount}[1]{\textsl {\small#1}}    ^^A typeset a counter
% \newcommand*{\pstyle}[1]{\textsl {#1}}          ^^A typeset a pagestyle
% \newcommand*{\Lenv}[1]{\texttt {#1}}            ^^A typeset an environment
%
% \title{The \Lpack{flippdf} package\thanks{This file
%     (\texttt{\filename}) has version number \fileversion, last
%     revised \filedate.}}
%
% \author{%
%   Sergio Callegari\thanks{Sergio Callegari can be reached at
%       \texttt{sergio.callegar at gmail dot com}}} 
%
% \date{\docdate}
%
% \maketitle
%
% \begin{abstract}
%   The \Lpack{pdfflip} package extends \hologo{pdfLaTeX} and
%   \hologo{LuaLaTeX} making it possible to typeset a ``mirrored'' version
%   of the document. This is sometimes required by publishers who use
%   photographic printing processes that need ``camera-ready'' documents
%   to be printable on transparent films, so that one reads the pages
%   correctly by looking \emph{through} the film with the \emph{unprinted}
%   side of the film towards his eyes. This package requires
%   \Lpack{everypage} by the same author and works exclusively with
%   \hologo{pdfLaTeX} and \hologo{LuaLaTeX} in PDF output mode.
% \end{abstract}
% 
% \section{Introduction}
% 
% This \LaTeX\ package makes it possible to typeset a document flipping
% its pages horizontally. This is sometimes required by publishers who use
% photographic printing process that need ``camera-ready'' documents to be
% printable on transparent films, so that one reads the pages correctly by
% looking \emph{through} the film (i.e., with the \emph{unprinted} side of
% the film towards his eyes).
%
% It is also possible to activate the mirroring capability on a page
% by page basis.
%
% This package requires \Lpack{everypage} by the same author and works
% exclusively with \hologo{pdfLaTeX} and \hologo{LuaLaTeX} in PDF output
% mode.
%
% \section{User interface}
% By default, once loaded as:
% \begin{quote}
% |\usepackage{pdfflip}|
% \end{quote}
% the \Lpack{pdfflip} becomes immediately \emph{active} (i.e., starts
% flipping horizontally every page). Conversely, by selecting the
% \Lopt{off} option as in
% \begin{quote}
% |\usepackage[off]{pdfflip}|
% \end{quote}
% The package is loaded but remains inactive.
%
% \DescribeMacro{\FlipPDF} The |\FlipPDF| command lets one switch on page
% flipping. Conversely, \DescribeMacro{\UnFlipPDF}|\UnFlipPDF| switches
% off page flipping.
%
%
% \section{Examples}
% \subsection{Plain case}
% In this example, every page of the document is flipped, relying on the
% automatic operation mode of the package.
% \iffalse
%<*test-1>
% \fi
%    \begin{macrocode}
\documentclass[a4paper]{article}
\usepackage{flippdf}
\usepackage{lipsum}

\title{Test document for the flippdf package}

\begin{document}
\maketitle
\lipsum[1-5]
\end{document}
%    \end{macrocode}
% \iffalse
%</test-1>
% \fi
%
% \subsection{Case with activation and deactivation}
% In this example, the page flipping is manually activated and deactivated.
% \iffalse
%<*test-2>
% \fi
%    \begin{macrocode}
\documentclass[a4paper]{article}
\usepackage[off]{flippdf}
\usepackage{lipsum}

\title{Test document for the flippdf package}

\begin{document}

\thispagestyle{empty}
{\Large Some non-mirrored initial info}

\bigskip

\lipsum[1]

\maketitle
\setcounter{page}{1}
\FlipPDF
\lipsum[2-6]

\clearpage
\UnFlipPDF
\thispagestyle{empty}
{\Large Some non-mirrored final info}

\bigskip

\lipsum[7]
\end{document}
%    \end{macrocode}
% \iffalse
%</test-2>
% \fi
%
% \section{Package redesign}
%
% Until Fall 2020, \Lpack{flippdf} relied on package \Lpack{everypage} for
% its operation. Recently, functionalities similar to those offered by
% \Lpack{everypage} have been incorporated into \hologo{LaTeX} and
% \Lpack{everypage} has been deprecated, maintaining support for it just
% in view of compatibility for legacy packages still relying on it. As a
% consequence, \Lpack{flippdf} has been redesigned to take advantage of the
% new \hologo{LaTeX} features and to drop the dependence on
% \Lpack{everypage}.
%
% Version 2.0 of \Lpack{flippdf} is the result of the redesign. Version
% 1.x remains availabe las \Lpack{flippdf-1x} and modern \Lpack{flippdf}
% knows how to fallback on it when used on a \hologo{LaTeX} format missing
% the new features.
%
% \StopEventually {}
%
% \section{Implementation}
%
% \subsection{Implementation of \Lpack{flippdf}}
%
% \iffalse
%<*flippdf>
% \fi
% \changes{R2.0}{2020/10/18}{Use modern \hologo{LaTeX} features.}%
% Announce the name and version of the package, that requires
% \hologo{LaTeX2e} (actually \hologo{pdfLaTeX} or \hologo{LuaLaTeX}).
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{flippdf}%
  [2020/10/27 R2.0b Horizontal flipping of pages with pdfLaTeX]
%    \end{macrocode}
% \changes{R2.0b}{2020/10/27}{Assure that options are passed to
% \Lpack{flippdf-1x} when the old code is used.}
% Depending on the actual functionalities provided by \hologo{LaTeX}
% consider loading \Lpack{flippdf-1x}. If so doing, warn about this,
% and hand over the operation to that package.
%    \begin{macrocode} 
\@ifundefined{AddToHook}{%
  \PackageWarningNoLine{flippdf}{%
    You appear to be running a version of LaTeX\MessageBreak
    unsupported by current flippdf.\MessageBreak
    Forcing fallback to `flippdf-1x` that\MessageBreak
    uses an older code base}%
  \RequirePackageWithOptions{flippdf-1x}%
  \endinput}{}
%    \end{macrocode}
% State package requirements, including \Lpack{iftex}
%    \begin{macrocode} 
\RequirePackage{iftex}
%    \end{macrocode}
% Error out if not working in PDF mode
%    \begin{macrocode}
\AtBeginDocument{%
  \ifpdf
    \relax
  \else
    \PackageError{flippdf}{%
      package only works in pdf output mode.}%
  \fi}
%    \end{macrocode}
%
% \begin{macro}{\if@sc@flippdf}
% Define a boolean variable to remember if pages are to be flipped or
% not.
%    \begin{macrocode}
\newif\if@sc@flippdf
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\FlipPDF}\begin{macro}{\UnFlipPDF}
% Define the commands used to switch on and off the horizontal
% flipping of the document pages.
%    \begin{macrocode}
\newcommand\FlipPDF{\@sc@flippdftrue}
\newcommand\UnFlipPDF{\@sc@flippdffalse}
%    \end{macrocode}
% \end{macro}\end{macro}
%
% By default activate the flipping:
%    \begin{macrocode}
\FlipPDF
%    \end{macrocode} 
% 
% Set up the processing of options:
%    \begin{macrocode}
\DeclareOption{off}{\UnFlipPDF}
\ProcessOptions
%    \end{macrocode}
%
% And eventually, tell \hologo{LaTeX} to flip every page, by using the
% \Lpack{everypage} hook. First consider the case when running in
% \hologo{pdfLaTeX}
%    \begin{macrocode}
\ifpdftex
  \AddToHook{shipout/background}{%
    \if@sc@flippdf
      \pdfliteral direct {-1 0 0 1 \strip@pt\paperwidth\space 0 cm}%
    \fi}%
\fi
%    \end{macrocode}
% Then consider the case when running in \hologo{LuaLaTeX}
% \changes{R1.1}{2020/10/17}{Extend package to work also with
% \hologo{LuaLaTeX}.}
%    \begin{macrocode}
\ifluatex
  \AddToHook{shipout/background}{%
    \if@sc@flippdf
    \pdfextension literal direct {%
      -1 0 0 1 \strip@pt\paperwidth\space 0 cm}%
    \fi}%
\fi
%    \end{macrocode}
% \iffalse
%</flippdf>
% \fi


% \subsection{Implementation of \Lpack{flippdf-1x}}
% \iffalse
%<*flippdf-1x>
% \fi
% Announce the name and version of the package, that requires
% \hologo{LaTeX2e} (actually \hologo{pdfLaTeX} or \hologo{LuaLaTeX}).
% \changes{R1.0b}{2020/10/11}{%
%  Require \Lpack{everypage} package to be at least at its 2007/06/20 (R1.1)
%  release.}
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{flippdf-1x}%
  [2020/10/17 1.1 Horizontal flipping of pages with pdfLaTeX]
%    \end{macrocode}
%
% Assure that the dependence on \Lpack{everypage} is satisfied.
%    \begin{macrocode}
\RequirePackage{everypage}[2007/06/20]
%    \end{macrocode}
%
% Depend on \Lpack{iftex} and error out if not working in PDF mode
% \changes{R1.1}{2020/10/17}{Error out if output mode is not PDF.}%
%    \begin{macrocode}
\RequirePackage{iftex}
\AtBeginDocument{%
  \ifpdf
    \relax
  \else
    \PackageError{flippdf}{%
      package only works in pdf output mode}%
  \fi}
%    \end{macrocode}
%
% \begin{macro}{\if@sc@flippdf}
% Define a boolean variable to remember if pages are to be flipped or
% not.
%    \begin{macrocode}
\newif\if@sc@flippdf
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\FlipPDF}\begin{macro}{\UnFlipPDF}
% Define the commands used to switch on and off the horizontal
% flipping of the document pages.
%    \begin{macrocode}
\newcommand\FlipPDF{\@sc@flippdftrue}
\newcommand\UnFlipPDF{\@sc@flippdffalse}
%    \end{macrocode}
% \end{macro}\end{macro}
%
% By default activate the flipping:
%    \begin{macrocode}
\FlipPDF
%    \end{macrocode} 
% 
% Set up the processing of options:
%    \begin{macrocode}
\DeclareOption{off}{\UnFlipPDF}
\ProcessOptions
%    \end{macrocode}
%
% And eventually, tell \LaTeX\ to flip every page, by using the
% \Lpack{everypage} hook. First consider the case when running in
% \hologo{pdfLaTeX}
%    \begin{macrocode}
\ifpdftex
  \AddEverypageHook{%
    \if@sc@flippdf
      \pdfliteral direct {-1 0 0 1 \strip@pt\paperwidth\space 0 cm}%
    \fi}%
\fi
%    \end{macrocode}
% Then consider the case when running in \hologo{LuaLaTeX}
% \changes{R1.1}{2020/10/17}{Extend package to work also with
% \hologo{LuaLaTeX}.}
%    \begin{macrocode}
\ifluatex
  \AddEverypageHook{%
    \if@sc@flippdf
    \pdfextension literal direct {%
      -1 0 0 1 \strip@pt\paperwidth\space 0 cm}%
    \fi}%
\fi
%    \end{macrocode}
% \iffalse
%</flippdf-1x>
% \fi
%
% \Finale
% \PrintChanges
% \PrintIndex
%
% \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         \~}
\endinput

% %% Local Variables: 
% %% mode: doctex
% %% TeX-master: t
% %% End: