[pstricks] Writing A PS String Macro

Vince McGarry vmcgarry at austin.rr.com
Sat Feb 28 23:36:00 CET 2004


Hi,

I'm new to the list but have been playing with PSTricks for awhile. I
heavily use psplot to graph polynomial equations. Based on some code I've
seen in various places I've worked for the past few hours on the following
macro (more than a little a bit awkward, I'm sure) which will create a PS
string for a polynomial function using horner's method by calling
\pseqh{variable}{coefficients}, where <coefficients> is a is a comma
separated string. (Next will be to change the code so that I pass the zeros
of the function.)

I can call, for example, \pseqh{x}{-3,5,-6} to graph -3x^2+5x+6 or
\pseqh{x}{1,3\ div\ 5} to graph x+(3/5). If I declare \SpecialCoor I can
define \myquadratic#1{\pseqh{#1}{-3,5,-6}}, then pass coordinates by simply
typing (! 2 \myquadratic{2}}

I want to add and optional parameter to scale the graph vertically so that I
can call \pseqh[0.5]{x}{5,-7,3,8}, but haven't had time to work on it yet.

This code works as expected:

\newif\ifnotfirsttime%  \notfirsttimefalse
\def\stopflag{z}%

\def\pseqh#1#2{\def\unknown{#1}\def\coeffs{#2}\createpsequation}
  
\def\createpsequation{

\notfirsttimefalse

\def\buildstring##1{\ifx##1\stopflag\noexpand\concat##1
\else\noexpand\concat##1\expandafter\buildstring\fi}

\edef\routine{\expandafter\buildstring\coeffs\stopflag}%

\def\concat##1{\ifnotfirsttime \ifx##1z add \else \ifx##1, add \unknown\ mul
\else ##1\fi\fi \else \ifx##1z  \unknown\ mul \else \ifx##1, \unknown\ mul
\notfirsttimetrue \else ##1\fi\fi\fi}

\routine
}

If, however, I change the def of concat to

\def\concat##1{\ifnotfirsttime \ifx##1\stopflag add \else \ifx##1, add
\unknown\ mul \else ##1\fi\fi \else \ifx##1\stopflag  \unknown\ mul \else
\ifx##1, \unknown\ mul \notfirsttimetrue \else ##1\fi\fi\fi}

It doesn't work. Can anyone explain why I can test \stopflag in
\buildstring, but not in \concat?

Thanks
 
Vince McGarry




More information about the PSTricks mailing list