6

The basic idea is from How can I create new commands in TikZ?

\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=Label,
    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=\mbftextalign,text=\mbftext,raise=\mbfraise}}](#2)(180:1:\mbfradius);
}

\begin{document}
 \begin{tikzpicture}
  \myvector[text align=right,raise=-1.25mm](0,0);
 \end{tikzpicture}
\end{document}

It works. But unfortunately if I use

\myvector[text align={right,right indent=1cm},raise=-1.25mm](0,0);

the result is

! Package pgfkeys Error: I do not know the key '/pgf/decoration/text align/righ t,right indent=1cm' and I am going to ignore it. Perhaps you misspelled it.

I read about key handlers but I didn't found a way out.

6
  • Have you tried \myvector[{text align={right,right indent=1cm}},raise=-1.25mm](0,0);?
    – cfr
    Commented Jul 4, 2017 at 12:16
  • I tried it just now. No change.
    – fatts
    Commented Jul 4, 2017 at 12:18
  • I guess text align=\mbftextalign will treat \mbftextalign as a key instead of list of keys. I think it is better to use /.style to store list of keys.
    – Symbol 1
    Commented Jul 4, 2017 at 12:33
  • Why do you need to even create all of those keys? Most of them are just standard keys anyway, including text align, aren't they?
    – cfr
    Commented Jul 4, 2017 at 12:58
  • For the mwe I changed the code to make it more easy. But in the end I want to use also own keys. The main goal is a command \myvector[options] (xcoord,ycoord); and options is key1=value1,key2=value2, ...; keys are standard, some are own and needed to calculate some thing for plotting the vector
    – fatts
    Commented Jul 4, 2017 at 13:04

1 Answer 1

4

This is the case where the .expand once handler is useful. In the myvector macro definition you have somewhere:

text align=\mbftextalign

What you want is to set text align to the expansion of the \mbftextalign macro. You can do this easily with:

text align/.expand once=\mbftextalign

Of course, you should do the same modification with the other keys where expansion is needed.

1
  • This solves it!
    – berkus
    Commented Jul 4, 2017 at 17:29

You must log in to answer this question.

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