# Unit-free ratios in \path let

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.

-
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

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:

\documentclass{article}
\usepackage{tikz} \usetikzlibrary{calc}
\begin{document}
\def\pgfmathpostparse{\global\pgfmathunitsdeclaredfalse}
\tikz \path let \n1 = {1pt} in node {\n1};
\end{document}


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.

-
Don't be sorry! –  Andrew Stacey Jun 8 '11 at 18:19