LaTeX forum ⇒ Document ClassesUsing default values from keys

Information and discussion about specific document classes and how to create your own document classes.
Borgia
Posts: 3
Joined: Sun Nov 05, 2023 10:51 pm

Using default values from keys

Postby Borgia » Mon Nov 06, 2023 2:01 pm

In this code, the third level picks up the colour value from level two. But I want the third level to take the default red colour value.

How can I apply a default set of keys at the start of each environment ?

\documentclass[a4paper,10pt]{article}
\usepackage{xcolor}
\usepackage{enumitem}

\ExplSyntaxOn

\makeatletter
\setlistdepth{13}
\newlist{wvTlaps}{enumerate}{13}
\setlist[wvTlaps]
  {
    label=$\langle$\the\enit@depth$\rangle$\arabic*.,
    left=0pt, parsep=0pt, itemindent=8pt,
  }
\makeatother

\tl_new:N \tlapis_kl_tl
\tl_new:N \tlapis_lv_tl

\keys_define:nn { tlapis_keys }
  %% Define Key-Value Interface within namespace tlapis_keys.
  {
    kl .tl_set:N = \tlapis_kl_tl,
    kl .default:n = {red},
    kl .initial:n = {red},

    lv .tl_set:N = \tlapis_lv_tl,
    lv .default:n = {},
    lv .initial:n = {},
  }

\NewDocumentEnvironment {wvTlapis} { O{} }
    {
      \keys_set:nn {tlapis_keys} {#1}

      \tl_if_empty:NTF {\tlapis_lv_tl}
          {
            \begin{wvTlaps}[format=\color{\tlapis_kl_tl}]
          }
        {
          \begin{wvTlaps}
            [format=\color{\tlapis_kl_tl},
             label=$\langle$\tlapis_lv_tl$\rangle$\arabic*.]
        }
      }
    { \end{wvTlaps} }

\ExplSyntaxOff

\begin{document}

\begin{wvTlapis}
    \item First level
    \begin{wvTlapis}[kl=green]
        \item Second level
        \begin{wvTlapis}
            \item Third level
        \end{wvTlapis}
    \end{wvTlapis}
\end{wvTlapis}

\end{document}



Recommended reading 2021:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics

Return to “Document Classes”

Who is online

Users browsing this forum: No registered users and 2 guests