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