[pstricks] expansion problem

John Frampton j.frampton at neu.edu
Thu Dec 8 19:10:53 CET 2005



In the macro files I use in undergraduate teaching, I define

\def\psexpA[#1,#2]{#2 x exp #1 mul}

so that I can say things like

\psplot{0}{10}{\psexpA[1.2,.9]}

to graph 1.2*.9^x over the interval 0 to 10

I also define

\def\psexpB(#1,#2)(#3,#4){%
   #4 #2 div x #1 sub #3 #1 sub div exp #2 mul}

so that I can say things like

\psplot{0}{10}{\psexpB(0,1)(10,8)}

to graph the exponential which goes through the points (0,1) and
(10,8).

Use of \psexpA and \psexpB (along with a dozen or so other
macros of this kind) makes it easy to construct various examples
for use in my undergraduate classes.

I tried

\def\psexp{\@ifnextchar[\psexpA\psexpB}

(in an environment in which @ was a letter) so that I would not
have to distinguish between \psexpA and \psexpB.  I expected
that I could then say either

\psplot{0}{10}{\psexp[1.2,.1]}

or

\psplot{0}{10}{\psexp(0,1)(10,8)}

Unfortunately, it doesn't work.  There is some complication in
the timing of expansion that I cannot understand.  I am hoping
that someone can help me out.

Thanks, John Frampton

Example (run to see it work correctly with \psexpA and \psexpB,
then uncomment the commented line to see the problem):

\input pstricks
\input pst-plot

\def\psexpA[#1,#2]{#2 x exp #1 mul}
\def\psexpB(#1,#2)(#3,#4){%
   #4 #2 div x #1 sub #3 #1 sub div exp #2 mul}
\catcode`@=11
\def\psexp{\@ifnextchar[\psexpA\psexpB}
\catcode`@=12
\psset{unit=1cm}

\pspicture(0,0)(2,4)
\psplot{0}{2}{\psexpA[1,2]}
\psplot{0}{2}{\psexpB(0,1)(2,3.5)}
%\psplot{0}{2}{\psexp(0,1)(2,4)}
\endpspicture

\bye

The error report from Tex is

! Argument of \pst@@object has an extra }.
<inserted text>
                \par
<to be read again>
                   }
<argument> ...0,1)(2,4) \pst at number \psyunit mul }
                                                   def
\addto at pscode #1->\xdef \pst at code {\pst at code #1
                                               \space }
\psplot at i ...ul #3 \pst at number \psyunit mul } def}
                                                  \gdef \psplot at init {}\@pst...
l.21 \psplot{0}{2}{\psexp(0,1)(2,4)}





More information about the PSTricks mailing list