diff options
Diffstat (limited to 'Master/texmf-dist/tex/generic/texdraw/texdraw.tex')
-rw-r--r-- | Master/texmf-dist/tex/generic/texdraw/texdraw.tex | 263 |
1 files changed, 149 insertions, 114 deletions
diff --git a/Master/texmf-dist/tex/generic/texdraw/texdraw.tex b/Master/texmf-dist/tex/generic/texdraw/texdraw.tex index e55c754bc52..a326538bd6a 100644 --- a/Master/texmf-dist/tex/generic/texdraw/texdraw.tex +++ b/Master/texmf-dist/tex/generic/texdraw/texdraw.tex @@ -1,6 +1,6 @@ % TeXdraw macros -% $Id: texdraw.tex,v 2.4 2019/03/28 texdraw-V2R0a $ +% $Id: texdraw.tex 2.7 2019/04/18 TeXdraw-v2r3 $ % Copyright (C) 1991-2019 Peter Kabal @@ -10,16 +10,14 @@ % Creative Commons, PO Box 1866, Mountain View, CA 94042, USA. % Peter Kabal -% Department of Electrical Engineering +% Department of Electrical & Computer Engineering % McGill University -% 3480 University -% Montreal, Quebec -% Canada H3A 2A7 % peter dot kabal at mcgill dot ca - +% http://www-mmsp.ece.mcgill.ca/MMSP/Documents/Software/ + \def\setRevDate $#1 #2 #3${#2} -\def\TeXdrawId{\setRevDate $Date: 2019/03/28 16:40:42 $ TeXdraw V2R0a} +\def\TeXdrawId{\setRevDate $Date: 2019/04/18 14:10:45 $ TeXdraw V2R3} % =============================================================== @@ -29,7 +27,7 @@ % superimposed on the figure. % (2) TeXdraw implements a \bsegment-\esegment environment which allows % parameter changes and coordinate changes to be kept local. In -% effect, these segments are self-contained relocatable procedures. +% effect these segments are self-contained relocatable procedures. % (3) TeX's macro facility can be used to modularize drawing units and % produce more complex entities from simple elements. % (4) The drawing can be positioned on the page like any other TeX box. @@ -78,12 +76,12 @@ \def\btexdraw {\x@pix=0 \y@pix=0 \x@segoffpix=\x@pix \y@segoffpix=\y@pix + \let\p@sfile=\p@sundef % Set the default values (define outside of the group so that \etexdraw can % see the scaling parameters) \t@exdrawdef \setbox\t@xdbox=\vbox\bgroup\offinterlineskip \global\d@bs=0 % pending segments - \global\t@extonlytrue % no PS commands yet \global\p@osinitfalse \s@avemove \x@pix \y@pix % capture the initial position \m@pendingfalse @@ -93,34 +91,40 @@ % ====== End TeXdraw % Write out a trailer, close the file, bring in the PostScript code as -% a \special include file. The \special is offset to position on the page -% to be (llx,ury) in PostScript coordinates. +% a \special include file. The \special is offset on the page to be at +% (llx,ury) in PostScript coordinates. % The drawing is placed in a \vbox of appropriate size (zero depth). The % temporary PostScript file is superimposed with offsets such that the % lower lefthand corner of the drawing is aligned with the lower lefthand of -% the box. Then, the position is temporarily offset to that corresponding -% to (0 0) to place the TeX text. Note that TeX text goes on top of the -% PostScript drawing. -\def\etexdraw {\ift@extonly \else - \t@drclose % close the PostScript file - \fi +% the box. +\def\etexdraw {\p@sclose % close the PostScript file \egroup % ends the \vbox \bgroup - \ifdim \wd\t@xdbox>0pt - \t@xderror {TeXdraw box non-zero size, - possible extraneous text}% - \fi \vbox {\offinterlineskip \pixtobp \xminpix \l@lxbp \pixtobp \yminpix \l@lybp \pixtobp \xmaxpix \u@rxbp \pixtobp \ymaxpix \u@rybp - \hbox{\t@xdinclude - [{\l@lxbp},{\l@lybp}][{\u@rxbp},{\u@rybp}]{\p@sfile}}% - \pixtodim \xminpix \t@xpos \pixtodim \yminpix \t@ypos - \kern \t@ypos - \hbox {\kern -\t@xpos - \box\t@xdbox % TeX text - \kern \t@xpos}% - \kern -\t@ypos\relax}} + \ifx\p@sfile\p@sundef + \hbox{\t@xdempty + [{\l@lxbp},{\l@lybp}][{\u@rxbp},{\u@rybp}]}% + \else + \hbox{\t@xdinclude + [{\l@lxbp},{\l@lybp}][{\u@rxbp},{\u@rybp}]{\p@sfile}}% + \fi + \t@xdtext}% +} +% Superimpose TeX text. The position is temporarily offset to a position +% corresponding to (0 0) to place the TeX text. +\def\t@xdtext { + \ifdim \wd\t@xdbox>0pt + \t@xderror {TeXdraw box non-zero size, possible extraneous text}% + \fi + \pixtodim \xminpix \t@xpos \pixtodim \yminpix \t@ypos + \kern \t@ypos + \hbox {\kern -\t@xpos + \box\t@xdbox % TeX text + \kern \t@xpos}% + \kern -\t@ypos\relax +} % ===== Drawing scaling % The units in any segment may be scaled arbitrarily. A unit scale is @@ -161,10 +165,10 @@ \f@lushmove \fi \begingroup - \x@segoffpix=\x@pix - \y@segoffpix=\y@pix - \setsegscale 1 - \global\advance \d@bs by 1\relax} + \x@segoffpix=\x@pix + \y@segoffpix=\y@pix + \setsegscale 1 + \global\advance \d@bs by 1\relax} \def\esegment {\endgroup \ifnum \d@bs=0 \writetx {es}% @@ -290,20 +294,20 @@ % Check if the argument starts with a left parenthesis \def\htext #1{\def\testit {#1}% \ifx \testit\l@paren - \let\next=\h@move + \let\t@cmd=\h@move \else - \let\next=\h@text + \let\t@cmd=\h@text \fi - \next {#1}} + \t@cmd {#1}} % Rotated text \def\rtext td:#1 #2{\def\testit {#2}% \ifx \testit\l@paren - \let\next=\r@move + \let\t@cmd=\r@move \else - \let\next=\r@text + \let\t@cmd=\r@text \fi - \next td:#1 {#2}} + \t@cmd td:#1 {#2}} % Vertical text \def\vtext {\rtext td:90 } @@ -626,7 +630,7 @@ % Need to be able to insert "%", "{" and "}" characters into the % PostScript file. % Define macros which have these characters with category "other". -% We will assume, that these characters have the standard meanings -- +% We will assume that these characters have the standard meanings - % after all, we use comments and braces in this code. \catcode`\%=12 \def\p@b {%!} \def\p@p {%%} @@ -693,8 +697,8 @@ \g@etargxy #2 #3 #4 \\#5#6% leading blank \else \def #6{#2}% - \def\next {#3}% - \ifx \next\empty \else + \def\a@rg {#3}% + \ifx \a@rg\empty \else \t@xderror {TeXdraw: invalid coordinate}% \fi \fi} @@ -725,8 +729,8 @@ % ===== Low level list decoding macros % Pick off the first item -> #3, rest of string -> #4 \def\g@etitem #1 #2\\#3#4{\edef #4{#2}\edef #3{#1}} -\def\a@pppix #1#2{\edef\next {#1}% - \ifx \next\empty \else +\def\a@pppix #1#2{\edef\a@rg {#1}% + \ifx \a@rg\empty \else \coordtopix {#1}\t@pixa \ifx #2\empty \edef #2{\the\t@pixa}% @@ -778,7 +782,7 @@ % Two flags are used. Both flags are local to a segment. % - move pending: Set when a move has been invoked but the move command -% has not been written out to the PostScript file +% has not been written out to the PostScript file. % - path in progress: Set when a PostScript path has been started but the % path has not been terminated and stroked. % (1) Moves are kept back. Using TeX's groups, a local flag and local @@ -862,7 +866,7 @@ % \ifp@osinit indicates whether the next move should be captured as the % initial values for \xminpix, \yminpix, \xmaxpix, and \ymaxpix. However, % if a \f@lushmove is invoked, then we assume that the appropriate initial -% values has already been set. The "mv" command in PostScript is defined +% values have already been set. The "mv" command in PostScript is defined % to stroke the current path (if any) and move to the pixel coordinates % specified. @@ -987,13 +991,26 @@ \advance \t@ypos by -#2 bp% \t@xpos=#3 bp% \advance \t@xpos by -#1 bp% - \dp0=0pt \ht0=\t@ypos \wd0=\t@xpos + \dp0=0pt \ht0=\t@ypos \wd0=\t@xpos \box0% \endgroup} \else \let\t@xdinclude=\includegraphics \fi +% Leave space without including a PS file +\def\t@xdempty [#1,#2][#3,#4]{% + \begingroup + \leavevmode + \setbox0=\hbox{}% + \t@ypos=#4 bp% + \advance \t@ypos by -#2 bp% + \t@xpos=#3 bp% + \advance \t@xpos by -#1 bp% + \dp0=0pt \ht0=\t@ypos \wd0=\t@xpos + \box0% + \endgroup} + % ===== Write to the PostScript file % Macro to write PostScript commands to the temporary PostScript file % To decrease the size of the PostScript file, moves are kept back to @@ -1008,76 +1025,94 @@ % only for those commands which just change line parameters % without drawing. This routine opens the file and writes the % PS file header the first time it is called. -% \w@rps : lowest level direct write to the PostScript file +% \p@swr : lowest level direct write to the PostScript file \def\writeps #1{\f@lushbs \f@lushmove \p@athtrue \writetx {#1}} -\def\writetx #1{\ift@extonly - \global\t@extonlyfalse - \t@xdpsfn \p@sfile - \t@dropen \p@sfile - \fi - \w@rps {#1}} -\def\w@rps #1{\immediate\write\drawfile {#1}} - -% ===== Open a PostScript file +\def\writetx #1{\p@sopen + \ifx\p@sfile\p@sundef \else + \p@swr {#1}% + \fi} +\def\p@swr #1{\immediate\write\drawfile {#1}} + +% ===== Open/Close a PostScript file % Open a PostScript file, write the definitions used by TeXdraw. -\def\t@xdpsfn #1{% - \global\advance \t@xdnum by 1 - \ifnum \t@xdnum<10 - \xdef #1{\jobname.ps\the\t@xdnum} - \else - \xdef #1{\jobname.p\the\t@xdnum} +\xdef\p@sundef{UnDeFiNeD} +\def\p@sopen {% + \ifx\p@sfile\p@sundef + \p@sopenI + \fi +} +% The code has a hook to avoid generating the PS file under certain +% circumstances. The amsmath package sometimes sets an expression twice, +% once to measure it and again to actually typeset it. In the first case, +% \ifmeasuring@ is set to true. For that setting, the PS file is not +% generated. +\def\p@sopenI {% + \ifx\ifmeasuring@\iftrue \else % \ifmeasuring@ undefined or false + \global\advance \t@xdnum by 1 + \ifnum \t@xdnum<10 + \xdef \p@sfile{\jobname.ps\the\t@xdnum}% + \else + \xdef \p@sfile{\jobname.p\the\t@xdnum}% + \fi + \t@xdopen \p@sfile + \fi +} + +\def\p@sclose { + \ifx\p@sfile\p@sundef \else + \t@xdclose \fi } -\def\t@dropen #1{% +\def\t@xdopen #1{% \immediate\openout\drawfile=#1% - \w@rps {\p@b PS-Adobe-3.0 EPSF-3.0}% - \w@rps {\p@p BoundingBox: (atend)}% - \w@rps {\p@p Title: TeXdraw drawing: #1}% - \w@rps {\p@p Pages: 1}% - \w@rps {\p@p Creator: \TeXdrawId}% - \w@rps {\p@p CreationDate: \the\year/\the\month/\the\day}% - \w@rps {50 dict begin}% - \w@rps {/mv {stroke moveto} def}% - \w@rps {/lv {lineto} def}% - \w@rps {/st {currentpoint stroke moveto} def}% - \w@rps {/sl {st setlinewidth} def}% - \w@rps {/sd {st 0 setdash} def}% - \w@rps {/sg {st setgray} def}% - \w@rps {/bs {gsave} def /es {stroke grestore} def}% - \w@rps {/fl \l@br gsave setgray fill grestore}% - \w@rps { currentpoint newpath moveto\r@br\space def}% - \w@rps {/fp {gsave setgray fill grestore st} def}% - \w@rps {/cv {curveto} def}% - \w@rps {/cr \l@br gsave currentpoint newpath 3 -1 roll 0 360 arc}% - \w@rps { stroke grestore\r@br\space def}% - \w@rps {/fc \l@br gsave setgray currentpoint newpath}% - \w@rps { 3 -1 roll 0 360 arc fill grestore\r@br\space def}% - \w@rps {/ar {gsave currentpoint newpath 5 2 roll arc stroke grestore} def}% - \w@rps {/el \l@br gsave /svm matrix currentmatrix def}% - \w@rps { currentpoint translate scale newpath 0 0 1 0 360 arc}% - \w@rps { svm setmatrix stroke grestore\r@br\space def}% - \w@rps {/fe \l@br gsave setgray currentpoint translate scale newpath}% - \w@rps { 0 0 1 0 360 arc fill grestore\r@br\space def}% - \w@rps {/av \l@br /hhwid exch 2 div def /hlen exch def}% - \w@rps { /ah exch def /tipy exch def /tipx exch def}% - \w@rps { currentpoint /taily exch def /tailx exch def}% - \w@rps { /dx tipx tailx sub def /dy tipy taily sub def}% - \w@rps { /alen dx dx mul dy dy mul add sqrt def}% - \w@rps { /blen alen hlen sub def}% - \w@rps { gsave tailx taily translate dy dx atan rotate}% - \w@rps { (V) ah ne {blen 0 gt {blen 0 lineto} if} {alen 0 lineto} ifelse}% - \w@rps { stroke blen hhwid neg moveto alen 0 lineto blen hhwid lineto}% - \w@rps { (T) ah eq {closepath} if}% - \w@rps { (W) ah eq {gsave 1 setgray fill grestore closepath} if}% - \w@rps { (F) ah eq {fill} {stroke} ifelse}% - \w@rps { grestore tipx tipy moveto\r@br\space def}% - \w@rps {\p@sfactor\space \p@sfactor\space scale}% - \w@rps {1 setlinecap 1 setlinejoin}% - \w@rps {3 setlinewidth [] 0 setdash}% - \w@rps {0 0 moveto}% + \p@swr {\p@b PS-Adobe-3.0 EPSF-3.0}% + \p@swr {\p@p BoundingBox: (atend)}% + \p@swr {\p@p Title: TeXdraw drawing: #1}% + \p@swr {\p@p Pages: 1}% + \p@swr {\p@p Creator: \TeXdrawId}% + \p@swr {\p@p CreationDate: \the\year/\the\month/\the\day}% + \p@swr {50 dict begin}% + \p@swr {/mv {stroke moveto} def}% + \p@swr {/lv {lineto} def}% + \p@swr {/st {currentpoint stroke moveto} def}% + \p@swr {/sl {st setlinewidth} def}% + \p@swr {/sd {st 0 setdash} def}% + \p@swr {/sg {st setgray} def}% + \p@swr {/bs {gsave} def /es {stroke grestore} def}% + \p@swr {/fl \l@br gsave setgray fill grestore}% + \p@swr { currentpoint newpath moveto\r@br\space def}% + \p@swr {/fp {gsave setgray fill grestore st} def}% + \p@swr {/cv {curveto} def}% + \p@swr {/cr \l@br gsave currentpoint newpath 3 -1 roll 0 360 arc}% + \p@swr { stroke grestore\r@br\space def}% + \p@swr {/fc \l@br gsave setgray currentpoint newpath}% + \p@swr { 3 -1 roll 0 360 arc fill grestore\r@br\space def}% + \p@swr {/ar {gsave currentpoint newpath 5 2 roll arc stroke grestore} def}% + \p@swr {/el \l@br gsave /svm matrix currentmatrix def}% + \p@swr { currentpoint translate scale newpath 0 0 1 0 360 arc}% + \p@swr { svm setmatrix stroke grestore\r@br\space def}% + \p@swr {/fe \l@br gsave setgray currentpoint translate scale newpath}% + \p@swr { 0 0 1 0 360 arc fill grestore\r@br\space def}% + \p@swr {/av \l@br /hhwid exch 2 div def /hlen exch def}% + \p@swr { /ah exch def /tipy exch def /tipx exch def}% + \p@swr { currentpoint /taily exch def /tailx exch def}% + \p@swr { /dx tipx tailx sub def /dy tipy taily sub def}% + \p@swr { /alen dx dx mul dy dy mul add sqrt def}% + \p@swr { /blen alen hlen sub def}% + \p@swr { gsave tailx taily translate dy dx atan rotate}% + \p@swr { (V) ah ne {blen 0 gt {blen 0 lineto} if} {alen 0 lineto} ifelse}% + \p@swr { stroke blen hhwid neg moveto alen 0 lineto blen hhwid lineto}% + \p@swr { (T) ah eq {closepath} if}% + \p@swr { (W) ah eq {gsave 1 setgray fill grestore closepath} if}% + \p@swr { (F) ah eq {fill} {stroke} ifelse}% + \p@swr { grestore tipx tipy moveto\r@br\space def}% + \p@swr {\p@sfactor\space \p@sfactor\space scale}% + \p@swr {1 setlinecap 1 setlinejoin}% + \p@swr {3 setlinewidth [] 0 setdash}% + \p@swr {0 0 moveto}% } % Notes: @@ -1116,15 +1151,15 @@ % indicate. This is due to the fact that multiple move commands in % a row are collapsed into a single move. The BoundingBox information % includes the effect of the moves which were expunged. -\def\t@drclose {% +\def\t@xdclose {% \bgroup - \w@rps {stroke end showpage}% - \w@rps {\p@p Trailer:}% + \p@swr {stroke end showpage}% + \p@swr {\p@p Trailer:}% \pixtobp \xminpix \l@lxbp \pixtobp \yminpix \l@lybp \pixtobp \xmaxpix \u@rxbp \pixtobp \ymaxpix \u@rybp - \w@rps {\p@p BoundingBox: \l@lxbp\space \l@lybp\space + \p@swr {\p@p BoundingBox: \l@lxbp\space \l@lybp\space \u@rxbp\space \u@rybp}% - \w@rps {\p@p EOF}% + \p@swr {\p@p EOF}% \egroup \immediate\closeout\drawfile } |