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 want to compute pure ratios of distances in a \path let construction; for example, in the document fragment

\path let \p1 = (1cm, 2cm), \n1 = {\y1 / \x1} in ...

I would like \n1 to be the number 2, not the string 2pt, which is what TikZ actually writes because the computation involves a unit somewhere, even though they cancel out. One bad solution is to write \expandafter\strip@pt\n1 everywhere, but is there a way to signal to the PGF math engine that \ifpgfmathunitsdeclared (which controls this decision and is set somewhere inside \pgfmathparse) should be let to \iffalse? I'm imagining a construction like

\path let \p1 = (1cm, 2cm), \n1 = {nounits(\y1 / \x1)} in ...

or some other thing that can be placed inside the math expression itself.

share|improve this question
Not a direct answer: You can add \pgfextra{\pgfmathsetmacro\ratio{\y1/x1}} to the path (after in). – Caramdir Jun 8 '11 at 15:39
You could use \def\m{\expandafter\expandafter\expandafter\strip@pt\n} and then use \m1 instead. – Martin Scharrer Jun 8 '11 at 15:39
I think it is a bug of pgf package. There is a real function to remove the units, but it does not work here. – Leo Liu Dec 16 '13 at 7:12
up vote 3 down vote accepted

After trawling through the documentation again, I discovered the function \pgfmathpostparse, which is called after \pgfmathparse. It is supposed to modify \pgfmathresult but there's no reason you can't just do this:

\usepackage{tikz} \usetikzlibrary{calc}
 \tikz \path let \n1 = {1pt} in node {\n1};

It prints "1.0"; commenting out the \def line makes it print "1.0pt" instead, so indeed this does what I want. The \global is necessary because, apparently, \pgfmathpostparse runs inside a group. Sorry for answering my own question.

share|improve this answer
Don't be sorry! – Loop Space Jun 8 '11 at 18:19

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.