1
% $Header: /usr/home/levy/texts/geomsty/RCS/geompsfi.sty,v 1.18 95/12/06 13:40:51 levy Exp $
3
% This is geompsfig.sty, based on psfig.tex by Trevor Darrell (as
4
% modified by Stefan Bechtoslheim).
6
% It works with Latex and plain TeX (normally under the name geompsfi.tex).
7
% Thanks to Ket Richter for working out the changes for Plain tex.
9
% Copyright 1991, 1992, 1993 Silvio Levy
11
% This file is part of the Geom Latex style files. It is distributed in
12
% the hope that it will be useful, but WITHOUT ANY WARRANTY. The author
13
% makes no representation as to its suitability for any purpose.
15
% Permission is granted for use and non-profit distribution of this
16
% file provided that this notice is clearly maintained. The right to
17
% distribute this file for profit or as part of any commercial
18
% product is specifically reserved for the author. If you make
19
% changes to this file you cannot distribute it under the same name,
20
% but you can distribute it under a different name provided it is not
21
% for profit of as part of a commercial product, and provided that the
22
% copyright line above and this notice are clearly maintained.
24
% This version assumes that dimensions read from a PostScript file or
25
% from a .lab file are in bp (big points). Dimensions found in the
26
% source TeX file (as in \psfig{...,height=2in}) are true dimensions
27
% (that is, are not scaled pt -> bp). This is all as it should be.
29
\edef\atcatcode{\the\catcode`\@}
32
\newif\ifoldlabels \oldlabelsfalse
33
\expandafter\ifx\csname @ifundefined\endcsname\relax
34
\long\def\@ifundefined#1#2#3{\expandafter\ifx\csname
35
#1\endcsname\relax#2\else#3\fi}
38
\alloc@1\dimen\dimendef\insc@unt\@tempdima
39
\def\@warning#1{\message{Warning: #1.}}
42
\@ifundefined{ps@init}{}{\endinput}
44
\@ifundefined{hyperactivelabels}{\let\hyperactivelabels\relax}{}
46
\newif\if@topspecials %false for Rokicki's dvips: \special is at bottom of box
47
% true for dvitps, dvi2ps
49
\input driver.chg % driver-dependent definitions (generally a symlink)
61
\newcount\psscale@count
63
% A dimension register for temporarily storing a dimension in
68
%\def\typeout#1{{\let\protect\string\immediate\write\@unused{#1}}}
70
% Identifying message is here.
71
% \typeout{psfig/tex 1.4.gcg / TeXPS}\fi
73
% @psdo control structure -- similar to Latex @for.
74
% I redefined these with different names so that psfig can
75
% be used with TeX as well as LaTeX, and so that it will not
76
% be vunerable to future changes in LaTeX's internal
80
\def\@psdonoop#1\@@#2#3{}
81
\def\@psdo#1:=#2\do#3{\edef\@psdotmp{#2}\ifx\@psdotmp\@empty \else
82
\expandafter\@psdoloop#2,\@nil,\@nil\@@#1{#3}\fi}
83
\def\@psdoloop#1,#2,#3\@@#4#5{\def#4{#1}\ifx #4\@nnil \else
84
#5\def#4{#2}\ifx #4\@nnil \else#5\@ipsdoloop #3\@@#4{#5}\fi\fi}
85
\def\@ipsdoloop#1,#2\@@#3#4{\def#3{#1}\ifx #3\@nnil
86
\let\@nextwhile=\@psdonoop \else
87
#4\relax\let\@nextwhile=\@ipsdoloop\fi\@nextwhile#2\@@#3{#4}}
88
\def\@tpsdo#1:=#2\do#3{\xdef\@psdotmp{#2}\ifx\@psdotmp\@empty \else
89
\@tpsdoloop#2\@nil\@nil\@@#1{#3}\fi}
90
\def\@tpsdoloop#1#2\@@#3#4{\def#3{#1}\ifx #3\@nnil
91
\let\@nextwhile=\@psdonoop \else
92
#4\relax\let\@nextwhile=\@tpsdoloop\fi\@nextwhile#2\@@#3{#4}}
96
%\typeout{draft level now is \@psdraft \space.}
100
%\typeout{draft level now is \@psdraft \space.}
104
\newif\if@postlogfile
114
% These are for the option list:
115
% a specification of the form a = b maps to calling \@p@@sa{b}.
125
\newif\if@proportional
128
\def\@p@@sclip#1{\@cliptrue}
129
\def\@p@@sproportional#1{\@proportionaltrue}
131
%\typeout{file is #1}
132
\def\@p@sfile{#1.ps}%
133
\def\@labfile{#1.lab}%
136
\def\@p@sfile{#1.ps}%
137
\def\@labfile{#1.lab}%
141
% Convert a dimension into scaled points.
142
% #1: the name of macro which will expand to the dimension in
143
% scaled points, without the unit 'sp' though, i.e. as a pure
145
% #2: the dimension (not a dimension register, use
146
% \the if dimension is stored in a dimension register).
147
\def\@pDimenToSpNumber #1#2{%
148
\psfig@dimen = #2\relax
149
\edef#1{\number\psfig@dimen}%
152
%\typeout{bbllx is #1}
154
\@pDimenToSpNumber{\@p@sbbllx}{#1}%
157
%\typeout{bblly is #1}
159
\@pDimenToSpNumber{\@p@sbblly}{#1}%
162
%\typeout{bburx is #1}
164
\@pDimenToSpNumber{\@p@sbburx}{#1}%
167
%\typeout{bbury is #1}
169
\@pDimenToSpNumber{\@p@sbbury}{#1}%
173
\@pDimenToSpNumber{\@p@sheight}{#1}%
174
%\typeout{Height is \@p@sheight}
177
%\typeout{Width is #1}
179
\@pDimenToSpNumber{\@p@swidth}{#1}%
181
\def\@p@@srheight#1{%
182
%\typeout{Reserved height is #1}
184
\@pDimenToSpNumber{\@p@srheight}{#1}%
187
%\typeout{Reserved width is #1}
189
\@pDimenToSpNumber{\@p@srwidth}{#1}%
199
\def\@p@@sprolog#1{\@prologfiletrue\def\@prologfileval{#1}}
200
\def\@p@@spostlog#1{\@postlogfiletrue\def\@postlogfileval{#1}}
201
\def\@cs@name#1{\csname #1\endcsname}
202
\def\@setparms#1=#2,{\def\@tempa{#2}\ifx\@tempa\@empty
203
\@warning{bad syntax (missing = or extra comma) in argument of \string\psfig}%
204
\else\@@setparms#1=#2,\fi}
205
\def\@@setparms#1=#2=,{\@cs@name{@p@@s#1}{#2}}
207
% Initialize the defaults.
210
\@bbllxfalse \@bbllyfalse
211
\@bburxfalse \@bburyfalse
212
\@heightfalse \@widthfalse
213
\@rheightfalse \@rwidthfalse
215
\def\@p@sbbllx{}\def\@p@sbblly{}%
216
\def\@p@sbburx{}\def\@p@sbbury{}%
217
\def\@p@sheight{}\def\@p@swidth{}%
218
\def\@p@srheight{}\def\@p@srwidth{}%
234
% Go through the options setting things up.
236
\def\parse@ps@parms#1{%
237
\@psdo\@psfiga:=#1\do
238
{\expandafter\@setparms\@psfiga=,}%
251
\newcount\maxheaderlines
255
% Scan header of file, looking for ``BoundingBox'' and ``Creator'' lines
258
\openin\ps@stream=\@p@sfile
259
\openin\lab@stream=\@labfile
261
\relax %needed so the \@warning won't cause trouble
262
\@warning{cannot open \@p@sfile}
266
\ifno@bb \@bbmatchfalse \else \@bbmatchtrue \fi
269
\catcode`\:=12 % in case punctuation is active (e.g., under french.sty)
270
\@linecount=\maxheaderlines
272
\read\ps@stream to \line@in
273
\global\psfigtoks@=\expandafter{\line@in}
274
\ifeof\ps@stream \not@eoffalse \fi
275
%\typeout{ looking at :: \the\psfigtoks@ }
276
\if@bbmatch \else \@bbtest{\psfigtoks@} \fi
277
\if@crematch \else \@cretest{\psfigtoks@} \fi
278
\if@crematch \if@bbmatch \not@eoffalse \fi \fi
279
\advance\@linecount-1
280
\ifnum\@linecount=0 \not@eoffalse \fi
286
% '% ' becomes a regular character for a very short time.
290
\gdef\@bbtest#1{\expandafter\@bb@\the#1%%BoundingBox:\@bbtest\@bb@}
291
\global\long\def\@bb@#1%%BoundingBox:#2#3\@bb@{\ifx\@bbtest#2
292
\else\@bbmatchtrue\expandafter\bb@cull\the\psfigtoks@\fi}
294
\gdef\@cretest#1{\expandafter\@cre@\the#1%%Creator:\@cretest\@cre@}
295
\global\long\def\@cre@#1%%Creator:#2#3\@cre@{\ifx\@cretest#2
296
\else\@crematchtrue\@mathtest{\psfigtoks@}\@illtest{\psfigtoks@}\fi}
300
% Takes action if ``Creator'' line contains ``Mathematica'' or ``Illustrator''
302
\def\@mathtest#1{\expandafter\@math@\the#1Mathematica\@mathtest\@math@}
303
\long\def\@math@#1Mathematica#2#3\@math@{\ifx\@mathtest#2
304
\else\mathematicatrue \fi}
306
\def\@illtest#1{\expandafter\@ill@\the#1Illustrator\@illtest\@ill@}
307
\long\def\@ill@#1Illustrator#2#3\@ill@{\ifx\@illtest#2
308
\else\illustratortrue \fi}
310
\def\bb@cull#1:{\expandafter\bb@@cull\@iden}
311
\long\def\bb@@cull#1 #2 #3 #4 {%
312
\@pDimenToSpNumber{\@p@sbbllx}{#1bp}%
313
\@pDimenToSpNumber{\@p@sbblly}{#2bp}%
314
\@pDimenToSpNumber{\@p@sbburx}{#3bp}%
315
\@pDimenToSpNumber{\@p@sbbury}{#4bp}%
319
% Compute \@bbw and \@bbh, the width and height of the
323
\if@bbllx \else \no@bbtrue \fi
324
\if@bblly \else \no@bbtrue \fi
325
\if@bburx \else \no@bbtrue \fi
326
\if@bbury \else \no@bbtrue \fi
331
\@warning{no bounding box found in \@p@sfile}
334
% Now compute the size of the bounding box.
337
\advance\psfc@c by -\@p@sbbllx
338
\advance\psfc@b by -\@p@sbblly
339
\edef\@bbw{\number\psfc@c}
340
\edef\@bbh{\number\psfc@b}
341
%\typeout{\string\compute@bb: bbh = \@bbh, bbw = \@bbw}
347
% \in@hundreds performs #1 * (#2 / #3) correct to the hundreds,
348
% then leaves the result in \@result.
350
% note: #3 should be a big number, or a multiple of 10.
352
\def\in@hundreds #1#2#3{%
356
\psfc@a=\psfc@g % First two digits #2/#3.
357
\divide\psfc@a by \psfc@d
359
\multiply\psfc@f by \psfc@d
360
\advance\psfc@g by -\psfc@f
361
\multiply\psfc@g by 10
362
\psfc@f=\psfc@g % Third digit of #2/#3.
363
\divide\psfc@f by \psfc@d
365
\multiply\psfc@j by \psfc@d
366
\advance\psfc@g by -\psfc@j
367
\multiply\psfc@g by 10
368
\psfc@j=\psfc@g % Third digit.
369
\divide\psfc@j by \psfc@d
372
\multiply\psfc@e by \psfc@a
373
\advance\psfc@i by \psfc@e
376
\multiply\psfc@e by \psfc@f
377
\advance\psfc@i by \psfc@e
380
\divide\psfc@e by 100
381
\multiply\psfc@e by \psfc@j
382
\advance\psfc@i by \psfc@e
385
\edef\@result{\number\psfc@i}
387
% Scale a value #1 by the current scaling factor and reassign the new
389
\def\@ScaleInHundreds #1{%
390
\in@hundreds{#1}{\@p@scale}{100}%
395
% Compute width from height.
396
\def\compute@wfromh{%
397
% computing : width = height * (bbw / bbh)
398
\in@hundreds{\@p@sheight}{\@bbw}{\@bbh}%
399
%\typeout{ \@p@sheight * \@bbw / \@bbh, = \@result }
400
\edef\@p@swidth{\@result}%
401
%\typeout{w from h: width is \@p@swidth}%
404
% Compute height from width.
406
\def\compute@hfromw{%
407
% computing : height = width * (bbh / bbw)
408
\in@hundreds{\@p@swidth}{\@bbh}{\@bbw}%
409
%\typeout{ \@p@swidth * \@bbh / \@bbw = \@result }
410
\edef\@p@sheight{\@result}%
411
%\typeout{h from w : height is \@p@sheight}%
414
% Compute height and width when both are given and proportionality
418
\in@hundreds{\@p@swidth}{\@bbh}{\@bbw}%
419
\ifnum\@p@sheight<\@result
420
\in@hundreds{\@p@sheight}{\@bbw}{\@bbh}%
421
\edef\@p@swidth{\@result}%
423
\edef\@p@sheight{\@result}%
427
% Compute height and width, i.e. \@p@sheight and \@p@swidth.
430
% If height is given.
438
% Height, no width: compute width.
444
% Width is given, no height though: compute it.
447
% Neither width no height is give.
448
\edef\@p@sheight{\@bbh}
449
\edef\@p@swidth{\@bbw}
453
% Compute the amount of space to reserve. Unless defined
454
% using rheight and rwidth when \psfig is called, these values
455
% default to \@p@sheight and \@p@swidth.
457
\if@rheight \else \edef\@p@srheight{\@p@sheight} \fi
458
\if@rwidth \else \edef\@p@srwidth{\@p@swidth} \fi
464
% usage: \psfig{file=, height=, width=, bbllx=, bblly=, bburx=, bbury=,
465
% rheight=, rwidth=, clip=, scale=, proportional=}
467
% "clip=" and "proportional=" are switches and take no value,
468
% but the `=' must be present.
476
% Compute any missing sizes.
478
\ifno@file\vbox{\hbox{{\tt\@p@sfile} not found}}%
483
%\if@verbose \typeout{psfig: scaling by \@p@scale}\fi
484
% We now scale the width and height as reported to the PS printer.
485
\@ScaleInHundreds{\@p@swidth}%
486
\@ScaleInHundreds{\@p@sheight}%
487
\@ScaleInHundreds{\@p@srwidth}%
488
\@ScaleInHundreds{\@p@srheight}%
491
\ifnum\@p@scost<\@psdraft
492
%\if@verbose \typeout{psfig: including \@p@sfile \space}\fi
493
\if@topspecials\do@specials\fi
494
% Create a vbox to reserve the proper amount of space for the figure.
495
\vbox to \@p@srheight sp{%
496
\hbox to \@p@srwidth sp{}%
499
\if@topspecials\else\do@specials\fi
501
%\if@verbose\typeout{psfig: no file \@labfile \space found}\fi
506
\read\lab@stream to \line@in \ifx\line@in\partest\else\line@in\fi
507
\ifeof\lab@stream \not@eoffalse \fi
511
% Draft mode: reserve the space for the figure and print the path name.
512
\vbox to \@p@srheight sp{%
513
\hbox to \@p@srwidth sp{%
525
\def\do@specials{\ps@init\ps@begin
527
%\if@verbose \typeout{(clip)} \fi
529
\if@prologfile \ps@prolog \fi \ps@include \if@postlogfile \ps@postlog \fi
533
\newdimen\x@lab \newdimen\y@lab
534
\newdimen\x@aux \newdimen\y@aux
535
\newdimen\hair\hair=3pt
536
\def\setlabel#1#2#3#4#5{%
537
\setbox\label@box\hbox{$#1$}%
538
\x@lab.5\wd\label@box \x@lab#4\x@lab
539
\y@lab.5\ht\label@box\advance\y@lab.5\dp\label@box \y@lab#5\y@lab
540
% rotate lab clockwise by 22.5 degrees to get aux
541
\x@aux.92388\x@lab \advance\x@aux.38268\y@lab
542
\y@aux-.38268\x@lab \advance\y@aux.92388\y@lab
546
\ifdim\x@aux>\y@aux\advance\x@lab.7071\hair\advance\y@lab.7071\hair
547
\else\advance\y@lab\hair\fi
549
\ifdim\x@aux>-\y@aux\advance\x@lab\hair
550
\else\advance\x@lab.7071\hair\advance\y@lab-.7071\hair\fi
554
\ifdim\x@aux>-\y@aux\advance\x@lab-.7071\hair\advance\y@lab.7071\hair
555
\else\advance\x@lab-\hair\fi
557
\ifdim\x@aux>\y@aux\advance\y@lab-\hair
560
\advance\x@lab-.7071\hair\advance\y@lab-.7071\hair\fi
564
\advance\x@lab.5\wd\label@box
565
\advance\y@lab.5\ht\label@box\advance\y@lab.5\dp\label@box
566
\x@aux=#2bp \ifoldlabels \else \advance\x@aux by -\@p@sbbllx sp \fi
567
\y@aux=#3bp \ifoldlabels \else \advance\y@aux by -\@p@sbblly sp \fi
568
\in@hundreds{\x@aux}{\@p@swidth}{\@bbw}
569
\edef\@xpos{\@result}
570
\in@hundreds{\y@aux}{\@p@sheight}{\@bbh}
571
\edef\@ypos{\@result}
573
\vss\hbox to\@p@srwidth sp{\hskip \@xpos sp \hskip-\x@lab
574
\box\label@box\hss}\vskip \@ypos sp \vskip-\y@lab}}
576
\catcode`@=\atcatcode
578
% $Log: geompsfi.sty,v $
579
%Revision 1.18 95/12/06 13:40:51 levy
580
%made geompsfi.tex work (\ifx\@ifundefined was wrong!)
582
%Revision 1.17 1994/06/23 04:36:58 levy
583
%added \ifoldlabels for compatibility with behavior before version 1.11
585
%Revision 1.16 1994/04/29 00:19:21 levy
586
%combined with geompsfi.tex
588
%Revision 1.16 1994/04/29 00:03:40 levy
589
%leave plenty of space so patch geompsfi.tex works
591
%Revision 1.15 1994/04/03 07:07:57 levy
592
%removed hair correction when x@lab and y@lab are both zero
594
%Revision 1.14 1993/09/16 22:22:38 levy
595
%\catcode`\:=12 % in case punctuation is active (e.g., under french.sty)
597
%Revision 1.13 1993/08/27 23:04:27 levy
598
%removed "true" from PS dimensions (so it works with \magnifications)
600
%Revision 1.12 93/08/16 12:28:46 levy
601
%\ifundefined\hyperactivelabels
603
%Revision 1.11 93/07/19 02:17:24 levy
604
%.lab coordinates should be world coordinates
606
%Revision 1.10 93/03/05 10:59:38 levy
607
%error message when arguments of \psfig are incorrect
609
%Revision 1.9 1993/01/13 15:50:36 levy
610
%expressed things in bp (correctly)
612
%Revision 1.8 1993/01/10 20:56:04 levy
613
%inhundreds -> inthousands
615
%Revision 1.6 92/07/13 11:12:40 levy
616
%better error message when bounding box not found
618
%Revision 1.5 92/06/15 22:05:22 levy
619
%proportional scaling
621
%Revision 1.4 92/06/10 13:03:45 levy
622
%extend header from 10 to 15 lines
624
%Revision 1.3 92/06/10 12:41:14 levy
625
%scan header for "Creator" line
627
%Revision 1.2 92/04/07 09:09:17 levy
628
%*** empty log message ***
630
% Revision 1.1 92/03/31 14:12:38 levy