我对 还不太熟悉pgfkeys
,在将默认值设置为 定义的布尔键时遇到了麻烦.is if
(如果有其他方法可以定义布尔键,请告诉我),我不知道为什么,但是这些值是全局更改的,而不是本地更改的。我尝试了以下方法:
proof here/.is if=proofhere,
proof here/.initial=true,
以及两个问题:
- 默认情况下,
\ifproofhere
为 false,尽管.initial
值 - 如果我改变一次值,它会改变对我的函数的所有后续调用的值。
我认为我没有以良好的方式使用 pgfkeys,但不知道哪里出了问题。
\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}
-- 编辑 -- 感谢您的评论,因此使用proof here=true
解决了第一个问题,但不是“可重用性”问题:如果我更改一次值,它也会更改下一次调用。现在我定义了一种default
重新初始化所有内容的样式,并在函数的开头调用该样式,但它看起来有点脏(特别是如果你嵌套 pgfkeys 调用,我猜它可能会遇到麻烦)。继续的好方法是什么?如果我不这样做,它会给出:
\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}