0

I have missed something with the definitely M(not)WE code below.

When the option auto is used, I would like to achieve the action in the "funny" macro \babellang that makes me feel ashamed. I have put it to show what I am trying to achieve.

Another question. What is the LaTeX3 equivalent of \@ifpackageloaded? NO! See below the comments of Cicada.

\begin{filecontents}{main.sty}
\RequirePackage{l3keys2e}

\ProvidesExplPackage{main}{}{}{}


% -- OPTIONS - MESSAGES -- %

\msg_set:nnnn { main } { options-unknown-lang }
    { Unknown ~ language. }
    { Languages ~ supported: ~ [FR]-ench ~ and ~ [EN]-glish. }

\msg_set:nnnn { main } { options-babel-not-loaded }
    { Unknown ~ language. }
    { Languages ~ supported: ~ [FR]-ench ~ and ~ [EN]-glish. }


% -- OPTIONS - KEYS & VALUES -- %

\NewDocumentCommand{ \babellang }{}{
    \@ifpackageloaded{babel}{
       \str_case_e:nF { \languagename } {
% French
            { french }{
                \tl_set:Nn \l_main_opt_lang { FR }
            }
% English
            { english }{
                \tl_set:Nn \l_main_opt_lang { EN }
            }
% Unsupported
        }{
            \msg_fatal:nn { main } { options-unknown-lang }
        }
    }{
        \msg_fatal:nn { main } { options-babel-not-loaded }
    }
}


\keys_define:nn { main } {
    lang .choices:nn =
        { auto, FR, EN }
        {
            \tl_set:Nn \l_main_opt_lang { \tl_use:N \l_keys_choice_tl }
        },
    lang .initial:n = auto,
    lang / auto .code:n = \babellang,
    lang / unknown .code:n =
        \msg_error:nnxxx { main } { options-unknown-lang }
            { lang }             % Name of choice key
            { FR, EN }           % Valid choices
            { \exp_not:n {#1} }  % Invalid choice given
}


% -- OPTIONS - KEYS FROM THE LOADING OF THE PACKAGE -- %

\ProcessKeysPackageOptions{ main }


\NewDocumentCommand{ \test }{}{
    LANG = \l_main_opt_lang
}
\end{filecontents}


\documentclass{article}

\usepackage[english]{babel} % KO if it is commented.

%\usepackage[lang = ILLEGAL]{main} % OK
%\usepackage[lang = FR]{main} % OK
%\usepackage[lang = EN]{main} % OK
\usepackage{main} % KO

\begin{document}

\test

\end{document}
4
  • For the other question: "expl3 is mainly focused on programming. This means that some areas still require the use of LATEX2e internal macros. For example, you may well need \@ifpackageloaded, as there is currently no native expl3 package loading module." (texdoc expl3).
    – Cicada
    Jul 15 at 10:28
  • Thanks for this clarification.
    – projetmbc
    Jul 15 at 10:32
  • You can build one: e.g., \let\ltx_if_pkg_loaded:nTF\@ifpackageloaded (see tex.stackexchange.com/questions/434193/…) - other answers there too.
    – Cicada
    Jul 15 at 10:46
  • Thanks for this link. I will read the answers.
    – projetmbc
    Jul 15 at 10:50

Your Answer

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

Browse other questions tagged or ask your own question.