GeneralUsing string values with l3keys

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
Salerdam
Posts: 2
Joined: Sat Dec 02, 2023 3:05 am

Using string values with l3keys

Post by Salerdam »

I am having trouble using string values when using l3keys. I can only get things to work using a token list followed by expansion. I find no problem using the code for the int case though.

Code: Select all

\documentclass{article}

\ExplSyntaxOn

\str_new:N \cake_lp
\keys_define:nn { cake_keys }
  {
    lp .str_set:N = \cake_lp,
    lp .default:n = {apple},
    lp .initial:n = {apple},
  }

\NewDocumentCommand {\cake} { O{apple} }
  {
    \noindent
    \group_begin:
    \str_case:nn {#1}
      {
        {apple}  { An~apple~cake }
        {carrot}  { A~carrot~cake}
      } 
      \group_end:
  }

\NewDocumentCommand {\goodie} { O{} }
  {
    \keys_set:nn {cake_keys} {#1}
    \cake [\str_use:N \cake_lp]
  }

\ExplSyntaxOff

\begin{document}

\goodie[lp=apple]

\end{document}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
Post Reply