6

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}

enter image description here

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:

enter image description here

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.

Notes:

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}

Peter Grill
  • 223,288

1 Answers1

3

this cw is to reduce the unanswered questions

In my opinion your code works well.

Marco Daniel
  • 95,681