3

There is a common thing that bothers me about the way ConTeXt makes page breaks : there are things I'd rather not have in first line. For instance, if the following code snippet is found within a longer document

which leads to the result
\startformula
  a = b
\stopformula

it may produce an output where the text is the last line of a page and the formula is starting the next page. Another exemple is the way I manage exercises in separate files, which look like

\exercisetitle{My title}
\startmode[questions]
    Here are the questions
\stopmode
\startmode[answer]
    Here are the answers
\stopmode

I often find the title at the bottom of a page and the beginning of the exercise on the next page, while the page break would be better before the title in order to keep the title and the exercise stuck together. However, I can't simply use a \vbox, since the exercise may be long and a page break inside the exercise may occur without problems.

I can manage it by hand, but it is quite stupid since the aim of a such a tool is to be free (at least, most of the time) of these minor adjustements. What are the configuration options that I could put in my environment file to regulate this behavior ? I am aware of \page[no], but it is not that automated, and sometimes just doesn't work (for instance, I the following MWE works, but I had an exactly similar situation in my real documents where the \page[no] command didn't work.

\setuppapersize[A5][A5]
\defineitemgroup[questions][levels=2]
\setupitemgroup[questions][1][n,packed]
\setupitemgroup[questions][2][a,packed,repeat][stopper=)]
\starttext
% A bit of text to reach the end of the page
\input knuth
\blank
\input knuth
% The useful part
{\sl My dear fellow TeX users}, I would like to introduce you the following itemize :
\page[no]
\startquestions[columns]
\item one !
\item two !
\item three !
\item four !
\item five !
\item six !
\stopquestions
\stoptext
  • 2
    Better use \blank[samepage] instead of \page[no]. The latter only works in vertical mode and will produce no result if applied in horizontal mode (which might happen by accident). – Henri Menke Aug 25 '16 at 9:46
  • Add autointro to your options: \setupitemgroup[questions][1][n,packed,autointro] – Aditya Aug 25 '16 at 17:12
3

Unfortunately, \defineitemgroup does not have a spacebefore option but instead you can put \blank[samepage] into the before key. Where spacebefore is available it makes more sense to use that, for instance with formulas: \setupformula[spacebefore={samepage}].

N.B.: By default itemgroup has \blank sitting in the before key. Without any optional argument \blank will insert a blank of size \currentvspacing. To maintain this amount (which is lost when saying \blank[samepage]) one has to include it, i.e. \blank[\currentvspacing,samepage]. This is somewhat ugly but I don't know a better way to fetch the current spacing value.

\setuppapersize[A5][A5]
\defineitemgroup[questions][levels=2,before={\blank[samepage]}]
\setupitemgroup[questions][1][n,packed]
\setupitemgroup[questions][2][a,packed,repeat][stopper=)]
\starttext
% A bit of text to reach the end of the page
\input knuth
\blank
\input knuth
% The useful part
{\sl My dear fellow TeX users}, I would like to introduce you the following itemize :
\startquestions[columns]
\item one !
\item two !
\item three !
\item four !
\item five !
\item six !
\stopquestions
\stoptext
  • It may be better to use intro or autointro keywords – Aditya Aug 25 '16 at 17:14
  • See my solution – Aditya Aug 25 '16 at 19:31
4

For itemize and itemgroups, you can use intro keyword to prevent pagebreak before the start of the itemgroup. For example:

\setuppapersize[A5][A5]
\defineitemgroup[questions][levels=2]
\setupitemgroup[questions][1][n,packed,intro]
\setupitemgroup[questions][2][a,packed,repeat][stopper=)]
\starttext
% A bit of text to reach the end of the page
\input knuth
\blank
\input knuth
% The useful part
{\sl My dear fellow TeX users}, I would like to introduce you the following itemize :
\startquestions
\item one !
\item two !
\item three !
\item four !
\item five !
\item six !
\stopquestions
\stoptext

It also prevents page breaks between the items if there are only two items.

Another option is to use the autointro key, that prevents a page break before the start of the item group if the previous paragraph is less than two lines. So, if you are inserting an itemgroup after a section head, you could also use autointro

Unfortunately, these options don't work with columns option before \startmixedcolumn comes too early in the definition.

  • You should remove \page[no] to show off that it really works... but for me it then doesn't :( – Henri Menke Aug 25 '16 at 19:35
  • @HenriMenke: Oops, didn't see the page[no]. Using intro works without the column. so the "bug" is with columns. – Aditya Aug 25 '16 at 19:49
  • Is it possible to use intro or autointro as arguments in the startquestions command ? Depending on the context, it can be perfectly acceptable to have a page break, so it must be tunable... – A. Licari Aug 25 '16 at 22:32
  • Yes. You can use the as option of \startquestions as well – Aditya Aug 25 '16 at 22:55

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.