The following expl3
class, that provides an option (mykeyword
) thanks to l3keys2e
, works like a charm:
\begin{filecontents*}{myclass.cls}
\RequirePackage{l3keys2e}
\RequirePackage{expl3}
\ExplSyntaxOn
\ProvidesExplClass
{myclass}
{2019/01/05}
{0.1}
{
My Nice Class.%
}
\NeedsTeXFormat{LaTeX2e}
\LoadClass { report }
\RequirePackage[utf8]{inputenc} % Useless nowadays
%
\tl_set:Nn \l__myclass_my_keyword_tl {Café}
\keys_define:nn { myclass }
{
mykeyword .tl_set:N = \l__myclass_my_keyword_tl,%
}%
\ProcessKeysOptions { myclass }
\AtEndDocument{\l__myclass_my_keyword_tl}
\end{filecontents*}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\documentclass{myclass}
% \documentclass[mykeyword=Bar]{myclass}
% \documentclass[mykeyword=Café]{myclass}
\begin{document}
Foo and
\end{document}
One can see that:
- the default value option contains an accent ("Café") and that's not a problem,
- some values may be given to this option, e.g. "Bar",
- some values cannot be given to this option, e.g. "Café" (indeed, the same as the default one!) and more generally any value that contains an accent. In this case, the compilation fails with the following error:
! Undefined control sequence. \UseTextAccent ...up @firstofone \let @curr@enc \cf@encoding @use@text@en...
How could I fix this issue?
Edit
As a workaround, it is enough to use this option not at the \documentclass
level but in a "setup" command, as in the following MWE:
\begin{filecontents*}{myclass.cls}
\RequirePackage{l3keys2e}
\RequirePackage{xparse}
\ExplSyntaxOn
\ProvidesExplClass
{myclass}
{2019/01/05}
{0.1}
{
My~Nice~Class.%
}
\NeedsTeXFormat{LaTeX2e}
\LoadClass { report }
\RequirePackage[utf8]{inputenc}
%
\tl_set:Nn \l__myclass_my_keyword_tl {Café}
\keys_define:nn { myclass }
{
mykeyword .tl_set:N = \l__myclass_my_keyword_tl
}%
\NewDocumentCommand \myclasssetup { m } {
\keys_set:nn { myclass } { #1 }
}
\ProcessKeysOptions { myclass }
\AtEndDocument{\l__myclass_my_keyword_tl}
\end{filecontents*}
\documentclass{myclass}
\myclasssetup{mykeyword=blé}
\begin{document}
Foo and
\end{document}