I'd like to enclose one entry of an enumerate
list in parentheses, with the opening parenthesis appearing before the index number. I can do this manually by using \item[(3.] Item text)
, but this requires hard-coding the item number. Is there a way to do this automatically?
\documentclass{article}
\begin{document}
\begin{enumerate}
\item Really important
\item Quite important
\item[(3.] If we have time)
\end{enumerate}
\end{document}
In the answer to Modifying labels on some enumerated items, an approach is suggested for modifying the item label, which gets me quite close to the goal. The opening parenthesis is added and the counter is still automatic. I only need to add the closing parenthesis by hand. Could that be automated as well?
\documentclass{article}
\begin{document}
\newcommand{\parenitem}{\stepcounter{enumi}\item[(\theenumi.]}
\begin{enumerate}
\item Really important
\item Quite important
\parenitem If we have time)
\end{enumerate}
\end{document}
Best Answer
Another attempt, counting the open parentheses.
The result is the following
As shown in the example, empty lines still cause a deserted parenthesis. Right now I have no idea how to fix this.
EDIT (2012-09-16)
Just had time to look into the TeXbook: the end-of-line character
\endlinechar
can be set to a negative value to ignore empty lines (or actually line breaks). If one includes this in the\pitem
macro, the lonesome paren artefact is fixed:The behavior will only be activated when the
\pitem
macro is used and the effect will be limited to the scope of theenumerate
environment. Note that explicit line breaks using\newline
or\\
ans explicit paragraphs with\par
still work.