TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I use \rput[B](1.5,4.1){\( 1 \)} to write a number at a specific place, now I would like to express an expression at the place of coordinates, for instance \rput[B](2+#1,4.1){\( 1 \)} where #1 is an input of my macro, it returns an error ERROR: Illegal unit of measure (pt inserted). Could anyone help?

enter image description here

share|improve this question
A MWE would be useful. – cacamailg Mar 5 '13 at 18:09
up vote 2 down vote accepted

For allow arithmetic in coordinates, you can use Reverse Polish Notation (or RPN for short). Here's a quick view on what you might be after:

enter image description here

\usepackage{pstricks}% http://tug.org/PSTricks/main.cgi/
  \rput[B](!1.5 #1 add 4.1){#2}

The RPN notation (used under PostScript) is described in section 54 Special coordinates of the pstricks documentation, and requires the use of \SpecialCoor.

RPN in PostScript works on the principle of maintaining a stack. For coordinates, the top two entries represent the x- and y-coordinates being used. By means of example, consider the RPN calculation

2 3 add 4 1 sub mul

I'll use the notation [a b c ...] to denote the PostScript stack, where a is the item at the bottom, with b above that, and c above that...

Read left to right, the following PostScript actions are taken:

  • 2 pushes the number 2 on the stack ~ [2];
  • 3 pushes the number 3 on the stack ~ [2 3];
  • add takes the top two elements from the stack, and adds them together, leaving the result on the stack ~ [5];
  • 4 pushes the number 4 on the stack ~ [5 4];
  • 1 pushes the number 1 on the stack ~ [5 4 1];
  • sub takes the top two elements from the stack, and subtracts them from one another, leaving the result on the stack ~ [5 3];
  • mul takes the top two elements from the stack, and multiplies them together, leaving the result on the stack ~ [15].

Using this, it should be clear that

1.5 #1 add 4.1
  • 1.5 is pushed on the stack ~ [1.5];
  • #1 (the first/optional argument) is pushed on the stack ~ [1.5 #1];
  • add pops the top two elements, adds them and pushes the result r back on the stack ~ [r];
  • 4.1 is pushed on the stack ~ [r 4.1].

Now \rput, knowing that it has been provided with the ! (RAW PostScript code) directive, pops the top two elements which provide the x- and y-coordinates of the point. This takes some getting used to, for sure.

A complete list/reference of PostScript commands (including the above), is available as part of the PostScript LANGUAGE REFERENCE (third edition). Sections of interest include:

  • 3.4 Stacks (p 45), which includes an example like the above;
  • 8.1 Operator Summary (p 508)

When using nodes, however, it offers a more intuitive way of looking at such arithmetic using [nodesep=..,offset=..].

share|improve this answer

That should do the trick:



\cs_new_eq:NN \calc \fp_eval:n




See the picture below An example with numbers

share|improve this answer
Sorry, did you try your code? It gives me ERROR: Undefined control sequence. around \calc, and it shows also +1, I don't where it comes from... – SoftTimur Mar 5 '13 at 18:50
I tried the code. I am using the latest TeXLive 2012. See if your LaTeX distribution is updated. – cacamailg Mar 5 '13 at 18:58

Your Answer


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.