| 1 |
\makeatletter |
| 2 |
\typeout{% |
| 3 |
Enhancements to Picture Environment. Version 1.2 - Released June 1, 1986} |
| 4 |
%---------------------------------------------------------------------- |
| 5 |
% Copyright (C) podar@sbcs (Sunil Podar) July 14,1986. |
| 6 |
% You may use this file in whatever way you wish. You are requested to |
| 7 |
% leave this notice intact, and report any bugs, enhancements, comments, |
| 8 |
% suggestions, etc. to: |
| 9 |
% USmail: Sunil Podar,Dept. of Computer Science,SUNY at Stony Brook,NY 11794. |
| 10 |
% CSNET: [email protected] |
| 11 |
% ARPA: podar%[email protected] |
| 12 |
% UUCP: {allegra, hocsd, philabs, ogcvax}!sbcs!podar |
| 13 |
%---------------------------------------------------------------------- |
| 14 |
% This file contains implementation of: |
| 15 |
% \multiputlist \matrixput \grid \picsquare |
| 16 |
% \dottedline \dashline \drawline \jput |
| 17 |
% \putfile |
| 18 |
% Environments: dottedjoin, dashjoin and drawjoin |
| 19 |
% |
| 20 |
% For documentation, see the accompanying manual. |
| 21 |
%---------------------------------------------------------------------- |
| 22 |
% usage: \multiputlist(x,y)(delta-x,delta-y)[tbrl]{item1,item2,item3,.....} |
| 23 |
% \lop and \lopoff taken from TeXbook. |
| 24 |
%---------------------------------------------------------------------- |
| 25 |
\def\lop#1\to#2{\expandafter\lopoff#1\lopoff#1#2} |
| 26 |
\long\def\lopoff,#1,#2\lopoff#3#4{\def#4{#1}\def#3{,#2}} |
| 27 |
\def\@@mlistempty{,} |
| 28 |
\newif\iflistnonempty |
| 29 |
\def\multiputlist(#1,#2)(#3,#4){\@ifnextchar |
| 30 |
[{\@imultiputlist(#1,#2)(#3,#4)}{\@imultiputlist(#1,#2)(#3,#4)[]}} |
| 31 |
|
| 32 |
\long\def\@imultiputlist(#1,#2)(#3,#4)[#5]#6{{% |
| 33 |
\@xdim=#1\unitlength \@ydim=#2\unitlength |
| 34 |
\listnonemptytrue \def\@@mlist{,#6,} % need this for end condition |
| 35 |
\loop |
| 36 |
\lop\@@mlist\to\@@firstoflist |
| 37 |
\@killglue\raise\@ydim\hbox to\z@{\hskip |
| 38 |
\@xdim\@imakepicbox(0,0)[#5]{\@@firstoflist}\hss} |
| 39 |
\advance\@xdim #3\unitlength\advance\@ydim #4\unitlength |
| 40 |
\ifx\@@mlist\@@mlistempty \listnonemptyfalse\fi |
| 41 |
\iflistnonempty |
| 42 |
\repeat\relax |
| 43 |
\ignorespaces}} |
| 44 |
%---------------------------------------------------------------------- |
| 45 |
% two-dimensional version of \multiput |
| 46 |
% \matrixput(0,0)(20,0){5}(0,20){3}{\circle{2}} |
| 47 |
%---------------------------------------------------------------------- |
| 48 |
\newcount\@@multicnt |
| 49 |
\def\matrixput(#1,#2)(#3,#4)#5(#6,#7)#8#9{% |
| 50 |
\ifnum#5>#8\@matrixput(#1,#2)(#3,#4){#5}(#6,#7){#8}{#9}% |
| 51 |
\else\@matrixput(#1,#2)(#6,#7){#8}(#3,#4){#5}{#9}\fi} |
| 52 |
|
| 53 |
%% here #5 >= #8 |
| 54 |
\long\def\@matrixput(#1,#2)(#3,#4)#5(#6,#7)#8#9{{\@killglue% |
| 55 |
\@multicnt=#5\relax\@@multicnt=#8\relax% |
| 56 |
\@xdim=0pt% |
| 57 |
\@ydim=0pt% |
| 58 |
\setbox\@tempboxa\hbox{\@whilenum \@multicnt > 0\do {% |
| 59 |
%%\typeout{\the\@multicnt, \the\@@multicnt}% |
| 60 |
\raise\@ydim\hbox to \z@{\hskip\@xdim #9\hss}% |
| 61 |
\advance\@multicnt \m@ne% |
| 62 |
\advance\@xdim #3\unitlength\advance\@ydim #4\unitlength}}% |
| 63 |
\@xdim=#1\unitlength% |
| 64 |
\@ydim=#2\unitlength% |
| 65 |
\@whilenum \@@multicnt > 0\do {% |
| 66 |
\raise\@ydim\hbox to \z@{\hskip\@xdim \copy\@tempboxa\hss}% |
| 67 |
\advance\@@multicnt \m@ne% |
| 68 |
\advance\@xdim #6\unitlength\advance\@ydim #7\unitlength}% |
| 69 |
\ignorespaces}} |
| 70 |
%---------------------------------------------------------------------- |
| 71 |
%\grid(wd,ht)(delta-wd,delta-ht)[initial-X-integer,initial-Y-integer] |
| 72 |
% example: 1. \put(0,0){\grid(95,100)(9.5,10)} |
| 73 |
% 2. \put(0,0){\grid(100,100)(10,5)[-10,0]} |
| 74 |
% or \put(0,0){\tiny \grid(100,100)(5,5)[0,0]}%numbers in \tiny font |
| 75 |
%---------------------------------------------------------------------- |
| 76 |
\newcount\d@lta |
| 77 |
\newdimen\@delta |
| 78 |
\newdimen\@@delta |
| 79 |
\newcount\@gridcnt |
| 80 |
\def\grid(#1,#2)(#3,#4){\@ifnextchar [{\@igrid(#1,#2)(#3,#4)}% |
| 81 |
{\@igrid(#1,#2)(#3,#4)[@,@]}} |
| 82 |
|
| 83 |
\long\def\@igrid(#1,#2)(#3,#4)[#5,#6]{% |
| 84 |
\makebox(#1,#2){% |
| 85 |
\@delta=#1pt\@@delta=#3pt\divide\@delta \@@delta\d@lta=\@delta% |
| 86 |
\advance\d@lta \@ne\relax\message{grid=\the\d@lta\space x}% |
| 87 |
%% copied the definition of \line(0,1){#2} for some efficiency!. |
| 88 |
\multiput(0,0)(#3,0){\d@lta}{\hbox to\z@{\hskip -\@halfwidth \vrule |
| 89 |
\@width \@wholewidth \@height #2\unitlength \@depth \z@\hss}}% |
| 90 |
\ifx#5@\relax\else% |
| 91 |
\global\@gridcnt=#5% |
| 92 |
\multiput(0,0)(#3,0){\d@lta}{% |
| 93 |
\makebox(0,-2)[t]{\number\@gridcnt\global\advance\@gridcnt by #3}}% |
| 94 |
\global\@gridcnt=#5% |
| 95 |
\multiput(0,#2)(#3,0){\d@lta}{\makebox(0,0)[b]{\number\@gridcnt\vspace{2mm}% |
| 96 |
\global\advance\@gridcnt by #3}}% |
| 97 |
\fi% |
| 98 |
\@delta=#2pt\@@delta=#4pt\divide\@delta \@@delta\d@lta=\@delta% |
| 99 |
\advance\d@lta \@ne\relax\message{\the\d@lta . }% |
| 100 |
%% copied the definition of \line(1,0){#1} for some efficiency!. |
| 101 |
\multiput(0,0)(0,#4){\d@lta}{\vrule \@height \@halfwidth \@depth \@halfwidth |
| 102 |
\@width #1\unitlength}% |
| 103 |
\ifx#6@\relax\else |
| 104 |
\global\@gridcnt=#6% |
| 105 |
\multiput(0,0)(0,#4){\d@lta}{% |
| 106 |
\makebox(0,0)[r]{\number\@gridcnt\ \global\advance\@gridcnt by #4}}% |
| 107 |
\global\@gridcnt=#6% |
| 108 |
\multiput(#1,0)(0,#4){\d@lta}{% |
| 109 |
\makebox(0,0)[l]{\ \number\@gridcnt\global\advance\@gridcnt by #4}}% |
| 110 |
\fi}} |
| 111 |
%---------------------------------------------------------------------- |
| 112 |
% \picsquare is a centered square of dimensions governed by \thinlines, |
| 113 |
% \thicklines or \linethickness declarations. |
| 114 |
\def\picsquare{\hskip -0.5\@wholewidth% |
| 115 |
\vrule height \@halfwidth depth \@halfwidth width \@wholewidth} |
| 116 |
% |
| 117 |
% just a square dot with reference point at bottom-left |
| 118 |
\def\picsquare@bl{\vrule height \@wholewidth depth \z@ width \@wholewidth} |
| 119 |
%---------------------------------------------------------------------- |
| 120 |
% \begin{dottedjoin}{interdot-gap in units} |
| 121 |
% ..... |
| 122 |
% \end{dottedjoin} |
| 123 |
% \begin{dashjoin}{dash-length in units}{interdotgap in each dash} |
| 124 |
% ..... |
| 125 |
% \end{dashjoin} |
| 126 |
% \begin{drawjoin} |
| 127 |
% ..... |
| 128 |
% \end{drawjoin} |
| 129 |
% \jput(x,y){character} |
| 130 |
% \dottedline[opt. dotcharacter]{dotgap in units}(x1,y1)(x2,y2)...(xN,yN) |
| 131 |
% \dashline[#]{dash-length}[opt. dotgap](x1,y1)(x2,y2)...(xN,yN) |
| 132 |
% \drawline[#](x1,y1)(x2,y2)...(xN,yN) |
| 133 |
%---------------------------------------------------------------------- |
| 134 |
% definitions for *join environment. had to do all this mess because of |
| 135 |
% optional arguments. |
| 136 |
%---------------------------------------------------------------------- |
| 137 |
\newif\if@jointhem \global\@jointhemfalse |
| 138 |
\newif\if@firstpoint \global\@firstpointtrue |
| 139 |
\newcount\@joinkind |
| 140 |
%\newenvironment{dottedjoin}[1]%[opt char]{dotgap} |
| 141 |
%{\global\@jointhemtrue \gdef\dotgap@join{#1}\global\@joinkind=0\relax}% |
| 142 |
%{\global\@jointhemfalse \global\@firstpointtrue} |
| 143 |
%---------------------------------------------------------------------- |
| 144 |
\def\dottedjoin{\global\@jointhemtrue \global\@joinkind=0\relax |
| 145 |
\bgroup\@ifnextchar[{\@idottedjoin}{\@idottedjoin[\picsquare@bl]}} |
| 146 |
\def\@idottedjoin[#1]#2{\gdef\dotchar@join{#1}\gdef\dotgap@join{#2}} |
| 147 |
\def\enddottedjoin{\global\@jointhemfalse \global\@firstpointtrue\egroup} |
| 148 |
%---------------------------------------------------------------------- |
| 149 |
\def\dashjoin{\global\@jointhemtrue \global\@joinkind=1\relax |
| 150 |
\bgroup\@ifnextchar[{\@idashjoin}{\@idashjoin[\dashlinestretch]}} |
| 151 |
\def\@idashjoin[#1]#2{\edef\dashlinestretch{#1}\gdef\dashlen@join{#2}% |
| 152 |
\@ifnextchar[{\@iidashjoin}{\gdef\dotgap@join{}}} |
| 153 |
\def\@iidashjoin[#1]{\gdef\dotgap@join{#1}} |
| 154 |
\let\enddashjoin\enddottedjoin |
| 155 |
%---------------------------------------------------------------------- |
| 156 |
\def\drawjoin{\global\@jointhemtrue \global\@joinkind=2\relax |
| 157 |
\bgroup\@ifnextchar[{\@idrawjoin}{}} |
| 158 |
\def\@idrawjoin[#1]{\def\drawlinestretch{#1}} |
| 159 |
\let\enddrawjoin\enddottedjoin |
| 160 |
%---------------------------------------------------------------------- |
| 161 |
%% this is equiv to \put(x,y){#1} when not in {dot*join} environment. |
| 162 |
\long\def\jput(#1,#2)#3{{\@killglue\raise#2\unitlength\hbox to \z@{\hskip |
| 163 |
#1\unitlength #3\hss}\ignorespaces} |
| 164 |
\if@jointhem |
| 165 |
\if@firstpoint \gdef\x@one{#1} \gdef\y@one{#2} \global\@firstpointfalse |
| 166 |
\else\ifcase\@joinkind |
| 167 |
\@dottedline[\dotchar@join]{\dotgap@join\unitlength}% |
| 168 |
(\x@one\unitlength,\y@one\unitlength)(#1\unitlength,#2\unitlength) |
| 169 |
\or\@dashline[\dashlinestretch]{\dashlen@join}[\dotgap@join]% |
| 170 |
(\x@one,\y@one)(#1,#2) |
| 171 |
\else\@drawline[\drawlinestretch](\x@one,\y@one)(#1,#2)\fi |
| 172 |
\gdef\x@one{#1} \gdef\y@one{#2} |
| 173 |
\fi |
| 174 |
\fi} |
| 175 |
%---------------------------------------------------------------------- |
| 176 |
\newdimen\@dotgap |
| 177 |
\newdimen\@ddotgap |
| 178 |
\newcount\@x@diff |
| 179 |
\newcount\@y@diff |
| 180 |
\newdimen\x@diff |
| 181 |
\newdimen\y@diff |
| 182 |
\newbox\@dotbox |
| 183 |
\newcount\num@segments |
| 184 |
\newcount\num@segmentsi |
| 185 |
\newif\ifsqrt@done |
| 186 |
%% from sqrtandstuff func basically need \num@segments. |
| 187 |
%% given a deltax, deltay and dotgap, it calculates \num@segments = number of |
| 188 |
%% segments along the hypotenuse. used by \dottedline & \dashline. |
| 189 |
%% It finishes quickly if any of deltax or deltay are zero or close to zero. |
| 190 |
\def\sqrtandstuff#1#2#3{ |
| 191 |
\ifdim #1 <0pt \@x@diff= -#1 \else\@x@diff=#1\fi |
| 192 |
\ifdim #2 <0pt \@y@diff= -#2 \else\@y@diff=#2\fi |
| 193 |
%% @diff's will be positive and diff's will retain their sign. |
| 194 |
\@dotgap=#3 \divide\@dotgap \tw@ |
| 195 |
\advance\@x@diff \@dotgap \advance\@y@diff \@dotgap% for round-off errors |
| 196 |
\@dotgap=#3 |
| 197 |
\divide\@x@diff \@dotgap \divide\@y@diff \@dotgap |
| 198 |
\sqrt@donefalse |
| 199 |
\ifnum\@x@diff < 2 |
| 200 |
\ifnum\@y@diff < 2 \num@segments=\@x@diff \advance\num@segments \@y@diff |
| 201 |
\sqrt@donetrue |
| 202 |
\else\num@segments=\@y@diff \sqrt@donetrue\fi |
| 203 |
\else\ifnum\@y@diff < 2 \num@segments=\@x@diff \sqrt@donetrue\fi |
| 204 |
\fi |
| 205 |
\ifsqrt@done \ifnum\num@segments=\z@ \num@segments=\@ne\fi\relax |
| 206 |
\else \ifnum\@y@diff >\@x@diff |
| 207 |
\@tempcnta=\@x@diff \@x@diff=\@y@diff \@y@diff=\@tempcnta |
| 208 |
\fi %exchange @x@diff & @y@diff, so now @x@diff > @y@diff |
| 209 |
\num@segments=\@y@diff |
| 210 |
\multiply\num@segments \num@segments |
| 211 |
\multiply\num@segments by 457 |
| 212 |
\divide\num@segments \@x@diff |
| 213 |
\advance\num@segments by 750 % for round-off, going to divide by 1000. |
| 214 |
\divide\num@segments \@m |
| 215 |
\advance\num@segments \@x@diff |
| 216 |
%num@segments = @x@diff + (0.457*sqr(@y@diff)/@x@diff) |
| 217 |
\fi} |
| 218 |
%---------------------------------------------------------------------- |
| 219 |
% \dottedline[opt. char]{interdot gap in units}(x1,y1)(x2,y2)....(xN,yN) |
| 220 |
%---------------------------------------------------------------------- |
| 221 |
%% Used the following construction earlier but that results in box memory |
| 222 |
%% full much too soon although it works perfectly. |
| 223 |
%% \setbox\@dotbox\vbox to\z@{\vss \hbox to\z@{\hss #1\hss}\vss}\relax} |
| 224 |
%% The cenetering of characters is achieved by substracting half the ht, wd |
| 225 |
%% of character from the (x,y) coordinates where they are to be put. We |
| 226 |
%% chose to use a macro for the ``dot'' instead of \copy\box to save memory |
| 227 |
%% at the expense of extra cpu, since memory becomes an issue very soon. |
| 228 |
%% \picsquare is already centered, whereas other characters, except \circle, |
| 229 |
%% will not be cenetered, hence to handle them all in a similar fashion, |
| 230 |
%% used \picsquare@bl. |
| 231 |
% |
| 232 |
% kind of tail recursion. |
| 233 |
\def\dottedline{\@ifnextchar [{\@idottedline}{\@idottedline[\picsquare@bl]}} |
| 234 |
\def\@idottedline[#1]#2(#3,#4){\@ifnextchar (% |
| 235 |
{\@iidottedline[#1]{#2}(#3,#4)}{\relax}} |
| 236 |
\def\@iidottedline[#1]#2(#3,#4)(#5,#6){\@dottedline[#1]{#2\unitlength}% |
| 237 |
(#3\unitlength,#4\unitlength)(#5\unitlength,#6\unitlength)% |
| 238 |
\@idottedline[#1]{#2}(#5,#6)} |
| 239 |
% |
| 240 |
%% user not supposed to use this directly. arguments in absolute dimensions. |
| 241 |
%% need to pass absolute dimens here because dashline calls dottedline and |
| 242 |
%% can supply only absolute dimensions. |
| 243 |
\long\def\@dottedline[#1]#2(#3,#4)(#5,#6){{% |
| 244 |
\x@diff=#5\relax\advance\x@diff by -#3\relax |
| 245 |
\y@diff=#6\relax\advance\y@diff by -#4\relax |
| 246 |
\sqrtandstuff{\x@diff}{\y@diff}{#2} |
| 247 |
\divide\x@diff \num@segments |
| 248 |
\divide\y@diff \num@segments |
| 249 |
\advance\num@segments \@ne % to put the last point at destination. |
| 250 |
%%\typeout{num@segments= \the\num@segments} |
| 251 |
\setbox\@dotbox\hbox{#1}% just to get the dimensions of the character. |
| 252 |
\@xdim=#3 \@ydim=#4 |
| 253 |
\ifdim\ht\@dotbox >\z@% otherwise its a circle. |
| 254 |
\advance\@xdim -0.5\wd\@dotbox |
| 255 |
\advance\@ydim -0.5\ht\@dotbox |
| 256 |
\advance\@ydim .5\dp\@dotbox\fi |
| 257 |
%%circle's have a ht=0, this is one way I could think of to catch circles. |
| 258 |
%%following loop is equiv to |
| 259 |
%%\multiput(\@xdim,\@ydim)(\x@diff,\y@diff){\num@segments}{#1} |
| 260 |
%%with arguments in absolute dimensions. |
| 261 |
\@killglue |
| 262 |
\loop \ifnum\num@segments > 0 |
| 263 |
\unskip\raise\@ydim\hbox to\z@{\hskip\@xdim #1\hss}% |
| 264 |
\advance\num@segments \m@ne\advance\@xdim\x@diff\advance\@ydim\y@diff% |
| 265 |
\repeat |
| 266 |
\ignorespaces}} |
| 267 |
%---------------------------------------------------------------------- |
| 268 |
% \dashline[#]{dash-length}[optional dotgap](x1,y1)(x2,y2)...(xN,yN) |
| 269 |
% The minimum # of dashes put is 2, one at either end point; dash-length is |
| 270 |
% reduced accordingly if necessary. Also have to some dirty work to account |
| 271 |
% for stretch & shrink. |
| 272 |
% \renewcommand{\dashlinestretch}{-50} %ONLY INTEGERS PERMITTED. |
| 273 |
%---------------------------------------------------------------------- |
| 274 |
\def\dashlinestretch{0} %well, could have used a counter. |
| 275 |
\def\dashline{\@ifnextchar [{\@idashline}{\@idashline[\dashlinestretch]}} |
| 276 |
\def\@idashline[#1]#2{\@ifnextchar [{\@iidashline[#1]{#2}}% |
| 277 |
{\@iidashline[#1]{#2}[\@empty]}} %\@empty needed-- later checked with \ifx |
| 278 |
\def\@iidashline[#1]#2[#3](#4,#5){\@ifnextchar (% |
| 279 |
{\@iiidashline[#1]{#2}[#3](#4,#5)}{\relax}} |
| 280 |
% |
| 281 |
\def\@iiidashline[#1]#2[#3](#4,#5)(#6,#7){% |
| 282 |
\@dashline[#1]{#2}[#3](#4,#5)(#6,#7)% |
| 283 |
\@iidashline[#1]{#2}[#3](#6,#7)} |
| 284 |
% |
| 285 |
\long\def\@dashline[#1]#2[#3](#4,#5)(#6,#7){{% |
| 286 |
\x@diff=#6\unitlength \advance\x@diff by -#4\unitlength |
| 287 |
\y@diff=#7\unitlength \advance\y@diff by -#5\unitlength |
| 288 |
%% correction to get actual width since the dash-length as taken in arguement |
| 289 |
%% is the center-to-center of the end-points. |
| 290 |
\@tempdima=#2\unitlength \advance\@tempdima -\@wholewidth |
| 291 |
\sqrtandstuff{\x@diff}{\y@diff}{\@tempdima} |
| 292 |
\ifnum\num@segments <3 \num@segments=3\fi% min number of dashes I can plot |
| 293 |
% is 2, 1 at either end, thus min num@segments is 3 (including 'empty dash'). |
| 294 |
\@tempdima=\x@diff \@tempdimb=\y@diff |
| 295 |
\divide\@tempdimb by\num@segments |
| 296 |
\divide\@tempdima by\num@segments |
| 297 |
%% ugly if-then-else. If optional dotgap specified, then use it otherwise |
| 298 |
%% make a solid looking dash. |
| 299 |
{\ifx#3\@empty \relax |
| 300 |
\ifdim\@tempdima < 0pt \x@diff=-\@tempdima\else\x@diff=\@tempdima\fi |
| 301 |
\ifdim\@tempdimb < 0pt \y@diff=-\@tempdimb\else\y@diff=\@tempdimb\fi |
| 302 |
\ifdim\x@diff < 0.3pt %it's a vertical dashline |
| 303 |
\ifdim\@tempdimb > 0pt |
| 304 |
\global\setbox\@dotbox\hbox{\hskip -\@halfwidth \vrule |
| 305 |
\@width \@wholewidth \@height \@tempdimb} |
| 306 |
\else\global\setbox\@dotbox\hbox{\hskip -\@halfwidth \vrule |
| 307 |
\@width \@wholewidth \@height\z@ \@depth -\@tempdimb}\fi |
| 308 |
\else\ifdim\y@diff < 0.3pt %it's a horizontal dashline |
| 309 |
\ifdim\@tempdima >0pt |
| 310 |
\global\setbox\@dotbox\hbox{\vrule \@height \@halfwidth |
| 311 |
\@depth \@halfwidth \@width \@tempdima} |
| 312 |
\else\global\setbox\@dotbox\hbox{\hskip \@tempdima |
| 313 |
\vrule \@height \@halfwidth \@depth \@halfwidth |
| 314 |
\@width -\@tempdima \hskip \@tempdima}\fi |
| 315 |
\else\global\setbox\@dotbox\hbox{% |
| 316 |
\@dottedline[\picsquare]{0.98\@wholewidth}(0pt,0pt)(\@tempdima,\@tempdimb)} |
| 317 |
\fi\fi |
| 318 |
\else\global\setbox\@dotbox\hbox{% |
| 319 |
\@dottedline[\picsquare]{#3\unitlength}(0pt,0pt)(\@tempdima,\@tempdimb)} |
| 320 |
\fi} |
| 321 |
\advance\x@diff by -\@tempdima % both have same sign |
| 322 |
\advance\y@diff by -\@tempdimb |
| 323 |
% |
| 324 |
%%here we correct the number of dashes to be put by reducing them |
| 325 |
%%appropriately. (num@segments*\@wholewidth) is in some way the slack we |
| 326 |
%%have,and division by dash-length gives the reduction. reduction = |
| 327 |
%%(2*num@segments*\@wholewidth)/dash-length |
| 328 |
%% (num@segments includes empty ones) |
| 329 |
\@tempdima=\num@segments\@wholewidth \@tempdima=2\@tempdima |
| 330 |
\@tempcnta=\@tempdima \@tempdima=#2\unitlength \@tempdimb=0.5\@tempdima |
| 331 |
\@tempcntb=\@tempdimb \advance\@tempcnta by \@tempcntb % round-off error |
| 332 |
\divide\@tempcnta by\@tempdima \advance\num@segments by -\@tempcnta |
| 333 |
% |
| 334 |
\ifnum #1=0 \relax\else\ifnum #1 < -100 |
| 335 |
\typeout{***dashline: reduction > -100 percent implies blankness!***} |
| 336 |
\else\num@segmentsi=#1 \advance\num@segmentsi by 100 |
| 337 |
\multiply\num@segments by\num@segmentsi \divide\num@segments by 100 |
| 338 |
\fi\fi |
| 339 |
% |
| 340 |
\divide\num@segments by 2 % earlier num@segments included 'empty dashes' too. |
| 341 |
\ifnum\num@segments >0 % if =0 then don't divide => \x@diff & \y@diff |
| 342 |
\divide\x@diff by\num@segments% remain same. |
| 343 |
\divide\y@diff by\num@segments |
| 344 |
\advance\num@segments by\@ne %for the last segment for which I subtracted |
| 345 |
%\@tempdima & \@tempdimb from \x@diff & \y@diff |
| 346 |
\else\num@segments=2 % one at each end. |
| 347 |
\fi |
| 348 |
%%\typeout{num@segments finally = \the\num@segments} |
| 349 |
%% equiv to \multiput(#4,#5)(\x@diff,\y@diff){\num@segments}{\copy\@dotbox} |
| 350 |
%% with arguements in absolute dimensions. |
| 351 |
\@xdim=#4\unitlength \@ydim=#5\unitlength |
| 352 |
\@killglue |
| 353 |
\loop \ifnum\num@segments > 0 |
| 354 |
\unskip\raise\@ydim\hbox to\z@{\hskip\@xdim \copy\@dotbox\hss}% |
| 355 |
\advance\num@segments \m@ne\advance\@xdim\x@diff\advance\@ydim\y@diff% |
| 356 |
\repeat |
| 357 |
\ignorespaces}} |
| 358 |
%---------------------------------------------------------------------- |
| 359 |
%%1.00 .833333 .80 .75 .66666 .60 .50 .40 .33333 .25 .20 .16666 |
| 360 |
%% .916666 .816666 .775 .708333 .633333 .55 .45 .366666 .291666 .225 .183333 |
| 361 |
%% 0.0 |
| 362 |
%%0.083333 |
| 363 |
%% the first line has absolute slopes corresponding to various permissible |
| 364 |
%% integer combinations representing slopes. The second line is the midpoint |
| 365 |
%% of all those slopes (attempted to show them in the middle of two entries). |
| 366 |
%% |
| 367 |
%% \lineslope(x@diff dimen, y@diff dimen) |
| 368 |
%% Given base (x@diff) and height (y@diff) in dimensions, determines the |
| 369 |
%% closest available slope and returns the two required integers in \@xarg |
| 370 |
%% and \@yarg. The given base and height can be ANYTHING, -ve or +ve, or |
| 371 |
%% even 0pt. \lineslope knows about (0,1) and (1,0) slopes too and returns |
| 372 |
%% correct values if the conditions regarding x@diff & y@diff are obeyed |
| 373 |
%% (see NOTE). Used by \drawline. This is the simplest and only way I could |
| 374 |
%% figure out to accomplish it!. |
| 375 |
%% NOTE: both the dimensions (x@diff & y@diff) must be in SAME units and the |
| 376 |
%% larger of the two dimensions must be atleast 1pt (i.e. 65536sp). To avoid |
| 377 |
%% dividing by 0, I make the larger dimension = 1pt if it is < 1pt. |
| 378 |
%% will need a similar one for vectors, or maybe this can be used. For |
| 379 |
%% vectors the range is -4, 4 unlike lines where it is -6, 6. |
| 380 |
\newif\if@flippedargs |
| 381 |
\def\lineslope(#1,#2){% |
| 382 |
\ifdim #1 <0pt \@xdim= -#1 \else\@xdim=#1\fi |
| 383 |
\ifdim #2 <0pt \@ydim= -#2 \else\@ydim=#2\fi |
| 384 |
%%\typeout{xdim,ydim= \the\@xdim, \the\@ydim} |
| 385 |
\ifdim\@xdim >\@ydim \@tempdima=\@xdim \@xdim=\@ydim \@ydim=\@tempdima |
| 386 |
\@flippedargstrue\else\@flippedargsfalse\fi% x < y |
| 387 |
\ifdim\@ydim >1pt \@tempcnta=\@ydim |
| 388 |
\divide\@tempcnta by 65536% now \@tempcnta=integral part of #1. |
| 389 |
\divide\@xdim \@tempcnta\fi |
| 390 |
\ifdim\@xdim <.083333pt \@xarg=1 \@yarg=0 |
| 391 |
\else\ifdim\@xdim <.183333pt \@xarg=6 \@yarg=1 |
| 392 |
\else\ifdim\@xdim <.225pt \@xarg=5 \@yarg=1 |
| 393 |
\else\ifdim\@xdim <.291666pt \@xarg=4 \@yarg=1 |
| 394 |
\else\ifdim\@xdim <.366666pt \@xarg=3 \@yarg=1 |
| 395 |
\else\ifdim\@xdim <.45pt \@xarg=5 \@yarg=2 |
| 396 |
\else\ifdim\@xdim <.55pt \@xarg=2 \@yarg=1 |
| 397 |
\else\ifdim\@xdim <.633333pt \@xarg=5 \@yarg=3 |
| 398 |
\else\ifdim\@xdim <.708333pt \@xarg=3 \@yarg=2 |
| 399 |
\else\ifdim\@xdim <.775pt \@xarg=4 \@yarg=3 |
| 400 |
\else\ifdim\@xdim <.816666pt \@xarg=5 \@yarg=4 |
| 401 |
\else\ifdim\@xdim <.916666pt \@xarg=6 \@yarg=5 |
| 402 |
\else \@xarg=1 \@yarg=1% |
| 403 |
\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi |
| 404 |
\if@flippedargs\relax\else\@tempcnta=\@xarg \@xarg=\@yarg |
| 405 |
\@yarg=\@tempcnta\fi |
| 406 |
\ifdim #1 <0pt \@xarg= -\@xarg\fi |
| 407 |
\ifdim #2 <0pt \@yarg= -\@yarg\fi |
| 408 |
%%\typeout{closest slope integers = \the\@xarg, \the\@yarg} |
| 409 |
} |
| 410 |
%---------------------------------------------------------------------- |
| 411 |
% usage: \drawline[#](x1,y1)(x2,y2)....(xN,yN) |
| 412 |
% % # is an optional integer between -100 & infinity. |
| 413 |
% \renewcommand{\drawlinestretch}{-50} %ONLY INTEGERS PERMITTED. |
| 414 |
%---------------------------------------------------------------------- |
| 415 |
\newif\if@toosmall |
| 416 |
\newif\if@drawit |
| 417 |
\newif\if@horvline |
| 418 |
\def\drawlinestretch{0} %well, could have used a counter. |
| 419 |
% kind of tail recursion. |
| 420 |
\def\drawline{\@ifnextchar [{\@idrawline}{\@idrawline[\drawlinestretch]}} |
| 421 |
\def\@idrawline[#1](#2,#3){\@ifnextchar ({\@iidrawline[#1](#2,#3)}{\relax}} |
| 422 |
\def\@iidrawline[#1](#2,#3)(#4,#5){\@drawline[#1](#2,#3)(#4,#5)% |
| 423 |
\@idrawline[#1](#4,#5)} |
| 424 |
% |
| 425 |
\def\@drawline[#1](#2,#3)(#4,#5){{% |
| 426 |
\x@diff=#4\unitlength \advance\x@diff by -#2\unitlength |
| 427 |
\y@diff=#5\unitlength \advance\y@diff by -#3\unitlength |
| 428 |
%% override any linethickness declarations, and since horiz & vertical lines |
| 429 |
%% come out thinner than the slanted ones, assign slightly larger values. |
| 430 |
%% default values are: thinlines=0.4pt, thicklines=0.8pt |
| 431 |
\ifx\@linefnt\tenln \linethickness{0.5pt} \else \linethickness{0.9pt}\fi |
| 432 |
\lineslope(\x@diff,\y@diff)% returns the two integers in \@xarg & \@yarg. |
| 433 |
%------ |
| 434 |
\@toosmalltrue |
| 435 |
{\ifdim\x@diff <\z@ \x@diff=-\x@diff\fi |
| 436 |
\ifdim\y@diff <\z@ \y@diff=-\y@diff\fi |
| 437 |
\ifdim\x@diff >10pt \global\@toosmallfalse\fi |
| 438 |
\ifdim\y@diff >10pt \global\@toosmallfalse\fi} |
| 439 |
%------ |
| 440 |
%% For efficiency, if the line is horiz or vertical then we draw it in one |
| 441 |
%% shot, only if the stretch is not -ve and the line is not too small. |
| 442 |
\@drawitfalse\@horvlinefalse |
| 443 |
\ifnum#1 <0 \relax\else\@horvlinetrue\fi |
| 444 |
\if@toosmall\@horvlinetrue\fi% to get 'or' condition. We necessarily draw a |
| 445 |
% solid line if the line is too small ignoring any -ve stretch. |
| 446 |
\if@horvline |
| 447 |
\ifdim\x@diff =0pt \put(#2,#3){\ifdim\y@diff >0pt \@linelen=\y@diff \@upline |
| 448 |
\else\@linelen=-\y@diff \@downline\fi}% |
| 449 |
\else\ifdim\y@diff =0pt |
| 450 |
\ifdim\x@diff >0pt \put(#2,#3){\vrule \@height \@halfwidth \@depth |
| 451 |
\@halfwidth \@width \x@diff} |
| 452 |
\else \put(#4,#5){\vrule \@height \@halfwidth \@depth |
| 453 |
\@halfwidth \@width -\x@diff}\fi |
| 454 |
\else\@drawittrue\fi\fi % construct the line explicitly |
| 455 |
\else\@drawittrue\fi |
| 456 |
%------------------------------- |
| 457 |
\if@drawit |
| 458 |
\ifnum\@xarg< 0 \@negargtrue\else\@negargfalse\fi |
| 459 |
\ifnum\@xarg =0 \setbox\@linechar% |
| 460 |
\hbox{\hskip -\@halfwidth \vrule \@width \@wholewidth \@height 10.2pt |
| 461 |
\@depth \z@} |
| 462 |
\else \ifnum\@yarg =0 \setbox\@linechar% |
| 463 |
\hbox{\vrule \@height \@halfwidth \@depth \@halfwidth \@width 10.2pt} |
| 464 |
\else \if@negarg \@xarg -\@xarg \@yyarg -\@yarg |
| 465 |
\else \@yyarg \@yarg\fi |
| 466 |
\ifnum\@yyarg >0 \@tempcnta\@yyarg \else \@tempcnta -\@yyarg\fi |
| 467 |
\setbox\@linechar\hbox{\@linefnt\@getlinechar(\@xarg,\@yyarg)}% |
| 468 |
\fi\fi |
| 469 |
%------ |
| 470 |
\if@toosmall% => it isn't a horiz or vert line and is toosmall. |
| 471 |
\@dottedline[\picsquare]{.98\@wholewidth}% |
| 472 |
(#2\unitlength,#3\unitlength)(#4\unitlength,#5\unitlength)% |
| 473 |
\else |
| 474 |
%% following is neat. The last segment takes \wd\@linechar & \ht\@linechar |
| 475 |
%% so plot the line as though it were from (#2,#3) to |
| 476 |
%% (#4-\wd\@linechar,#5-\ht\@linechar) (i.e. for positive slope; of course, |
| 477 |
%% signs are reversed for other slopes). For horizontal & vertical dashes we |
| 478 |
%% don't have to subtract the ht & wd resp. since they are already centered. |
| 479 |
\ifnum\@xarg=0\relax\else\ifdim\x@diff >\z@ \advance\x@diff -\wd\@linechar |
| 480 |
\else\advance\x@diff \wd\@linechar\fi\fi |
| 481 |
\ifnum\@yarg=0\relax\else\ifdim\y@diff >\z@\advance\y@diff -\ht\@linechar |
| 482 |
\else\advance\y@diff \ht\@linechar\fi\fi |
| 483 |
\ifdim\x@diff <\z@ \@x@diff=-\x@diff \else\@x@diff=\x@diff\fi |
| 484 |
\ifdim\y@diff <\z@ \@y@diff=-\y@diff \else\@y@diff=\y@diff\fi |
| 485 |
%%\typeout{x@diff,y@diff=\the\x@diff , \the\y@diff} |
| 486 |
\num@segments=0 \num@segmentsi=0 |
| 487 |
\ifdim\wd\@linechar >1pt |
| 488 |
\num@segmentsi=\@x@diff \divide\num@segmentsi \wd\@linechar\fi |
| 489 |
\ifdim\ht\@linechar >1pt |
| 490 |
\num@segments=\@y@diff \divide\num@segments \ht\@linechar\fi |
| 491 |
\ifnum\num@segmentsi >\num@segments \num@segments=\num@segmentsi\fi |
| 492 |
\advance\num@segments \@ne %to account for round-off error |
| 493 |
% |
| 494 |
\ifnum #1=0 \relax \else\ifnum #1 < -99 |
| 495 |
\typeout{***drawline: reduction <= -100 percent implies blankness!***} |
| 496 |
\else\num@segmentsi=#1 \advance\num@segmentsi by 100 |
| 497 |
\multiply\num@segments \num@segmentsi |
| 498 |
\divide\num@segments by 100 |
| 499 |
\ifnum \num@segments=0 \num@segments=1 \fi |
| 500 |
\fi\fi |
| 501 |
%%\typeout{num@segments after = \the\num@segments} |
| 502 |
% |
| 503 |
\divide\x@diff \num@segments |
| 504 |
\divide\y@diff \num@segments |
| 505 |
\advance\num@segments \@ne %for the last segment for which I subtracted |
| 506 |
%\wd & \ht of \@linechar from \@x@diff & \@y@diff. |
| 507 |
%%\typeout{numseg,x@diff,y@diff= \the\num@segments, \the\x@diff, \the\y@diff} |
| 508 |
% |
| 509 |
\@xdim=#2\unitlength \@ydim=#3\unitlength |
| 510 |
\if@negarg \advance\@xdim -\wd\@linechar\fi |
| 511 |
\ifnum\@yarg <0 \advance\@ydim -\ht\@linechar\fi |
| 512 |
%%following loop equiv to \multiput@abs(\@xdim,\@ydim)% |
| 513 |
%%(\x@diff,\y@diff){\num@segments}{\copy\@linechar} |
| 514 |
%%with arguements in absolute dimensions. |
| 515 |
\@killglue |
| 516 |
\loop \ifnum\num@segments > 0 |
| 517 |
\unskip\raise\@ydim\hbox to\z@{\hskip\@xdim \copy\@linechar\hss}% |
| 518 |
\advance\num@segments \m@ne\advance\@xdim\x@diff\advance\@ydim\y@diff% |
| 519 |
\repeat |
| 520 |
\ignorespaces |
| 521 |
\fi%the if of @toosmall |
| 522 |
\fi}}% for \if@drawit |
| 523 |
%---------------------------------------------------------------------- |
| 524 |
%usage: \putfile{datafile}{OBJECT} |
| 525 |
% The OBJECT is plotted at EACH of the coordinates read from the datafile. |
| 526 |
% The idea of these macros is to generate (x,y) pairs using some program |
| 527 |
% and then directly use those coordinates. Since TeX doesn't have real |
| 528 |
% floating point calculations, it is much more efficient and accurate to do |
| 529 |
% things this way. One can also use the unix facility 'spline' now to |
| 530 |
% generate smooth curves with equidistant ``dots''. |
| 531 |
% NOTE: the external file of coordinates must have x y pairs with a space |
| 532 |
% between them. Also it is suggested that some extension such as '.put' |
| 533 |
% be used for such datafiles to distinguish them in which case it must |
| 534 |
% be explicitely specified in the 1st argument so that TeX doesn't look |
| 535 |
% for a .tex extension. |
| 536 |
% The % char remains valid as a comment char and such lines are ignored; |
| 537 |
% however, there should be atleast one space after the second entry if a |
| 538 |
% comment is on the same line as data since % eats up the newline. |
| 539 |
%----------------------------------------------------------------------- |
| 540 |
\long\def\splittwoargs#1 #2 {(#1,#2)} |
| 541 |
% |
| 542 |
\newif\if@stillmore |
| 543 |
\newread\@datafile |
| 544 |
\long\def\putfile#1#2{\openin\@datafile = #1 |
| 545 |
\@stillmoretrue |
| 546 |
\loop |
| 547 |
\ifeof\@datafile\relax\else\read\@datafile to\@dataline\fi |
| 548 |
%if file nonexistent, do nothing. |
| 549 |
\ifeof\@datafile\@stillmorefalse |
| 550 |
\else\ifx\@dataline\@empty \relax |
| 551 |
\else |
| 552 |
\expandafter\expandafter\expandafter\put\expandafter\splittwoargs% |
| 553 |
\@dataline{#2} |
| 554 |
\fi |
| 555 |
\fi |
| 556 |
\if@stillmore |
| 557 |
\repeat |
| 558 |
\closein\@datafile |
| 559 |
} |
| 560 |
%---------------------------------------------------------------------- |
| 561 |
\makeatother |