1

I would like to use tikz graph to draw graphs of function calling relations. But I have trouble with function names from C programming language, where underscore is allowed in a function name.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{graphs}
\usepackage{shortvrb}
\MakeShortVerb{\|}

\begin{document}
|func_one()| calls |func_two()|:

\tikz \graph {
    "|func_one()|" -> "|func_two()|";
};
\end{document}

For the above example, TeX complains

Missing $ inserted. }

Is there a simple way to let C function name be the name of a tikz graph node without much handling with the function name? In my case, there will be many functions in a calling graph and each name may include multiple underscores. Sigh.

Thanks in advance.

pngleo
  • 11

1 Answers1

3

You could just use \catcode\_=11 before the picture, or if you are happy to use \scantokens, you could try using a custom typesetter using the key /tikz/graphs/typeset:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{graphs}
\def\typesetter{{\catcode`\_=11
\ttfamily\expandafter\scantokens\expandafter{\tikzgraphnodetext}}}
\begin{document}
\tikz\graph [typeset=\typesetter, grow down] {
  "func_one()" -> "func_two()";
};
\end{document} 

enter image description here

Mark Wibrow
  • 70,437