In the stamp class example in the pgfmanual, the position for the stamp is passed in as two separate numbers, an x coordinate and a y coordinate. Is it possible, instead, to pass in a coordinate or a 'point' of some kind?

@percusse I have made some progress since I posted the question but it's not very elegant. I would welcome pointers on a better way to get the coordinates into the class.


  \method rr(#1,#2) { % The constructor; everything is done in here
    % This doesn't seem to work
    % \def\start{#1} % nor \def\start{(#1)}
    % But here I can get named x and y coordinates
    % I'd like named points to work with
    \coordinate (Start) at (\spx, \spy);
    \coordinate (End) at (\epx, \epy);
   \draw (Start) -- (End) node[right] {It works!};

    \coordinate (A) at (0,0);
    \coordinate (B) at (0,-1);
    \pgfoonew \AB=new rr(A,B);
    \fill (A) circle (3pt);
    \fill (B) circle (3pt);

I am refactoring some code I wrote years ago. This is where I'm going:enter image description here

  • Yes but then you have to process the point and use the coordinates, can you provide your own code?
    – percusse
    Commented Oct 9, 2016 at 12:05
  • @percusse I have added code to my original question but I'm not sure whether you will be notified of the change so I've added this comment. I see your name frequently answering questions here and I'd appreciate feedback on the etiquette: should I edit the question or include all the code in a comment?
    – dmorg
    Commented Oct 12, 2016 at 2:08
  • No this is perfect. Thank you. Indeed it is the comment ping that goes out to users inbox not the question edits. I'll try to have a look in the evening.
    – percusse
    Commented Oct 12, 2016 at 9:27
  • You start with named coordinates. Then you break them up. Then you turn them back into named coordinates, where these are the same coordinates you started with but named differently. This seems a very scenic route .... Why not just \coordinate (start) at (#1);? I'm missing something obvious, I guess ....
    – cfr
    Commented Oct 13, 2016 at 21:58
  • Yes, it's a circuitous route but I haven't managed to access the coordinates directly from the method parameters. @percusse mentioned above that, although you can pass the coordinates, you then have to extract the x and the y coordinates. If you h
    – DaveM
    Commented Oct 15, 2016 at 18:57

1 Answer 1


The reason why the position is passed as two separate numbers is that the comma in \mystamp.apply(1,2) serve as the separator of parameters, not part of the coordinate.

You probably had already known that in the usual TikZ, it is inappropriate to write


simply because the comma serves as the separator of styling keys, and one should instead write


Here the idea is the same: if you are willing to protect your parameters by braces, then you can pass almost everything: including but not limited to

  • xy-coordinates (1,2)
  • xyz-coordinates (3,4,5)
  • polar coordinates (60:7)
  • coordinate system (canvas cs:x=8,y=9)
  • node and node-anchor (A.south east)
  • calculations provided by calc library ($(A)+(B)!.5!(C)$)

Basically the dirty job is done by the underlying TikZ parser, and the oo part is merely syntactic sugar.


    \method pen(){
    \method point(#1,#2,#3){ % position,name,color
        \path(#1)coordinate(#2)node[below right,text=#3]{$#2$};
    \method segment(#1,#2,#3){ % start,end,color
    \method ray(#1,#2,#3){ % start,end,color
        \draw[#3,overlay,shorten >=-10000](#1)--(#2);
    \method line(#1,#2,#3){ % start,end,color
        \draw[#3,overlay,shorten <=-10000,shorten >=-10000](#1)--(#2);
\pgfoonew \mypen=new pen()
    \mypen.point({current bounding box.200},B,olive)


  • What I've ended up doing is passing the coordinates, then using a \gettikzxy function to extract the x and y values. It's easier to do that once in the object constructor than every time I instantiate a new object.
    – dmorg
    Commented Dec 4, 2016 at 6:52
  • @dmorg It is good to see you solve the problem by yourself. By the way, I have never seen any PGF/TikZ library that is built over oo. I certainly have no idea, and no preference, how things should be done.
    – Symbol 1
    Commented Dec 4, 2016 at 16:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .