重置 pgfkeys/删除 pgfkeys

重置 pgfkeys/删除 pgfkeys

有没有简单的方法来清除/重置/删除 pgfkeys?首先我认为该命令可能会保存旧值。但例如\let\mbftext\undefined文本键的值仍然存在。我希望第二个 myvector 中没有文本。当然text=是可能的,但这不是一个好方法。

\documentclass[10pt]{article}
\usepackage[a4paper,top=1in, bottom=1in, left=1in, right=1in]{geometry}
\usepackage{tikz}
\usetikzlibrary{calc,arrows.meta,bending,decorations.text,positioning}

\def\centerarct[#1](#2)(#3:#4:#5)% Syntax: [draw options] (center) (start angle:end angle:radius)
{ \path[#1] ($(#2)+({#5*cos(-#3+90)},{#5*sin(-#3+90)})$) arc [start angle={-#3+90}, end angle={-#4+90}, radius=#5)]; }

\pgfkeys{
 myvector/.is family,
 myvector,
 radius/.initial=4.5cm,
 line width/.initial =5mm,
 color/.initial=orange,
 text align/.initial=center,
 text/.initial,
 raise/.initial=0mm
}


\newcommand\myvectorset[1]{\pgfkeys{myvector,#1}}

\def\myvector[#1](#2){
 \myvectorset{#1,
  radius/.get=\mbfradius,
  line width/.get=\mbflinewidth,
  color/.get=\mbfcolor,
  text align/.get=\mbftextalign,
  text/.get=\mbftext,
  raise/.get=\mbfraise
     }
 \centerarct[{Triangle[width=9mm,length=5mm]}-,draw=\mbfcolor,line width=\mbflinewidth,postaction={decorate,decoration={text along path,text align/.expand once=\mbftextalign,text=\mbftext,raise=\mbfraise}}](#2)(180:1:\mbfradius);
 \let\mbftext\undefined
}

\begin{document}
 \begin{tikzpicture}
  \myvector[text align={right,right indent=1cm},raise=-1.25mm,text=Test (0,0);
  \myvector[{text align={right,right indent=1cm}},raise=-1.25mm,radius=6cm](0,0);
 \end{tikzpicture}
\end{document}

答案1

您应该将\myvectorset调用放在一个组中,以便 pgf 键定义保持在您的\myvector宏的本地。

\def\myvector[#1](#2){
\begingroup
\myvectorset{#1,
  radius/.get=\mbfradius,
  line width/.get=\mbflinewidth,
  color/.get=\mbfcolor,
  text align/.get=\mbftextalign,
  text/.get=\mbftext,
  raise/.get=\mbfraise
}
\centerarct[
    {Triangle[width=9mm,length=5mm]}-,
    draw=\mbfcolor,
    line width=\mbflinewidth,
    postaction={
        decorate,
        decoration={
            text along path,
            text align/.expand once=\mbftextalign,
            text=\mbftext,
            raise=\mbfraise
        }
    }
](#2)(180:1:\mbfradius);
\endgroup % When leaving a group, local definitions are reverted.
}

相关内容