# enumdepth and ifthenelse

I would like to generate text based on my current depth of the enumeration. After a little search, I found this. It seems ifthenelse is not respecting enumdepth properly. Am I doing something wrong?

Working example:

\documentclass{article}
\usepackage{ifthen}
\newcommand{\curdepth}[1] %
{
\ifthenelse{\equal{\@enumdepth}{1}}
{\small Current counter is \theenumi}
{\small Current counter is \theenumi~(\theenumii)}
}

\begin{document}
\begin{enumerate}
\item This is the first item in the list. \curdepth

\item Sample
\begin{enumerate}
\item This is the first item in the list. \curdepth

\end{enumerate}
\end{enumerate}
\end{document}


The output is:

1. This is the first item in the list. Current counter is 1 ()
2. Sample
(a) This is the first item in the list. Current counter is 2 (a)


The expected output is:

1. This is the first item in the list. Current counter is 1
2. Sample
(a) This is the first item in the list. Current counter is 2 (a)


-- Mike

• Can you provide a complete, compiling, working example? – Steven B. Segletes Sep 18 '17 at 11:52
• you should always provide a full example, for example have you used this code at a point where @ may be used in command names (eg inside a package file) – David Carlisle Sep 18 '17 at 11:54
• Edited the original post and added working example! – Mike V.D.C. Sep 18 '17 at 12:20
• I agree with both above comments. I just adding that if you use this code in your preamble you possibly need to put the command using it inside \makeatletter and \makeatother – koleygr Sep 18 '17 at 12:21
• @koleygr, modifying the line to \makeatletter\@enumdepth\makeatother is not making change! Do I need to use them (these two commands) some-where-else? Adding it at the point where \curdepth is called also doesnt help! Sorry if I am doing something stupid! – Mike V.D.C. Sep 18 '17 at 12:27

As \@enumdepth is equal to a TeX count, you should add \the to make it work (and, of course, makeat...).

\documentclass{article}
\usepackage{ifthen}
\makeatletter
\newcommand{\curdepth}[1]{
\ifthenelse{\equal{\the\@enumdepth}{1}}
{\small Current counter is \theenumi}
{\small Current counter is \theenumi~(\theenumii)}
}
\makeatother

\begin{document}
\begin{enumerate}
\item This is the first item in the list. \curdepth

\item Sample
\begin{enumerate}
\item This is the first item in the list. \curdepth

\end{enumerate}
\end{enumerate}
\end{document}

• WOW!!! Thanks @TeXnician(tex.stackexchange.com/users/124577/texnician) and @Michael Palmer (tex.stackexchange.com/users/117431/michael-palmer). Its working like a charm... I didnt think of \the, as I thought @enumdepth is not a counter, so \the is not necessary! – Mike V.D.C. Sep 18 '17 at 12:51
• @MikeV.D.C. It is no counter, it is a TeX count register (that's more basic than a counter). If you encounter such a problem in future, you can try using \show\@enumdepth (or whatever) to see what it really is. – TeXnician Sep 18 '17 at 12:56
\documentclass{article}
\makeatletter
\newcommand\curdepth[1]{\small Current counter is \theenumi%
\ifnum\@enumdepth>\@ne ~(\theenumii)\fi}
\makeatother

• Way too simple... ;) – TeXnician Sep 18 '17 at 12:56

By default, \ifthenelse performs numeric tests, so \@enumdepth=1 is sufficient; the \equal test is about strings.

You also need to surround the \newcommand with \makeatletter and \makeatother, because you need to use a macro with @ in its name.

\documentclass{article}
\usepackage{ifthen}

\makeatletter
\newcommand{\curdepth}[1]{% <-- don't forget
\ifthenelse{\@enumdepth=1}
{\small Current counter is \theenumi}
{\small Current counter is \theenumi~(\theenumii)}% <-- don't forget
}
\makeatother

\begin{document}
\begin{enumerate}
\item This is the first item in the list. \curdepth

\item Sample
\begin{enumerate}
\item This is the first item in the list. \curdepth

\end{enumerate}
\end{enumerate}
\end{document}