重設 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.
}

相關內容