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.

3
  • 1
    Welcome to TeX.SX! Try with \_
    – CarLaTeX
    Jan 5, 2018 at 6:58
  • @CarLaTeX Thanks for your comments. Since many C function names have underscore, to append a backslash to each underscore is heavy for me. I prefer some way like shortvrb or to make shortvrb to work in graph node.
    – pngleo
    Jan 5, 2018 at 7:11
  • OK, I leave the answer to some expert :)
    – CarLaTeX
    Jan 5, 2018 at 7:13

1 Answer 1

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

0

You must log in to answer this question.

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