Scenario
I want to write a tutorial on PSTricks, but because latex-dvips-ps2pdf (see the code shown in First Attempt section) makes
my effort to prevent reader from copying the listing numbers no longer work
\usepackage{accsupp}
\newcommand*{\noaccsupp}[1]{\BeginAccSupp{ActualText={}}#1\EndAccSupp{}}
and I cannot use microtype and the output is a bit strange as follow

As a result, this problem forced me to use pdflatex (see Second Attempt section).
First Attempt (latex-dvips-ps2pdf)
\documentclass[dvipsnames,border=12pt,preview]{standalone}
\usepackage{pstricks}
\usepackage{showexpl}
\usepackage{accsupp}
\newcommand*{\noaccsupp}[1]{\BeginAccSupp{ActualText={}}#1\EndAccSupp{}}
\makeatletter
\newlength{\parindent@save}
\setlength{\parindent@save}{\parindent}
\lstdefinestyle{PSTricks}
{
language={[LaTeX]TeX},
alsolanguage={PSTricks},
basicstyle=\small\ttfamily\null,
keywordstyle=\color{blue},
backgroundcolor=\color{yellow!10},
numbers=left,
numbersep=1em,
numberstyle=\tiny\color{Red}\noaccsupp,
frame=single,
framesep=\fboxsep,% expands outward, cannot affect if frame=none
framerule=\fboxrule,% expands outward, cannot affect if frame=none
rulecolor=\color{red},% cannot affect if frame=none
xleftmargin=\dimexpr\fboxsep+\fboxrule,
xrightmargin=\dimexpr\fboxsep+\fboxrule,
breaklines=true,
breakindent=0pt,
tabsize=5,
columns=flexible,
preset={\setlength{\parindent}{\parindent@save}\centering},
}
\makeatother
\begin{document}
\LTXexample[pos=t,style=PSTricks]
\begin{pspicture}[showgrid](3,3)
\pscircle[linecolor=red](1.5,1.5){1.5}
\end{pspicture}
\endLTXexample
\end{document}
Second Attempt (pdflatex)
Using pdflatex can prevent users from copying the listing numbers. However, preset=\centering is no longer work when I use graphic.
\documentclass[dvipsnames,border=12pt,preview]{standalone}
\usepackage{xcolor}
\usepackage{showexpl}
\usepackage{accsupp}
\newcommand*{\noaccsupp}[1]{\BeginAccSupp{ActualText={}}#1\EndAccSupp{}}
\makeatletter
\newlength{\parindent@save}
\setlength{\parindent@save}{\parindent}
\lstdefinestyle{PSTricks}
{
language={[LaTeX]TeX},
alsolanguage={PSTricks},
basicstyle=\small\ttfamily\null,
keywordstyle=\color{blue},
backgroundcolor=\color{yellow!10},
numbers=left,
numbersep=1em,
numberstyle=\tiny\color{Red}\noaccsupp,
frame=single,
framesep=\fboxsep,% expands outward, cannot affect if frame=none
framerule=\fboxrule,% expands outward, cannot affect if frame=none
rulecolor=\color{red},% cannot affect if frame=none
xleftmargin=\dimexpr\fboxsep+\fboxrule,
xrightmargin=\dimexpr\fboxsep+\fboxrule,
breaklines=true,
breakindent=0pt,
tabsize=5,
columns=flexible,
preset={\setlength{\parindent}{\parindent@save}\centering},
}
\makeatother
\usepackage{filecontents}
\begin{filecontents*}{diagram.tex}
\documentclass[pstricks,border=12pt]{standalone}
\begin{document}
\begin{pspicture}[showgrid](3,3)
\pscircle[linecolor=red](1.5,1.5){1.5}
\end{pspicture}
\end{document}
\end{filecontents*}
\immediate\write18{latex diagram.tex && dvips diagram.dvi && ps2pdf diagram.ps}
\begin{document}
\LTXinputExample[pos=t,style=PSTricks,graphic={[scale=1]"diagram"}]{diagram.tex}
\end{document}
Original Output:

Expected Output:

Question
How to center the graphic of \LTXexample for the code shown in the Second Attempt section?

LTXexampleandLTXinputExamplewith nographicoption used. – kiss my armpit Jul 26 '14 at 05:01