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.

I would like to understand (and to find a solution for it) the following problem. First, the MWE :

\documentclass{article}
\usepackage{mdframed}
\usepackage{fancybox}


\newsavebox{\mcBox}

\newenvironment{monItemize}{
\renewcommand{\item}%
{\end{lrbox}%
\fbox{
\usebox{\mcBox}
}   \\\begin{lrbox}{\mcBox}}%
\begin{lrbox}{\mcBox}%
}
{\end{lrbox}
\fbox{%
\usebox{\mcBox}%
}%
}

\newcommand{\itemm}{}
\newenvironment{monItemizeMD}{
\renewcommand{\itemm}%
{\end{lrbox}%
\begin{mdframed}[userdefinedwidth=3cm]%
\usebox{\mcBox}
\end{mdframed}%
    \begin{lrbox}{\mcBox}}%
\begin{lrbox}{\mcBox}%
}
{\end{lrbox}
\begin{mdframed}[userdefinedwidth=3cm]%
\usebox{\mcBox}
\end{mdframed}%
}

\begin{document}


\begin{monItemize}
\item aaa
\item bbb
\end{monItemize}

\begin{monItemizeMD}
\itemm ccc
\itemm ddd
\end{monItemizeMD}

\end{document}

In the environment monItemize, I redefine \item, which puts the content in a fbox.

In the environment monItemizeMD, I define the items thru a command \itemm, instead of \item, and the content lies in a mdframed-Box instead of a \fbox.

  1. Question: If I use \item in monItemizeMD (of course, both in the definition and in the Instance of the environment), it fails to compile. Why ?
  2. Question: How secure is it, generally speaking, to redefine \item ?
  3. Question: Can i solve the problem of Question 1, still using \item ? Because my problem is, that, in many already existing documents, i have such an environment with \item redefined. And in my documentclass, i wanted to replace the \fbox by mdframed boxes.
share|improve this question
    
Please have a look at this tex.stackexchange.com/questions/56435/… It works well. –  Marco Daniel May 19 '12 at 11:31
add comment

2 Answers

1) \item is a vertical mode command, it starts a new paragraph, basically, but lrbox is like \fbox which is like \mbox a horizontal (LR) mode construct that doesn't allow vertical material unless you first nest a parbox or minipage or similar.

2) As noted the other day in Use of \trivlist and \list in defining environments LaTeX uses lists everywhere. If you redefine \item you have redefined center and verbatim environments for example. UPDATE In particular you would also be redefining mdframed.

3) I'm not sure quite what the top level requirement is that you want to solve, you want to box each item of an enumerate and allow breaking within the box?

share|improve this answer
    
about 2 : just for science, i would like to know what makes in this case the interference with \item. the center –  nicolas roy Mar 9 '12 at 18:19
2  
like all trivlist environments (actually mdf@trivlist variant here), the mdframed environment is implemented as a single item list so it calls \item\relax internally, so if you define \item to end one environment and start another it's bound to go wrong. –  David Carlisle Mar 9 '12 at 18:50
add comment

Redefining \item can be dangerous and have impredictable results, as you discovered. If all you want is to box the text after \item with a width of 3cm, then

\newsavebox{\mcBox}
\newif\ifstartmonItemize
\newenvironment{monItemize}
  {\startmonItemizetrue
   \renewcommand{\item}{%
     \ifstartmonItemize
       \startmonItemizefalse
     \else
       \end{lrbox}
       \noindent
       \framebox[3cm][l]{\usebox{\mcBox}}\\
     \fi
     \begin{lrbox}{\mcBox}\strut}%
  }
  {\end{lrbox}\noindent\framebox[3cm][l]{\usebox{\mcBox}}}

will do.

share|improve this answer
    
Unfortunately, i want more. Depending on some boolean it should display the items in a itemizeor in a tabular, with some extra feature. But this all works without mdframd... or wit another command name as \item. I think i learnt a lesson : \item should be used ... only for what it is intended to :) –  nicolas roy Mar 9 '12 at 15:46
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.