# Command to find current enum depth?

I was wondering if there was a command to find what at what depth of the enum counter (i.e. enumi, enumii, etc.) a command was at compile time. I'm attempting to create a \question command. What I have so far:

\newcommand{\question}[2][\value{enumi}+1]{\setcounter{enumi}{#1-1} \item \textbf{#2}}


Which works great for the first level (Note: requires the calc package). What I'm looking for is a command (or series of commands) to replace the \value{enumi}+1 with whatever the current depth is so that something like:

\begin{enumerate}
\question{Whatever}
\question[10]{Blah}
\begin{enumerate}
\question[2]{Stuff}
\end{enumerate}
\end{enumerate}


would produce output like:

1. Whatever
10. Blah
(b). Stuff

-

## migrated from stackoverflow.comSep 5 '11 at 19:06

This question came from our site for professional and enthusiast programmers.

You need to know the depth of the current enumerate to modify the appropriate counter; \@enumdepth holds the current enumeration nesting depth:

\documentclass{article}
\usepackage{calc}

\makeatletter
\newcommand{\question}[2][\value{enum\romannumeral\@enumdepth}+1]{\setcounter{enum\romannumeral\@enumdepth
}{#1-1} \item \textbf{#2}}
\makeatother
\begin{document}

\begin{enumerate}
\question{Whatever}
\question[10]{Blah}
\begin{enumerate}
\question[2]{Stuff}
\begin{enumerate}
\question[6]{Other stuff}
\end{enumerate}
\end{enumerate}
\end{enumerate}

\end{document}


-
You beat me to it. Two notes: 1) You don't need \the after \romannumeral as it automatically looks for a number; 2) I'd include the enum\romannumeral\@enumdepth in the default for the optional argument as well as in the command body. –  Joseph Wright Sep 5 '11 at 19:19
@Joseph: ah, yes. Done! Thank you. –  Gonzalo Medina Sep 5 '11 at 19:25
Thanks, I wasn't able to find anything on \@enumdepth when I was searching (although I can now obviously find plenty). –  Drayton Munster Sep 5 '11 at 20:02
You can find the definition \newcount\@enumdepth \@enumdepth = 0 in the LaTeX kernel. Run texdoc source2e in a terminal, and search for \@enumdepth. –  Gonzalo Medina Sep 5 '11 at 21:28