Why cannot XeLaTeX clip my PSTricks graph plot correctly?

The following screenshot produced by latex-dvips-ps2pdf and the clipping is well done.

\documentclass{article}
\usepackage{xcolor}
\usepackage{pstricks,pst-func}

\newpsstyle{gridstyle}
{
gridwidth=0.4pt,%default: 0.8pt
gridcolor=red!20,%default: black
griddots=0,%default: 0
%
gridlabels=3pt,%default: 10pt
gridlabelcolor=blue,%default: black
%
subgriddiv=5,%default: 5
subgridwidth=0.2pt,%default: 0.4pt
subgridcolor=green!20,%default: gray
subgriddots=0%default: 0
}

\psset{style=gridstyle}
\newpsobject{psGrid}{psgrid}{}

\begin{document}
\noindent%
\renewcommand{\pshlabel}[1]{\bfseries\tiny #1}% for x-axis
\renewcommand{\psvlabel}[1]{\bfseries\tiny #1}% for y-axis
\psset{yunit=0.4cm,xunit=0.5cm}
\centering\begin{pspicture*}(-4,-5)(4,15)
\psGrid
\psaxes[Dy=2,Dx=2]{<->}(0,0)(-4,-5)(4,15)
\psset{linewidth=1pt,linecolor=blue}
\psPolynomial[coeff=-1 0 1,linecolor=red]{-4}{4}
\psPolynomial[coeff=-1 0 1,xShift=1,linestyle=dashed]{-4}{4}
\rput[rt](3,12){\textcolor{red}{$f(x)$}}
\rput[lt](2.5,1){\textcolor{blue}{$g(x)$}}
\end{pspicture*}
\end{document}


But the following screenshot produced by xelatex and the clipping is bad done

Why cannot XeLaTeX clip my PSTricks graph plot correctly?

Last edit: After updating Miktex packages, xelatex clips the graph correctly.

-
do you work in a Windows environment? with Miktex? –  pluton Jun 5 '11 at 17:52
sorry I completely missed that. I think there is a problem with miktex on this. I had the same experience a while ago. Herbert knows more but it may be related to xdvipdfmx. Your code may run correctly with texlive (on a linux system I would say). –  pluton Jun 5 '11 at 18:05
I get correct output with XeLaTeX on Mac OS X (TeX Live 2010). It does not compile with the 2011 pretest because of a known bug of xdvipdfmx which should be already solved for next update. –  egreg Jun 5 '11 at 20:56

I can confirm the problem. Clipping doesn't work with xetex at all in miktex. Even with such a simple example like this:

\documentclass{article}
\usepackage{pstricks}

\begin{document}
abc\begin{pspicture*}(1,1)
\psline(-1,-1)(2,2)
\end{pspicture*}abc

\end{document}


I don't think that the version of the xdvipdfmx.cfg is the problem. Miktex use the same version as the one on CTAN (Version 0.02 (2010/08/02)). Also the miktex ghostscript isn't responsable either, it doesn't help if I change to gswin32c.

The problem doesn't seem to be new: I can reproduce it in my old miktex 2.7 (xdvipdfmx version is 0.7.3).

-
@xport You could use TeXlive instead of MikTeX. The clipping works fine for me, Win 7 with TeXlive 2010. –  Torbjørn T. Jun 6 '11 at 10:22
@Torbjorn: Can TeXLive and MikTeX get installed on the same machine? –  xport Jun 6 '11 at 10:41
@xport: Sorry, I don't know. –  Torbjørn T. Jun 6 '11 at 10:49
@Torbjorn: they can be installed side by side. I have tried and there is no problem. –  xport Jun 6 '11 at 11:36
@Herbert, @xport: The bug in miktex has been corrected. With the update of xdvipdfmx of today clipping works fine. –  Ulrike Fischer Jun 8 '11 at 7:04

I cannot see any problem with running xelatex under TeXLive2010 and Linux. However, here is a shorten variant of your code:

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

\newpsstyle{gridstyle}{
gridwidth=0.4pt,%default: 0.8pt
gridcolor=red!20,%default: black
griddots=0,%default: 0
%
gridlabels=0pt,%default: 10pt
gridlabelcolor=blue,%default: black
%
subgriddiv=5,%default: 5
subgridwidth=0.2pt,%default: 0.4pt
subgridcolor=green!20,%default: gray
subgriddots=0%default: 0
}

\begin{document}
\noindent%
\psset{yunit=0.4cm,xunit=0.5cm}
\centering\begin{pspicture*}[showgrid](-4,-5)(4,15)
\psaxes[Dy=2,Dx=2,labelFontSize=\bfseries\tiny,mathLabel=false]{<->}(0,0)(-4,-5)(4,15)
\psset{linewidth=1pt,linecolor=blue}
\psPolynomial[coeff=-1 0 1,linecolor=red]{-4}{4}
\psPolynomial[coeff=-1 0 1,xShift=1,linestyle=dashed]{-4}{4}
\rput[rt](3,12){\textcolor{red}{$f(x)$}}
\rput[lt](2.5,1){\textcolor{blue}{$g(x)$}}
\end{pspicture*}

\end{document}

-
If I set showgrid explicitly in the pspicture then I cannot turn it off globally in the preamble. That's why I define a new \psGrid as the temporary grid. But other simplifications are accepted and good. Thanks. –  xport Jun 6 '11 at 10:14