# tkz-graph : inconsistency between edge and loop

I'm discovering the great package tkz-graph and I am experiencing some trouble with the \Loop macro.

There seem to be some inconsistencies between the \Loop macro and the \Edge macro. For example, in the following document, the labels of the edges are not placed in the same way. First, the loop has an array but the edge does not. Second, the syntax  for math-mode works only in the case of the loop.

\documentclass{minimal}
\usepackage{fixltx2e}
\usepackage{tkz-graph}
\begin{document}
\begin{tikzpicture}[scale=1]
\Vertex{A}
\Vertex[x=2,y=0]{B}
\Loop[dist=1.5cm,dir=WE,label=$$x$$](A)
\Edges[label=$y$](A,B)
\end{tikzpicture}
\end{document}


Third, the macro \tikzset{EdgeStyle/.append style = …}doesn't work for loops and I did not find a solution in the user manual. For example, \tikzset{EdgeStyle/.append style ={->}} doesn't use the same arrow tip for the edge and for the loop.

Finally, the use of style={->} produces different results in the loop than in the edge (the path is thicker in the latter). Here is the output from the code above, but with \tikzset{EdgeStyle/.append style ={->}}:

-
I get a ./file.tex:8:Bad math environment delimiter. \Loop[dist=1.5cm,dir=WE,label=$$x$$](A). So the $$x$$ doesn't work for the loop for me either. Furthermore, if I set the EdgeStyle it also applies to the loop for me. Which version of tkz-berge are you using? –  Roelof Spijker Nov 22 '11 at 11:12
The MWE works with me... (Win7, MikTeX 2.9, tkz-berge updated today) –  Count Zero Nov 22 '11 at 11:13
@wh1t3 I use the 2011/06/01 1.00 version of tkz-berge. Note that you need to use the fixltx2e package in order to $$x$$ works in the loop. –  Matsaya Nov 22 '11 at 12:00
Apparently I had an outdated version of fixltx2e. After using that, it appeats that $$x$$ is indeed working. In the Edge it complains about a missing argument though. For some reason it appears that it is expecting an argument after \). Putting {} after it confirms this by fixing the error and resulting in output as we would expect. As far as the EdgeStyle goes, I presume the Loop defines it's own arrow tip, since it already has one by default. The EdgeStyle is loaded first and is then replaced. If you use ,for instance, dashed as the EdgeStyle it does operate on the loop. –  Roelof Spijker Nov 22 '11 at 12:14
@Matsaya I agree with about some inconsistency between the loop macro and the edge macro : with edge style is before EdgeStyle and with with Loop it's EdgeStyle the first option. Sorry for this bug because the behavior is different. –  Alain Matthes Nov 22 '11 at 17:13

Sorry for the french documentation but with the next version I will try to write a english version. The question is about tkz-graphand not tkz-bergeand tkz-bergehas an english doc !!

A last detail before my answer, I'm not happy about the options(styles) of these packages because I wrote them with xkeyval and it's difficult to get the same options than Tikz. I will write the next version with pgfkeys.

Now the problem appears because there are a lot of method to change the styles. EdgeStyleis used to modify a global style for edges, LoopStyle is a global style for loops and style is local; Loop first looks at EdgeStyle, then at LoopStyle and at the end applies a local style if this style exists. For the labels, you have LabelStyle and then labelstyle

The code is

\def\tkzGR@loop[#1](#2){%
\setkeys[GR]{loop}{#1}%
\protected@edef\@tempa{%
\noexpand \draw[\cmdGR@loop@color] (#2)%
edge [EdgeStyle,LoopStyle,\cmdGR@loop@style]%
node [LabelStyle,\cmdGR@loop@labelstyle]%
{\cmdGR@loop@label} (#2)}\@tempa;%
}%


A possible solution is

\documentclass{minimal}
\usepackage{fixltx2e}
\usepackage{tkz-berge}

\tikzset{LabelStyle/.style= {fill=yellow}}

\begin{document}
\begin{tikzpicture}[scale=1]
\Vertex{A}
\Vertex[x=2,y=0]{B}
\Loop[dist=1.5cm,dir=WE,label=$$x$$,
labelstyle={left=12pt,color=red,fill=white,draw}](A)
\Edges[label=$y$](A,B)
\end{tikzpicture}
\end{document}


I agree if you find the styles unclear or confused but I will make something better with pgfkeysin the next version. I need to make the versions compatible because tkz-graph is used by lot of people.

The first solution of Count Zero is fine too

Update : Another solution is to define a personal style and to use only Tikzto draw the loops. It's always possible to use tikz.

-
Maybe I can help with the translation? –  Count Zero Nov 22 '11 at 18:26
yes your help is welcome because my english language is poor!! –  Alain Matthes Nov 22 '11 at 19:48
Thank you for the precise explanation, and for the future changes in tkz-graph ;) –  Matsaya Nov 25 '11 at 13:42

You have two options:

1. either you put a white (or other color, but not transparent) background to your node:

\documentclass{minimal}
\usepackage{fixltx2e}
\usepackage{tkz-berge}

\tikzset{LabelStyle/.style= {fill=white}}

\begin{document}
\begin{tikzpicture}[scale=1]
\Vertex{A}
\Vertex[x=2,y=0]{B}
\Loop[dist=1.5cm,dir=WE,label=$$x$$](A)
\Edges[label=$y$](A,B)
\end{tikzpicture}
\end{document}

2. or you displace the label (this is probably a less elegant hack):

\documentclass{minimal}
\usepackage{fixltx2e}
\usepackage{tkz-berge}

\begin{document}
\begin{tikzpicture}[scale=1]
\Vertex{A}
\Vertex[x=2,y=0]{B}
\tikzset{LabelStyle/.style= {xshift=-.25cm}}
\Loop[dist=1.5cm,dir=WE,label=$$x$$](A)
\tikzset{LabelStyle/.style= {xshift=0cm}}% set shift back to original (0) value
\Edges[label=$y$](A,B)
\end{tikzpicture}
\end{document}


whichever you prefer. :) Note that in both cases I fumbled with LabelStyle/.style=... not EdgeStyle.

EDIT: EdgeStyle takes a labelstyle parameter, which is basically the same as modifying directy the LabelStyle. Therefore I doubt there is another workaround.

PS: Too bad the documentation is only in French... I'm saying this because the tkz package family is asolutely terrific and in fact this language barrier prevents lots of people from using them.

-
I have thought about the withe background, but I think it's more a hack than an elegant way do do it. But maybe it's not possible to do better. –  Matsaya Nov 22 '11 at 11:52
P.S. For me I don't complain for the documentation as I understand french better than english ;), but I see your point. –  Matsaya Nov 22 '11 at 11:53
@Matsaya: moin non plus, ça ne me dérange pas :) –  Count Zero Nov 22 '11 at 11:56