The following MWE works fine when plotting a square using pstricks with xelatex.

   \def\x{0 } % Notice that there MUST be a white space after 0
   \psframe(\x, 1)(!1 \x add 1 1 add)

The problems is, when I try to make the \psframe in a whiledo loop with a counter, the space after a command is swallowed. Look at the following MWE:

   \def\x{0 }
   \def\Y{\theY  }
   \psframe(\x, \Y)(!1 \x add 1 \Y add)

When compile with the command xelatex test where test.tex is the name of the source file, it throws the following error:

 Using PSTricks configuration for XeTeX+xdvipdfmx
 ))) (/usr/share/texlive/texmf-dist/tex/generic/pstricks/pst-fp.tex))
 (./test.aux) [1] (./test.aux)Error: /undefined in 1add
 Operand stack:
    --nostringval--   0.0   true   0.0   28.4527   1   1

Looks like after expanding \Y in \psframe, the second coordinate becomes (!1 0 add 1 1add) where the white space between the last 1 and add is swallowed.

How can the value of a counter be used in the coordinate calculations in pstricks? Thanks.

\psframe(\x, \Y)(!1 \x\space add 1 \Y\space add}

Otherwise the spaces get lost

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