4

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.
1

2 Answers 2

5

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?

2
  • about 2 : just for science, i would like to know what makes in this case the interference with \item. the center Mar 9, 2012 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. Mar 9, 2012 at 18:50
3

Redefining \item can have dangerous and unpredictable 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.

3
  • 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 :) Mar 9, 2012 at 15:46
  • As a linguist I really enjoy reading impredictable, that's a great example of partial anticipatory assimilation – thank you!
    – dessert
    Oct 23, 2017 at 16:48
  • @dessert False friend, should be unpredictable, I guess
    – egreg
    Oct 23, 2017 at 16:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .