1

In the package created by the following source, how can one change the value of \optB to true if \optA is true — so that the message written to the log would become >>> optB is true even though the option \optB=false had been passed to the package, as shown (but optA=true had been passed, as shown).

\RequirePackage{filecontents}
\begin{filecontents}{mypkg.sty}
\RequirePackage{kvoptions}
\SetupKeyvalOptions{family=MY,prefix=MY@}
\DeclareBoolOption{optA}
\DeclareBoolOption{optB}
\ProcessKeyvalOptions*
% what code here to switch value of optB *if* optA is true?
\ifMY@optB \typeout{>>> optB is true} \else \typeout{>>> optB is false}\fi
\end{filecontents}
%
\documentclass{article}
\usepackage[optA=true,optB=false]{mypkg}
\begin{document}
Hello.
\end{document}
1

For each Boolean option three commands are created:

  • \if<prefix><option name> which acts as one of TeX's conditional commands,
  • \<prefix><option name>true to enable the option, and
  • \<prefix><option name>false to disable the option.

Based on these commands, you can easily define custom conditions to override the values passed from the user (after the \ProcessKeyvalOptions call). In your case it's simply:

\ifMY@optA
    \MY@optBtrue
\fi
|improve this answer|||||
  • Thank you for the explanation, not just the method. The explanation fleshes out, and puts together, the terse information in the kvoptions documentation (in section 2.2.2, where it says, for a boolean option verbose, that the corresponding switch is initialized as \foobar@verbosefalse; and the "Summary of internal macros" section 2.4, where it lists \if<prefix><key>true and \if<prefix><key>false to enable & disable the switch, respectively. – murray Jul 15 '19 at 13:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for?Browse other questions tagged or ask your own question.