# Conversion from pstricks coordinates to postscript coordinates

I am making a custom graphics library on top of pstricks and I need to convert from pstricks coordinates to postscript coordinates. I have a "working" example, cooked up via painful trial-and-error process, but I am sure it can be done properly. Reading the pstricks.tex file, I was left with the impression that pstricks uses somehow \pst@coor or - some other macro - perhaps you know better - to convert from pstricks coordinates to postscript coordinates. I have not been able to decode how that works. So here is my working solution.

My concrete question to you is: what are the native pstricks conversion functions I should use in place of \fcConvertPSXUnit and \fcConvertPSYUnit in the code below?  Question was answered below by Herbert. Including his answer in this post.

If done properly, the code below should display a perfect square cross (the top part of the cross is drawn using native pstricks, and the bottom part is drawn via the conversion functions).

\documentclass{article}
\usepackage{auto-pst-pdf}
%to convert points to numbers, macro copied from stackexchange
\makeatletter
\begingroup
\catcode P=12  % digits and punct. catcode
\catcode T=12  % digits and punct. catcode
\lowercase{%
\def\x{\def\rem@pt##1.##2PT{##1\ifnum##2>\z@.##2\fi}}}
\expandafter\endgroup\x%
\newcommand{\stripPoints}[1]{\expandafter\rem@pt\the#1}
\newcommand{\fcConvertPSXUnit}{\stripPoints{\psxunit} 72.27 div 8000 mul mul\space %
\pst@number\pst@dima\space %3 sub
72.27 div 8000 mul sub  %
}%
\newcommand{\fcConvertPSYUnit}{\stripPoints{\psyunit} 72.27 div -8000 mul mul\space %
\pst@number\pst@dimb\space 72.27 div -8000 mul sub %
}%
\makeatother

\begin{document}
\psset{xunit=1.2cm, yunit=1.2cm}
\begin{pspicture}(-2.3,-2.7)(2.1,2.55)%
\psline (0,0)(0,1)%
\psline (0,0)(1,0)%
\pstVerb{ %
100 setlinewidth %
newpath %
0 \fcConvertPSXUnit 0 \fcConvertPSYUnit moveto %
-1 \fcConvertPSXUnit 0 \fcConvertPSYUnit lineto %
0 \fcConvertPSXUnit 0 \fcConvertPSYUnit moveto %
0 \fcConvertPSXUnit -1 \fcConvertPSYUnit lineto %
stroke %
}%
\end{pspicture}
\end{document}


The code from Herbert that answers my question:

\documentclass{article}
\usepackage{auto-pst-pdf}
\usepackage{pstricks} %that should had been included

\begin{document}

\psset{xunit=1.2cm, yunit=1.2cm}
\begin{pspicture}(-2.3,-2.7)(2.1,2.55)%
\makeatletter
\psline (0,0)(0,1)%
\psline (0,0)(1,0)%
\pscustom{ %
\code{ %
100 setlinewidth %
newpath %
0  0 \tx@ScreenCoor\space moveto %
-1 0 \tx@ScreenCoor\space lineto %
0 0 \tx@ScreenCoor\space moveto %
0 -1 \tx@ScreenCoor\space lineto %
stroke %
}%
}%
\makeatother

\end{pspicture}
\end{document}

• How should your example work? You did not load the package pstricks!
– user2478
Commented Sep 28, 2014 at 16:06
• The % inside \pstVerb are cpmpletely superflous
– user2478
Commented Sep 30, 2014 at 13:53
• And use 2 \pst@number\psunit mul setlinewidth. However, as I already wrote your origin is not the one from pspicture.
– user2478
Commented Sep 30, 2014 at 14:22
• That was a typo, editted the wrong piece of code. Now uses \pscustom and \code, and so does my library. Commented Oct 1, 2014 at 15:00

\documentclass{article}
\usepackage{pstricks}

\begin{document}
\psset{xunit=1.2cm, yunit=1.2cm}
\begin{pspicture}[showgrid](-2.3,-2.7)(2.1,2.55)
\psline (0,0)(0,1)
\psline (0,0)(1,0)
\pscustom{
\moveto(0,0)
\lineto(-1,0)
\moveto(0,0)
\lineto(0,-1)
\stroke[linewidth=2pt,linecolor=red]
}
\end{pspicture}
\end{document}


if you do not want the basic macros \moveto et al then use for example:

\code{0 0 moveto -1 0 \tx@ScreenCoor\space lineto}


inside \pscustom and with a \makeatletter before the pspicture environment:

\documentclass{article}
\usepackage{auto-pst-pdf}
\usepackage{pstricks}
\begin{document}

\makeatletter
\psset{xunit=1.2cm, yunit=1.2cm}
\begin{pspicture}(-2.3,-2.7)(2.1,2.55)
\psline (0,0)(0,1)
\psline (0,0)(1,0)
\pscustom{%
\code{
newpath
2 setlinewidth
0  0 \tx@ScreenCoor\space moveto
-1 0 \tx@ScreenCoor\space lineto
0 0 \tx@ScreenCoor\space moveto
0 -1 \tx@ScreenCoor\space lineto
stroke
}}%
\end{pspicture}
\makeatother
\end{document}

• The very last doesn't appear to work on my machine, something is not ok with \tx@ScreenCoor. Posting my code above .... Commented Sep 28, 2014 at 13:36
• I want to do everything in postscript - I am going to be doing complex tasks such as z-buffering, so I want to work in postscript directly. Commented Sep 28, 2014 at 13:39
• using \code and \pscustom is using PS directly. It has only the advantage that the origin of the coordinate system is used.
– user2478
Commented Sep 28, 2014 at 15:46
• I see, that may indeed be a nice way to integrate with pstricks. What is the difference between \pstVerb and \code? Commented Sep 28, 2014 at 16:20
• \pstVerb uses the global origin (upper left corner of the page). \pscustom uses the local origin defined by the coordinates of pspicture
– user2478
Commented Sep 28, 2014 at 16:32