0

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:

  1. the default value option contains an accent ("Café") and that's not a problem,
  2. some values may be given to this option, e.g. "Bar",
  3. 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}
  • 3
    It's not my fault: it's the kernel ... – Joseph Wright Jan 5 '19 at 21:25
  • Glad to know I'm not the culprit and such a responsive, available, and competent team is at work: thanks for all the excellent job! :) – Denis Bitouzé Jan 5 '19 at 21:30
  • @JosephWright Well, maybe I read to quickly your comment: you said it's the kernel but will it be fixed regarding this issue? – Denis Bitouzé Jan 6 '19 at 7:25
1

This is a very general problem, for instance exhibited by:

\RequirePackage{xstring}
\StrBehind*{Café}{f}[\var]

producing indeed, with pdflatex:

This is pdfTeX, Version 3.14159265-2.6-1.40.19 (TeX Live 2018/Arch Linux) (preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode
(./b.tex
LaTeX2e <2018-12-01>
(/usr/share/texmf-dist/tex/generic/xstring/xstring.sty
(/usr/share/texmf-dist/tex/generic/xstring/xstring.tex))
! Undefined control sequence.
\UseTextAccent ...up \@firstofone \let \@curr@enc 
                                                  \cf@encoding \@use@text@en...
l.2 \StrBehind*{Café}{f}
                         [\var]
!  ==> Fatal error occurred, no output PDF file produced!

The simplest workaround is to use XeLaTeX.

  • 1
    No problem with \StrBehind*{Café}{f}[\var] if \usepackage[T1]{fontenc} is used as well. – Denis Bitouzé Jun 4 '19 at 6:47
  • May well be, be why would we need to specify anything related to fonts when doing string manipulations? Also, did you mean RequirePackage? – Michaël Jun 4 '19 at 8:18
  • Also, using \RequirePackage[T1]{fontenc} in your original question does solve your problem. But again, it should not be needed. – Michaël Jun 5 '19 at 4:43
1

To fix this, use the package [T1]fontenc before using any accent. This was not particularly problematic when running pdflatex in Linux, but it was important when running it on Mac Mojave using MacTeX.

\RequirePackage[T1]{fontenc}
\ProvidesClass{myclass}[Using accent: Café]

This answer is based on Denis Bitouzés comment.

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.