home *** CD-ROM | disk | FTP | other *** search
- Subject: v08i098: Including PostScript/Macintosh figures in TeX documents, Part03/03
- Newsgroups: mod.sources
- Approved: mirror!rs
-
- Submitted by: trevor@grasp.cis.upenn.edu (Trevor Darrell)
- Mod.sources: Volume 8, Issue 98
- Archive-name: psfig-tex/Part03
-
- #! /bin/sh
- # This is a shell archive. Remove anything before this line,
- # then unpack it by saving it in a file and typing "sh file".
- # If all goes well, you will see the message "End of archive 3 (of 3)."
- # Contents: src/psfig.tex
- PATH=/bin:/usr/bin:/usr/ucb; export PATH
- echo shar: extracting "'src/psfig.tex'" '(8941 characters)'
- if test -f 'src/psfig.tex' ; then
- echo shar: will not over-write existing file "'src/psfig.tex'"
- else
- sed 's/^X//' >src/psfig.tex <<'@//E*O*F src/psfig.tex//'
- X% psfigTeX macros
- X%
- X% All software, documentation, and related files in this distribution of
- X% psfig/tex are Copyright (c) 1987 Trevor J. Darrell
- X%
- X% Permission is granted for use and non-profit distribution of psfig/tex
- X% providing that this notice be clearly maintained, but the right to
- X% distribute any portion of psfig/tex for profit or as part of any commercial
- X% product is specifically reserved for the author.
- X%
- X%
- X% $Header: psfig.tex,v 1.7 87/01/19 15:55:27 trevor Exp $
- X%
- X\catcode`\@=11\relax
- X\newwrite\@unused
- X\def\typeout#1{{\let\protect\string\immediate\write\@unused{#1}}}
- X\def\psglobal#1{
- X\immediate\special{ps:plotfile #1 global}}
- X\def\psfiginit{\typeout{psfiginit}
- X\immediate\psglobal{figtex.pro}}
- X%
- X% @psdo control structure -- similar to Latex @for.
- X% I redefined these with different names so that psfig can
- X% be used with TeX as well as LaTeX, and so that it will not
- X% be vunerable to future changes in LaTeX's internal
- X% control structure,
- X%
- X\def\@nnil{\@nil}
- X\def\@empty{}
- X\def\@psdonoop#1\@@#2#3{}
- X\def\@psdo#1:=#2\do#3{\edef\@psdotmp{#2}\ifx\@psdotmp\@empty \else
- X \expandafter\@psdoloop#2,\@nil,\@nil\@@#1{#3}\fi}
- X\def\@psdoloop#1,#2,#3\@@#4#5{\def#4{#1}\ifx #4\@nnil \else
- X #5\def#4{#2}\ifx #4\@nnil \else#5\@ipsdoloop #3\@@#4{#5}\fi\fi}
- X\def\@ipsdoloop#1,#2\@@#3#4{\def#3{#1}\ifx #3\@nnil
- X \let\@nextwhile=\@psdonoop \else
- X #4\relax\let\@nextwhile=\@ipsdoloop\fi\@nextwhile#2\@@#3{#4}}
- X\def\@tpsdo#1:=#2\do#3{\xdef\@psdotmp{#2}\ifx\@psdotmp\@empty \else
- X \@tpsdoloop#2\@nil\@nil\@@#1{#3}\fi}
- X\def\@tpsdoloop#1#2\@@#3#4{\def#3{#1}\ifx #3\@nnil
- X \let\@nextwhile=\@psdonoop \else
- X #4\relax\let\@nextwhile=\@tpsdoloop\fi\@nextwhile#2\@@#3{#4}}
- X%
- X%
- X\def\psdraft{
- X \def\@psdraft{0}
- X %\typeout{draft level now is \@psdraft \space . }
- X}
- X\def\psfull{
- X \def\@psdraft{100}
- X %\typeout{draft level now is \@psdraft \space . }
- X}
- X\psfull
- X\newif\if@prologfile
- X\newif\if@postlogfile
- X%%% These are for the option list.
- X%%% A specification of the form a = b maps to calling \@p@@sa{b}
- X\newif\if@bbllx
- X\newif\if@bblly
- X\newif\if@bburx
- X\newif\if@bbury
- X\newif\if@height
- X\newif\if@width
- X\newif\if@rheight
- X\newif\if@rwidth
- X\newif\if@clip
- X\def\@p@@sclip#1{\@cliptrue}
- X\def\@p@@sfile#1{%\typeout{file is #1}
- X \def\@p@sfile{#1}
- X}
- X\def\@p@@sfigure#1{\def\@p@sfile{#1}}
- X\def\@p@@sbbllx#1{
- X %\typeout{bbllx is #1}
- X \@bbllxtrue
- X \dimen100=#1
- X \edef\@p@sbbllx{\number\dimen100}
- X}
- X\def\@p@@sbblly#1{
- X %\typeout{bblly is #1}
- X \@bbllytrue
- X \dimen100=#1
- X \edef\@p@sbblly{\number\dimen100}
- X}
- X\def\@p@@sbburx#1{
- X %\typeout{bburx is #1}
- X \@bburxtrue
- X \dimen100=#1
- X \edef\@p@sbburx{\number\dimen100}
- X}
- X\def\@p@@sbbury#1{
- X %\typeout{bbury is #1}
- X \@bburytrue
- X \dimen100=#1
- X \edef\@p@sbbury{\number\dimen100}
- X}
- X\def\@p@@sheight#1{
- X \@heighttrue
- X \dimen100=#1
- X \edef\@p@sheight{\number\dimen100}
- X %\typeout{Height is \@p@sheight}
- X}
- X\def\@p@@swidth#1{
- X %\typeout{Width is #1}
- X \@widthtrue
- X \dimen100=#1
- X \edef\@p@swidth{\number\dimen100}
- X}
- X\def\@p@@srheight#1{
- X %\typeout{Reserved height is #1}
- X \@rheighttrue
- X \dimen100=#1
- X \edef\@p@srheight{\number\dimen100}
- X}
- X\def\@p@@srwidth#1{
- X %\typeout{Reserved width is #1}
- X \@rwidthtrue
- X \dimen100=#1
- X \edef\@p@srwidth{\number\dimen100}
- X}
- X\def\@p@@sprolog#1{\@prologfiletrue\def\@prologfileval{#1}}
- X\def\@p@@spostlog#1{\@postlogfiletrue\def\@postlogfileval{#1}}
- X\def\@cs@name#1{\csname #1\endcsname}
- X\def\@setparms#1=#2,{\@cs@name{@p@@s#1}{#2}}
- X%
- X% initialize the defaults (size the size of the figure)
- X%
- X\def\ps@init@parms{
- X \@bbllxfalse \@bbllyfalse
- X \@bburxfalse \@bburyfalse
- X \@heightfalse \@widthfalse
- X \@rheightfalse \@rwidthfalse
- X \def\@p@sbbllx{}\def\@p@sbblly{}
- X \def\@p@sbburx{}\def\@p@sbbury{}
- X \def\@p@sheight{}\def\@p@swidth{}
- X \def\@p@srheight{}\def\@p@srwidth{}
- X \def\@p@sfile{}
- X \def\@p@scost{10}
- X \def\@sc{}
- X \@prologfilefalse
- X \@postlogfilefalse
- X \@clipfalse
- X}
- X%
- X% Go through the options setting things up.
- X%
- X\def\parse@ps@parms#1{
- X \@psdo\@psfiga:=#1\do
- X {\expandafter\@setparms\@psfiga,}}
- X%
- X% Compute bb height and width
- X%
- X\newif\ifno@bb
- X\newif\ifnot@eof
- X\newread\ps@stream
- X\def\bb@missing{
- X \typeout{psfig: searching \@p@sfile \space for bounding box}
- X \openin\ps@stream=\@p@sfile
- X \no@bbtrue
- X \not@eoftrue
- X \catcode`\%=12
- X \loop
- X \read\ps@stream to \line@in
- X \global\toks200=\expandafter{\line@in}
- X \ifeof\ps@stream \not@eoffalse \fi
- X %\typeout{ looking at :: \the\toks200 }
- X \@bbtest{\toks200}
- X \if@bbmatch\not@eoffalse\expandafter\bb@cull\the\toks200\fi
- X \ifnot@eof \repeat
- X \catcode`\%=14
- X}
- X\catcode`\%=12
- X\newif\if@bbmatch
- X\def\@bbtest#1{\expandafter\@a@\the#1%%BoundingBox:\@bbtest\@a@}
- X\long\def\@a@#1%%BoundingBox:#2#3\@a@{\ifx\@bbtest#2\@bbmatchfalse\else\@bbmatchtrue\fi}
- X\long\def\bb@cull#1 #2 #3 #4 #5 {
- X \dimen100=#2 bp\edef\@p@sbbllx{\number\dimen100}
- X \dimen100=#3 bp\edef\@p@sbblly{\number\dimen100}
- X \dimen100=#4 bp\edef\@p@sbburx{\number\dimen100}
- X \dimen100=#5 bp\edef\@p@sbbury{\number\dimen100}
- X \no@bbfalse
- X}
- X\catcode`\%=14
- X%
- X\def\compute@bb{
- X \no@bbfalse
- X \if@bbllx \else \no@bbtrue \fi
- X \if@bblly \else \no@bbtrue \fi
- X \if@bburx \else \no@bbtrue \fi
- X \if@bbury \else \no@bbtrue \fi
- X \ifno@bb \bb@missing \fi
- X \ifno@bb \typeout{FATAL ERROR: no bb supplied or found}
- X \no-bb-error
- X \fi
- X %
- X \count203=\@p@sbburx
- X \count204=\@p@sbbury
- X \advance\count203 by -\@p@sbbllx
- X \advance\count204 by -\@p@sbblly
- X \edef\@bbw{\number\count203}
- X \edef\@bbh{\number\count204}
- X %\typeout{ bbh = \@bbh, bbw = \@bbw }
- X}
- X%
- X% \in@hundreds performs #1 * (#2 / #3) correct to the hundreds,
- X% then leaves the result in @result
- X%
- X\def\in@hundreds#1#2#3{\count240=#2 \count241=#3
- X \count100=\count240 % 100 is first digit #2/#3
- X \divide\count100 by \count241
- X \count101=\count100
- X \multiply\count101 by \count241
- X \advance\count240 by -\count101
- X \multiply\count240 by 10
- X \count101=\count240 %101 is second digit of #2/#3
- X \divide\count101 by \count241
- X \count102=\count101
- X \multiply\count102 by \count241
- X \advance\count240 by -\count102
- X \multiply\count240 by 10
- X \count102=\count240 % 102 is the third digit
- X \divide\count102 by \count241
- X \count200=#1\count205=0
- X \count201=\count200
- X \multiply\count201 by \count100
- X \advance\count205 by \count201
- X \count201=\count200
- X \divide\count201 by 10
- X \multiply\count201 by \count101
- X \advance\count205 by \count201
- X %
- X \count201=\count200
- X \divide\count201 by 100
- X \multiply\count201 by \count102
- X \advance\count205 by \count201
- X %
- X \edef\@result{\number\count205}
- X}
- X\def\compute@wfromh{
- X % computing : width = height * (bbw / bbh)
- X \in@hundreds{\@p@sheight}{\@bbw}{\@bbh}
- X %\typeout{ \@p@sheight * \@bbw / \@bbh, = \@result }
- X \edef\@p@swidth{\@result}
- X %\typeout{w from h: width is \@p@swidth}
- X}
- X\def\compute@hfromw{
- X % computing : height = width * (bbh / bbw)
- X \in@hundreds{\@p@swidth}{\@bbh}{\@bbw}
- X %\typeout{ \@p@swidth * \@bbh / \@bbw = \@result }
- X \edef\@p@sheight{\@result}
- X %\typeout{h from w : height is \@p@sheight}
- X}
- X\def\compute@handw{
- X \if@height
- X \if@width
- X \else
- X \compute@wfromh
- X \fi
- X \else
- X \if@width
- X \compute@hfromw
- X \else
- X \edef\@p@sheight{\@bbh}
- X \edef\@p@swidth{\@bbw}
- X \fi
- X \fi
- X}
- X\def\compute@resv{
- X \if@rheight \else \edef\@p@srheight{\@p@sheight} \fi
- X \if@rwidth \else \edef\@p@srwidth{\@p@swidth} \fi
- X}
- X%
- X% Compute any missing values
- X\def\compute@sizes{
- X \compute@bb
- X \compute@handw
- X \compute@resv
- X}
- X%
- X% \psfig
- X% usage : \psfig{file=, height=, width=, bbllx=, bblly=, bburx=, bbury=,
- X% rheight=, rwidth=, clip=}
- X%
- X% "clip=" is a switch and takes no value, but the `=' must be preset.
- X\def\psfig#1{\vbox {
- X % do a zero width hard space so that a single
- X % \psfig in a centering enviornment will behave nicely
- X %{\setbox0=\hbox{\ }\ \hskip-\wd0}
- X %
- X \ps@init@parms
- X \parse@ps@parms{#1}
- X \compute@sizes
- X %
- X \ifnum\@p@scost<\@psdraft{
- X \typeout{psfig: including \@p@sfile \space }
- X %
- X \special{ps::[begin] \@p@swidth \space \@p@sheight \space
- X \@p@sbbllx \space \@p@sbblly \space
- X \@p@sbburx \space \@p@sbbury \space
- X startTexFig \space }
- X \if@clip{
- X \typeout{(clip)}
- X \special{ps:: \@p@sbbllx \space \@p@sbblly \space
- X \@p@sbburx \space \@p@sbbury \space
- X doclip \space }
- X }\fi
- X \if@prologfile
- X \special{ps: plotfile \@prologfileval \space } \fi
- X \special{ps: plotfile \@p@sfile \space }
- X \if@postlogfile
- X \special{ps: plotfile \@postlogfileval \space } \fi
- X \special{ps::[end] endTexFig \space }
- X % Create the vbox to reserve the space for the figure
- X \vbox to \@p@srheight true sp{
- X \hbox to \@p@srwidth true sp{
- X \hfil
- X }
- X \vfil
- X }
- X }\else{
- X % draft figure, just reserve the space and print the
- X % path name.
- X \vbox to \@p@srheight true sp{
- X \vss
- X \hbox to \@p@srwidth true sp{
- X \hss
- X \@p@sfile
- X \hss
- X }
- X \vss
- X }
- X }\fi
- X}}
- X\catcode`\@=12\relax
- X
- @//E*O*F src/psfig.tex//
- if test 8941 -ne "`wc -c <'src/psfig.tex'`"; then
- echo shar: error transmitting "'src/psfig.tex'" '(should have been 8941 characters)'
- fi
- fi # end of overwriting check
- echo shar: "End of archive 3 (of 3)."
- cp /dev/null ark3isdone
- DONE=true
- for I in 1 2 3; do
- if test -! f ark${I}isdone; then
- echo "You still need to run archive ${I}."
- DONE=false
- fi
- done
- case $DONE in
- true)
- echo "You have run all 3 archives."
- echo 'See the README'
- ;;
- esac
- ## End of shell archive.
- exit 0
-