home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume8 / psfig-tex / part03 < prev    next >
Encoding:
Internet Message Format  |  1987-03-02  |  10.3 KB

  1. Subject:  v08i098:  Including PostScript/Macintosh figures in TeX documents, Part03/03
  2. Newsgroups: mod.sources
  3. Approved: mirror!rs
  4.  
  5. Submitted by: trevor@grasp.cis.upenn.edu (Trevor Darrell)
  6. Mod.sources: Volume 8, Issue 98
  7. Archive-name: psfig-tex/Part03
  8.  
  9. #! /bin/sh
  10. # This is a shell archive.  Remove anything before this line,
  11. # then unpack it by saving it in a file and typing "sh file".
  12. # If all goes well, you will see the message "End of archive 3 (of 3)."
  13. # Contents:  src/psfig.tex
  14. PATH=/bin:/usr/bin:/usr/ucb; export PATH
  15. echo shar: extracting "'src/psfig.tex'" '(8941 characters)'
  16. if test -f 'src/psfig.tex' ; then 
  17.   echo shar: will not over-write existing file "'src/psfig.tex'"
  18. else
  19. sed 's/^X//' >src/psfig.tex <<'@//E*O*F src/psfig.tex//'
  20. X% psfigTeX macros
  21. X%
  22. X% All software, documentation, and related files in this distribution of
  23. X% psfig/tex are Copyright (c) 1987 Trevor J. Darrell
  24. X%
  25. X% Permission is granted for use and non-profit distribution of psfig/tex 
  26. X% providing that this notice be clearly maintained, but the right to
  27. X% distribute any portion of psfig/tex for profit or as part of any commercial
  28. X% product is specifically reserved for the author.
  29. X%
  30. X%
  31. X% $Header: psfig.tex,v 1.7 87/01/19 15:55:27 trevor Exp $
  32. X%
  33. X\catcode`\@=11\relax
  34. X\newwrite\@unused
  35. X\def\typeout#1{{\let\protect\string\immediate\write\@unused{#1}}}
  36. X\def\psglobal#1{
  37. X\immediate\special{ps:plotfile #1 global}}
  38. X\def\psfiginit{\typeout{psfiginit}
  39. X\immediate\psglobal{figtex.pro}}
  40. X%
  41. X% @psdo control structure -- similar to Latex @for.
  42. X% I redefined these with different names so that psfig can
  43. X% be used with TeX as well as LaTeX, and so that it will not 
  44. X% be vunerable to future changes in LaTeX's internal
  45. X% control structure,
  46. X%
  47. X\def\@nnil{\@nil}
  48. X\def\@empty{}
  49. X\def\@psdonoop#1\@@#2#3{}
  50. X\def\@psdo#1:=#2\do#3{\edef\@psdotmp{#2}\ifx\@psdotmp\@empty \else
  51. X    \expandafter\@psdoloop#2,\@nil,\@nil\@@#1{#3}\fi}
  52. X\def\@psdoloop#1,#2,#3\@@#4#5{\def#4{#1}\ifx #4\@nnil \else
  53. X       #5\def#4{#2}\ifx #4\@nnil \else#5\@ipsdoloop #3\@@#4{#5}\fi\fi}
  54. X\def\@ipsdoloop#1,#2\@@#3#4{\def#3{#1}\ifx #3\@nnil 
  55. X       \let\@nextwhile=\@psdonoop \else
  56. X      #4\relax\let\@nextwhile=\@ipsdoloop\fi\@nextwhile#2\@@#3{#4}}
  57. X\def\@tpsdo#1:=#2\do#3{\xdef\@psdotmp{#2}\ifx\@psdotmp\@empty \else
  58. X    \@tpsdoloop#2\@nil\@nil\@@#1{#3}\fi}
  59. X\def\@tpsdoloop#1#2\@@#3#4{\def#3{#1}\ifx #3\@nnil 
  60. X       \let\@nextwhile=\@psdonoop \else
  61. X      #4\relax\let\@nextwhile=\@tpsdoloop\fi\@nextwhile#2\@@#3{#4}}
  62. X% 
  63. X%
  64. X\def\psdraft{
  65. X    \def\@psdraft{0}
  66. X    %\typeout{draft level now is \@psdraft \space . }
  67. X}
  68. X\def\psfull{
  69. X    \def\@psdraft{100}
  70. X    %\typeout{draft level now is \@psdraft \space . }
  71. X}
  72. X\psfull
  73. X\newif\if@prologfile
  74. X\newif\if@postlogfile
  75. X%%% These are for the option list.
  76. X%%% A specification of the form a = b maps to calling \@p@@sa{b}
  77. X\newif\if@bbllx
  78. X\newif\if@bblly
  79. X\newif\if@bburx
  80. X\newif\if@bbury
  81. X\newif\if@height
  82. X\newif\if@width
  83. X\newif\if@rheight
  84. X\newif\if@rwidth
  85. X\newif\if@clip
  86. X\def\@p@@sclip#1{\@cliptrue}
  87. X\def\@p@@sfile#1{%\typeout{file is #1}
  88. X           \def\@p@sfile{#1}
  89. X}
  90. X\def\@p@@sfigure#1{\def\@p@sfile{#1}}
  91. X\def\@p@@sbbllx#1{
  92. X        %\typeout{bbllx is #1}
  93. X        \@bbllxtrue
  94. X        \dimen100=#1
  95. X        \edef\@p@sbbllx{\number\dimen100}
  96. X}
  97. X\def\@p@@sbblly#1{
  98. X        %\typeout{bblly is #1}
  99. X        \@bbllytrue
  100. X        \dimen100=#1
  101. X        \edef\@p@sbblly{\number\dimen100}
  102. X}
  103. X\def\@p@@sbburx#1{
  104. X        %\typeout{bburx is #1}
  105. X        \@bburxtrue
  106. X        \dimen100=#1
  107. X        \edef\@p@sbburx{\number\dimen100}
  108. X}
  109. X\def\@p@@sbbury#1{
  110. X        %\typeout{bbury is #1}
  111. X        \@bburytrue
  112. X        \dimen100=#1
  113. X        \edef\@p@sbbury{\number\dimen100}
  114. X}
  115. X\def\@p@@sheight#1{
  116. X        \@heighttrue
  117. X        \dimen100=#1
  118. X           \edef\@p@sheight{\number\dimen100}
  119. X        %\typeout{Height is \@p@sheight}
  120. X}
  121. X\def\@p@@swidth#1{
  122. X        %\typeout{Width is #1}
  123. X        \@widthtrue
  124. X        \dimen100=#1
  125. X        \edef\@p@swidth{\number\dimen100}
  126. X}
  127. X\def\@p@@srheight#1{
  128. X        %\typeout{Reserved height is #1}
  129. X        \@rheighttrue
  130. X        \dimen100=#1
  131. X        \edef\@p@srheight{\number\dimen100}
  132. X}
  133. X\def\@p@@srwidth#1{
  134. X        %\typeout{Reserved width is #1}
  135. X        \@rwidthtrue
  136. X        \dimen100=#1
  137. X        \edef\@p@srwidth{\number\dimen100}
  138. X}
  139. X\def\@p@@sprolog#1{\@prologfiletrue\def\@prologfileval{#1}}
  140. X\def\@p@@spostlog#1{\@postlogfiletrue\def\@postlogfileval{#1}}
  141. X\def\@cs@name#1{\csname #1\endcsname}
  142. X\def\@setparms#1=#2,{\@cs@name{@p@@s#1}{#2}}
  143. X%
  144. X% initialize the defaults (size the size of the figure)
  145. X%
  146. X\def\ps@init@parms{
  147. X        \@bbllxfalse \@bbllyfalse
  148. X        \@bburxfalse \@bburyfalse
  149. X        \@heightfalse \@widthfalse
  150. X        \@rheightfalse \@rwidthfalse
  151. X        \def\@p@sbbllx{}\def\@p@sbblly{}
  152. X        \def\@p@sbburx{}\def\@p@sbbury{}
  153. X        \def\@p@sheight{}\def\@p@swidth{}
  154. X        \def\@p@srheight{}\def\@p@srwidth{}
  155. X        \def\@p@sfile{}
  156. X        \def\@p@scost{10}
  157. X        \def\@sc{}
  158. X        \@prologfilefalse
  159. X        \@postlogfilefalse
  160. X        \@clipfalse
  161. X}
  162. X%
  163. X% Go through the options setting things up.
  164. X%
  165. X\def\parse@ps@parms#1{
  166. X         \@psdo\@psfiga:=#1\do
  167. X           {\expandafter\@setparms\@psfiga,}}
  168. X%
  169. X% Compute bb height and width
  170. X%
  171. X\newif\ifno@bb
  172. X\newif\ifnot@eof
  173. X\newread\ps@stream
  174. X\def\bb@missing{
  175. X    \typeout{psfig: searching \@p@sfile \space  for bounding box}
  176. X    \openin\ps@stream=\@p@sfile
  177. X    \no@bbtrue
  178. X    \not@eoftrue
  179. X    \catcode`\%=12
  180. X    \loop
  181. X        \read\ps@stream to \line@in
  182. X        \global\toks200=\expandafter{\line@in}
  183. X        \ifeof\ps@stream \not@eoffalse \fi
  184. X        %\typeout{ looking at :: \the\toks200 }
  185. X        \@bbtest{\toks200}
  186. X        \if@bbmatch\not@eoffalse\expandafter\bb@cull\the\toks200\fi
  187. X    \ifnot@eof \repeat
  188. X    \catcode`\%=14
  189. X}    
  190. X\catcode`\%=12
  191. X\newif\if@bbmatch
  192. X\def\@bbtest#1{\expandafter\@a@\the#1%%BoundingBox:\@bbtest\@a@}
  193. X\long\def\@a@#1%%BoundingBox:#2#3\@a@{\ifx\@bbtest#2\@bbmatchfalse\else\@bbmatchtrue\fi}
  194. X\long\def\bb@cull#1 #2 #3 #4 #5 {
  195. X    \dimen100=#2 bp\edef\@p@sbbllx{\number\dimen100}
  196. X    \dimen100=#3 bp\edef\@p@sbblly{\number\dimen100}
  197. X    \dimen100=#4 bp\edef\@p@sbburx{\number\dimen100}
  198. X    \dimen100=#5 bp\edef\@p@sbbury{\number\dimen100}
  199. X    \no@bbfalse
  200. X}
  201. X\catcode`\%=14
  202. X%
  203. X\def\compute@bb{
  204. X        \no@bbfalse
  205. X        \if@bbllx \else \no@bbtrue \fi
  206. X        \if@bblly \else \no@bbtrue \fi
  207. X        \if@bburx \else \no@bbtrue \fi
  208. X        \if@bbury \else \no@bbtrue \fi
  209. X        \ifno@bb \bb@missing \fi
  210. X        \ifno@bb \typeout{FATAL ERROR: no bb supplied or found}
  211. X            \no-bb-error
  212. X        \fi
  213. X        %
  214. X        \count203=\@p@sbburx
  215. X        \count204=\@p@sbbury
  216. X        \advance\count203 by -\@p@sbbllx
  217. X        \advance\count204 by -\@p@sbblly
  218. X        \edef\@bbw{\number\count203}
  219. X        \edef\@bbh{\number\count204}
  220. X        %\typeout{ bbh = \@bbh, bbw = \@bbw }
  221. X}
  222. X%
  223. X% \in@hundreds performs #1 * (#2 / #3) correct to the hundreds,
  224. X%    then leaves the result in @result
  225. X%
  226. X\def\in@hundreds#1#2#3{\count240=#2 \count241=#3
  227. X             \count100=\count240    % 100 is first digit #2/#3
  228. X             \divide\count100 by \count241
  229. X             \count101=\count100
  230. X             \multiply\count101 by \count241
  231. X             \advance\count240 by -\count101
  232. X             \multiply\count240 by 10
  233. X             \count101=\count240    %101 is second digit of #2/#3
  234. X             \divide\count101 by \count241
  235. X             \count102=\count101
  236. X             \multiply\count102 by \count241
  237. X             \advance\count240 by -\count102
  238. X             \multiply\count240 by 10
  239. X             \count102=\count240    % 102 is the third digit
  240. X             \divide\count102 by \count241
  241. X             \count200=#1\count205=0
  242. X             \count201=\count200
  243. X            \multiply\count201 by \count100
  244. X             \advance\count205 by \count201
  245. X             \count201=\count200
  246. X            \divide\count201 by 10
  247. X            \multiply\count201 by \count101
  248. X            \advance\count205 by \count201
  249. X            %
  250. X             \count201=\count200
  251. X            \divide\count201 by 100
  252. X            \multiply\count201 by \count102
  253. X            \advance\count205 by \count201
  254. X            %
  255. X             \edef\@result{\number\count205}
  256. X}
  257. X\def\compute@wfromh{
  258. X        % computing : width = height * (bbw / bbh)
  259. X        \in@hundreds{\@p@sheight}{\@bbw}{\@bbh}
  260. X        %\typeout{ \@p@sheight * \@bbw / \@bbh, = \@result }
  261. X        \edef\@p@swidth{\@result}
  262. X        %\typeout{w from h: width is \@p@swidth}
  263. X}
  264. X\def\compute@hfromw{
  265. X        % computing : height = width * (bbh / bbw)
  266. X        \in@hundreds{\@p@swidth}{\@bbh}{\@bbw}
  267. X        %\typeout{ \@p@swidth * \@bbh / \@bbw = \@result }
  268. X        \edef\@p@sheight{\@result}
  269. X        %\typeout{h from w : height is \@p@sheight}
  270. X}
  271. X\def\compute@handw{
  272. X        \if@height 
  273. X            \if@width
  274. X            \else
  275. X                \compute@wfromh
  276. X            \fi
  277. X        \else 
  278. X            \if@width
  279. X                \compute@hfromw
  280. X            \else
  281. X                \edef\@p@sheight{\@bbh}
  282. X                \edef\@p@swidth{\@bbw}
  283. X            \fi
  284. X        \fi
  285. X}
  286. X\def\compute@resv{
  287. X        \if@rheight \else \edef\@p@srheight{\@p@sheight} \fi
  288. X        \if@rwidth \else \edef\@p@srwidth{\@p@swidth} \fi
  289. X}
  290. X%        
  291. X% Compute any missing values
  292. X\def\compute@sizes{
  293. X    \compute@bb
  294. X    \compute@handw
  295. X    \compute@resv
  296. X}
  297. X%
  298. X% \psfig
  299. X% usage : \psfig{file=, height=, width=, bbllx=, bblly=, bburx=, bbury=,
  300. X%            rheight=, rwidth=, clip=}
  301. X%
  302. X% "clip=" is a switch and takes no value, but the `=' must be preset.
  303. X\def\psfig#1{\vbox {
  304. X    % do a zero width hard space so that a single
  305. X    % \psfig in a centering enviornment will behave nicely
  306. X    %{\setbox0=\hbox{\ }\ \hskip-\wd0}
  307. X    %
  308. X    \ps@init@parms
  309. X    \parse@ps@parms{#1}
  310. X    \compute@sizes
  311. X    %
  312. X    \ifnum\@p@scost<\@psdraft{
  313. X        \typeout{psfig: including \@p@sfile \space }
  314. X        %
  315. X        \special{ps::[begin]     \@p@swidth \space \@p@sheight \space
  316. X                \@p@sbbllx \space \@p@sbblly \space
  317. X                \@p@sbburx \space \@p@sbbury \space
  318. X                startTexFig \space }
  319. X        \if@clip{
  320. X            \typeout{(clip)}
  321. X            \special{ps:: \@p@sbbllx \space \@p@sbblly \space
  322. X                \@p@sbburx \space \@p@sbbury \space
  323. X                doclip \space }
  324. X        }\fi
  325. X        \if@prologfile
  326. X            \special{ps: plotfile \@prologfileval \space } \fi
  327. X        \special{ps: plotfile \@p@sfile \space }
  328. X        \if@postlogfile
  329. X            \special{ps: plotfile \@postlogfileval \space } \fi
  330. X        \special{ps::[end] endTexFig \space }
  331. X        % Create the vbox to reserve the space for the figure
  332. X        \vbox to \@p@srheight true sp{
  333. X            \hbox to \@p@srwidth true sp{
  334. X                \hfil
  335. X            }
  336. X        \vfil
  337. X        }
  338. X    }\else{
  339. X        % draft figure, just reserve the space and print the
  340. X        % path name.
  341. X        \vbox to \@p@srheight true sp{
  342. X        \vss
  343. X            \hbox to \@p@srwidth true sp{
  344. X                \hss
  345. X                \@p@sfile
  346. X                \hss
  347. X            }
  348. X        \vss
  349. X        }
  350. X    }\fi
  351. X}}
  352. X\catcode`\@=12\relax
  353. X
  354. @//E*O*F src/psfig.tex//
  355. if test 8941 -ne "`wc -c <'src/psfig.tex'`"; then
  356.     echo shar: error transmitting "'src/psfig.tex'" '(should have been 8941 characters)'
  357. fi
  358. fi # end of overwriting check
  359. echo shar: "End of archive 3 (of 3)."
  360. cp /dev/null ark3isdone
  361. DONE=true
  362. for I in 1 2 3; do
  363.     if test -! f ark${I}isdone; then
  364.         echo "You still need to run archive ${I}."
  365.         DONE=false
  366.     fi
  367. done
  368. case $DONE in
  369.     true)
  370.         echo "You have run all 3 archives."
  371.         echo 'See the README'
  372.         ;;
  373. esac
  374. ##  End of shell archive.
  375. exit 0
  376.