I am writing a math book. I have exercises that have questions AND subquestions (for example 1 then 1.a, 1.b, 2 then 2.a, 2.b, 2.c etc.). I also have exercises that have one questions, without subquestions (1, 2, 3,...).
I would like to make LaTeX check how many \begin{enumerate}
s there are. If there is just 1 (which means that I only have questions, no subquestions), I want the label to be a letter. Otherwise, keep it as is.
Here is a MWE where I do that manually.
\documentclass{article}
\usepackage{enumitem}
\usepackage{xsim} % I'm using this package for the exercise environment
\begin{document}
\section*{Exercise 2}
% This enumerate has only 1 level, so enumerate using a letter (\alph).
\begin{enumerate}[label=\textbf{\alph*.}]
\item Question 1
\item Question 2
\item Question 3
\end{enumerate}
\section*{Exercise 2}
% This enumerate has only 1 level, so enumerate using using a number (\arabic).
\begin{enumerate}[label=\textbf{\arabic*.}]
\item Question 1
\begin{enumerate}[label=\textbf{\alph*.}]
\item Subquestion a
\item Subquestion b
\end{enumerate}
\item Question 2
\begin{enumerate}[label=\textbf{\alph*.}]
\item Subquestion a
\item Subquestion b
\item Subquestion c
\end{enumerate}
\end{enumerate}
\end{document}
N.B. The exercise environment already exists in xsim,and I'm using it.Thank you
\usepackge{enumerate}
from your preamble as it is best to stick to one package that provides a certain functionality (list management) -enumitem
in this case - otherwise there may be conflicts.