\enum

Automatic commas and and in enumerations

The following code defines a command \enum, which allows to automate insertion of commas and and in enumerations.

Code for the \enum command
\ExplSyntaxOn

\seq_new:N \l__my_enum_seq
\tl_new:N \l__my_enum_item_tl
\int_new:N \l__number_of_args

\NewDocumentCommand{\enum}{ O{;} m o o s } {
  \seq_set_split:Nnn \l__my_enum_seq { #1 } { #2 }
  \seq_remove_all:Nn \l__my_enum_seq {}
  \int_set_eq:NN \l__number_of_args { \seq_count:N \l__my_enum_seq }
  \seq_use:Nnnn \l__my_enum_seq { ~and~ } { ,~ } { ,~and~ }
  \IfValueTF{#3}{
    \IfValueTF{#4}{
      \space
      #3~
      \int_compare:nNnTF{ \l__number_of_args } < {2}{ \proves[#4] }{ \prove[#4] }
    } {
      \IfBooleanTF{#5}{
        \space
        #3~
        \int_compare:nNnTF{ \l__number_of_args } < {2}{ \proves[sindep] }{ \prove[sindep] }
      } {
        \space
        \int_compare:nNnTF{ \l__number_of_args } < {2}{ \proves[#3] }{ \prove[#3] }
      }
    }
  } {
    \IfBooleanT{#5}{
      \space
        \int_compare:nNnTF{ \l__number_of_args } < {2}{ \proves[sindep] }{ \prove[sindep] }
    }
  }
}

\ExplSyntaxOff

The following example illustrates how this command works:

\enum{
  Let $L\in\R$;
}

\enum{
  Let $L\in\R$;
  let $f\colon\R\to\R$ be a function;
}

\enum{
  Let $L\in\R$;
  let $f\colon\R\to\R$ be a function;
  assume that for all $x,y\in\R$ it holds that $\abs{f(x)-f(y)}\leq L\abs{x-y}$. 
}

Let $L\in\mathbb R$.

Let $L\in\mathbb R$ and let $f\colon\mathbb R\to\mathbb R$ be a function.

Let $L\in\mathbb R$, let $f\colon\mathbb R\to\mathbb R$ be a function, and assume for all $x,y\in\mathbb R$ that $\lvert f(x)-f(y)\rvert\leq L\lvert x-y\rvert$.

One very common application for this command is the enumeration of arguments in an argumentation sentence. If the \proves and \prove commands are available, then \enum can take an optional argument, analogous to the one for those commands and will then insert a corresponding verb at the end of the enumeration, in the singular or plural form depending on whether there is one or more elements in the enumeration. In place of the optional argument, you can also use a * which is equivalent to the optional argument [sindep] (i.e., cycling through all verbs). Finally, there may be another optional argument containing text that should be inserted between the enumeration and the verb (such as hence or therefore):

\enum{
  This;
  the triangle inequality;
}[sin] that
  $f$ is continuous.
\enum{
  The fact that $A$ is compact
}[\hence]* that
  $\sup_{x\in A} f(x)<\infty$.
\enum{
  \Cref{it:1};
  the fundamental theorem of calculus;
  the axiom of choice;
}[\hence][ep] \cref{eq:claim}.
This and the triangle inequality imply that $f$ is continuous. The fact that $A$ is compact therefore proves that $\sup_{x\in A} f(x)<\infty$. Item (i), the fundamental theorem of calculus, and the axiom of choice hence establish (12).

Unless otherwise noted, all LaTeX snippets on this site are released under the Zero-Clause BSD (0BSD) license. You may copy them into your documents without attribution or including any license. No warranty.