
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% the portion of code adapted from the TeXBOOK, Excercise 11.5 %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def\dolist{\afterassignment\dodolist\let\next= }
\def\dodolist{\ifx\next\endlist\let\next\relax
  \else \\\let\next\dolist \fi
\next}
\def\endlist{\endlist}

\def\\{\if\space\next\ % assume that \next is unexpandable
\else\setbox0=\hbox{\next}\setbox1=\hbox{}%
  \dp1=\dp0\ht1=\ht0\wd1=\wd0\box1\fi}

\def\demobox#1{{\dolist#1\endlist}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\setupframed[strut=no,offset=0pt]
\setupcolors[state=start]
\starttext

%%%%%%%%%%%%%%
% this works %
%%%%%%%%%%%%%%

\color[blue]{This works OK:}

bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla \demobox{bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla} bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla

bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The examples below have some troubles %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\color[blue]{This is not 100\% properly aligned, but works:}\par
a\demobox{Tough exercise.}b\par
a\hbox{Tough exercise.}b\par
a\framed{\hbox{Tough exercise.}}b\par
a\framed{\demobox{Tough exercise.}}b\par
%a\demobox{\framed{Tough exercise.}}b\par % this doesn't work

a\externalfigure[cow]b\par
\color[blue]{This cow has shrinked:}\par
a\demobox{\externalfigure[cow]}b\par
a\framed{\externalfigure[cow]}b\par
\color[blue]{And this cow disappeared:}\par
a\framed{\demobox{\externalfigure[cow]}}b\par
% a\demobox{\framed{\externalfigure[cow]}}b\par % this doesn't work

\color[blue]{The commented stuff didn't even dare to compile.}

%\input tufte \demobox{{\input tufte }}\input tufte\par
%\input tufte \input tufte \input tufte

%\dorecurse{10}{bla }
%\demobox{\dorecurse{10}{bla }}
%\dorecurse{10}{bla }\par
%\dorecurse{10}{bla }
%\dorecurse{10}{bla }
%\dorecurse{10}{bla }

\stoptext

