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.

I want to do a vector addition with different units as follows,

(1+2pt,3+4pt) % of course this point format will not work for the current PSTricks

My solution is to write the point in PostScript notation. However a problem occurs: I need a new operator to convert pt to the active unit.

The operation I want to do in PostScript looks like the following,

(!1 2 Pt2AU add 3 4 Pt2AU add)

And how to define Pt2AU?

Note that the default active unit in PSTricks is 1 centimeter. But we can change it.

The MWE you can use is given as follows,

\documentclass[pstricks,border=12pt]{standalone}
\SpecialCoor

\pstVerb{/Pt2AU {72.27 div 2.54 mul} bind def}% needs correction to accommodate all possible active unit
\psset{unit=1cm}

\begin{document}
\begin{pspicture}[showgrid](4,4)
    \psline(1,3)(!1 2 Pt2AU add 3 4 Pt2AU add)
\end{pspicture}
\end{document}
share|improve this question
    
You might look inside pstricks.pro and pst-eucl.pro to find cool tricks for manipulating PostScripts. –  A.Ellett Feb 19 '13 at 2:53
add comment

3 Answers

up vote 4 down vote accepted

Try something like this: (I think this version works).

\documentclass{article}
\usepackage{pstricks,pst-node,pst-eucl}
\pagestyle{empty}
\makeatletter
\pstVerb{ /aceGetXcoor {GetNode 0 mul add} bind def
          /aceGetYcoor {GetNode exch 0 mul add} bind def
        }
\newcommand{\mynewnode}[4]{%
    %% #1 = old node
    %% #2 = addition to x-value
    %% #3 = addition to y-value
    %% #4 = new node name
    \pnode( !   tx@EcldDict begin
                /N@#1 aceGetYcoor \expandafter\pst@number\dimexpr #3\relax\space add 
                /N@#1 aceGetXcoor \expandafter\pst@number\dimexpr #2\relax\space add 
                \pst@number\psxunit div exch 
                \pst@number\psyunit div
                end
            ){#4}}
\makeatother
\begin{document}
\psset{xunit=2cm,yunit=20pt}
\begin{pspicture}[showgrid=true](0,0)(5,5)
    \pnode(2,3){A}
    \mynewnode{A}{2cm}{1cm}{B}
    \mynewnode{B}{-1in}{10pt}{C}
    \mynewnode{C}{2em-2ex}{-20ex}{D}
    \psline(A)(B)(C)(D)
\end{pspicture}

\end{document}

enter image description here

This example uses the PostScript library from pst-eucl. It looks like, if you approach it this way (since LaTeX converts all units to pts), that you can pass any unit you like through the parameters #2 and #3 to get the point placed where you want.

share|improve this answer
add comment
\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-node}
\psset{yunit=10pt}

\begin{document}
\begin{pspicture}[showgrid](4,4)
  \pcline[YnodesepB=-3pt,offsetB=10pt](1,3)(1,3)
\end{pspicture}

\end{document}

or

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pstricks-add}
\psset{yunit=10pt}

\def\myLine(#1)(#2){\rput(#1){\psline(#2)}}

\begin{document}
\begin{pspicture}[showgrid](4,4)
  \myLine(1,3)(3pt,10pt)
\end{pspicture}

\end{document}
share|improve this answer
add comment

Stealing the important parts of the A.Ellett's answer.

\documentclass[pstricks,border=12pt]{standalone}
\SpecialCoor
\psset{xunit=1cm,yunit=10pt}% must be declare before \pstVerb!

\makeatletter
\pstVerb
{
    /pt2xu {\pst@number\psxunit div} bind def
    /pt2yu {\pst@number\psyunit div} bind def
}
\makeatother



\begin{document}
\begin{pspicture}[showgrid](4,4)
    \psline(1,3)(!1 3 pt2xu add 3 10 pt2yu add)
\end{pspicture}

\end{document}
share|improve this answer
add comment

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.