# Issues with node labels using quotes on referenced nodes in graphs

The following:

\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{graphs, graphs.standard, quotes}
\begin{document}
\begin{tikzpicture}
\graph[grid placement, n = 4, chain shift = {(2,0)}, group shift = {(0,-2)},
math nodes, nodes = {circle, draw, thick}, edges={very thick}] {
%subgraph I_n[V={s_1, s_2, s_3, s_4}],
s_1["$P,Q$" left],
s_2["$P, \neg Q$" right],
s_3["$\neg P, Q$" left],
s_4["$\neg P, \neg Q$" right],
s_1 -> s_3,
s_4 -> s_2,
s_3 -> {s_3[>loop below], s_4},
s_2 -> {s_2[>loop above], s_1}
};
\end{tikzpicture}
\end{document}


Works and does what it is supposed to do. However, if I uncomment the subgraph I_n, I end up with numerous errors like this:

Missing \endcsname inserted. }


While the same visual output is produced anyways. So, for whatever reason, specifying node labels using quotes on referenced nodes causes issues.
I could however trace down the cause further. The following:

\graph[grid placement, n = 4, chain shift = {(2,0)}, group shift = {(0,-2)},
math nodes, nodes = {circle, draw, thick}, edges={very thick}] {
subgraph I_n[V={s_1, s_2, s_3, s_4}],
s_1["$P,Q$" left],
s_2["Some Label" right],
s_3["Label" left],
s_4["$0^0$" right],
s_1 -> s_3,
s_4 -> s_2,
s_3 -> {s_3[>loop below], s_4},
s_2 -> {s_2[>loop above], s_1}
};


Does work.
The problem seems to only occur when commands are used inside quotes labels on referenced nodes. And yes, even with non-math commands, I checked that, too.
After further reading of the documentation, I realised that what I am doing shouldn't even be working, as I have , in the quotes, which would have to be surrounded by {}. And, it does not work if used in a normal \node like this. This is weird in itself, as what is clearly wrong is working, at least partially.
However, this:

\graph[grid placement, n = 4, chain shift = {(2,0)}, group shift = {(0,-2)},
math nodes, nodes = {circle, draw, thick}, edges={very thick}] {
subgraph I_n[V={s_1, s_2, s_3, s_4}],
s_1["{$P,Q$}" left],
s_2["{$P, \neg Q$}" right],
s_3["{$\neg P, Q$}" left],
s_4["{$\neg P, \neg Q$}" right],
s_1 -> s_3,
s_4 -> s_2,
s_3 -> {s_3[>loop below], s_4},
s_2 -> {s_2[>loop above], s_1}
};


Will still not work.
You might be wondering why this is a problem, as my first example shows the solution. However, this is no real solution. Imagine you are creating a large graph, and then you might want to use something like subgraph I_n for this, and then label just one of these nodes. But you can't do that, because it won't work.
An actual solution would be something like this:

\node["{$P, \neg Q$}" right] at (s_2) {};


or

\node[circle, "{$P, \neg Q$}" right] at (s_2) {};


But for this example, in both cases, the label will be too close. So something like this:

\node[anchor=west, xshift=12pt] at (s_2) {$P, \neg Q$};


Is the better way it seems.
Now I talked a lot around the bush. My question is: Can anybody explain why this weird behaviour happens? I imagine that the reason will be related to the graph parsing. And: Can it actually be solved somehow, without any of the workarounds (so, with actually using the quotes label syntax inside the graph and on referenced nodes)?

Edit:

\graph[grid placement, n = 4, chain shift = {(2,0)}, group shift = {(0,-2)},
math nodes, nodes = {circle, draw, thick}, edges={very thick}] {
s_1["{$P,Q$}" left],
s_2["{$P, \neg Q$}" right],
s_3["{$\neg P, Q$}" left],
s_4["{$\neg P, \neg Q$}" right],
subgraph I_n[V={s_1, s_2, s_3, s_4}],
s_1 -> s_3,
s_4 -> s_2,
s_3 -> {s_3[>loop below], s_4},
s_2 -> {s_2[>loop above], s_1}
};


This is another way of solving the issue, but my question concerning referenced nodes still remains.

• If I recall correctly, the quotation mark triggers a special command that handled commas separately. – Symbol 1 Jan 31 '18 at 1:31
• The error is probably because the parser put the label in a \csname-\endcsname pair and anything more than plain-text does not make sense there. (\neg is not a character, more like a command to draw something on the canvas.) – Symbol 1 Jan 31 '18 at 1:33
• If you use unicode-math and label the node by "$P,¬Q$" then it works. Because ¬ is a (unicode) character. – Symbol 1 Jan 31 '18 at 1:35