GeneralExpl3: Passing bool variable to a key that "accepts boolean values only"

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
LukeDrew
Posts: 4
Joined: Wed Apr 03, 2024 8:50 pm

Expl3: Passing bool variable to a key that "accepts boolean values only"

Post by LukeDrew »

Hello,

I have two Expl packages: pkga.sty and pkgb.sty. Both accept boolean key hyper. I want to nest pkgb setup in pkga, so can I pass hyper=true|false from my document to pkga, which in turn passes it to the pkgb.

The problem is that I am getting the error
Key 'pkgb/hyper' accepts boolean values only
when I try to use any method to pass value of boolean variable defined in pkga to key hyper in pkgb.

Here's the minimum (non) working example (EDIT: added filecontents usage):

Code: Select all

\documentclass{article}

\begin{filecontents}[overwrite]{pkga.sty}
    \ProvidesExplPackage{pkga}{2024-10-31}{0.0.1}{pkga}

    \keys_define:nn { pkga } {
        hyper .bool_set:N = \l_pkga_hyper_bool,
        hyper .initial:n = true,
    }
    \ProcessKeyOptions

    \RequirePackage[
        % THESE ARE WORKING FINE:
        % hyper=false,
        % hyper={false},
        % NONE OF THESE IS WORKING:
        % hyper=\l_pkga_hyper_bool,
        % hyper={\bool_to_str:N \l_pkga_hyper_bool},
        hyper={\bool_if:NTF \l_pkga_hyper_bool {true} {false}},
    ]{pkgb}
\end{filecontents}

\begin{filecontents}[overwrite]{pkgb.sty}
    \ProvidesExplPackage{pkgb}{2024-10-31}{0.0.1}{pkgb}

    \keys_define:nn { pkgb } {
        hyper .bool_set:N = \l_pkgb_hyper_bool,
        hyper .initial:n = true,
    }
    \ProcessKeyOptions

    \NewDocumentCommand{\mycommand}{ m }{
        #1\\
        \bool_if:NTF \l_pkgb_hyper_bool {Use~hyper}{Do~not~use~hyper}
    }
\end{filecontents}

\usepackage[hyper=false]{pkga}

\begin{document}
    \mycommand{Hello}
\end{document}
To summarize, I cannot pass a boolean variable directly as a value to the boolean key, converting it to string doesn't help either, and using branching is also not a solution.

What I am doing wrong? Any help will be appreciated.

Regards,
Luke

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Post Reply