[Tex/LaTex] Enumeration problem redefining `enumerate` enivironment

#enumerate

I would like to redefine the enumerate environment with an optional argument. Basically I want to redefine \theenumi so that each time I label an item and call it with \ref I get the real label printed, and not just the (arabic) value of counter enumi.

I tried with the code below, and it works except for the fact it always adds an extra point (.) to each label. When I call it with \ref it prints the correct label though.

Here is a MWE of what I tried:

\documentclass{book}
\usepackage{enumerate}
%%
%%
\let\oldenumerate\enumerate
\let\endoldenumerate\endenumerate
\renewenvironment{enumerate}[1][\arabic{enumi}.]% Defaults to 1. 2. 3. ...
{%
    \bgroup\renewcommand\theenumi{#1}%
    \oldenumerate%
}%
{%
    \endoldenumerate\egroup%
}%
\begin{document}
First list with default enumeration
\begin{enumerate}
\item First item
\item Second item
\end{enumerate}
Second list with custom enumeration
\begin{enumerate}[(\emph{\roman{enumi}})]
\item First item
\item Second item
\end{enumerate}
Labels have an extra dot in the lists, but references \ref{a} and \ref{b} are printed correctly.
\end{document}

and this is the output of the above code:

Output of the above MWE

How should I redefine enumerate in order to avoid the extra dot in the lists?

Best Answer

Rather than reinventing the wheel, it's much easier to use the enumitem package for this sort of thing. For this particular example I've added a negative kern so that the parentheses are spaced nicely with the italic numeral. As Kannappan Sampath points out, you can specify the format of the references separately as well.

\documentclass{article}
\usepackage{enumitem}
\begin{document}
Second list with custom enumeration
\begin{enumerate}[label=(\kern-.5pt\emph{\roman*}),ref=(\roman*)]
\item First item \label{a}
\item Second item \label{b}
\end{enumerate}
Labels have an extra dot in the lists, but references \ref{a} and \ref{b} are printed correctly.
\end{document}

enter image description here