# pgfkeys: set default value to boolean “.is if”, and values are changed globally

I'm quite new with pgfkeys, and I'm having troubles to set default values to boolean keys defined with .is if (let me know if there is another way to define boolean keys), and I don't know why, but the values are changed globally instead of locally. I tried the following:

proof here/.is if=proofhere,
proof here/.initial=true,


and two problems:

• by default, \ifproofhere is false, despite the .initial value
• if I change the value once, it changes the value for all the subsequent calls to my function.

I think I don't use pgfkeys in the good way, but don't know what's wrong.

MWE:

\documentclass{article}
\usepackage{pgfkeys}
\newif\ifproofhere
\pgfkeys{
/prAtEnd/.cd, %% Proof at end will be the main path
proof here/.is if=proofhere,
proof here/.initial=true,
no proof here/.style={proof here=false}, % alias
}

\usepackage{xparse}
\NewDocumentCommand\theoremProofEnd{O{}}{
\pgfkeys{
/prAtEnd/.cd,
#1
}
\ifproofhere
The proof is here ! :D
\else
Sorry, no proof.
\fi
}

\begin{document}\noindent\\
Should be proof here'': \theoremProofEnd[] === Pb\\
Should be proof here'': \theoremProofEnd[proof here]\\
Should be no proof'': \theoremProofEnd[no proof here]\\
Should be like first line: \theoremProofEnd[]\\
Should be proof here'': \theoremProofEnd[proof here]\\
Should be like first line: \theoremProofEnd[] === Pb
\end{document}


-- EDIT -- Thanks for the comments, so using proof here=true solve the first problem, but not the "reusability" one: if I change once the value, it's change for the next calls as well. For now I define a default style that re-initialize everything, and I call that style at the beginning of my function, but it looks a bit dirty (especially if you nest pgfkeys calls, I guess it can get into troubles). What's the good way to proceed? If I don't, it gives:

\documentclass{article}
\usepackage{pgfkeys}
\newif\ifproofhere
\pgfkeys{
/prAtEnd/.cd, %% Proof at end will be the main path
proof here/.is if=proofhere,
proof here=true,
no proof here/.style={proof here=false}, % alias
% default/.style = {proof here=true}, %% <= is it the good solution
}

\usepackage{xparse}
\NewDocumentCommand\theoremProofEnd{O{}}{
\pgfkeys{
/prAtEnd/.cd,
% default, %% <= is it the good solution
#1
}
\ifproofhere
The proof is here ! :D
\else
Sorry, no proof.
\fi
}

\begin{document}\noindent\\
Should be proof here'': \theoremProofEnd[]\\
Should be no proof'': \theoremProofEnd[no proof here]\\
Should be like first line: \theoremProofEnd[] === Pb\\
\end{document}

• Imho you can simply use proof here=true to set the boolean to true. Or \proofheretrue. But yes, it it looks odd that .initial doesn't work here. You could add an issue at the github site. – Ulrike Fischer Apr 12 '19 at 8:51
• .initial doesn't work because proof here does not hold a value (it is an if). The correct way to initialize is proof here=true (as is also documented). – Henri Menke Apr 12 '19 at 8:54
• @HenriMenke I don't think that the distinction "value or not" is really clear for a user: The description of the is if handler also speaks of "value". In expl3 .initial:n works with booleans too (as expected by me). – Ulrike Fischer Apr 12 '19 at 9:47
• @HenriMenke : thanks. It solved one problem, but not the "reusability" one. I updated my question ;) – tobiasBora Apr 12 '19 at 12:03
• @UlrikeFischer : Thank you, it solved one problem, but not the "reusability" one. I updated my question ;) – tobiasBora Apr 12 '19 at 12:04