2

I am trying to reformat an enumerated value depending on whether I am "grading" or not, and I have a working solution, but I would like to know would be how to automatically switch between \theenumi, \theenumii, and \theenumiii based on \@enumdepth in the minimum working example that I have posted below:

\documentclass{article}
\usepackage{ifthen, amsmath, tikz, enumerate}

\newif\ifgrading
\gradingtrue

\newcommand*\circleAns[1]{\tikz[baseline=(char.base)]{
            \node[shape=circle,draw,inner sep=2pt,color=blue] (char) {#1};}}

\makeatletter        
\newcommand{\itemAns}{
    \ifgrading
        \stepcounter{enum\romannumeral\@enumdepth}
        \item[\circleAns{\textcolor{blue}{\theenumi)}}]
    \else \item
    \fi
}
\makeatother

\begin{document}

\begin{enumerate}[a)]
    \item 
    \itemAns
    \item
\end{enumerate}

\end{document}

I tried using \theenum\romannumeral\@enumdepth instead of \theenumii, similar to what I did with \stepcounter{enum\romannumeral\@enumdepth}, which didn't work though I think I understand why. If anyone has any suggestions for how to implement this solution better and update based on the level, I am very open to suggestions.

--------------------------- EDIT

Using Donald Arseneau's solution as a basis, I've modified my implementation to also include the label automatically: \textcolor{ForestGreen}{\@nameuse{label\@enumctr}} So the code

\begin{enumerate}[a)]
    \item 
    \itemAns
    \item 
\end{enumerate}
\begin{enumerate}[a.]
    \item 
    \item 
    \itemAns
\end{enumerate}

produces So it has the functionality I need it to. If anyone knows a simple way of recentering the circled items, let me know but otherwise I'm very happy with the result!

6

Use \@nameuse{ } or \csname \endcsname.

\textcolor{blue}{\@nameuse{theenum\romannumeral\@enumdepth})}

But since you already know about \@enumdepth and use it, you probably have seen \@enumctr which will simplify usage

\textcolor{blue}{\@nameuse{the\@enumctr})}
| improve this answer | |
  • That worked perfectly, thank you for your help! – Shaun Oct 25 at 4:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.