# pgfplots: Boolean key for a style does not work

I trièd to insert a Bool Title=true|false:

\pgfplotsset{
%/pgfplots/.cd, % no effect
Title/.is choice,
Title/.style={title={A title.}},
}


Why does Title, Title=true and Title=false not work and I get a title both times?
What do I have to make better?

\documentclass[border=3.14pt]{standalone}
\usepackage{pgfplots}
\begin{document}

\pgfplotsset{
%/pgfplots/.cd, % no effect
Title/.is choice,
Title/.style={title={A title.}},
}

\begin{tikzpicture}
\begin{axis}[Title=true]
\addplot[] {x} node[pos=0.5]{Has a title. :)};;
\end{axis}
\end{tikzpicture}

\begin{tikzpicture}
\begin{axis}[Title=false]
\addplot[red] {x} node[pos=0.5]{Has a title too. :(};
\end{axis}
\end{tikzpicture}

• With etoolbox, something like \pgfplotsset{Title/.code={\ifblank{#1}{}{\pgfplotsset{title={#1}}}}} should do the trick. .is choice expects that you define a key for each choice. Not at a computer, can't test. If you really want to use true and false, how are you going to enter the title? – frougon Sep 16 '20 at 18:02

You can use the handler .is choice that you define a key for each choice, then each of the different possible choices true or false should be given by a subkey.

\pgfplotsset{
Title/.is choice,
Title/true/.style={title={A title.}},
Title/false/.style={},
}


If you want to restrict the key to a boolean value, with the package etoolbox, you can use the handler .is if,

\pgfplotsset{Title/.is if,
Title/.code={\ifbool{#1}{\pgfplotsset{title={A title}}}{}}
}


• Ah, good. I wonder, why it worked here: tex.stackexchange.com/a/560804/46023 – cis Sep 16 '20 at 19:09
• @cis Actually, it doesn't work there. You can set the key ShowPageFrame to any value, and the output will not change since you don't pass the parameter (true or false) into its handler. – Amita Sep 16 '20 at 19:25
• Ok, thx. But I wonder: At such bool-keys, normally you do not have to say Title=true,...., it is Title,... enough. Could this be added here? – cis Sep 18 '20 at 20:06