# Latex packages Graphviz and Babel conflict

When babel package is loaded graphviz does not accept double quotes in graphviz code. See https://www.overleaf.com/13251515ycdczbrgzczy#/51024557/

\documentclass{standalone}
\usepackage{inputenc}
%\usepackage[german]{babel}

\usepackage[pdf]{graphviz}

\begin{document}

\digraph[scale=0.5]{abc}{
b [ shape = none
label = <<table border="0">
<tr><td>b</td></tr>
</table>>];

a -> b -> c;

}
\end{document}


This code is correctly interpreted if either the border attribute is removed or package babel is commented out (as in the example code).

I wonder if there is a workaround or what is babel anyway.

UPDATE: I found a practicable workaround:

1. use babel with both german and english language;
2. use \selectlanguage{english} before you enter the graphviz code;
3. \selectlanguage{german} again after the code.

The disadvantage of this solution is that German umlauts cannot be used in graphviz code labels, so maybe there exists some better workaround.

• Welcome! You can turn off short-hands rather than switching language. (See Babel's docs for how to do this.) If graphviz can cope with unicode, you could input the accented characters that way. There's no point in loading inputenc without an option, is there? Don't you want utf8 there? – cfr Jan 20 '18 at 2:45
• Thank you. Tuning short-hands off is a good idea. However, as you can see in the edited overleaf example, latex's graphviz package doesn't translate umlauts though the generic graphviz dot routine does, but this is an other problem. Maybe I start a new question. – user1491229 Jan 20 '18 at 9:01

You can redefine the internal \@@digraph macro so that it disables shorthands before grabbing the code for the graph.

\documentclass{standalone}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}

\usepackage[pdf]{graphviz}

\makeatletter
\let\saved@@digraph\@@digraph
\def\@@digraph{\@safe@activestrue\saved@@digraph}
\makeatother

\begin{document}

\digraph[scale=0.5]{abc}{
b [ shape = none
label = <<table border="0">
<tr><td>b</td></tr>
</table>>];

a -> b -> c;

}
\end{document}


A neater alternative with etoolbox:

\documentclass{standalone}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}

\usepackage[pdf]{graphviz}
\usepackage{etoolbox}

\makeatletter
\pretocmd\@@digraph{\@safe@activestrue}{}{}
\makeatother

\begin{document}

\digraph[scale=0.5]{abc}{
b [ shape = none
label = <<table border="0">
<tr><td>b</td></tr>
</table>>];

a -> b -> c;

}
\end{document}

• Thank you. Its an excellent answer as it also solves the problem that only html labels were allowed in digraph. With that little routine double quoted labels are no longer blocked with German babel. Next, I wonder if by such approach the umlaut problem with latex's graphviz package can be solved (tex.stackexchange.com/questions/411284/…) – user1491229 Jan 20 '18 at 16:07
• @user1491229 If this answer solved the problem, please consider answering it when you are no longer waiting for better solutions. After all, egreg surely needs the points :-). – cfr Jan 21 '18 at 0:15
• @cfr what did you mean by that? "please consider answering it when you are no longer waiting for better solutions." – user1491229 Jan 21 '18 at 6:24
• @user1491229 Lapsus for accepting – egreg Jan 21 '18 at 10:21
• Oops. @user1491229 Sorry. I indeed meant 'accepting' rather than 'answering'. s/answering/accepting/. – cfr Jan 22 '18 at 12:52