# How to pass a constant defined in \pstVerb as the most right argument of \rput?

\documentclass[border=12pt]{standalone}

\def\i{1}

\begin{document}
\begin{pspicture}(4,4)
\pstVerb{/two \i\space 1 add def}
\rput(2,2){<the value of two>}
\end{pspicture}
\end{document}


How to pass a constant defined in \pstVerb as the most right argument of \rput?

-
what do you want to do with it? you could use \rput(2,2){\pstVerb{two}} which will insert two into the postscript so put the integer 2 on the stack, or you could use \pstVerb{two 10 string cvs show} which will convert the integer 2 into the string (2) (using a buffer of length 10 so assuming the integer not too big) then show it at the current point, but I have no idea where the current point is in a pstVerb context (not looked at the manual for a decade or two:-) \pstVerb{two ==}  make postscript echo 2 (as you will see on the terminal if you run ps2pdf on the dvips output – David Carlisle Jul 19 '12 at 19:34

This makes some assumptions on dvips, probably but:

\documentclass[border=12pt]{standalone}

\def\i{1}

\begin{document}
\begin{pspicture}(4,4)
\pstVerb{/two \i\space 1 add def}
\rput(2,2){zzz \pstVerb{/Times-Roman findfont 100 scalefont 1 -1 scale setfont two 10 string cvs  show}}
\end{pspicture}
\end{document}

-
Let us change zzz to 2 and compare both numbers. They look different in size and appearance. Could you make them identical? – kiss my armpit Jul 19 '12 at 20:37
no. even if I restricted completely to assumptions about dvips internal postscript definitions I have no idea what postscript font name dvips would use for the current font. if dvips is doing font subsetting and the 2 isn't used via tex then there may not even be a font defined with that character in. So I ignored the TeX fonts and loaded the core postscript times roman font. Similarly I don't know (but it's possible to discover from the header or asking postscript for the current coordinate matrix what the scale factor should be I just made it 100 -100 so it was visible and not reflected. – David Carlisle Jul 19 '12 at 20:44

After struggling for many hours, I found a macro called \psPrintValue that is buried in pst-tools package.

\documentclass[border=0pt]{standalone}

\def\i{1}

\begin{document}
\begin{pspicture}(1,1)
\pstVerb{/two \i\space 1 add def}
\rput(0.5,0.5){2\psPrintValue{two}}
\end{pspicture}
\end{document}


However, the font is not identical to the font used in TeX. If you have any idea to fix it, please edit this answer.

Edit: Use times package to fix the font issue.

-
yes looking at the source of that it's doing basically the same as my answer (but more carefully and covering more cases, as it's more than a line of code:-) But it still doesn't try to match fonts. (as you note, if changing the font of the entire document to times is an option that makes it easier to match) – David Carlisle Jul 19 '12 at 21:54