4 % Copyright (c) 2001, Radhakrishnan CV <cvr@river-valley.com>
5 % Rajagopal CV <cvr3@river-valley.com>
6 % http://www.river-valley.com
8 % River Valley Technologies, Software Technology Park,
9 % Trivandrum, India 695034
11 % Tel: +91 471 33 7501/7502
13 % Antoine Chambert-Loir
14 % <chambert@math.polytechnique.fr>
15 % http://www.math.polytechnique.fr/~chambert
17 % Ecole polytechnique, Palaiseau Cedex, France
20 % This program is free software; you can redistribute it and/or
21 % modify it under the terms of the GNU General Public License
22 % as published by the Free Software Foundation; either version 2
23 % of the License, or (at your option) any later version.
25 % This program is distributed in the hope that it will be useful,
26 % but WITHOUT ANY WARRANTY; without even the implied warranty of
27 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 % GNU General Public License for more details.
30 % You should have received a copy of the GNU General Public License
31 % along with this program (gpl.txt); if not, write to the Free
32 % Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
35 % $Id: pdftricks.sty,v 1.15 2001/09/30 11:21:23 cvr Exp $
37 \NeedsTeXFormat{LaTeX2e}
38 \def\Fileversion$#1: #2 ${\gdef\fileversion{#2}}
39 \def\Filedate$#1: #2 #3 ${\gdef\filedate{#2}}
40 \Fileversion$Revision: 1.15 $
41 \Filedate$Date: 2001/09/30 11:21:23 $
42 \ProvidesPackage{pdftricks}
43 [\filedate\space\fileversion\space psTricks support in PDF (CVRACL)]
44 \PackageWarningNoLine{pdftricks}
45 {****************************************\MessageBreak
46 Package pdftricks v,\fileversion\space loaded\MessageBreak
47 [psTricks support in PDF (CVR, ACL)]\MessageBreak
48 ****************************************}
49 \RequirePackage{graphicx,color}
50 \newif\if@debug\@debugfalse
53 \newif\ifnoprocess \noprocessfalse
54 \newif\ifmiktex \miktexfalse
55 \DeclareOption{debug}{\@debugtrue}
56 \DeclareOption{noshell}{\PDFTshellfalse}
57 \DeclareOption{shell}{\PDFTshelltrue}
58 \DeclareOption{miktex}{\global\miktextrue}
59 \ExecuteOptions{shell}
62 % we must set it to false if \write18 doesn't work.
63 % Hack given by Thierry Bouche (Thanks !)
64 \def\tmpfile{/tmp/w18-test-\the\year\the\month\the\day\the\time}
66 \immediate\write18{rem >"\tmpfile"}%%%%%% LDL-2
68 \immediate\write18{touch \tmpfile} %%%%%% LDL-1
71 \IfFileExists{\tmpfile.}{\PDFTshelltrue}{\PDFTshellfalse} %%%%%% LDL-4
73 \IfFileExists{\tmpfile}{\PDFTshelltrue}{\PDFTshellfalse} %%%%%% LDL-3
77 \PackageWarningNoLine{pdftricks}
78 {****************************************\MessageBreak
79 Using \csname write\endcsname18 capability \MessageBreak
80 for producing PDF-figures. \MessageBreak
81 ****************************************}
83 \PackageWarningNoLine{pdftricks}
84 {****************************************\MessageBreak
85 No \csname write\endcsname18 capability.\MessageBreak
86 You'll have to run a script by yourself!\MessageBreak
87 ****************************************}
90 % warning! the definition of FIGURES if pst2pdf must be set accordingly !!
91 \def\PDFTfigname{\jobname-fig\thepsfig}
92 \def\PDFTWarning#1#2{\if@debug\PackageWarning{#1}{#2}\fi}
93 \def\PDFTWarningNoLine#1#2{\if@debug\PackageWarningNoLine{#1}{#2}\fi}
94 \def\makeinnocent#1{\catcode`#1=12 }
95 \def\csarg#1#2{\expandafter#1\csname#2\endcsname}
96 \def\latexname{lplain}\def\latexename{LaTeX2e}
99 \long\def\ProcessStream#1% start it all of
101 \def\CurrentStream{#1}%
102 \let\do\makeinnocent \dospecials
103 \makeinnocent\^^L% and whatever other special cases
104 \endlinechar`\^^M \catcode`\^^M=12 \xStream}
105 {\catcode`\^^M=12 \endlinechar=-1 %
107 \expandafter\ProcessStreamLine}
108 \gdef\ProcessStreamLine#1^^M{\def\test{#1}
109 \csarg\ifx{End\CurrentStream Test}\test
110 \edef\next{\noexpand\EndOfStream{\CurrentStream}}%
111 \else \ThisStream{#1}\let\next\ProcessStreamLine
114 \long\def\streaminfo{\string\end{document}}
115 \def\CSstringmeaning#1{\expandafter\CSgobblearrow\meaning#1}
116 \def\CSstringcsnoescape#1{\expandafter\CSgobbleescape\string#1}
118 \expandafter\expandafter\expandafter\gdef
119 \expandafter\expandafter\expandafter\CSgobblearrow
120 \expandafter\string\csname macro:->\endcsname{}
122 \def\CSgobbleescape#1{\ifnum`\\=`#1 \else #1\fi}
123 \def\WriteStreamLine#1{\def\CStmp{#1}%
124 \immediate\write\PDFStream{\CSstringmeaning\CStmp}}
126 \def\AfterIncludedStream
127 {\immediate\closeout\PDFStream %changed on 2001/1/20
130 \def\BeforeIncludedStream
131 {\stepcounter{psfig}\xdef\PDFCutFile{\PDFTfigname.tex}%
132 \message{Opening PDFStream=\PDFCutFile}%
133 \immediate\openout\PDFStream=\PDFCutFile
134 \immediate\write\PDFStream{\string\documentclass{article}}
135 \immediate\write\PDFStream{\string\input\space tmp.inputs}
136 \immediate\write\PDFStream{\string\pagestyle{empty}}
137 \immediate\write\PDFStream{\string\usepackage{amssymb,amsbsy}}
138 \immediate\write\PDFStream{\string\begin{document}}
139 \let\ThisStream\WriteStreamLine}
140 \long\def\specialstream #1#2#3{%
141 \message{Special stream '#1'}%
142 \csarg\def{After#1Stream}{#2\AfterIncludedStream#3}%
143 \csarg\def{#1}{\BeforeIncludedStream\relax
146 \def\EndOfStream#1{\endgroup\end{#1}%
147 \csname After#1Stream\endcsname}
148 \def\PDFEndDef#1{{\escapechar=-1\relax
149 \csarg\xdef{End#1Test}{\string\\end\string\{#1\string\}}%
152 %% The real meat of psfile manipulation starts here.
155 \AtEndDocument{\endPShook%
157 \PackageWarningNoLine{pdftricks}
158 {******************************************\MessageBreak
159 Some PDF files of images were not found.\MessageBreak
160 Run the script `pst2pdf' before the next\MessageBreak
161 run of pdfLaTeX\MessageBreak
162 ******************************************}
166 \def\noprocess{\global\noprocesstrue
167 \PackageWarning{pdftricks}
168 {******************************************\MessageBreak
169 Figure Number: \PDFTfigname\space is not processed \MessageBreak
170 ******************************************\MessageBreak}
172 \specialstream{pdfpic}{%
173 \immediate\write\PDFStream{\streaminfo}}
174 {\psgraphicsinclude\global\noprocessfalse}
176 \newif\if@pdfGINwidth
177 \newif\if@pdfGINheight
178 \newif\if@pdfGINscale
179 \long\gdef\psgraphicsinclude{%
180 \@ifundefined{Fig\thepsfig}
181 {\PDFTWarningNoLine{pdftricks}
182 {******************************************\MessageBreak
183 ************ Processing Fig: \thepsfig\space**********\MessageBreak
184 ******************************************}
187 \ifPDFTshell\ifnoprocess\relax\else
188 \IfFileExists{\PDFTfigname.tex}{%
189 \immediate\write18{latex -interaction=batchmode \PDFTfigname}
190 \PDFTWarningNoLine{pdftricks}
191 {******************************************\MessageBreak
192 \PDFTfigname.tex converted to \PDFTfigname.dvi\MessageBreak
193 ******************************************}
195 \IfFileExists{\PDFTfigname.dvi}{%
196 \immediate\write18{dvips -o \PDFTfigname.ps \PDFTfigname}
197 \immediate\write18{ps2eps -f \PDFTfigname.ps}
198 \PDFTWarningNoLine{pdftricks}
199 {******************************************\MessageBreak
200 \PDFTfigname.eps generated\MessageBreak
201 ******************************************}
203 \IfFileExists{\PDFTfigname.eps}{%
204 \immediate\write18{epstopdf \PDFTfigname.eps}
205 \PDFTWarningNoLine{pdftricks}
206 {******************************************\MessageBreak
207 \PDFTfigname.eps converted to \PDFTfigname.pdf\MessageBreak
208 ******************************************}
211 \immediate\write18{del \PDFTfigname.aux \PDFTfigname.dvi \PDFTfigname.log \PDFTfigname.eps} %%%%%% LDL-6
213 \immediate\write18{rm \PDFTfigname.aux \PDFTfigname.dvi \PDFTfigname.log \PDFTfigname.eps} %%%%%% LDL-5
216 \IfFileExists{\PDFTfigname.pdf}%
218 \bgroup\fboxsep\@PDFboxsep\fboxrule\@PDFboxrule%
219 \color{\@PDFgraphiccolor}%
220 \fcolorbox{\@PDFgraphiclinecolor}{\@PDFgraphicbackground}%
222 \includegraphics[width=\@PDFgraphicwidth]{\PDFTfigname}\else%
224 \includegraphics[height=\@PDFgraphicheight]{\PDFTfigname}\else%
226 \includegraphics[scale=\@PDFgraphicscale]{\PDFTfigname}\else%
227 \includegraphics{\PDFTfigname}\fi\fi\fi%
228 }\egroup\end{center}%
229 \global\@pdfGINwidthfalse\let\@PDFgraphicwidth\relax
230 \global\@pdfGINheightfalse\let\@PDFgraphicheight\relax
231 \global\@pdfGINscalefalse\let\@PDFgraphicscale\relax
233 \gdef\@PDFgraphiclinecolor{white}
234 \gdef\@PDFgraphicbackground{white}
235 \gdef\@PDFboxsep{0pt}
236 \gdef\@PDFboxrule{0pt}
238 \definecolor{gray30}{gray}{.70}
239 \definecolor{gray10}{gray}{.90}
240 \RequirePackage{keyval}
241 \def\configure[#1][#2]{\setkeys{#1}{#2}
242 \PDFTWarning{pdftricks}{Reconfigured #1 parameter(s)\MessageBreak #2\MessageBreak}
244 \define@key{pdfgraphic}{width} {\gdef\@PDFgraphicwidth{#1}\global\@pdfGINwidthtrue}
245 \define@key{pdfgraphic}{height} {\gdef\@PDFgraphicheight{#1}\global\@pdfGINheighttrue}
246 \define@key{pdfgraphic}{scale} {\gdef\@PDFgraphicscale{#1}\global\@pdfGINscaletrue}
247 \define@key{pdfgraphic}{color} {\gdef\@PDFgraphiccolor{#1}}
248 \define@key{pdfgraphic}{linecolor} {\gdef\@PDFgraphiclinecolor{#1}}
249 \define@key{pdfgraphic}{background}{\gdef\@PDFgraphicbackground{#1}}
250 \define@key{pdfgraphic}{linewidth} {\gdef\@PDFboxrule{#1}}
251 \define@key{pdfgraphic}{rulesep} {\gdef\@PDFboxsep{#1}}
252 \gdef\@PDFgraphiccolor{black}
253 \gdef\@PDFgraphiclinecolor{white}
254 \gdef\@PDFgraphicbackground{white}
255 \gdef\@PDFboxrule{0pt}
256 \gdef\@PDFboxsep{0pt}
258 %% Tweak to grab all the packages used in the master doc.
259 %% This forces you to load pdftricks as the first package.
261 \newenvironment{psinputs}{\begingroup
263 \immediate\openout\CVinputs=tmp.inputs
264 \def\usepackage{\@ifnextchar[\@CVUsepackage\@@CVUsepackage}
265 \def\@CVUsepackage[##1]##2{\immediate\write\CVinputs%
266 {\string\usepackage[##1]{##2}}}
267 \def\@@CVUsepackage##1{\immediate\write\CVinputs%
268 {\string\usepackage{##1}}}
270 {\endgroup\immediate\closeout\CVinputs}
272 %% Arrays to keep the fig numbers
274 \newcounter{arraylength}%
275 \newcounter{ArrayIndex}%
276 \newcounter{zeroCtr}%
277 \newcounter{recordCtr}
278 \setcounter{recordCtr}{1}
280 \def\DeclareArray#1{\Array{#1}[0]{}}%
283 \expandafter\gdef\csname #1#2\endcsname{#3}%
284 \expandafter\gdef\csname #1\endcsname[##1]{\csname #1##1\endcsname}}%
286 \def\getArraylength#1{\setcounter{arraylength}{0}%
287 \loop\expandafter\ifx\csname #1\thearraylength\endcsname\relax%
288 \else\stepcounter{arraylength}\repeat}%
290 \def\addToArray#1#2{\setcounter{arraylength}{0}%
291 \loop\expandafter\ifx\csname #1\thearraylength\endcsname\relax%
292 \else\stepcounter{arraylength}\repeat%
293 \Array{#1}[\thearraylength]{#2}}%
295 \def\clearArray#1{\getArraylength{#1}%
296 \loop\ifnum\c@arraylength >0%
297 \global\expandafter\let\csname #1\thearraylength\endcsname\relax%
298 \addtocounter{arraylength}{-1}\repeat}%
300 \long\def\ArrayIterator#1#2{%
301 \setcounter{ArrayIndex}{1}\getArraylength{#1}%
302 \setcounter{zeroCtr}{\c@arraylength}%
303 \loop\ifnum\c@ArrayIndex<\c@zeroCtr{#2}%
304 \stepcounter{ArrayIndex}\repeat%
308 \def\@cvrstop#1\@@#2{}
310 %% Equivalent of \@tfor and \@for where any delimiter can be
311 %% provided instead of LaTeX's default comma character
313 \long\def\cvr@delimfor#1#2#3{\DeclareArray{#1}\clearArray{#1}%
314 \long\def\@icvrloop##1#2##2\@@##3{\def##3{##1}\ifx ##3\@nnil%
315 \expandafter\@cvrstop \else\addToArray{#1}{##1}%
316 \relax\expandafter\@icvrloop\fi##2\@@##3}%
317 \long\def\@cvrloop##1#2##2#2##3\@@##4{\addToArray{#1}{##1}%
318 \def##4{##1}\ifx ##4\@nnil \else%
319 \def##4{##2}\def\y@y{##2}\ifx\y@y\@nnil\else%
320 \addToArray{#1}{##2}\fi\ifx ##4\@nnil \else%
321 \@icvrloop ##3\@@##4\fi\fi}%
322 \expandafter\def\expandafter\@fortmp\expandafter{#3}%
323 \ifx\@fortmp\@empty \else%
324 \expandafter\@cvrloop#3#2\@nil#2\@nil\@@\@ee@\fi}%
326 % Dont look into the following code. It is harmful
327 % for your eyes and brain as well.
329 \newcounter{f@irstCtr}
330 \newcounter{s@econdCtr}
331 \long\gdef\NoProcess[#1]{%
332 \long\def\@i@@noprocess##1,##2\@@##3{\def##3{##1}\ifx ##3\@nnil%
333 \expandafter\@cvrstop \else
334 \expandafter\hyphencheck##1-@-*[*]
335 \relax\expandafter\@i@@noprocess\fi##2\@@##3}%
336 \long\def\@@@noprocess##1,##2,##3\@@##4{
337 \expandafter\hyphencheck##1-@-*[*]
338 \def##4{##1}\ifx ##4\@nnil \else%
339 \def##4{##2}\def\y@y{##2}\ifx\y@y\@nnil\else%
340 \expandafter\hyphencheck##2-@-*[*]
341 \fi\ifx ##4\@nnil \else%
342 \@i@@noprocess ##3\@@##4\fi\fi}%
343 \expandafter\def\expandafter\@fortmp\expandafter{#1}%
344 \ifx\@fortmp\@empty \else%
345 \expandafter\@@@noprocess#1,\@nil,\@nil\@@\@ee@\fi}%
347 \def\hyphencheck#1-#2-#3{\def\r@r{@}\def\s@s{*}\edef\c@c{#3}
349 \setcounter{f@irstCtr}{#1}
350 \setcounter{s@econdCtr}{#2}
351 \stepcounter{s@econdCtr}
352 \loop\ifnum\thes@econdCtr > \thef@irstCtr%
353 \expandafter\edef\csname Fig\thef@irstCtr\endcsname{TRUE}
354 \stepcounter{f@irstCtr}
357 \expandafter\edef\csname Fig#1\endcsname{TRUE}
362 %% End of file `pdftricks.sty'