3

I'm supposed to answer the following math problems from my textbook: 1, 10, 19 and 34. How would I number these using LaTeX?

1 Answers1

3

A little bit of code golfing: Define a sequence with 1,10,19,34 for example and redefine \refstepcounter, that uses another \theenumi if the counter is enumi and grabs the relevant value from the sequence.

No check is done when the list does not have enough items.

In order to clear the list and revert to the original enumi, use \clearenumerateselection.

Other way: Use enumitem with special AddEnumerateCounter setup.

\documentclass{article}

\makeatletter

\let\latex@@refstepcounter\refstepcounter
\usepackage{expl3}

\ExplSyntaxOn


\seq_new:N \g_thomas_enumerateselection_seq 
\int_new:N \g_thomas_enumi_int

\cs_new:Npn \setenumerateselection #1{%
  \seq_set_from_clist:Nn \g_thomas_enumerateselection_seq  {#1}
}

\cs_new:Npn \clearenumerateselection {
  \seq_gclear:N \g_thomas_enumerateselection_seq
}

\cs_generate_variant:Nn \str_if_eq:nnT  {xnT}

\AtBeginDocument{%
  \cs_set:Npn \refstepcounter #1 {%
    \str_if_eq:xnT {#1} {enumi} {
      \seq_if_empty:NF \g_thomas_enumerateselection_seq {%
        % Redefine \theenumi
        \cs_set:cpn {the#1} {\seq_item:Nn \g_thomas_enumerateselection_seq {\value{#1}}}
      }
    }
    \latex@@refstepcounter{#1}
  }
}

\ExplSyntaxOff

\makeatother

\begin{document}

\setenumerateselection{1,10,19,34}

\begin{enumerate}
  \item Foo
  \item Bar
  \item And now for something completely different
  \item May the Fourth/Force be with you ;-)
\end{enumerate}

\clearenumerateselection

\begin{enumerate}
  \item Foo
  \item Bar
  \item And now for something completely different
  \item May the Fourth/Force be with you ;-)
\end{enumerate}


\end{document}

enter image description here