# Why does this pgfopts example using ".is choice" not work?

I'm trying to get this trivial proof of concept demo of pgfopts to work and I keep getting inconsistent results. I have another version working in which the keys are handled with an .is if handler and now I'm trying to use the .is choice handler. I understand that .default and .initial won't work with .is choice.

The default with no keys specified should be bold. Loading the demo package with no keys given yields the correct result (the correct code executes, and the vector is bold). Loading the demo package with [vectors=arrowed] still gives a bold vector and both code choices execute. Loading the demo package with [vectors=bold] gives a bold vector, but the corresponding code executes twice. I can't see what's causing the problem.

Here is the demo pgfoptspkgtwo.sty file.

\ProvidesPackage{pgfoptspkgtwo}
\RequirePackage[math-style=ISO]{unicode-math}
\setmathfont{Latin Modern Math}
\RequirePackage{pgfopts}

\pgfkeys{%
/pgfoptspkgtwo/.cd,
vectors/.is choice,
%  vectors/.default = bold, % won't work with .is choice
%  vectors/.initial = bold, % won't work with .is choice
vectors/bold/.code={%
\typeout{}%
\typeout{pgfoptspkgtwo: You'll get bold vectors.}%
\typeout{}%
\renewcommand{\vec}{\symbfit}%
},
vectors/arrowed/.code={%
\typeout{}%
\typeout{pgfoptspkgtwo: You'll get arrowed vectors.}%
\typeout{}%
},
vectors=bold % this should be the default
}%

\ProcessPgfPackageOptions{/pgfoptspkgtwo}


Here is the demo document pgfoptstestingtwo.tex.

% !TEX TS-program = lualatexmk
% !TEX encoding = UTF-8 Unicode

\documentclass{article}
\usepackage{pgfoptspkgtwo}
%\usepackage[vectors=arrowed]{pgfoptspkgtwo}
%\usepackage[vectors=bold]{pgfoptspkgtwo}
\begin{document}

$\vec{E}$
\end{document}


You're unconditionally redefining \vec to \symbfit, because your arrowed choice does nothing else than printing information.

\ProvidesPackage{pgfoptspkgtwo}
\RequirePackage[math-style=ISO]{unicode-math}
\setmathfont{Latin Modern Math}
\RequirePackage{pgfopts}

\pgfkeys{%
/pgfoptspkgtwo/.cd,
vectors/.is choice,
vectors/bold/.code={%
\typeout{}%
\typeout{pgfoptspkgtwo: You'll get bold vectors.}%
\typeout{}%
\renewcommand{\vec}{\symbfit}%
},
vectors/arrowed/.code={%
\typeout{}%
\typeout{pgfoptspkgtwo: You'll get arrowed vectors.}%
\typeout{}%
\renewcommand{\vec}{\standardvec}%
},
}%

\NewCommandCopy{\standardvec}{\vec}
\renewcommand{\vec}{\symbfit}
\ProcessPgfPackageOptions{/pgfoptspkgtwo}

• Thank you. I apparently don't understand the logic flow. Nov 29, 2020 at 17:45
• There doesn't seem to be a way to write the "You'll get bold vectors." message unless an option is specified. Nov 29, 2020 at 20:40
• @LaTeXereXeTaL The package documentation will tell it, why littering the log file? Nov 29, 2020 at 21:24
• It's how I've always done it. It's more convenient to look at the console than to open the log file, which is something students probably don't know how to do. It's helpful for debugging. Nov 29, 2020 at 22:18
• @LaTeXereXeTaL People using front-ends such as TeXStudio won't even see the console. Nov 29, 2020 at 22:30