# How to use a macro as the point arguments of both pspicture and \psframe?

I forgot the rule to use \expandafter such that \rect can be used as the point arguments of both psframe and pspicture.

\documentclass{standalone}

\usepackage{pstricks}

\def\rect{(-3,-3)(3,3)}

\begin{document}

\begin{pspicture}[showgrid=top]\rect
\psframe[linecolor=red]\rect
\end{pspicture}

\end{document}


Could you review it once more?

-

PSTricks expects

\begin{pspicture}[<options>]


to be followed by explicit coordinates. Thus \rect must be expanded before TeX starts looking to \begin.

\newcommand{\expandcoord}[2]{%
\expandafter\expandcoordaux\expandafter{#2}{#1}%
}
\newcommand\expandcoordaux[2]{#2#1}


Then you can say

\expandcoord{\begin{pspicture}[showgrid=top]}{\rect}
\expandcoord{\psframe[linecolor=red]}{\rect}
\end{pspicture}


The main problem here is that \expandafter only jumps over one token, so an indirect way has to be taken. This, of course, will break auto-pst-pdf or similar packages.

-
Is it possible no to use \expandcoordaux but merge it into a single \expandcoord? –  Please don't touch Jul 12 '12 at 9:33
@HiggsBoson No. There is no primitive method for jumping over a braced group, so in a way or the other auxiliary macros must be employed. It wouldn't be too difficult to extend PSTricks so that \begin{pspicture}[<options>] accepts to be followed by "implicit coordinates"; however, doing it for all PSTricks commands such as \psframe would require extensive work. –  egreg Jul 12 '12 at 9:46