Is there anyway that during the decoration process I can save the value of \pgfdecoratedpathlength to some macro (via xdef or some other mechanism)?

  • Yes, it's possible. Do you want to store the length of the input path or the length of the path after some decoration process? – Paul Gaborit May 30 '15 at 6:57
  • @PaulGaborit i want the input length, assuming that's the entire length of the – A.Ellett May 30 '15 at 7:02

Here is a way to globally store the path length.


\pgfdeclaredecoration{store path length}{final}{
\tikzset{store path length/.style={
   preaction={decorate,decoration={store path length}}}


  \draw[store path length] (0,0) -- (1in,0) -- (1in,1in);
  \typeout{==> \pathlength}

  \draw[store path length] circle(50pt);
  \typeout{==> \pathlength}

During compilation, this document writes:

==> 144.53998pt
==> 314.19373pt
  • Argh. I thought I'd tried something like this. Only I was mucking around in \state{initial}. – A.Ellett May 30 '15 at 15:59
  • I'm traveling most of today and tomorrow. I'll look at this a bit closer on Monday. – A.Ellett May 30 '15 at 15:59
  • I just successfully used your code. It would be great if you could explain a little bit what is happening (pseudo code)? – Dr. Manuel Kuehner Jan 6 '17 at 20:22
  • 1
    @Dr.ManuelKuehner The store path length decoration is a fake decoration that only store the total length of the path into \pathlength. The store path length style apply this decoration as preaction to a path. – Paul Gaborit Jan 7 '17 at 0:25

Here's another way...

  get path length/.code={%
\begin{tikzpicture}[x=1pt, y=1pt]
\draw [get path length=\a] (-20, -20) rectangle ++(40, 40);
\node {\a};

\draw [get path length=\b] circle [radius=50];
\node  {\b};


enter image description here

  • Very interesting. I'll have to play with this a bit since you're using several macros I'm unfamiliar with. – A.Ellett May 30 '15 at 16:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.