home *** CD-ROM | disk | FTP | other *** search
/ ftp.umcs.maine.edu / 2015-02-07.ftp.umcs.maine.edu.tar / ftp.umcs.maine.edu / pub / WISR / wisr4 / proceedings / tex / davis_psfig.tex < prev    next >
Text File  |  1991-10-24  |  9KB  |  337 lines

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