You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

psfig.tex 10 kB

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