# Modifying labels on some enumerated items

In an enumerate environment, I want a few (not all) of the items to have asterisks which appear before the number (I don't feel strongly about whether the number or the asterisk is horizontally aligned with the other numbers). Is there a less crufty way to do this than, say, using multiple lists (or — horrors — numbering manually)?

I'm already using enumitem for an unrelated purpose, if that helps, although I didn't find a solution after a quick skim of its manual.

• Is the number of asterisks variable or is it always the same number independently of the item number? Apr 20 '12 at 17:11
• Always the same and always one; sorry, I wasn't very clear. Apr 20 '12 at 17:15

\documentclass{article}
\newcommand{\myitem}{\refstepcounter{enumi}\item[$*$\theenumi.]}

\begin{document}
\begin{enumerate}
\myitem first
\item second
\item third
\myitem fourth
\end{enumerate}
\end{document}

• I'm not sure whether this is relevant, but this way the * will not be part of a reference to the item. Apr 20 '12 at 17:14
• Fortunately I don't need to make any references to the list items. Apr 20 '12 at 17:16
• I'm accepting this right away partly because I'm amused at how well it confirmed my feeling that there may be a really easy solution which I could find more quickly using this site than thinking about it myself. Nevertheless, I'd be interested to see others. Apr 20 '12 at 17:18
• @cmhughes -- the asterisk might show up a bit more prominently if the digits were aligned. for that, just add the (default) period after \theenumi: \newcommand{\myitem}{\stepcounter{enumi}\item[$*$\theenumi.]} Apr 20 '12 at 17:26
• @barbarabeeton good idea, thanks- see edit Apr 20 '12 at 18:10

Redefine momentarily \labelenumi (it's a bit more difficult if you want it for any nesting level). It works also with \label, but the asterisk won't be part of the reference.

\documentclass{article}
\def\asteriskitem{*\,}
\def\sitem{%
\let\originallabelenumi\labelenumi
\expandafter\def\expandafter\labelenumi\expandafter{%
\expandafter\asteriskitem\labelenumi}%
\item
\let\labelenumi\originallabelenumi
}

\begin{document}
\begin{enumerate}
\item a
\sitem b
\item c
\end{enumerate}
\end{document}


Just for the record, here is something that should work with every nesting level:

\makeatletter
\def\sitem{%
\expandafter\let\expandafter\originallabel\csname labelenum\romannumeral\@enumdepth\endcsname
\expandafter\def\csname labelenum\romannumeral\@enumdepth\expandafter\endcsname\expandafter{%
\expandafter\asteriskitem\originallabel}%
\item
\expandafter\let\csname labelenum\romannumeral\@enumdepth\endcsname\originallabel
}
\makeatother


## Explanation

Let's see how the simpler solution works. To begin with, we have to know that \item uses \labelenumi for typesetting the first level numbers, and that it is a parameterless macro.

We want to change the meaning of \labelenumi so that it typesets also the asterisk, so we define a macro for the asterisk and a small space; then we define a command \sitem that changes the definition, issues \item and restores the original \labelenumi. The "easy" method for doing this, that is, changing the definition in a group, doesn't unfortunately work. So we save the original meaning in \originallabelenumi and do

\expandafter\def\expandafter\labelenumi\expandafter{%
\expandafter\asteriskitem\labelenumi}%


The first \expandafter activates all the following ones, so that the expansion of \labelenumi is obtained before \def acts (the fact that \labelenumi has no arguments is very important here).

The general solution is very similar, but requires knowing something more about enumerate. The nesting level is accessible through the value of \@enumdepth, which is a "TeX counter"; with \romannumeral\@enumdepth we can thus refer to the right LaTeX macro \labelenumi, \labelenumii, \labelenumiii or \labelenumiv with \csname labelenum\romannumeral\@enumdepth\endcsname.

Therefore we save the meaning of the right macro with

\expandafter\let\expandafter\originallabel\csname labelenum\romannumeral\@enumdepth\endcsname


With etoolbox this might become

\letcs\originallabel{labelenum\romannumeral\@enumdepth}


Getting the expansion of \originallabel is done essentially as before:

\expandafter\def\csname labelenum\romannumeral\@enumdepth\expandafter\endcsname\expandafter{%
\expandafter\asteriskitem\originallabel}


but using a slick trick. The first \expandafter triggers \csname, which expands everything it finds up to the matching \endcsname, including the inner \expandafter which triggers the following ones. Finally the right token (say \labelenumi if the value of \@enumdepth is 1) is put after \def and TeX would see the correct command among

\def\labelenumi{\asterisk<expansion of \originallabel>}
\def\labelenumii{\asterisk<expansion of \originallabel>}
\def\labelenumiii{\asterisk<expansion of \originallabel>}
\def\labelenumiv{\asterisk<expansion of \originallabel>}


according to the value of \@enumdepth, as desired. After issuing \item, the meaning of \labelenum?? is restored.

• +1 wonderful answer! I plan to study it in the hope of gaining a better understanding of \expandafter Apr 21 '12 at 10:31
• @cmhughes I've added some explanations. Apr 21 '12 at 10:52

Here is a much simpler approach.

Borrowing (heavily) from this answer, define a command (\difficult) that will put the asterisk in place:

\documentclass{article}

\newcommand{\difficult}{%
\leavevmode\makebox[0pt][r]{\large$\ast$\hspace{1.5em}}}

\begin{document}
\begin{enumerate}
\item a
\item \difficult b
\item c
\end{enumerate}

\end{document}


Note that this will behave well with \label (the asterisk will not appear however).

You can define your own item. In the following example I used \bulletitem.

To take care of nested environments you can do the following:

\documentclass{article}
\makeatletter
\newcommand\bulletitem{%
\edef\@tempctr{\csname c@enum\romannumeral\the\@enumdepth\endcsname}%
\item[$\bullet$(\the\@tempctr)]}
\makeatletter

\begin{document}

\begin{enumerate}
\item item no.1
\item item no.2
\bulletitem No.3
\item item no.4
\end{enumerate}

\end{document}


The following updates \item to work with either \item* or \item[..] (the former being new and the latter being the default):

\documentclass{article}

\let\olditem\item
\makeatletter
\renewcommand{\item}{\@ifstar\@sitem\olditem}
\newcommand{\@sitem}{%
\refstepcounter{\@enumctr}%
\olditem[\textbullet~\csname label\@enumctr\endcsname]}
\makeatother

\begin{document}

\begin{enumerate}
\item item no.1
\item item no.2
\item[$\bullet$~3.] item no.3
\item item no.4
\end{enumerate}

\begin{enumerate}
\item item no.1
\item item no.2
\item* item no.3
\item item no.4
\end{enumerate}

\end{document}