# Problems with the graphs library

According to the documentation for version 3.0.0 of PGF/TikZ (Section 19 Specifying Graphs, page 258), the powerful graphs library:

[...] offers a powerful path command for specifying how the nodes in a graph are connected by edges and arcs: The graph path command, which becomes available when you load the graphs library.

A few lines below there are some examples of the use of the path; amongst those examples one finds:

\tikz
\graph [nodes={draw, circle}, clockwise, radius=.5cm, empty nodes, n=5] {
subgraph I_n [name=inner] --[complete bipartite]
subgraph I_n [name=outer]
};


and

\tikz
\graph [nodes={draw, circle}, clockwise, radius=.75cm, empty nodes, n=8] {
subgraph C_n [name=inner] <->[shorten <=1pt, shorten >=1pt]
subgraph C_n [name=outer]
};


which should produce the following images (taking directly from the documentation):

However, when I try the exact same code in a "real" document:

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

\begin{document}

\tikz
\graph [nodes={draw, circle}, clockwise, radius=.5cm, empty nodes, n=5] {
subgraph I_n [name=inner] --[complete bipartite]
subgraph I_n [name=outer]
};
\tikz
\graph [nodes={draw, circle}, clockwise, radius=.75cm, empty nodes, n=8] {
subgraph C_n [name=inner] <->[shorten <=1pt, shorten >=1pt]
subgraph C_n [name=outer]
};

\end{document}


This is all I get (image zoomed at 400%):

Even more disppointing is the following example on page 276:

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

\begin{document}

\tikz \graph [simple] {
subgraph K_n [n=8, clockwise];
% Get rid of the following edges:
1 -!- 2;
3 -!- 4;
6 -!- 8;
% And make one edge red:
1 --[red] 3;
};

\end{document}


The documentation shows this as the result:

but I only get an error message:

! Missing $inserted. <inserted text>$
l.15 }
;
?


Am I missing something? Is some other library required in order to get the expected graphs?

• Did some digging in the code for the documentation to find this: your MWEs work if the graphs and graphs.standard libraries are loaded (in that order). I don't see why this requirement would be intentional... maybe a bug? – Paul Gessler Mar 7 '14 at 5:05
• IMHO, the bug is with the subgraph keyword. It is not documented (alone)... and it offers no protection against errors: you may use any word after it without error (and without effect). – Paul Gaborit Mar 7 '14 at 7:05
• @PaulGessler That's correct, would you like to turn this comment into an answer? – Stefan Kottwitz Mar 10 '14 at 8:42
• @StefanKottwitz, I could, but I'm not entirely sure why both are required. The documentation only uses lists graphs as being needed, so I wasn't sure if this was expected/intended or not. – Paul Gessler Mar 10 '14 at 12:31
• @PaulGessler graphs.standard is required to use subgraph K_n or subgraph I_n. The documentation only lists graphs because subgraph ... is used only to built an arbitrary graph in these examples. – Paul Gaborit Mar 10 '14 at 17:14

## 1 Answer

Based on looking through the pgf documentation's LaTeX source and also this answer, I believe that the documentation should list that both the graphs and graphs.standard libraries are included to produce these graphics.

All your examples work if I use \usetikzlibrary{graphs,graphs.standard} instead of only \usetikzlibrary{graphs}. Here is one sample:

Code

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{graphs,graphs.standard} % both are required, in this order

\begin{document}
\tikz \graph [simple] {
subgraph K_n [n=8, clockwise];
% Get rid of the following edges:
1 -!- 2;
3 -!- 4;
6 -!- 8;
% And make one edge red:
1 --[red] 3;
};
\end{document}


Output