You're in a tough situation, which stems from history.
The few examples in the documentation of xkeyval
for \define@choicekey
all use [\val\nr]
and this has instilled the idea that these are mandatory tokens for this case.
They aren't. Any two control sequences are allowed and they are used as scratch macros. Package writers should use their own control sequences; so the example in the documentation
\define@choicekey*{fam}{align}[\val\nr]{left,center,right}{%
\ifcase\nr\relax
\raggedright
\or
\centering
\or
\raggedleft
\fi
}
adapted to the package foo
should better be
\define@choicekey*{fam}{align}[\foo@val\foo@nr]{left,center,right}{%
\ifcase\foo@nr\relax
\raggedright
\or
\centering
\or
\raggedleft
\fi
}
and the code in the polyglossia
definition files should be
\define@choicekey*+{welsh}{date}[\xpg@val\xpg@nr]{long,short}[short]{%
\ifcase\xpg@nr\relax
% long:
\welsh@formaldatetrue
\or
% accented:
\welsh@formaldatefalse
\fi
\xpg@info{Option: Welsh, date=\xpg@val}%
}{\xpg@warning{Unknown date value `#1'}}
Unfortunately, most packages or classes using xkeyval
and choice keys adopted \var\nr
. These scratch control sequences are not set inside a group, so any time one performs a choice key using them they are redefined and their final value is unpredictable.
What can you do? Avoid \val
as the name of a personal macro.
I filed a issue report for polyglossia
and I'll do what's possible to inform authors of other packages. But it will take long until the situation improves.
\AfterEndPreamble
. – Ulrike Fischer Feb 9 '20 at 20:52xkeyval
. I'll open an issue. – egreg Feb 9 '20 at 21:31\val
and\nr
are redefined. So doing the definition of\val
at begin document is not really safe. – egreg Feb 9 '20 at 21:41xkeyval
is loaded and a choice is performed, because of bad documentation of the package that leads people to think that\val\nr
is mandatory usage. – egreg Feb 9 '20 at 21:46