Modifying labels on some enumerated items
How about this
\documentclass{article}
\newcommand{\myitem}{\refstepcounter{enumi}\item[$*$\theenumi.]}
\begin{document}
\begin{enumerate}
\myitem first
\item second
\item third
\myitem fourth
\end{enumerate}
\end{document}
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.
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).