]> git.donarmstrong.com Git - lib.git/blob - texmf/tex/latex/pdftricks.sty
add pdftricks
[lib.git] / texmf / tex / latex / pdftricks.sty
1 %
2 % pdftricks.sty 
3 %
4 % Copyright (c) 2001, Radhakrishnan CV <cvr@river-valley.com>
5 %                     Rajagopal CV <cvr3@river-valley.com>
6 %                     http://www.river-valley.com
7 %
8 % River Valley Technologies, Software Technology Park,
9 % Trivandrum, India 695034
10 %
11 % Tel: +91 471 33 7501/7502
12 %
13 %                     Antoine Chambert-Loir 
14 %                     <chambert@math.polytechnique.fr>
15 %                     http://www.math.polytechnique.fr/~chambert
16 %
17 % Ecole polytechnique, Palaiseau Cedex, France
18
19 %
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.
24 %
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.
29
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,
33 % MA  02111-1307, USA.
34 %
35 % $Id: pdftricks.sty,v 1.15 2001/09/30 11:21:23 cvr Exp $
36 %
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
51 \DeclareOption{debug}{\@debugtrue}
52 \DeclareOption{noshell}{\PDFTshellfalse}
53 \DeclareOption{shell}{\PDFTshelltrue}
54 \newif\ifPDFTshell
55 \newif\ifPDFTnopdf
56 \newif\ifnoprocess \noprocessfalse
57 \ExecuteOptions{shell}
58 \ProcessOptions\relax
59 \ifPDFTshell
60 % we must set it to false if \write18 doesn't work.
61 % Hack given by Thierry Bouche (Thanks !)
62 \def\tmpfile{/tmp/w18-test-\the\year\the\month\the\day\the\time} 
63 \immediate\write18{touch \tmpfile}
64 \IfFileExists{\tmpfile}{\PDFTshelltrue}{\PDFTshellfalse}
65 \fi
66 \ifPDFTshell
67   \PackageWarningNoLine{pdftricks}
68    {****************************************\MessageBreak
69     Using \csname write\endcsname18 capability \MessageBreak
70     for producing PDF-figures.  \MessageBreak
71     ****************************************}
72 \else
73   \PackageWarningNoLine{pdftricks}
74    {****************************************\MessageBreak
75     No \csname write\endcsname18 capability.\MessageBreak
76     You'll have to run a script by yourself!\MessageBreak
77     ****************************************}
78 \fi
79
80 % warning! the definition of FIGURES if psrun must be set accordingly !!
81 \def\PDFTfigname{\jobname-fig\thepsfig}
82 \def\PDFTWarning#1#2{\if@debug\PackageWarning{#1}{#2}\fi}
83 \def\PDFTWarningNoLine#1#2{\if@debug\PackageWarningNoLine{#1}{#2}\fi}
84 \def\makeinnocent#1{\catcode`#1=12 }
85 \def\csarg#1#2{\expandafter#1\csname#2\endcsname}
86 \def\latexname{lplain}\def\latexename{LaTeX2e}
87 \newwrite\PDFStream
88
89 \long\def\ProcessStream#1% start it all of
90    {\begingroup%
91     \def\CurrentStream{#1}%
92     \let\do\makeinnocent \dospecials 
93     \makeinnocent\^^L% and whatever other special cases
94     \endlinechar`\^^M \catcode`\^^M=12 \xStream}
95 {\catcode`\^^M=12 \endlinechar=-1 %
96  \gdef\xStream#1^^M{%
97     \expandafter\ProcessStreamLine}
98  \gdef\ProcessStreamLine#1^^M{\def\test{#1}
99       \csarg\ifx{End\CurrentStream Test}\test
100           \edef\next{\noexpand\EndOfStream{\CurrentStream}}%
101       \else \ThisStream{#1}\let\next\ProcessStreamLine
102       \fi \next}
103 }
104 \long\def\streaminfo{\string\end{document}}
105 \def\CSstringmeaning#1{\expandafter\CSgobblearrow\meaning#1}
106 \def\CSstringcsnoescape#1{\expandafter\CSgobbleescape\string#1}
107 {\escapechar-1
108 \expandafter\expandafter\expandafter\gdef
109   \expandafter\expandafter\expandafter\CSgobblearrow
110     \expandafter\string\csname macro:->\endcsname{}
111 }
112 \def\CSgobbleescape#1{\ifnum`\\=`#1 \else #1\fi}
113 \def\WriteStreamLine#1{\def\CStmp{#1}%
114     \immediate\write\PDFStream{\CSstringmeaning\CStmp}}
115
116 \def\AfterIncludedStream
117    {\immediate\closeout\PDFStream  %changed on 2001/1/20
118     \relax
119     }%
120 \def\BeforeIncludedStream
121    {\stepcounter{psfig}\xdef\PDFCutFile{\PDFTfigname.tex}%
122     \message{Opening PDFStream=\PDFCutFile}%
123     \immediate\openout\PDFStream=\PDFCutFile
124     \immediate\write\PDFStream{\string\documentclass{article}}
125     \immediate\write\PDFStream{\string\input\space tmp.inputs}
126     \immediate\write\PDFStream{\string\pagestyle{empty}}
127     \immediate\write\PDFStream{\string\usepackage{amssymb,amsbsy}}
128     \immediate\write\PDFStream{\string\begin{document}}
129     \let\ThisStream\WriteStreamLine}
130 \long\def\specialstream #1#2#3{%
131      \message{Special stream '#1'}%
132     \csarg\def{After#1Stream}{#2\AfterIncludedStream#3}%
133     \csarg\def{#1}{\BeforeIncludedStream\relax
134           \ProcessStream{#1}}%
135     \PDFEndDef{#1}}
136 \def\EndOfStream#1{\endgroup\end{#1}%
137     \csname After#1Stream\endcsname}
138 \def\PDFEndDef#1{{\escapechar=-1\relax
139     \csarg\xdef{End#1Test}{\string\\end\string\{#1\string\}}%
140     }}
141 %%
142 %% The real meat of psfile manipulation starts here.
143 %%
144 %%
145 \AtEndDocument{\endPShook%
146                 \ifPDFTnopdf
147         \PackageWarningNoLine{pdftricks}
148         {******************************************\MessageBreak
149          Some PDF files of images were not found.\MessageBreak
150          Run the script `pst2pdf' before the next\MessageBreak
151          run of pdfLaTeX\MessageBreak
152          ******************************************}
153                  \fi
154 }
155 \gdef\endPShook{}
156 \def\noprocess{\global\noprocesstrue
157   \PackageWarning{pdftricks}
158         {******************************************\MessageBreak
159                      Figure Number: \PDFTfigname\space is not processed \MessageBreak
160          ******************************************\MessageBreak}
161 }
162 \specialstream{pdfpic}{%
163          \immediate\write\PDFStream{\streaminfo}}
164         {\psgraphicsinclude\global\noprocessfalse}
165 \newcounter{psfig}
166 \newif\if@pdfGINwidth
167 \newif\if@pdfGINheight
168 \newif\if@pdfGINscale
169 \long\gdef\psgraphicsinclude{%
170   \@ifundefined{Fig\thepsfig}
171   {\PDFTWarningNoLine{pdftricks}{************ PROCESSING FIG: \thepsfig\space **********}}
172   {\noprocess}
173    \ifPDFTshell\ifnoprocess\relax\else
174     \IfFileExists{\PDFTfigname.tex}{%
175      \immediate\write18{latex -interaction=batchmode \PDFTfigname}
176      \PDFTWarning{pdftricks3}{\PDFTfigname.tex converted to \PDFTfigname.dvi}}{}
177     \IfFileExists{\PDFTfigname.dvi}{%
178      \immediate\write18{dvips -E -o \PDFTfigname.eps \PDFTfigname}
179      \PDFTWarning{pdftricks}{EPS generated -- \PDFTfigname.eps}}{}
180     \IfFileExists{\PDFTfigname.eps}{%
181       \immediate\write18{epstopdf \PDFTfigname.eps}
182       \PDFTWarning{pdftricks3}{\PDFTfigname.eps converted to \PDFTfigname.pdf}}{}
183     \immediate\write18{rm \PDFTfigname.aux \PDFTfigname.dvi \PDFTfigname.log \PDFTfigname.eps}
184    \fi\fi
185 %  \fi
186   \IfFileExists{\PDFTfigname.pdf}%
187      {\begin{center}
188      \bgroup\fboxsep\@PDFboxsep\fboxrule\@PDFboxrule%
189       \color{\@PDFgraphiccolor}%
190       \fcolorbox{\@PDFgraphiclinecolor}{\@PDFgraphicbackground}%
191      {\if@pdfGINwidth%
192        \includegraphics[width=\@PDFgraphicwidth]{\PDFTfigname}\else%
193       \if@pdfGINheight%
194        \includegraphics[height=\@PDFgraphicheight]{\PDFTfigname}\else%
195       \if@pdfGINscale%
196        \includegraphics[scale=\@PDFgraphicscale]{\PDFTfigname}\else%
197        \includegraphics{\PDFTfigname}\fi\fi\fi%
198      }\egroup\end{center}%
199       \global\@pdfGINwidthfalse\let\@PDFgraphicwidth\relax
200       \global\@pdfGINheightfalse\let\@PDFgraphicheight\relax
201       \global\@pdfGINscalefalse\let\@PDFgraphicscale\relax
202       }{\PDFTnopdftrue}
203    \gdef\@PDFgraphiclinecolor{white}
204    \gdef\@PDFgraphicbackground{white}
205    \gdef\@PDFboxsep{0pt}
206    \gdef\@PDFboxrule{0pt}
207 }
208 \definecolor{gray30}{gray}{.70}
209 \definecolor{gray10}{gray}{.90}
210 \RequirePackage{keyval}
211 \def\configure[#1][#2]{\setkeys{#1}{#2}
212   \PDFTWarning{pdftricks}{Reconfigured #1 parameter(s)\MessageBreak  #2\MessageBreak}
213   }
214 \define@key{pdfgraphic}{width}     {\gdef\@PDFgraphicwidth{#1}\global\@pdfGINwidthtrue}
215 \define@key{pdfgraphic}{height}    {\gdef\@PDFgraphicheight{#1}\global\@pdfGINheighttrue}
216 \define@key{pdfgraphic}{scale}     {\gdef\@PDFgraphicscale{#1}\global\@pdfGINscaletrue}
217 \define@key{pdfgraphic}{color}     {\gdef\@PDFgraphiccolor{#1}}
218 \define@key{pdfgraphic}{linecolor} {\gdef\@PDFgraphiclinecolor{#1}}
219 \define@key{pdfgraphic}{background}{\gdef\@PDFgraphicbackground{#1}}
220 \define@key{pdfgraphic}{linewidth} {\gdef\@PDFboxrule{#1}}
221 \define@key{pdfgraphic}{rulesep}   {\gdef\@PDFboxsep{#1}}
222 \gdef\@PDFgraphiccolor{black}
223 \gdef\@PDFgraphiclinecolor{white}
224 \gdef\@PDFgraphicbackground{white}
225 \gdef\@PDFboxrule{0pt}
226 \gdef\@PDFboxsep{0pt}
227 %%
228 %% Tweak to grab all the packages used in the master doc.
229 %% This forces you to load pdftricks as the first package.
230 %%
231 \newenvironment{psinputs}{\begingroup
232  \newwrite\CVinputs
233  \immediate\openout\CVinputs=tmp.inputs
234   \def\usepackage{\@ifnextchar[\@CVUsepackage\@@CVUsepackage}
235   \def\@CVUsepackage[##1]##2{\immediate\write\CVinputs%
236      {\string\usepackage[##1]{##2}}}
237   \def\@@CVUsepackage##1{\immediate\write\CVinputs%
238      {\string\usepackage{##1}}}
239  }
240  {\endgroup\immediate\closeout\CVinputs}
241 %%
242 %% Arrays to keep the fig numbers
243 %%
244 \makeatletter
245 \newcounter{arraylength}%
246 \newcounter{ArrayIndex}%
247 \newcounter{zeroCtr}%
248 \newcounter{recordCtr}
249 \setcounter{recordCtr}{1}
250 \newcounter{Ctr}
251 \def\DeclareArray#1{\Array{#1}[0]{}}%
252 %
253 \def\Array#1[#2]#3{%
254                 \expandafter\gdef\csname #1#2\endcsname{#3}%
255                 \expandafter\gdef\csname #1\endcsname[##1]{\csname #1##1\endcsname}}%
256 %
257 \def\getArraylength#1{\setcounter{arraylength}{0}%
258         \loop\expandafter\ifx\csname #1\thearraylength\endcsname\relax%
259         \else\stepcounter{arraylength}\repeat}%
260 %
261 \def\addToArray#1#2{\setcounter{arraylength}{0}%
262         \loop\expandafter\ifx\csname #1\thearraylength\endcsname\relax%
263         \else\stepcounter{arraylength}\repeat%
264         \Array{#1}[\thearraylength]{#2}}%
265 %
266 \def\clearArray#1{\getArraylength{#1}%
267         \loop\ifnum\c@arraylength >0%
268         \global\expandafter\let\csname #1\thearraylength\endcsname\relax%
269         \addtocounter{arraylength}{-1}\repeat}%
270 %
271 \long\def\ArrayIterator#1#2{%
272         \setcounter{ArrayIndex}{1}\getArraylength{#1}%
273         \setcounter{zeroCtr}{\c@arraylength}%
274         \loop\ifnum\c@ArrayIndex<\c@zeroCtr{#2}%
275         \stepcounter{ArrayIndex}\repeat%
276 }%
277 \def\@nnil{\@nil}
278 \def\@empty{}
279 \def\@cvrstop#1\@@#2{}
280 %%
281 %% Equivalent of \@tfor and \@for where any delimiter can be 
282 %% provided instead of LaTeX's default comma character
283 %%
284 \long\def\cvr@delimfor#1#2#3{\DeclareArray{#1}\clearArray{#1}%
285         \long\def\@icvrloop##1#2##2\@@##3{\def##3{##1}\ifx ##3\@nnil%
286         \expandafter\@cvrstop \else\addToArray{#1}{##1}%
287     \relax\expandafter\@icvrloop\fi##2\@@##3}%
288         \long\def\@cvrloop##1#2##2#2##3\@@##4{\addToArray{#1}{##1}%
289         \def##4{##1}\ifx ##4\@nnil \else%
290     \def##4{##2}\def\y@y{##2}\ifx\y@y\@nnil\else%
291                         \addToArray{#1}{##2}\fi\ifx ##4\@nnil \else%
292                 \@icvrloop ##3\@@##4\fi\fi}%
293   \expandafter\def\expandafter\@fortmp\expandafter{#3}%
294   \ifx\@fortmp\@empty \else%
295     \expandafter\@cvrloop#3#2\@nil#2\@nil\@@\@ee@\fi}%
296 %
297 % Dont look into the following code. It is harmful
298 % for your eyes and brain as well.
299 %
300 \newcounter{f@irstCtr}
301 \newcounter{s@econdCtr}
302 \long\gdef\NoProcess[#1]{%
303         \long\def\@i@@noprocess##1,##2\@@##3{\def##3{##1}\ifx ##3\@nnil%
304         \expandafter\@cvrstop \else
305                 \expandafter\hypencheck##1-@-*[*]
306     \relax\expandafter\@i@@noprocess\fi##2\@@##3}%
307         \long\def\@@@noprocess##1,##2,##3\@@##4{
308                 \expandafter\hypencheck##1-@-*[*]
309         \def##4{##1}\ifx ##4\@nnil \else%
310     \def##4{##2}\def\y@y{##2}\ifx\y@y\@nnil\else%
311                 \expandafter\hypencheck##2-@-*[*]
312                         \fi\ifx ##4\@nnil \else%
313                 \@i@@noprocess ##3\@@##4\fi\fi}%
314   \expandafter\def\expandafter\@fortmp\expandafter{#1}%
315   \ifx\@fortmp\@empty \else%
316     \expandafter\@@@noprocess#1,\@nil,\@nil\@@\@ee@\fi}%
317 \def\d@d#1[*]{}
318 \def\hypencheck#1-#2-#3{\def\r@r{@}\def\s@s{*}\edef\c@c{#3}
319         \ifx\c@c\r@r
320         \setcounter{f@irstCtr}{#1}
321         \setcounter{s@econdCtr}{#2}
322         \stepcounter{s@econdCtr}
323         \loop\ifnum\thes@econdCtr > \thef@irstCtr% 
324                 \expandafter\edef\csname Fig\thef@irstCtr\endcsname{TRUE}
325                 \stepcounter{f@irstCtr}
326         \repeat%
327         \else\ifx\c@c\s@s% 
328                 \expandafter\edef\csname Fig#1\endcsname{TRUE}
329         \fi\fi\d@d}
330
331 %%
332 %%
333 %% End of file `pdftricks.sty'
334 %%