%% $Id: xytpic.doc,v 3.3 1996/12/18 09:50:38 ross Exp $ %% %% Xy-pic ``tpic'' TPIC backend, for lines, curves and fills. %% Copyright (c) 1995-1996 Ross Moore %% %% This file is part of the Xy-pic package for graphs and diagrams in TeX. %% See the companion README and INSTALL files for further information. %% Copyright (c) 1991-1996 Kristoffer H. Rose %% %% The Xy-pic package is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published by the %% Free Software Foundation; either version 2 of the License, or (at your %% option) any later version. %% %% The Xy-pic package is distributed in the hope that it will be useful, but %% WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY %% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License %% for more details. %% %% You should have received a copy of the GNU General Public License along %% with this package; if not, write to the Free Software Foundation, Inc., %% 675 Mass Ave, Cambridge, MA 02139, USA. %% \ifx\xyloaded\undefined \input xy \fi \xyprovide{tpic}{TPIC backend}{\stripRCS$Revision: 3.3 $}% {Ross Moore}{ross@mpce.mq.edu.au}% {Mathematics Department, Macquarie University, NSW~2109, Australia} \DOCMODE3%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \ifx\undefined\TPIC \def\TPIC{{\smc tpic}}\fi This option allows the \Xy-pic fonts to be replaced by \TPIC\ |\special|s, when used with a dvi-driver capable of supporting them. Extra capabilities include smoother lines, evenly spaced dotted/dashed curves, variable line-widths, gray-scale fills of circles, ellipses and polygonal regions. \DOCMODE2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \paragraph*{Header:}\leavevmode \DOCHEADER \DOCMODE3%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Use of \TPIC\ |\special|s offers an alternative to the \Xy-pic fonts. However they require a dvi-driver that is capable of recognizing and interpreting them. One such viewer is |xdvik|, Karl Berry's modification to the |xdvi| viewer on \unix\ systems running X-windows or a derivative. |dvipsk|, Karl Berry's modification to |dvips| also handles \TPIC\ |\special|s, so |xdvik|/|dvipsk| is an good combination for quality screen-display and \PS\ printing. Once loaded using |\xyoption{tpic}|, with an appropriate also specified either already or subsequently, the following commands are available to turn the \TPIC\ backend off/on. % \begin{defs} |\NoTPICspecials| & turns off \TPIC\ specials.\kern-50pt\cr |\UseTPICspecials| & reinstates \TPIC\ specials.\kern-30pt \end{defs} \DOCMODE( \xynew@{if}\ifTPICspecials@ \xydef@\UseTPICspecials{\TPICspecials@true} \xydef@\NoTPICspecials{\TPICspecials@false} \DOCMODE) \DOCMODE3%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% There is a limit to the number of points allowable in a path. For paths constructed by \Xy-pic, which includes spline curves, when the limit is reached the path is automatically flushed and a new path commenced. The following command can be used to customise this limit---initially set at $300$ for use with \xdvi---to suit alternative s. % \begin{defs} |\maxTPICpoints{||}| & set maximum for paths \end{defs} \DOCMODE( \xynew@{count}\xytpic@cnt \xydef@\xytpic@max{300} \xydef@\maxTPICpoints#1{\count@=#1 \relax \ifnum\count@>\tw@ \edef\xytpic@max{\the\count@}% \else\expandafter\xyTPICmaxwarning@\expandafter{\the\count@}\fi} \xydef@\xyTPICmaxwarning@#1{max points must be at least 2, #1 invalid} \DOCMODE) \DOCMODE2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Each object involving \TPIC\ |\special|s must set the style, using |\xytpic@set@| to store a macro as the expansion of |\xytpic@style@@|. Currently this is global, since a \TPIC\ object must be completed once it has been started --- perhaps this is not necessary. Note that |\xytpic@set@| uses |\xdef|, but has a |\noexpand| in its expansion; this forces expansion of the argument, when there is one, to the control sequence passed as the first token following |\xytpic@set@|. \DOCMODE( \xydef@\xytpic@style@@{\xytpic@fp} \xydef@\xytpic@reset@{\gdef\xytpic@style@@{\xytpic@fp}% \global\xytpic@cnt=\z@ } \xydef@\xytpic@set@#1{\xdef\xytpic@style@@{\noexpand#1}} \DOCMODE) Here are the actual |\specials| that get placed in the dvi-file. \DOCMODE( \xydef@\xytpic@pn#1{\xyTPIC@special{pn #1}} \xydef@\xytpic@pa#1#2{\global\advance\xytpic@cnt\@ne\relax \ifnum\xytpic@cnt=\xytpic@max\relax \xyTPIC@special{pa #1 #2}% \kern-\X@c\raise-\Y@c\hbox{\xytpic@style@@}\kern\X@c % \xytpic@ip \global\xytpic@cnt=\@ne \relax\fi \xyTPIC@special{pa #1 #2}} \xydef@\xytpic@fp{\xyTPIC@special{fp}} \xydef@\xytpic@ip{\xyTPIC@special{ip}} \xydef@\xytpic@da#1{\xyTPIC@special{da #1}} \xydef@\xytpic@dt#1{\xyTPIC@special{dt #1}} \xydef@\xytpic@sp#1{\xyTPIC@special{sp #1}} \xydef@\xytpic@ar#1#2#3#4#5#6{\xyTPIC@special{ar #1 #2 #3 #4 #5 #6}} \xydef@\xytpic@ia#1#2#3#4#5#6{\xyTPIC@special{ia #1 #2 #3 #4 #5 #6}} \xydef@\xytpic@sh#1{\xyTPIC@special{sh #1}} %\xydef@\xytpic@psb#1{\xyTPIC@special{:[begin] #1}} %\xydef@\xytpic@pse#1{\xyTPIC@special{:[end]}} % \xydef@\xytpic@wh{\xyTPIC@special{sh 0}} % obsolete \xydef@\xytpic@bk{\xyTPIC@special{sh 1}} % obsolete \xydef@\xyTPIC@special#1{\special{#1}} \xydef@\xyTPIC@noisy#1{\W@{TPIC: #1}\special{#1}} \xydef@\NoisyTPIC{\let\xyTPIC@special=\xyTPIC@noisy} \DOCMODE) Some effects may require a \TPIC\ |\special| to be placed both before and after the . \DOCMODE( \xydef@\xyTPICsplit@#1#2{\setboxz@h{#1\boxz@#2}}% \DOCMODE) \DOCMODE2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \TPIC\ uses units of `milli-inches' for coordinates, but inches for dot-separations and dash-length. \DOCMODE( \xydef@\xytpic@pt#1{\dimen@=#1\divide\dimen@ by72 % \multiply\dimen@ by 1000 \advance\dimen@.5\p@ \count@=\dimen@ \divide\count@\p@ } \xydef@\xytpic@in#1{\dimen@=#1\divide\dimen@ by72 % \edef\next@{\expandafter\removePT@\the\dimen@}}% \DOCMODE) The \TPIC\ location is calculated relative to the current \TeX\ reference point. Hence most \TPIC\ objects start at the $(0,0)$ location. \DOCMODE( \xydef@\xytpic@dot@@{\xytpic@pa00} \xydef@\xytpic@width@{\xytpic@pt{\xylinethick@}% \expandafter\xytpic@pn\expandafter{\the\count@}} %\xylet@\xytpic@width@=\relax \xydef@\xytpic@line{% \xytpic@dot@@ \xytpic@pt{-\d@X}\count@@=\count@ \xytpic@pt\d@Y \edef\next@{{\the\count@@}{\the\count@}}% \expandafter\xytpic@pa\next@ \xytpic@style@@ \xytpic@reset@ } \xydef@\xytpic@solid@@{\xytpic@set@\xytpic@fp} \xydef@\xytpic@dashed@@{\xytpic@in\xydashl@ \xytpic@dad} \xydef@\xytpic@dotted@@{\dimen@=.5\xydashl@ \xytpic@in\dimen@ \xytpic@dtd} \xydef@\xytpic@dad{\expandafter\xytpic@set@\expandafter{% \expandafter\xytpic@da\expandafter{\next@}}} \xydef@\xytpic@dtd{\expandafter\xytpic@set@\expandafter{% \expandafter\xytpic@dt\expandafter{\next@}}} \xydef@\xytpic@polysolid@{\xytpic@set@\xytpic@fp} \xydef@\xytpic@polydashed@#1{\count@=#1 \xytpic@dad} \xydef@\xytpic@polydotted@#1{\count@=#1 \xytpic@dtd} \xydef@\xytpic@postpoly@{\xytpic@style@@ \xytpic@reset@} \DOCMODE) \DOCMODE2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \paragraph*{re-bindings} This is similar to the mechanism used by the \PS\ back-end to rebind ``hooks'' to incorporate a switch according to the current value of |\ifTPICspecials@|. \DOCMODE( \xydef@\TPICalternative@#1#2{% \expandafter\global\expandafter\let\csname origxy#2@\endcsname=#1% \xdef#1{\noexpand\ifTPICspecials@ \noexpand\expandafter\expandafter\noexpand\csname xytpic@#2@\endcsname \noexpand\else \noexpand\expandafter\expandafter\noexpand\csname origxy#2@\endcsname \noexpand\fi}}% \DOCMODE) Allow only one instance of |\setupxyTPIC@|; thereafter simply do |\reloadxyTPIC@| to turn on anything that has been turned off. \DOCMODE( \xydef@\setupxyTPIC@{\xywarning@{using TPIC specials}% \TPICalternative@{\solid@}{solid}% \TPICalternative@{\dash@}{dashed}% \TPICalternative@{\point@}{point}% \TPICalternative@{\circhar@@}{circhar}% \TPICalternative@{\splinesolid@}{splinesolid}% % \TPICalternative@{\splinedashed@}{splinedashed}% % \TPICalternative@{\splinedotted@}{splinedotted}% \xywithoption{frame}{\xyinputorelse@{xytp-f}{}\xyuncatcodes}% \let\setupxyTPIC@=\reloadxyTPIC@ \activateTPIC@ } \xydef@\xyunloadTPIC@{\xywarning@{TPIC specials turned off}% \xywithoption{curve}{\xysetup@@\uninstallTPICcurves@ }% \xywithoption{line}{\xysetup@@\uninstallTPICline@ }% \xywithoption{frame}{\xysetup@@\uninstallTPICframes@ }% \TPICspecials@false \let\setupxyTPIC@=\reloadxyTPIC@ } \xydef@\activateTPIC@{% \xywithoption{line}{\xysetup@@\installTPICline@}% \xywithoption{curve}{\xysetup@@\installTPICcurves@}% \xywithoption{frame}{\xysetup@@\installTPICframes@}% \TPICspecials@true } \xydef@\reloadxyTPIC@{\xywarning@{TPIC specials back on}\activateTPIC@ } \DOCMODE) \DOCMODE2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \paragraph*{straight lines} \DOCMODE( \xydef@\xytpic@solid@{% \ifInvisible@ \let\next@=\no@@ \else \DN@{\xyTPICstraight@{\xytpic@solid@@ \xytpic@line}}\fi \next@ } \xydef@\xytpic@dashed@{\line@ \def\Connect@@{\xyTPICstraight@{\xytpic@dashed@@ \xytpic@line}}} \xydef@\xytpic@point@{\xytpic@dot@@\xytpic@fp\egroup \Invisible@false \Hidden@false \def\Leftness@{.5}\def\Upness@{.5}\ctipEdge@ \def\Drop@@{\styledboxz@}% \def\Connect@@{\xyTPICstraight@{\xytpic@dotted@@ \xytpic@line}}} \xydef@\xyTPICstraight@#1{\setupDirection@ \edef\Creset@@{\cfromthec@ \pfromthep@ \DirectionfromtheDirection@}% \DN@##1##2{\def\checkoverlap@@{% \ifdim##1\X@p>##1\X@c \let\next@=\relax \fi \ifdim##2\Y@p>##2\Y@c \let\next@=\relax \fi}}% \edef\nextii@{{\sd@X}{\sd@Y}}\expandafter\next@\nextii@ \noCshavep@@ \edef\Cshavep@@{\pfromthep@ \noexpand\resetDirection@}% \noCshavec@@ \edef\Cshavec@@{\cfromthec@ \noexpand\resetDirection@}% \ifHidden@\else \ifdim\Y@c>\Y@max \Y@max=\Y@c \fi \ifdim\Y@p>\Y@max \Y@max=\Y@p \fi \ifdim\Y@c<\Y@min \Y@min=\Y@c \fi \ifdim\Y@p<\Y@min \Y@min=\Y@p \fi \ifdim\X@c>\X@max \X@max=\X@c \fi \ifdim\X@p>\X@max \X@max=\X@p \fi \ifdim\X@c<\X@min \X@min=\X@c \fi \ifdim\X@p<\X@min \X@min=\X@p \fi \fi \ifInvisible@\let\next@=\relax \else \DN@{\setboxz@h{\kern\X@c \raise\Y@c\hbox{#1}}% \ht\z@=\z@ \wd\z@=\z@ \dp\z@=\z@ {\Drop@@}}% \fi \checkoverlap@@ \ifdim\d@X=\z@ \ifdim\d@Y=\z@ \DN@{\relax}\fi\fi \next@ \def\Cslidep@@{\noCslidep@@}\def\Cslidec@@{\noCslidec@@}% \def\Calong@@{\noCalong@@}\Creset@@ } \DOCMODE) \DOCMODE2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \paragraph*{spline curves} \DOCMODE3%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \noindent Of the curves defined in the |xycurve| extension, only solid spline curves are supported. This is done by treating the spline as a polygon (poly-line) with many segments. The dotted or dashed variants do not work correctly. Implementations of \TPIC\ draw dashed polygons such that the start and finish of each segment is solid. Since these segments can be very short, the effect is simply to create a solid line. Similarly the shortness of the segments tends to give nothing at all for large portions of a dotted curve. What is needed is an implementation whereby the on/off nature of a dashed or dotted polygon is determined by the accumulated length, not the length along just the current segment. \DOCMODE2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \DOCMODE( \xydef@\xytpic@splinesolid@{\xyTPICspline@\xytpic@fp } \xydef@\xytpic@splinedashed@{\xytpic@in\xydashl@\expandafter\xyTPICspline@ \expandafter{\expandafter\xytpic@da\expandafter{\next@}}} \xydef@\xytpic@splinedotted@{\xytpic@in{.5\xydashl@}\expandafter\xyTPICspline@ \expandafter{\expandafter\xytpic@dt\expandafter{\next@}}} \xydef@\xyTPICspline@#1{\setbox\splinebox@=\copy\voidb@x %\zerodot \SloppyCurves %\splinetol@=\xydashl@ % \xytpic@ip \global\xytpic@cnt=\@ne \xytpic@set@{#1}% \def\splineextra@@{\xyTPICspline@dot}% \def\xycrvdrop@{ }\def\xycrvconn@{}\splineset@@ \xytpic@style@@} \xydef@\xyTPICspline@dot{\xytpic@pt{\X@c}\count@@=\count@ \xytpic@pt{-\Y@c}\edef\next@{{\the\count@@}{\the\count@}}% \expandafter\xytpic@pa\next@ } \DOCMODE) \DOCMODE2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \paragraph*{line width} \DOCMODE( \xydef@\xyTPIClinewidth@#1{\xytpic@pt{#1}\edef\next@{\the\count@}} \xydef@\installTPICline@{% \let\xylinewidth@@=\xylinewidth@ \let\xylineSpecial@@=\xytpic@pn \let\transxyline@@=\xyTPIClinewidth@ } \xydef@\uninstallTPICline@{\UnloadLine@}% \DOCMODE) \DOCMODE2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \paragraph*{circles and ellipses} Here we catch circles and ellipses specified using the |\xycircle| command from the |xycurve| extension. Since TPIC supports only solid circles, we catch it only when the