TransWikia.com

Automatically switch between theenumi, theenumii, and theenumiii based on @enumdepth

TeX - LaTeX Asked by Shaun on November 28, 2020

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}

newififgrading
gradingtrue

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

makeatletter        
newcommand{itemAns}{
    ifgrading
        stepcounter{enumromannumeral@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 theenumromannumeral@enumdepth instead of theenumii, similar to what I did with stepcounter{enumromannumeral@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!

One Answer

Use @nameuse{ } or csname endcsname.

textcolor{blue}{@nameuse{theenumromannumeral@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})}

Correct answer by Donald Arseneau on November 28, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP