summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/flipbook/flipbook.sty
blob: 67ce84d6b5491b863dae3bc72342b581fca94228 (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
%  flipbook.sty --- style file for flip books
%% Copyright 2011 Olivier Buffet
%
% This material is subject to the LaTeX Project Public License. See http://www.ctan.org/tex-archive/help/Catalogue/licenses.lppl.html for the details of that license.
%
% This program consists of the files flipbook.sty and documentation.tex (and some less important files).
%  
%  Report bugs and comments to:
%  buffet-AT-AT-loria-DOT-DOT-fr
%
%  $Id: flipbook.sty,v 0.1 2011/12/05 16:26:53 buffet Exp $
%
%  PACKAGES REQUIRED:
%
%  - fancyhdr
%  - graphicx
%  - scalefnt
%  - verbatim
%  - everypage
%  - ifthen

\NeedsTeXFormat{LaTeX2e}[1994/12/01]
\ProvidesPackage{flipbook}[2011/12/05 Standard LaTeX class]

% The type of headings that allows for customization:
\RequirePackage{fancyhdr}
\RequirePackage{graphicx}
\RequirePackage{scalefnt}
\RequirePackage{verbatim}
\RequirePackage{everypage}
\RequirePackage{ifthen}
\pagestyle{fancyplain}

\newcommand{\fbDebug}[1]{}
\DeclareOption{debug}{%
  \renewcommand{\fbDebug}[1]{{\tiny #1} \@latex@warning{#1}}
}
\ProcessOptions

\newcounter{fbpage}
\setcounter{fbpage}{0}
\AddEverypageHook{
  \addtocounter{fbpage}{1}
}

% How to get the total number of pages. Inspired from the files
% lastpage.sty and beamerbasemisc.sty .

\newcounter{numpages}

\AtEndDocument{%
   \clearpage \setcounter{numpages}{\thefbpage}
   \if@filesw
   \immediate\write\@auxout{\noexpand\setcounter{numpages}{\the\c@page}}
   \fi
}%

% The important command (but which can probably be improved):
% 3 parameters:
% - prefix of your images
% - suffix (extension) of your images
% - displaying options of your images
\makeatletter
\newcommand\fbImageF[3]{ % flip-book \includegraphics{...} forward
  \@tempcnta 0
  \advance\@tempcnta+\thefbpage
  \if@twoside
  \divide\@tempcnta2
  \fi
  \IfFileExists{#1\number\@tempcnta .#2}
               {
                 \includegraphics[#3]{#1\number\@tempcnta .#2}
               }{
                 \fbDebug{``#1\number\@tempcnta .#2'' NOT FOUND}
               }
}
\newcommand\fbImageB[3]{ % flip-book \includegraphics{...} backward
  \@tempcnta\value{numpages}
  \advance\@tempcnta-\thefbpage
  \if@twoside
  \divide\@tempcnta2
  \fi
  \IfFileExists{#1\number\@tempcnta .#2}
               {
                 \includegraphics[#3]{#1\number\@tempcnta .#2}
               }{
                 \fbDebug{``#1\number\@tempcnta .#2'' NOT FOUND}
               }
}
\makeatother

\makeatletter
\newcommand\fbInputF[3]{ % flip-book \input{...} forward
  \@tempcnta 0
  \advance\@tempcnta+\thefbpage
  \if@twoside
  \divide\@tempcnta2
  \fi
  \IfFileExists{#1\number\@tempcnta .#2}
               {
                 \scalefont{#3}
                 \input{#1\number\@tempcnta .#2}
               }{
                 \fbDebug{``#1\number\@tempcnta .#2'' NOT FOUND}
               }
}
\newcommand\fbInputB[3]{ % flip-book \input{...} backward
  \@tempcnta\value{numpages}
  \advance\@tempcnta-\thefbpage
  \if@twoside
  \divide\@tempcnta2
  \fi
  \IfFileExists{#1\number\@tempcnta .#2}
               {
                 \scalefont{#3}
                 \input{#1\number\@tempcnta .#2}
               }{
                 \fbDebug{``#1\number\@tempcnta .#2'' NOT FOUND}
               }
}
\makeatother

\makeatletter
\newcommand\fbVerbF[3]{ % flip-book \verbatiminput{...} forward
  \@tempcnta 0
  \advance\@tempcnta+\thefbpage
  \if@twoside
  \divide\@tempcnta2
  \fi
  \IfFileExists{#1\number\@tempcnta .#2}
               {
                 \scalefont{#3}
                 \verbatiminput{#1\number\@tempcnta .#2}
               }{
                 \fbDebug{``#1\number\@tempcnta .#2'' NOT FOUND}
               }
}
\newcommand\fbVerbB[3]{ % flip-book \verbatiminput{...} backward
  \@tempcnta\value{numpages}
  \advance\@tempcnta-\thefbpage
  \if@twoside
  \divide\@tempcnta2
  \fi
  \IfFileExists{#1\number\@tempcnta .#2}
               {
                 \scalefont{#3}
                 \verbatiminput{#1\number\@tempcnta .#2}
               }{
                 \fbDebug{``#1\number\@tempcnta .#2'' NOT FOUND}
               }
}
\makeatother

% Fancyhdr moves the center of pages.
% To compensate this I have found the following piece of code.
% But there must be a better solution.
\makeatletter
\@tempdima=\paperwidth
\advance\@tempdima by -\textwidth
\divide\@tempdima by 2
\advance\@tempdima by -1in
\oddsidemargin=\@tempdima
\let\evensidemargin=\oddsidemargin
\makeatother