[pstricks] Writing A PS String Macro

Herbert Voss Herbert.Voss at alumni.TU-Berlin.DE
Sun Feb 29 12:56:26 CET 2004


Vince McGarry wrote:

> 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}}

it is uch more easier, when you pass the values as parameter directly
to PostScript. For example
\plot[a0 a1 a2 a3 a4 ...]{start}{end}


\documentclass{article}
\usepackage{pst-plot}

\def\plot[#1]#2#3{%
	\psplot{#2}{#3}{%
		/Horner {
			aload length
			dup 2 add -1 roll
			exch 1 sub {
				dup 4 1 roll
				mul add exch
			} repeat
			pop
		} def
		x [#1] Horner
	}
}
\begin{document}
\psset{yunit=0.5,xunit=1}
\begin{pspicture}(-2,-3)(5,10)
	\psaxes(0,0)(-2,-3)(5,10)
	\plot[6 3 -1]{-2}{5}
\end{pspicture}
\end{document}


> 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.

\def\myFunc{\@ifnextchar[{\myFunc at i}{\myFunc[]}}
\def\myFunc at i[#1]#2{%
...
}

> 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?

I can not see a problem here when using concatII  ...

\documentclass{article}

\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\concatII##1\expandafter\buildstring%
		\fi%
	}
	\edef\routine{\expandafter\buildstring\coeffs\stopflag}%
	\def\concatII##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%
	}
	\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%
}

\begin{document}



Herbert



-- 
http://www.pstricks.de/





More information about the PSTricks mailing list