Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PGFKeys' First Char Syntax with non-csname-able content raises error message in graphs library. #1355

Open
Qrrbrbirlbel opened this issue Aug 29, 2024 · 0 comments

Comments

@Qrrbrbirlbel
Copy link
Contributor

Qrrbrbirlbel commented Aug 29, 2024

As Q406795 shows non-csname-able content in a label with the quotes/" syntax will raise an error message (but produces correct output) because \tikz@lg@local@node@handle uses the node's options in \tikzgraphsset without the first char setup so that \pgfkeysifdefined tries the whole "…" … as a key name.

\def\tikz@lg@local@node@handle#1{%
%
% Handle late options and operators
\tikzgraphsset{source,target,.unknown/.code=,#1}%
\tikzgdlatenodeoptionacallback{\tikz@pp@name\tikz@lib@graph@name}%
\node also[graphs/redirect unknown to tikz,/tikz/graphs/.cd,#1](\tikz@lib@graph@name);%
\pgfkeysvalueof{/tikz/graphs/@operators}%
}%

Here, this can be easily solved by setting " to be gobbled:

\def\tikz@lg@local@node@handle#1{% 
   % 
   % Handle late options and operators 
   \pgfkeyssetvalue{/handlers/first char syntax/\expandafter\meaning\string"}{\pgfutil@gobble}% ← !
   \tikzgraphsset{source,target,.unknown/.code=,#1}% 
   \tikzgdlatenodeoptionacallback{\tikz@pp@name\tikz@lib@graph@name}% 
   \node also[graphs/redirect unknown to tikz,/tikz/graphs/.cd,#1](\tikz@lib@graph@name);% 
   \pgfkeysvalueof{/tikz/graphs/@operators}% 
}

The \tikz@lg@local@node@handle macro is only used once


where it is executed inside a group so setting the first char syntax should have no consequences.


Though, I wonder if we can just adjust \pgfkeysifdefined

\long\def\pgfkeysifdefined#1{%
\ifcsname pgfk@#1\endcsname
\expandafter\pgfkeys@firstoftwo
\else
\expandafter\pgfkeys@secondoftwo
\fi
}

so that it is safer without breaking everything else:

\long\def\pgfkeysifdefined#1{%
  \ifcsname pgfk@\detokenize\expandafter{\pgfkeys@expanded{#1}}\endcsname
    \expandafter\pgfkeys@firstoftwo
  \else
    \expandafter\pgfkeys@secondoftwo
  \fi
}

MWE

\documentclass[tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{graphs, graphs.standard, quotes}
\makeatletter
\def\tikz@lg@local@node@handle#1{% 
   % 
   % Handle late options and operators 
   \pgfkeyssetvalue{/handlers/first char syntax/\expandafter\meaning\string"}{\pgfutil@gobble}%
   \tikzgraphsset{source,target,.unknown/.code=,#1}% 
   \tikzgdlatenodeoptionacallback{\tikz@pp@name\tikz@lib@graph@name}% 
   \node also[graphs/redirect unknown to tikz,/tikz/graphs/.cd,#1](\tikz@lib@graph@name);% 
   \pgfkeysvalueof{/tikz/graphs/@operators}% 
}
%\long\def\pgfkeysifdefined#1{%
%  \ifcsname pgfk@\detokenize\expandafter{\pgfkeys@expanded{#1}}\endcsname
%    \expandafter\pgfkeys@firstoftwo
%  \else
%    \expandafter\pgfkeys@secondoftwo
%  \fi
%}
\makeatother
\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}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant