2

Is there a easy way to clear/reset/delete pgfkeys? First I thought that maybe the command saves the old values. But also with \let\mbftext\undefined the value of e.g. the text key is still there. I want that there is no text in the second myvector. Of course text= would be possible but it's not a nice way.

\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
  • One way is text/.default= in \pgfkeys{} and text in \myvectorset{#1, ...}. But I need to do that for every key ... is there a more usable way?
    – fatts
    Jul 5, 2017 at 11:55

1 Answer 1

2

You should put the \myvectorset call in a group, so that the pgf keys definitions stay local to your \myvector macro.

\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.
}
1
  • This is surely the reason why you can find these \begingroup \endgroup commands in a lot of macrodefenitions. Thx. So many things need to be considered.
    – fatts
    Jul 5, 2017 at 12:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .