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 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
add comment

1 Answer

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:

\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.

share|improve this answer
1  
Don't be sorry! –  Andrew Stacey Jun 8 '11 at 18:19
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.