summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/epspdfconversion/epspdfconversion.sty
blob: ed6816a6f0b39e1170d8200f947ca82a0f457dcd (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
%%
%% This is file `epspdfconversion.sty',
%%
%%
%% It is based on epstopdf.sty by Heiko Oberdiek and is a tool to use Siep
%% Kroonenberg's Epspdf-tools  (http://tex.aanhet.net/epspdf/)
%% "on the fly" in LaTeX
%%
%% Please send suggestions to d.becker@jpberlin.de
%%
%%
%% version history:
%% 0.61 * new options pdftopdf and pstopdf. Uses epspdf to do pdf-to-pdf and ps-to-pdf conversions. Allows grayscaling, calculation of 
%%        bounding boxes etc for pdf's that already exist an for .ps-files. Disabled by default.
%%      * bugfix for the outdir-option (converted files in subdirectories are again saved in those subdirectories)
%%        (Thanks to Stefan Pofahl for the feedback.)
%%      * small improvement of the documentation (on the windows epspdf.bat file, on epstopdf's option 'outdir')
%%      * now uses epstopdf's \epstopdfDeclareGraphicsRule
%% 0.6  * pdfversion now uses epspdf's --pdfversion. --version in epspdf is to print the 
%%        version number of epspdf (currently, epspdf is at 0.5)
%%      * new author email
%% 0.5  this update makes use of changes in the epstopdf-package v2.2
%%      * new options 
%%        update,verbose,prefersuffix,suffix,outdir
%%        (they are really epstopdf options, but can be set 
%%        as options for this package)
%%      * default is that converted files have a suffix
%%      * info in logfile about the setup that is used for epstopdf
%%      * new options hires, no-hires
%% 0.4: the epstopdf-package is now loaded with options [update,prepend] 
%%      (works only when epstopdf version 1.5 is used) An update of epstopd.sty
%%      (part of the oberdiek-bundle) is recommended. Added options nogrey,nogray
%% 0.3: Heiko Oberdiek substantially improved the code. 
%%      The kvoptions-package is now used for the implemention of options. 
%%      See the documentation for effects and additional features. 
%% 0.2: the package is now simply based on epstopdf. This package essentially
%%      defines \@namedef{Gin@rule@.eps}#1{{pdf}{.pdf}{`\conversioncommand #1}}
%%      differently than epstopdf. The code has been cleaned up. Improvements of
%%      documentation and additional warning about pdfminorversion....
%% 0.1: first try
%%




\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{epspdfconversion}%
  [2010/06/01 v0.61 Conversion eps->pdf with epspdf-tools on the fly]


%% this loads the graphics, epstopdf and the kvoptions packages. 
\RequirePackage{graphics}
\RequirePackage{epstopdf-base}[2009/07/16]% version 2.2 is necessary
\RequirePackage{kvoptions}[2006/08/22]% because of \DeclareBoolOption


\SetupKeyvalOptions{
  family=EPC,
  prefix=EPC@
}


%% this is the basic command necessary for the conversion with epspdf 
\DeclareStringOption[epspdf]{cmd}

% Gray
% \EPC@gray stores the whole option
\DeclareVoidOption{gray}{%this is for the \usepackage[gray]{...
  \def\EPC@optgray{--gray }%this is the effect in the command line
}
\DeclareVoidOption{GRAY}{%
  \def\EPC@optgray{--GRAY }%
}
\DeclareVoidOption{grey}{%
  \def\EPC@optgray{--grey }%
}
\DeclareVoidOption{GREY}{%
  \def\EPC@optgray{--GREY }%
}
\DeclareVoidOption{nogrey}{%
  \def\EPC@optgray{ }%
}
\DeclareVoidOption{nogray}{%
  \def\EPC@optgray{ }%
}



% Target
% \EPC@target stores the target only
% target         ==> --target=default
% target=printer ==> --target=printer
% screen         ==> --target=screen
\DeclareStringOption{target}[default]
\DeclareVoidOption{default}{%
  \def\EPC@target{default}%
}
\DeclareVoidOption{printer}{%
  \def\EPC@target{printer}%
}
\DeclareVoidOption{prepress}{%
  \def\EPC@target{prepress}%
}
\DeclareVoidOption{screen}{%
  \def\EPC@target{screen}%
}
\DeclareVoidOption{ebook}{%
  \def\EPC@target{ebook}%
}



         
% Version
% \EPC@pdfversion stores the version only
% pdfversion=1.2 ==> --pdfversion=1.2
% the warning with pdfminorversion does not work?

\define@key{EPC}{pdfversion}[default]{%
  \@ifundefined{EPC@pdfversion@#1}{% 
    \PackageError{epspdfconversion}{%
      Ignoring unknown value for `pdfversion'. Known values are: 1.2,1.3, 1.4, default%
    }\@ehc
  }{%
    \def\EPC@pdfversion{#1}%
    \begingroup
      \let\MinorVersion\relax
      \@ifundefined{pdfminorversion}{%
        \@ifundefined{pdfoptionpdfminorversion}{}{%
          \def\MinorVersion{\pdfoptionpdfminorversion}%
        }%
      }{%
        \def\MinorVersion{\pdfminorversion}%
      }%
      \ifx\MinorVersion\relax
      \else
        \ifnum\@nameuse{EPC@pdfversion@#1}>\MinorVersion
          \PackageWarning{epspdfconversion}{%
            You have chosen pdfversion=#1,\MessageBreak  
            but you generate PDF-1.\number\MinorVersion.%
            \MessageBreak
            This can be changed by\MessageBreak
            \expandafter\string\MinorVersion=%
            \@nameuse{EPC@pdfversion@#1}%
            \MessageBreak
            (at the very beginning of your .tex file).\MessageBreak Or try `pdfversion=1.\number\MinorVersion'%
          }%
        \fi
      \fi
    \endgroup
  }%
}

\@namedef{EPC@pdfversion@1.2}{2}
\@namedef{EPC@pdfversion@1.3}{3}
\@namedef{EPC@pdfversion@1.4}{4}
\@namedef{EPC@pdfversion@default}{0}% disable version check

% bbox       ==> --bbox
% bbox=true  ==> --bbox
% bbox=false ==> option disabled
\DeclareBoolOption{bbox}

%support for pdftopdf-conversion
\DeclareBoolOption{pdftopdf}

%support for pstopdf-conversion
\DeclareBoolOption{pstopdf}

\DeclareVoidOption{pdftops}{%
  \def\EPC@optpdftops{-U }%
}
\DeclareVoidOption{nopdftops}{%
  \def\EPC@optpdftops{-I }%
}

\DeclareVoidOption{hires}{%
  \def\EPC@opthires{--hires }%
}
\DeclareVoidOption{no-hires}{%
  \def\EPC@opthires{--no-hires }%
}

\DeclareStringOption{custom}
\DeclareStringOption{psoptions}
\DeclareStringOption{pagenumber}

\DeclareVoidOption{simple}{%
  % disable other options
  \let\EPC@optgray\@empty
  \let\EPC@optpdftops\@empty
  \let\EPC@opthires\@empty
  \let\EPC@target\@empty
  \let\EPC@pdfversion\@empty
  \let\EPC@custom\@empty
  \let\EPC@psoptions\@empty
  \let\EPC@pagenumber\@empty
  \EPC@bboxfalse
}

% default setting: all options cleared
\EPC@simple

% Options help works immediately, if shell escape feature is enabled.
\DeclareVoidOption{help}{%
  \immediate\write18{\EPC@cmd\space--help}%
}

\def\EPC@addopt#1{%
  \expandafter\ifx\csname EPC@#1\endcsname\@empty
  \else
    --#1=\@nameuse{EPC@#1} %
  \fi
}

%% this is the setup of the command line....
\newcommand*{\epspdfconversioncmdline}[1]{%
  \EPC@cmd\space
  \EPC@optpdftops
  \EPC@opthires
  \EPC@addopt{target}%
  \ifx\EPC@pdfversion\@empty
  \else
    --pdfversion=\EPC@pdfversion\space
  \fi
  \EPC@addopt{custom}%
  \EPC@addopt{psoptions}%
  \EPC@addopt{pagenumber}%
  \ifEPC@bbox
    --bbox %
  \else
  \fi
  \EPC@optgray
  #1%
}

%% message in the log-file:
\def\EPC@printlog{\PackageInfo{epspdfconversion}{\MessageBreak%
\epspdfconversioncmdline{<file>} is used to convert eps->pdf \MessageBreak(not epstopdf (script))\MessageBreak
  }%
}


%% this allows to change the options on the fly
% Use example: \epspdfconversionsetup{target=prepress,bbox}
\newcommand*{\epspdfconversionsetup}[1]{%
  \setkeys{EPC}{#1}%
  \EPC@printlog
}
%%%%%  epstopdf-options .....

% update, default is true, can be set as update=false
\DeclareBoolOption[true]{update}
% verbose, default is true, can be set as verbose=false
\DeclareBoolOption[true]{verbose}
% if there is original.pdf and original-suffix.pdf, prefer original-suffix.pdf
% (the one that has been generated by epspdf), can be set as prefersuffix=false
\DeclareBoolOption[true]{prefersuffix}
% suffix. Avoids accidental overwriting of files. 
% usage: suffix={bla}
\DeclareStringOption[-epspdf-to]{suffix}
%  specifies an outdir, default is current directory ...
\DeclareStringOption{outdir}

\DeclareBoolOption[false]{prepend}




% Important: !!!
\ProcessKeyvalOptions*

\typeout{%
^^Jepspdfconversion.sty is using epstopdf.sty with the following setup:}

% use them to set epstopdf up
% update
\ifEPC@update
\epstopdfsetup{update=true}%
\typeout{\space\space\space\space update=true,}%
\else
\epstopdfsetup{update=false}%
\typeout{\space\space\space\space update=false,}%
\fi
% verbose
\ifEPC@verbose
\epstopdfsetup{verbose=true}%
\typeout{\space\space\space\space verbose=true,}%
\else
\epstopdfsetup{verbose=false}%
\typeout{\space\space\space\space verbose=false,}%
\fi
% prefersuffix
\ifEPC@prefersuffix
\epstopdfsetup{prefersuffix=true}%
\typeout{\space\space\space\space prefersuffix=true,}%
\else
\epstopdfsetup{prefersuffix=false}%
\typeout{\space\space\space\space prefersuffix=false,}%
\fi
% suffix
\epstopdfsetup{suffix=\EPC@suffix}%
\typeout{\space\space\space\space suffix=\EPC@suffix,}%

% outdir
\let\CheckOutdir\EPC@outdir
    \ifx\CheckOutdir\@empty
      \typeout{\space\space\space\space option outdir not set. Default: same directory as the .eps-source-file}%
    \else
     \epstopdfsetup{outdir={\EPC@outdir}}%
     \typeout{\space\space\space\space outdir=\EPC@outdir}%
    \fi

% prepend
\ifEPC@prepend
\epstopdfsetup{prepend}%
\typeout{\space\space\space\space prepend,}%
\else
\epstopdfsetup{append}%
\typeout{\space\space\space\space append,}%
\fi
% enable
\epstopdfsetup{enable}%
\typeout{\space\space\space\space enable}%


% another message...
\typeout{epspdf is used with the following command:}
\typeout{\space\space\space\space \epspdfconversioncmdline{<file>} }




\EPC@printlog


%%% the main functionality of this package: 
%%% this changes the definition provided by epstopdf:

% previously, I used:
%\@namedef{Gin@rule@.eps}#1{{pdf}{.pdf}{`\epspdfconversioncmdline{#1} \OutputFile}}

% since version 0.61: use the mechanism provided by epstopdf to define the eps-pdf conversion rule:

\epstopdfDeclareGraphicsRule{.eps}{pdf}{.pdf}{% 
\epspdfconversioncmdline #1 \OutputFile
}

% pdftopdf
\ifEPC@pdftopdf
\epstopdfDeclareGraphicsRule{.pdf}{pdf}{.pdf}{% 
\epspdfconversioncmdline #1 \OutputFile
}
\typeout{support for pdf-to-pdf is ENABLED}%
\typeout{}
\else
\typeout{support for pdf-to-pdf is DISABLED}%
\typeout{}
\fi

% pstopdf
\ifEPC@pstopdf
\epstopdfDeclareGraphicsRule{.ps}{pdf}{.pdf}{% 
\epspdfconversioncmdline #1 \OutputFile
}
\typeout{support for ps-to-pdf is ENABLED}%
\typeout{}
\else
\typeout{support for ps-to-pdf is DISABLED}%
\typeout{}
\fi



\endinput