I am trying to build an environment/command that allows me to place comments in the text. The idea is to have colored box that can break across pages and use the \ttfamily font with hyphenation. I also want to use any structure (table, enumerate, itemize, etc.) inside it. Moreover the box width is variable and the maximum is \linewidth. My MWE is below.
\documentclass{article}
\usepackage{blindtext}
\usepackage[showframe]{geometry}
\usepackage{xcolor}
\usepackage{calc}
\usepackage{mdframed}
\usepackage{environ,varwidth}
\newsavebox\MyTempBox
\NewEnviron{mycomment}{%
\savebox\MyTempBox{%
\begin{varwidth}{\linewidth}
\BODY
\end{varwidth}}%
\begin{mdframed}
[topline=false,
rightline=false,
bottomline=false,
leftline=false,
innerleftmargin=1ex,
innerrightmargin=1ex,
innertopmargin=1ex,
innerbottommargin=1ex,
backgroundcolor=pink,
font=\ttfamily,
userdefinedwidth=\dimexpr\wd\MyTempBox\relax
]
\hyphenchar\font=\defaulthyphenchar\relax
\BODY
\end{mdframed}%
}%
\begin{document}
\begin{mycomment}
\blindtext
\blindtext
\blindtext
\blindtext
\blindtext
\blindtext
\end{mycomment}
\end{document}
So far it almost works, the problem is that it generates a lot of Overfull \hbox because the text does strictly not respect the box boundaries. If I put the second \BODY inside a minipage
\begin{minipage}{\linewidth}
\BODY
\end{minipage}
It works better, but I loose the break over pages feature. I think that a minipage that can break over pages can be the solution.
I am not attached to the mdframed package. For example,
\newcommand{\ccomment}[1]{%
\noindent\colorbox{pink}{\begin{varwidth}{\linewidth-1em}%
\ttfamily
\hyphenchar\font=\defaulthyphenchar\relax % enable hyphenation
#1
\end{varwidth}}}
Would be ok for me, but once more I cannot use it for long text that may break across pages.
Thanks.

\ttfamily. Without this font everything works well. Why have your comments to be in type writer? If they have to be type write may be packagelistingscan help? – Kurt Aug 28 '12 at 17:27