Within an enumerated list, I would like some "meta"-level annotations: Mark a single, specific item in boldface, or another colour, or have an arrow point at it from the left margin, or surround it with a box. But the \item macro cannot be embedded within some other macro. Is there any way to accomplish this?
Asked
Active
Viewed 286 times
1
doncherry
- 54,637
Mayer Goldberg
- 2,215
1 Answers
1
Of course you can embed \item inside a macro. Below I define \specialitem to set an \item with the necessary non-argument formatting specified via \setspecialitem:
\documentclass{article}
\usepackage{xcolor}
\makeatletter
\newcommand{\setspecialitem}[1]{\def\specialitem@{#1}}
\newcommand{\specialitem}{%
\begingroup
\specialitem@
\item\leavevmode
\endgroup
}
\setspecialitem{}% Default
\begin{document}
\begin{enumerate}
\item First
\setspecialitem{\color{red}}
\specialitem Second
\setspecialitem{\itshape}
\specialitem Third
\item Last
\end{enumerate}
\end{document}
It would also be possible to do more complex things (like boxing a special number). Here's one showing a \boxeditem:
\documentclass{article}
\makeatletter
\newcommand{\boxeditem}{%
\begingroup
\expandafter\expandafter\expandafter
\let\expandafter\expandafter\expandafter
\oldlabelenum@\expandafter\csname labelenum\romannumeral\the\@enumdepth\endcsname
\@namedef{labelenum\romannumeral\the\@enumdepth}{\fbox{\oldlabelenum@}}
\item\leavevmode%
\endgroup
}
\makeatother
\begin{document}
\begin{enumerate}
\item First
\boxeditem Second
\boxeditem Third
\boxeditem Fourth
\item Last
\end{enumerate}
\end{document}
Werner
- 603,163


\specialitembe acceptable? Or do you want\item{\highlight ... }? – Alan Munn May 15 '15 at 20:04\itemmacro cannot be embedded within some other macro" suggest that you may have serious constraints so you should spell out what you need in more detail. it would, for example, be possible to do something that fits your description by modifying the\itemcommand except that this might violate your unexplained embedding requirement. – May 16 '15 at 07:46