Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.
\documentclass[border=12pt]{standalone}
\usepackage{pstricks-add}

\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?

share|improve this question
    
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

2 Answers 2

up vote 2 down vote accepted

This makes some assumptions on dvips, probably but:

enter image description here

\documentclass[border=12pt]{standalone}
\usepackage{pstricks-add}

\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} 
share|improve this answer
    
Let us change zzz to 2 and compare both numbers. They look different in size and appearance. Could you make them identical? –  stalking is prohibited 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}
\usepackage{pstricks-add,pst-tools}

\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} 

enter image description here

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.

share|improve this answer
    
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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