如何从现有路径中提取生成路径所需的文本?

如何从现有路径中提取生成路径所需的文本?

我需要提取 tikz 路径生成的文本。例如,如果我有一个定义为如下的路径:

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

我希望能够提取以下路径:

\def\pathtwo{(\CX,\CY) circle (\CR)}

答案1

至少,您可以存储并在以后重用相同的路径:

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}

相关内容