Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Background

Let

\def\RR#1{(2^(#1/10))}
\def\TT#1{(#1)}

be the radius and angle functions, respectively.

Christoph defined a PS operator AAA as follows.

/AAA {AlgParser cvx exec exch AlgParser cvx exec exch RadtoDeg PtoC} def 

It can be used to translate

\pscircle*[linecolor=red](!\RR{7*Pi/2} \TT{7*Pi/2} AAA){2pt}

from polar infix to polar postfix. However 7*Pi/2 are repeated, it breaks DRY (Don't Repeat Yourself) principle and cannot make use of t as explained shortly below.

I modified Herbert's operators as follows

/BBB {/TT ED TT AlgParser cvx /t ED  /RR ED RR AlgParser cvx /r ED r t RadtoDeg PtoC} def
/CCC { AlgParser cvx /t ED  AlgParser cvx exec t RadtoDeg PtoC} def

to allow me to write two styles as follows.

\pscircle*[linecolor=green](!{(2^(t/10))} {(3*Pi/2)} BBB){2pt}
\pscircle*[linecolor=blue](!\RR{t} \TT{5*Pi/2} CCC){2pt}

The first does not make use of \RR and \TT and the last does make use of \RR and \TT.

Complete code

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-plot}
\pstVerb
{
    /AAA {AlgParser cvx exec exch AlgParser cvx exec exch RadtoDeg PtoC} def 
    /BBB {/TT ED TT AlgParser cvx /t ED  /RR ED RR AlgParser cvx /r ED r t RadtoDeg PtoC} def
    /CCC { AlgParser cvx /t ED  AlgParser cvx exec t RadtoDeg PtoC} def
}


\def\RR#1{(2^(#1/10))}
\def\TT#1{(#1)}

\begin{document}
\begin{pspicture}[showgrid](-3,-3)(3,3)
  \psplot[algebraic,polarplot]{TwoPi}{TwoPi 2 mul}{\RR{x}}
    \pscircle*[linecolor=red](!\RR{7*Pi/2} \TT{7*Pi/2} AAA){2pt}
    \pscircle*[linecolor=green](!{(2^(t/10))} {(3*Pi/2)} BBB){2pt}
    \pscircle*[linecolor=blue](!\RR{t} \TT{5*Pi/2} CCC){2pt}
\end{pspicture}

\end{document}

Question

Can I combine BBB and CCC to create DDD as simple as AAA but they must still work for the following?

\pscircle*[linecolor=green](!{(2^(t/10))} {(3*Pi/2)} DDD){2pt}
\pscircle*[linecolor=blue](!\RR{t} \TT{5*Pi/2} DDD){2pt}

Bonus question: I still don't understand why Herbert used only one exec while Christoph used 2 execs? What does exec do actually?

share|improve this question
    
What about defining \def\RT#1{\RR{#1} \TT{#1}} and calling \pscircle*[linecolor=red](!\RT{7*Pi/2} AAA){2pt}, so that DRY is not broken ? –  Adam B. Nov 28 '13 at 8:02
    
@AdamB. But now there is a constraint more, \RR cannot be represented as an expression with t when passed as a point. –  Please don't touch Nov 28 '13 at 8:14
add comment

3 Answers 3

up vote 5 down vote accepted

simplified

/AAA {AlgParser cvx exec exch AlgParser cvx exec exch RadtoDeg PtoC} def 
/BBB {exec AlgParser cvx /t ED  exec AlgParser cvx exec t RadtoDeg PtoC} def
/CCC {AlgParser cvx /t ED  AlgParser cvx exec t RadtoDeg PtoC} def

for /BBB: the expression {(2^(t/10))} is moved to PostScript with the parentheses {...} the reason why we first need an exec for removing it, or, of course, /anyvar exch def anyvar or /anyvar ED anyvar (saving it and pushing the saved data onto the stack) will do the same. Without the {...} it can't work on TeX side.

For your examples you need only /BBB, it works for all:

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-plot}
\pstVerb{
  /A2P {exec AlgParser cvx /t ED  exec AlgParser cvx exec t RadtoDeg PtoC} def }

\def\RR#1{(2^(#1/10))}
\def\TT#1{(#1)}

\begin{document}
\begin{pspicture}[showgrid](-3,-3)(3,3)
  \psplot[algebraic,polarplot]{2 Pi mul neg}{4 Pi mul}{\RR{x}}
  \pscircle*[linecolor=red  ](!\RR{7*Pi/2} \TT{7*Pi/2} A2P){2pt}
  \pscircle*[linecolor=green](!{(2^(t/10))} {(3*Pi/2)} A2P){2pt}
  \pscircle*[linecolor=blue ](!\RR{t} \TT{5*Pi/2} A2P){2pt}
\end{pspicture}

\end{document}
share|improve this answer
add comment

Thanks to Christoph's answer on exec, I managed to make a DDD working in both cases. Here is the MWE (Minimal Working Example).

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-plot}
\pstVerb
{
    /AAA {AlgParser cvx exec exch AlgParser cvx exec exch RadtoDeg PtoC} def 
    /DDD {exec AlgParser cvx /t ED exec AlgParser cvx exec t RadtoDeg PtoC} def
}    

\def\RR#1{(2^(#1/10))}
\def\TT#1{(#1)}
\def\RT#1{\RR{#1} \TT{#1}}

\begin{document}
\begin{pspicture}[showgrid](-3,-3)(3,3)
  \psplot[algebraic,polarplot]{2 Pi mul neg}{4 Pi mul}{\RR{x}}
  \pscircle*[linecolor=red](!\RT{7*Pi/2} AAA){2pt}
  \pscircle*[linecolor=green](!{(2^(t/10))} {(3*Pi/2)} DDD){2pt}
  \pscircle*[linecolor=blue](!\RR{t} \TT{5*Pi/2} DDD){2pt}
\end{pspicture}
\end{document}
share|improve this answer
    
DDD works for all ... –  Herbert Nov 28 '13 at 9:56
    
@Herbert I actually just tested it in replacement of BBB and CCC, but yes it works for all –  Adam B. Nov 28 '13 at 10:09
add comment

Only the bonus answer regarding the exec:

AlgParser parses a string (...) and leaves an array [...] on the stack. The expression

(2^(Pi/10)) AlgParser

evaluates to the array

[tx@AddMathFunc begin 2.0 Pi 10.0 div exp end]

In order to evaluate this, one must turn this into an executable array (or procedure) with cvx, which gives

{tx@AddMathFunc begin 2.0 Pi 10.0 div exp end}

Now you can either call exec to execute this procedure which is on the stack (which is what I did twice), or you can save it and execute it by calling the variable, i.e. use /x exch def x to execute it (which is what Herbert did once).

So the following statements are equal

(2^(Pi/10)) AlgParser cvx exec

and

(2^(Pi/10)) AlgParser cvx /x exch def x
share|improve this answer
    
you also need the cvx when saving the expression –  Herbert Nov 28 '13 at 9:02
    
@Herbert Right, thanks for the correction. –  Christoph Nov 28 '13 at 9:07
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.