I've got that code from a website to make grey areas in my LaTeX document.
% http://www.alfredklomp.com/programming/tex/macros/
\long\def\greybox#1{%
\newbox\contentbox%
\newbox\bkgdbox%
\setbox\contentbox\hbox to \hsize{%
\vtop{
\kern\columnsep
\hbox to \hsize{%
\kern\columnsep%
\advance\hsize by -2\columnsep%
\setlength{\textwidth}{\hsize}%
\vbox{
\parskip=\baselineskip
\parindent=0bp
#1
}%
\kern\columnsep%
}%
\kern\columnsep%
}%
}%
\setbox\bkgdbox\vbox{
\pdfliteral{0.85 0.85 0.85 rg}
\hrule width \wd\contentbox %
height \ht\contentbox %
depth \dp\contentbox
\pdfliteral{0 0 0 rg}
}%
\wd\bkgdbox=0bp%
\vbox{\hbox to \hsize{\box\bkgdbox\box\contentbox}}%
\vskip\baselineskip%
}
But it happens that use in conjunction with nested lists, the text is not correctly wrapped.

I'm far a novice in TeX macro, so I would be interested in advices on if I can and how to modify it fits automatically to the page layout. Would a minipage solve this? Or am I bound to make it with manual line breaks?

\grayboxyou proposed? For my theorems I set an automatic indent before they begin, but your box seems to break/ignore this indent. – Richard Oct 16 '22 at 15:14