3

I just ran into a problem : I defined a randomized background for theorems (I just copied-pasted code found on the net for the MP part, since I am not a user of metapost ; an example of such a definition by Aditya can be found here). However, when I use it with a side float, the frame doesn't take it into account at all :

\useexternalfigure[ctanlion][http://www.ctan.org/lion/ctan_lion_350x350.png][width=5cm]
\startuseMPgraphic{background:random}
  path p;
  for i = 1 upto nofmultipars :
    p = (multipars[i] topenlarged 0pt bottomenlarged 0pt) randomized 3pt ;
    fill p withcolor 0.95white ;
    draw p withcolor black withpen pencircle scaled \MPvar{linewidth};
  endfor;
  setbounds currentpicture to OverlayBox ;
\stopuseMPgraphic
\definetextbackground[axiomframe]
                     [mp=background:random,
                       location=paragraph,
                       rulethickness=1pt,
                       width=local,
                       leftoffset=.5\bodyfontsize,rightoffset=.5\bodyfontsize,
                       topoffset=.5\bodyfontsize,bottomoffset=.5\bodyfontsize,
                       before={\testpage[3]\blank},
                       after={\blank[2*medium]},
                     ]
\definedescription[theorem]
                  [text=,
                    before={\setupnarrower[middle=1cm]\startnarrower\startaxiomframe},
                    after={\stopaxiomframe\stopnarrower},
                    title=yes,
                    titlestyle=bold,
                    alternative=top,
                    inbetween=\nowhitespace]

\starttext

\starttheorem{Test}
  In this theorem, we test the background behavior. It seems to be alright for text, not
  for background.
\stoptheorem
\placefigure[right,none]{}{\externalfigure[ctanlion]}
In order to test the behavior in cas of side floats, we need a picture.
Let me introduce you the glorious CTAN lion :
\starttheorem{CTAN Lion}
  The CTAN Lion is very useful for tests. In this case, we can see that the background is
  not consistent with the figure, while the text is consistent.
\stoptheorem

The complex case is the one of very long text :
\placefigure[right,none]{}{\externalfigure[ctanlion]}
\starttheorem{Long blabla}
  \input knuth
\stoptheorem

\stoptext

result

Ideally, I would like : - if the side float was inserted before the theorem, the frame is reduced to the correct size and the text is this size all along - if the theorem is too long, I choose to flush the side float before / insert the float inside the theorem frame (which works perfectly)

Thank you in advance

  • This is quite a hard problem. What the sidefloats in ConTeXt do is use \parshape to shorten the correct amount of lines. The problem is that while the paragraph is being built the correct linewidth is not available (see this question). Thus you cannot shrink the theorem box to the narrowed paragraph. You can however flush the sidefloat before typsetting the theorem. – Henri Menke Nov 2 '16 at 8:12
3

I don’t think it is easily possible to make the sidefloats respect the narrowed paragraph of your theorems. I also don’t think that it is easily feasible to have the theorem decide whether to flush the sidefloat or take it into account (which would be the same as problem 1).

You can however flush all sidefloats before the theorem environment by using \flushsidefloats.

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

\startuseMPgraphic{background:random}
  path p;
  for i = 1 upto nofmultipars :
    p = (multipars[i] topenlarged 0pt bottomenlarged 0pt) randomized 3pt ;
    fill p withcolor 0.95white ;
    draw p withcolor black withpen pencircle scaled \MPvar{linewidth};
  endfor;
  setbounds currentpicture to OverlayBox ;
\stopuseMPgraphic

\definetextbackground
  [axiomframe]
  [
    mp=background:random,
    location=paragraph,
    rulethickness=1pt,
    width=local,
    leftoffset=.5\bodyfontsize,rightoffset=.5\bodyfontsize,
    topoffset=.5\bodyfontsize,bottomoffset=.5\bodyfontsize,
    before={\testpage[3]\blank},
    after={\blank[2*medium]},
  ]

\definedescription
  [theorem]
  [
    text=,
    before={\flushsidefloats
      \setupnarrower[middle=1cm]\startnarrower\startaxiomframe},
    after={\stopaxiomframe\stopnarrower},
    title=yes,
    titlestyle=bold,
    alternative=top,
    inbetween=\nowhitespace,
  ]

\starttext

\starttheorem{Test}
  In this theorem, we test the background behavior. It seems to be
  alright for text, not for background.
\stoptheorem
\placefigure[right,none]{}{\externalfigure[ctanlion]}
In order to test the behavior in cas of side floats, we need a
picture.  Let me introduce you the glorious CTAN lion :

\starttheorem{CTAN Lion}
  The CTAN Lion is very useful for tests. In this case, we can see
  that the background is not consistent with the figure, while the
  text is consistent.
\stoptheorem

The complex case is the one of very long text :
\placefigure[right,none]{}{\externalfigure[ctanlion]}
\starttheorem{Long blabla}
  \input knuth
\stoptheorem

\stoptext

enter image description here

  • Don’t use \page_otr_command_flush_side_floats, what you can do is to add the tall keyword to \placefigure or use \flushsidefloats at the begin of the description, e.g. \setupdescription[…][before=\flushsidefloats]. – Wolfgang Schuster Nov 2 '16 at 10:59
  • Thank you for your explanation. I'll work out every case independently then, and I'll decide if I want an automatic flush. Question for Metafox : what is the difference between \page_otr_command_flush_side_floats (that I didn't know) and \flushsidefloats (which I already knew and used) ? – A. Licari Nov 2 '16 at 11:37
  • \flushsidefloats is the user level form of the \page_otr_command_flush_side_floats command, the problem with internal commands is that key can be renamed or removed. – Wolfgang Schuster Nov 2 '16 at 12:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.