# Replace \item with \MyItem to box each list member with an mdframed

Since it was pointed out that redefining \item can be dangerous in strange interaction between mdframed and \item, I am wondering if there are going to be problems with this solution.

My goal is to replace:

\begin{enumerate}[label={(\alph*)}]
\MyItem \TextA
\MyItem \TextB
\end{enumerate}


with (i.e., only the environment name is changed):

\begin{MyEnumerate}[label={(\alph*)}]
\MyItem \TextA
\MyItem \TextB
\end{MyEnumerate}


to obtain an mdframe around each item:

The solution as below seems to work, at least for this test case. So, is this way of using \MyItem instead of \item have hidden dangers that are not obvious in this test case.

## Code:

\documentclass{article}
\usepackage{etoolbox}% for toggles
\usepackage{enumitem}
\usepackage{mdframed}

\newcommand{\TextA}{%
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Sed accumsan hendrerit velit, vitae ultrices sapien porta nec.
}%
\newcommand{\TextB}{%
Duis blandit tempus placerat.
Nulla vitae erat ante. Nulla facilisi.
Aliquam tristique interdum suscipit.
Duis posuere orci vel velit suscipit in porttitor purus eleifend.
}%

\newcommand{\MyItem}{\item}

\newtoggle{FirstItem}%
\toggletrue{FirstItem}%
\newenvironment{MyEnumerate}[1][]{%
\renewcommand{\MyItem}{%
\iftoggle{FirstItem}{%
\global\togglefalse{FirstItem}
%--------- start new frame
\begin{mdframed}[skipbelow=2pt]%
\begin{enumerate}[#1,series=MySeries]%
}{%
\end{enumerate}%
\end{mdframed}%
%--------- end previous frame and start new one
\begin{mdframed}[skipbelow=2pt]%
\begin{enumerate}[#1,resume*=MySeries]%
}%
\item%
}%
}{%
\end{enumerate}%
\end{mdframed}% --------- end last frame
\global\toggletrue{FirstItem}%
}%

\begin{document}\noindent
\textbf{enumerate:}
\begin{enumerate}[label={(\alph*)}]
\MyItem \TextA
\MyItem \TextB
\end{enumerate}
%
\medskip
\textbf{MyEnumerate:}
\begin{MyEnumerate}[label={(\alph*)}]
\MyItem \TextA
\MyItem \TextB
\end{MyEnumerate}
\end{document}

-
I think it's easier to provide a command like mydoubleline which will be passed before every item is set. –  Marco Daniel May 18 '12 at 20:55
@MarcoDaniel: That seems like redefining \item which according to the linked question is dangerous. Or, perhaps I misunderstood what you meant. –  Peter Grill May 18 '12 at 20:58
The command must be set by hand. You are right your solution is more comfortable. –  Marco Daniel May 18 '12 at 21:01
I tested your example and it works well with the current version at github -- Great. (Side note: mdframed loads etoolbox) –  Marco Daniel May 18 '12 at 21:14
I suggest to answer your own question with works well ;-) –  Marco Daniel May 21 '12 at 16:20