3

The question might be dumb but I can't find an adequate solution.

If I put a comma separated value list as parameter using pgfkeys, then the result of pgfkeysvalueof is an atomic value and not a list.

The code (that is not working) is this:

\documentclass{article}
\usepackage{fontenc}
\usepackage{tikz}
\usepackage{color}
\usetikzlibrary{shapes,
    shapes.geometric,
    shapes.symbols,
    shapes.arrows,
    shapes.multipart,
    shapes.callouts,
    shapes.misc,
    tikzmark,
    arrows, 
    positioning,
    calc,
    math,
    scopes,
}

\tikzstyle{every entity} = []
\tikzstyle{entity} = [shape=rectangle, draw, black,  thick,
                      minimum width=6em, minimum height=3em,
                      every entity]

% \usepackage[active,pdftex,tightpage]{preview}
\newcommand{\rol}[3][type=normal,arcfmt=--,card=N,total=false]{
\pgfkeys{/incoMer/.cd,
startPoint/.initial={-},
endPoint/.initial={},
arcfmt/.initial={--},
rolname/.initial={},
rolnameParams/.initial={},
card/.initial={N},
cardpos/.initial={above},
#1,
}

\draw [-] (#2) \pgfkeysvalueof{/incoMer/arcfmt} node[pos=0.80,\pgfkeysvalueof{/incoMer/cardpos}]{\pgfkeysvalueof{/incoMer/card}} 
            node[\pgfkeysvalueof{/incoMer/rolnameParams}]{\pgfkeysvalueof{/incoMer/rolname}} (#3);
}

\title{prueba}
\begin{document}
% Comienza el Mer
\begin{tikzpicture}
  % Entidad Estudiantes
\node[entity](st){Students};

\node[entity][left=5cm of st](cs){Courses};

\rol[%
    arcfmt={edge[bend left,sloped]},
    rolname={very very very long test},
    rolnameParams={below,sloped},
    %rolnameParams={below},
    ]{st}{cs};

\end{tikzpicture}


\end{document}

When the rolnameParams line is changed by commenting the line and removing the % in the next line, it all works fine.

The error is:

Package pgfkeys Error: I do not know the key '/tikz/below,sloped' and I am going to ignore it. Perhaps you misspelled it.

It must be noted that the arcfmt parameter works fine but if the same strategy is used for the node, it doesn't work.

Why is this and how can this be solved?

1 Answer 1

2

The parser for the list of PGF keys in the optional argument of \node looks for the comma separators before expanding anything, therefore in your case \pgfkeysvalueof{/incoMer/rolnameParams} is considered to produce (after expansion!) a single PGF key, hence the error message.

I propose to use a style here (named /incoMer/impl/rolnameParams@style), and define this style from key rolnameParams of the optional argument of \rol using \pgfqkeys{/incoMer}{#1}, where rolnameParams is itself a style that defines /incoMer/impl/rolnameParams@style using its argument:

rolnameParams/.style={/incoMer/impl/rolnameParams@style/.style={#1}}

The same holds for cardpos, which is also used to produce a list of PGF keys. Other things:

  • I improved the structure;

  • don't use the long-obsolete \tikzstyle—use \tikzset and the .style pgfkeys handler instead;

  • don't use ; after your own macro calls (this causes the warning Missing character: There is no ; in font nullfont! in your example);

  • please write a minimal example next time.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}

\tikzset{
  every entity/.style={},
  entity/.style={
    shape=rectangle, draw, black, thick,
    minimum width=6em, minimum height=3em, every entity},
}

\makeatletter
\pgfkeys{
  /incoMer/.cd,
  arcfmt/.initial={--},
  rolname/.initial={},
  card/.initial={N},
  % Styles
  impl/cardpos@style/.style={above},
  cardpos/.style={/incoMer/impl/cardpos@style/.style={#1}},
  impl/rolnameParams@style/.style={},
  rolnameParams/.style={/incoMer/impl/rolnameParams@style/.style={#1}},
}

\newcommand*{\rol}[3][type=normal,arcfmt=--,card=N,total=false]{%
  \begingroup
    \pgfqkeys{/incoMer}{#1}%
    \draw [-] (#2) \pgfkeysvalueof{/incoMer/arcfmt}
      node[pos=0.80, /incoMer/impl/cardpos@style]{\pgfkeysvalueof{/incoMer/card}}
      node[/incoMer/impl/rolnameParams@style] {\pgfkeysvalueof{/incoMer/rolname}}
      (#3);
  \endgroup
}
\makeatother

\begin{document}
\begin{tikzpicture}
\node[entity] (st) {Students};

\node[entity, left=5cm of st] (cs) {Courses};

\rol[%
    arcfmt={edge[bend left,sloped]},
    rolname={very very very long test},
    rolnameParams={pos=0.3,below,sloped},
  ]{st}{cs}                 % don't end this with ';'

\end{tikzpicture}
\end{document}

enter image description here

You must log in to answer this question.

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