测试通过 pgf 定义的包选项是否为空

测试通过 pgf 定义的包选项是否为空

我想通过pgfopts包定义包/类选项进行分支。以下是示例:

% CLASS

% Preamble
\NeedsTeXFormat{LaTeX2e}[1994/06/01]
\ProvidesClass{myclass}[2022/10/01]
\LoadClass{article}

% Packages
\RequirePackage{pgfopts}

% Pgfoptions
\pgfkeys{
    /myclass/.cd,
    myoption/.store in = \myoption,
    myoption =,
    optionA/.code = \def\myoption{optionA},
    optionA/.value forbidden
    optionB/.code = \def\myoption{optionB},
    optionB/.value forbidden
}
\ProcessPgfOptions{/myclass}

% Trying to branch on myoption (but not working)
\if\relax\detokenize{\myoption}\relax
    \newcommand{\printmyoption}{\texttt{myoption = NOT DEFINED}}
\else
    \newcommand{\printmyoption}{\texttt{myoption = \myoption}}
\fi

该语法的思想是能够编写:

\documentclass[optionA]{myclass}
\begin{document}
\printmyoption % Should write "myoption = optionA"
\end{document}

或者

\documentclass[myoption = optionB]{myclass}
\begin{document}
\printmyoption % Should write "myoption = optionB"
\end{document}

\documentclass{myclass}
\begin{document}
\printmyoption % Should write "myoption = NOT DEFINED"
\end{document}

问题:如何根据包/类选项类别之一是否已定义进行分支?我应该用什么来替换\if\relax\detokenize{\myoption}\relax

附加问题:我需要使用,但请让我知道是否有更好的方法使用语法和直接pgfopts处理选项类别。[myoption = optionX][optionX]

相关内容