Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
    
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
1  
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
add comment

1 Answer

up vote 2 down vote accepted

this cw is to reduce the unanswered questions

In my opinion your code works well.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.