5

I'm trying to reproduce something like that with MetaFun:

For now with these links, I managed to get that:

\definecolor[darkblue][r=20,g=30,b=50]
\startuseMPgraphic{MPTheoremFrame}
    % Useful values
    numeric w, h, o, b ;
    w := OverlayWidth ; h := OverlayHeight ; o := BodyFontSize ;
    b := 1pt ; % border size

    path theorembox ;% contentbox ;


    % LABEL
    picture theorem ;
    %% Get label and counter
    theorem := textext.rt("~\bf\ss\currentconstructionsample~\getnumber[\currentconstruction]~") ;
    %% Shift it to the right place
    theorem := theorem shifted (o-b/2,h+3(o-b)/2) ;


    % THEOREMBOX
    %% Set theorembox as a boundingbox around title
    theorembox := boundingbox theorem enlarged o;
    %% Set theorembox background color
    fill theorembox withcolor darkblue ;
    %% Draw label/counter with the right color inside theorembox
    draw theorem withcolor white ;


    % THEOREMTITLE
    picture title;
    %% Get theorem title
    title := textext.rt("~\bf\ss\currentconstructiontitle~") ;
    % Shift theorem title next to theorembox
    title := title shifted (bbwidth(theorembox), h+3(o-b)/2);
    % Draw theorem title
    draw title withcolor darkblue ;


    % CONTENT
    drawoptions (withpen pencircle scaled b withcolor darkblue) ;
    draw (0,h)--(0,h)--(0,0)--(w,0)--(w,h)--(xpart urcorner theorembox, h) ;


    setbounds currentpicture to OverlayBox ;
\stopuseMPgraphic

\defineoverlay[MPTheoremFrame][\useMPgraphic{MPTheoremFrame}]

\defineframedtext[TheoremFramedText][frame=off,
                                     background=MPTheoremFrame,
                                     offset=\bodyfontsize,
                                     width=\textwidth]
\defineenumeration[theorem][title=yes,
                            text={\labeltext{theorem}},
                            alternative=empty,
                            before=\startTheoremFramedText,
                            after=\stopTheoremFramedText,
                            prefix=yes,
                            way=bysection,
                            prefixsegments={chapter:section}]

As you can see, there is some issues I can't fix:

  • boxes are above the sections names and text : here there is a section named "Test" hidden by the theorem box
  • boxes are above each others
  • There is a little glitch with the labelbox and the content box...

Also:

  • how to place the theorem name outside the titlebox?
  • is there a proper way to use these boxes in margins?
  • how can I edit the content box? (background, changing fonts, etc...)
3
  • It's done with ConTeXt MKIV.
    – user213111
    Commented Apr 19, 2020 at 10:21
  • 2
    And since I already have a large document written in ConTeXt I am not sure I want to move in LaTeX with lualatex.
    – user213111
    Commented Apr 19, 2020 at 10:27
  • Basically, you are placing the theorem number and theorem title using metapost but are telling metapost that the image that is has drawn has the bounding box of the content of the theorem. So, no space is reserved for it. The simplest fix is to add before={\blank[2*line]} in \defineenumeration.
    – Aditya
    Commented Apr 20, 2020 at 5:24

1 Answer 1

4

Here is an altogether different and much simpler approach to get the same result.

The example is simply the alternative=top with a left frame and a bottom frame, which is easy to achieve by wrapping the theorem inside a framedtext.

The tricky part is the fancy title. ConTeXt provides three hooks to wrap a command around an enumeration:

  • numbercommand, which is applied only to the number,
  • titlecommand, which is applied to the title only
  • headcommand, which is applied to both the number and the title.

So, all you need to do is set the numbercommand as a frame with blue background, and you are done.

Here is the complete code:

\definecolor[darkblue][b=0.8]

\definemeasure[frameoffset][2ex]
\definemeasure[rulethickness][2pt]

\defineframedtext
  [theoremframe]
  [
    frame=off,
    leftframe=on,
    bottomframe=on,
    framecolor=darkblue,
    rulethickness=\measure{rulethickness},
    width=broad,
    offset=overlay,
    loffset=\measure{frameoffset},
    boffset=\measure{frameoffset},
    toffset=-\measure{rulethickness},
  ]

\defineframed
  [headframed]
  [
    background=color,
    backgroundcolor=darkblue,
    foregroundcolor=white,
    frame=off,
    toffset=1ex,
    boffset=1ex,
    roffset=1ex,
    loffset=\measure{frameoffset},
    location=low,
  ]

\defineenumeration
  [theorem]
  [
    text=Theorem,
    % Number
    prefix=yes,
    prefixsegments={chapter:section},
    way=bysection,
    numbercommand={\hskip-\measure{frameoffset}\relax\headframed},
    % Title
    title=yes,
    titlecolor=darkblue,
    titleleft=,
    titleright=,
    % Frame
    before=\starttheoremframe,
    after=\stoptheoremframe,
  ]

\starttext
\startsection[title=An example theorem]
\starttheorem[title={Pythagorean Theorem}]
  Let $V$ be an inner product space. If $(u,v) \in V^2$ are orthogonal to each
  other, then
  \startformula
    \lVert u + v \rVert^2 = \lVert u \rVert^2 + \lVert v \rVert^2.
  \stopformula
\stoptheorem
\stopsection
\stoptext

which gives

enter image description here

0

You must log in to answer this question.