
Я пытаюсь определить причудливые рамки с помощью ConTeXt, но у меня возникают некоторые трудности. Поскольку я нашел много примеров, я в основном использовал Metapost, но поскольку я больше адепт TiKz, я не совсем понимаю, что происходит.
Сначала я попробовал использовать среду framedtext, но она ведет себя неправильно при встраивании рисунка (что мне часто нужно). Вот рамка, как мне хотелось бы.
\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
Затем я попробовал с текстовым фоном; я изменил определения наложения и фреймированного текста с помощью
\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]
Это решает проблему с обтеканием, но приводит к следующей проблеме: рамка занимает всю страницу вместо необходимого пространства, и мне не удалось получить пробелы по краям:
Наконец, я попытался изменить часть MP, используя документ от 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
Но он ведет себя не очень хорошо и, похоже, не допускает переменной толщины линий (и я не смог найти никакой документации по массиву multipars...)
решение1
Я рекомендую использовать textbackground
, потому что это может привести к разрыву между страницами. Поэтому я адаптировал решение Вольфганга изОбрамление целых разделов в 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