# ConTeXt : frame problems

I'm trying to define fancy frames with ConTeXt, but I get some difficulties. Since I found many examples of this, I mainly used Metapost, but since I'm more of a TiKz adept, I don't really understand what is going on.

First I tried to use a framedtext environment, but it misbehaves when embedding a figure (which is something I often need). This is the frame as I'd like it.

\usesymbols[mvs]
\definesymbol[info][{\symbol[martinvogel 2][Info]}]

\startuseMPgraphic{mp:axiomframe}
draw (OverlayWidth,OverlayHeight) -- (0,OverlayHeight) -- (0,0);
draw (0.5pt,0) -- (OverlayWidth,0) -- (OverlayWidth,OverlayHeight-
0.5pt) withpen pencircle scaled 1.2bp;
fill OverlayBox withcolor 0.95 white;
fill bbox textext.top("\tfd\symbol[info]") shifted
(0.5EmWidth,OverlayHeight-3ExHeight) withcolor white;
draw textext.top("\tfd\symbol[info]") shifted
(0.5EmWidth,OverlayHeight-3ExHeight) ;
setbounds currentpicture to OverlayBox ;
\stopuseMPgraphic
\defineoverlay[axiomframe][\useMPgraphic{mp:axiomframe}]
\defineframedtext[theoremFrame]
[frame=off,
rulethickness=1pt,
offset=5pt,
background=axiomframe,
width=fit,
location=middle]

\def\starttheorem{\dosingleempty\doStarttheorem}
\def\doStarttheorem[#1]{
\starttheoremFrame
\iffirstargument \hskip2em {\bfa #1} \\ \fi
}
\def\stoptheorem{\stoptheoremFrame}

\useexternalfigure[ctanlion]
[http://www.ctan.org/lion/ctan_lion_350x350.png][width=5cm]

\starttext
\starttheorem[Hello]
\placefigure[here,right,none]{}{\externalfigure[ctanlion]}
\input knuth
\stoptheorem


Then I tried with a textbackground ; I changed the overlay and framedtext definitions with

\definetextbackground[theoremFrame]
[mp=mp:axiomframe,
leftoffset=2\bodyfontsize,rightoffset=.5\bodyfontsize,
topoffset=.5\bodyfontsize,bottomoffset=.5\bodyfontsize,
before={\testpage[3]\blank},
after={\blank[2*medium]},
width=local]


This resolves the float problem, but leads to the following problem : the frame takes all the page instead of the required space, and I couldn't manage to get spaces on the edges :

Finally, I tried to modify the MP part using a document from Aditya :

\startuseMPgraphic{mp:axiomframe}
path p;
for i = 1 upto nofmultipars :
p = (multipars[i] topenlarged 0pt bottomenlarged 0pt);
fill p withcolor 0.95white ;
draw p withcolor black withpen pencircle scaled
\MPvar{linewidth};
endfor;
fill bbox textext.top("\tfd\symbol[info]") shifted
(0.5EmWidth,OverlayHeight-3ExHeight) withcolor white;
draw textext.top("\tfd\symbol[info]") shifted
(0.5EmWidth,OverlayHeight-3ExHeight) ;
setbounds currentpicture to OverlayBox ;
\stopuseMPgraphic


But it doesn't behave well, and it doesn't seem to permit variable line thickness (and I couldn't find any documentation on the multipars array...)

I recommend using textbackground, because this can break across pages. Therefore I adapted Wolfgang's solution from Frame whole sections in ConTeXt.

\usesymbols[mvs]
\definesymbol[info][{\symbol[martinvogel 2][Info]}]

\startuseMPgraphic{mp:axiomframe}
begingroup;
for i=1 upto nofmultipars :
% Draw the surrounding box
path p;
p := ( llcorner multipars[i]
-- lrcorner multipars[i]
-- urcorner multipars[i]
-- ulcorner multipars[i]
-- cycle )
enlarged (EmWidth,EmWidth) ;
fill p withcolor boxfillcolor ;
draw p withcolor boxlinecolor ;
draw (p cutbefore point 2 of p cutafter point 4 of p)
withpen pencircle scaled 2pt
withcolor boxlinecolor ;
% Draw the info symbol
picture pic;
pic := textext.ulft("\tfd\symbol[info]");
pic := pic shifted ulcorner multipars[i];
fill bbox pic withcolor white;
draw pic;
endfor ;
setbounds currentpicture to OverlayBox ;
endgroup;
\stopuseMPgraphic

\definetextbackground
[theoremFrame]
[mp=mp:axiomframe,
location=paragraph,
backgroundcolor=green,
framecolor=red,
before={\testpage[3]\blank},
after={\blank[2*medium]}]

\defineenumeration
[theorem]
[text=,
number=no,
title=yes,
titledistance=2em,
titleleft=,
titleright=,
before={\starttextbackground[theoremFrame]},
after={\stoptextbackground}]

\useexternalfigure[ctanlion]
[http://www.ctan.org/lion/ctan_lion_350x350.png][width=5cm]

\starttext
\starttheorem[title=Hello]
\placefigure[here,right,none]{}{\externalfigure[ctanlion]}
\input knuth
\stoptheorem

\input lorem

\starttheorem[title=Hello]
\placefigure[here,right,none]{}{\externalfigure[ctanlion]}
\input knuth
\stoptheorem
\stoptext


• I already achieved a similar result ; the problem with this method for drawing the surrounding box (with multipars) is that I don't see how I can change the rule thickness for some of the borders, or keep only some borders. I've tried to create two other paths p1 and p2 by changing the p definition, fill p and draw p1 and p2 separately, but it doesn't compile. – A. Licari Jun 29 '17 at 9:51
• @A.Licari Which borders do you want to keep? – Henri Menke Jun 29 '17 at 10:15
• Depending on the environment (theorems, remarks, traps...) it may depend. I might also change the background color from one environment to the other, or the upper left picture, that's why I like to understand how it works. For theorems it would be all borders kept, with bottom and right thicker. I also found out with your solution that if you use two theorem environments on the same page, only the first one has the pic. – A. Licari Jun 29 '17 at 10:18
• @A.Licari See updated answer. – Henri Menke Jun 29 '17 at 10:52
• @HenriMenke: Then why didn't you correct it :-) – Aditya Jun 29 '17 at 23:26