2

I need to extract the text that a tikz path generates. for example if I have a path defined as:

\path[name path = pathtwo, draw,blue] (\CX,\CY) circle (\CR);

I want to be able to extract the path as:

\def\pathtwo{(\CX,\CY) circle (\CR)}
M.M.
  • 75
  • 2
    That's not possible with TikZ unless you define the path with a macro and use it on the path. – percusse Mar 25 '18 at 18:07
  • 2
    There is no such thing as "the text" of a path. Different commands can generate the same path. – Kpym Mar 25 '18 at 19:55
  • There are different ways to interpret this question. So let me ask you: do you know that it is a circle and you want to extract its radius and center? If so, this is perhaps possible. –  Mar 26 '18 at 02:30

1 Answers1

2

At least, you could store and reuse later the same path :

enter image description here

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections}

\makeatletter

%%%%                ---- Use path several times
%%%%                ---- thanks to Andrew Stacey
%%% http://tex.stackexchange.com/questions/26382/calling-a-previously-named-path-in-tikz


\makeatletter
\tikzset{
  use path for main/.code={%
    \tikz@addmode{%
      \expandafter\pgfsyssoftpath@setcurrentpath\csname tikz@intersect@path@name@#1\endcsname
    }%
  },
  use path for actions/.code={%
    \expandafter\def\expandafter\tikz@preactions\expandafter{\tikz@preactions\expandafter\let\expandafter\tikz@actions@path\csname tikz@intersect@path@name@#1\endcsname}%
  },
  use path/.style={%
    use path for main=#1,
    use path for actions=#1,
  }
}

\makeatother
\begin{document}
\begin{tikzpicture}

\path[name path = pathtwo] (0,0) circle (2);

\draw[use path = pathtwo, red,ultra thick] ;

\draw[use path = pathtwo, white] ;

\end{tikzpicture}
\end{document}
Tarass
  • 16,912
  • It's cool, but I need to extract the text that generates the path. – M.M. Mar 25 '18 at 19:52
  • 1
    You could not with TikZ unless you define the path with a macro and use it on the path. You have to store the definition text in a macro for example, and reuse it then. As YOU generate the first path, YOU alraidy know its definiton, keep a copy of it then you dont have to recreate its definition knowing that is not possible. – Tarass Mar 25 '18 at 19:58
  • 1
    Very nice! (+1) But could you perhaps link Andrew Stacey's post to your answer? –  Mar 25 '18 at 21:59
  • 1
    @marmot I found it, was a long time ago. He made a new package since : spath. – Tarass Mar 26 '18 at 08:20