# Including a LaTex citation in a GraphViz graph

I am trying to generate a graph showing the relationships among papers in a bibliography. I use GraphViz inside a LaTex document to generate the graph. So far, so good: the graph is generated correctly.

The problem arises because I would like to have citations inside the graph.

I know that it is possible to do something similar using Tikz instead of GraphViz, but I would like to stick with GraphViz because I find it much easier to set the graph up.

This is the code I am able to run, with a citation outside the graph:

\documentclass[a4paper,10pt]{article}
\usepackage[pdf]{graphviz}
\begin{document}

Some text with a citation~\cite{lecun1990handwritten}.

\digraph{bibliography}{
{
/* Timeline */
node[shape=plaintext, fontsize=15];
1980 -> 1985 -> 1990;
}

/* Papers */
{
node[shape=plaintext, fontsize=13];
NeoCognitron [ label=<NeoCognitron> ]
BackPropagation [ label=<BackPropagation> ]
LeNet [ label=<LeNet> ]
}

/* Year-paper relation */
{ rank=same; 1980; NeoCognitron; }
{ rank=same; 1985; BackPropagation; }
{ rank=same; 1990; LeNet; }

/* Paper-to-paper influence */
BackPropagation -> LeNet
NeoCognitron -> LeNet
}

\bibliographystyle{plain}
\bibliography{deepLearningBibliography}
\end{document}


This is the result I get:

If I put the citation inside the graph, like this, the compilation succeeds, but I get some errors and the the citation does not appear in the graph:

  LeNet [ label=<LeNet\cite{lecun1990handwritten}> ]


The first error I get is:

./example.tex:30:Use of \Gin@ii doesn't match its definition }


In case this information is useful, I am using PdfLaTeX via Kile on Ubuntu.

My goal is to embed the citation in the graph, as part of the node label.

Thanks in advance for any help!

## 1 Answer

The graphviz package allows psfrag replacements which you can use to add the citations, with \usepackage[psfrag]{graphviz}.

MWE:

\documentclass[a4paper,10pt]{article}
\usepackage[psfrag]{graphviz}
\begin{document}

Some text with a citation~\cite{book1}.

\psfrag{lenetref}[cc][cc]{Lenet\cite{book1}}
\psfrag{neocognitronref}[cc][cc]{NeoCognitron\cite{misc1}}
\psfrag{backproprefabcdef}[cc][cc]{BackPropagation\cite{article1}}
\Large
\digraph{bibliography}{
{
/* Timeline */
node[shape=plaintext, fontsize=15];
1980 -> 1985 -> 1990;
}

/* Papers */
{
node[shape=plaintext, fontsize=13];
NeoCognitron [ label=<neocognitronref> ]
BackPropagation [ label=<backproprefabcdef> ]
LeNet [ label=<lenetref> ]
}

/* Year-paper relation */
{ rank=same; 1980; NeoCognitron; }
{ rank=same; 1985; BackPropagation; }
{ rank=same; 1990; LeNet; }

/* Paper-to-paper influence */
BackPropagation -> LeNet
NeoCognitron -> LeNet
}

\bibliographystyle{plain}
\bibliography{sample1}
\end{document}


Result:

The main drawback of this solution is that you cannot use pdflatex for compilation, because that interferes with the PostScript processing of psfrag. Therefore you need to run latex --shell-escape yourfile.tex twice, then dvips yourfile.dvi and then ps2pdf yourfile.ps. Also the font looks different from the standard Graphviz font, but that might not necessarily be a problem if all your nodes contain references. Third, the positioning of the nodes is determined by Graphviz based on the size of the original label before replacement, so you need to make sure that the labels and the replacements are approximately the same size otherwise the graph layout may be off (for example the backproprefabcdef label above, where the abcdef part is added to make the label longer).