# ConTeXt: Page break preference between nested itemize environments

I frequently have nested itemize environments that must appear on the same page as the item that they are nested under, such as parts of a question on an assignment or exam. I can't seem to figure out the right options to force this behavior in all cases where nested content is physically able to fit on the page.

I had tried to use \page[bigpreference] after the nested itemize:

\usemodule[visual]

\setupitemize[2][after={\page[bigpreference]}]

\starttext

\startitemize
\dorecurse{20}{
\item This is an exam/assignment question item: \fakewords{10}{20}

\startitemize
\dorecurse{3}{
\item subquestion or multiple choice answer: \fakewords{10}{20}
}
\stopitemize
}
\stopitemize

\stoptext


But I get an unwanted break immediately on the first page:

I found a reference to \c_strc_itemgroups_spacing_mode=0 in another question and while this helps, I still see an unwanted page break on page 3. I also tried \setupitemize[1][inbetween={\page[bigpreference]}] with no improvement.

I'm not entirely sure whether this behavior is specific to nested itemize environments but is there any general way to make sure that the top-level item content is never split across pages?

Update:

While playing around some more with the page preference options, I found that the combination of \page[no] and \page[bigpreference] seems to work best, but as it is based on preferences, the end result is not guaranteed. Including the following options into the above code still results in an unwanted page break on page 6:

\setupitemize[2][inbetween={\page[no]},
before={\page[no]},
after={\page[bigpreference]}]


Perhaps some sort of framing solution would be best, but I'm not sure how to implement one in a generic fashion (without manually defining frames).

• A very dirty trick is putting your items and subitems in a \vbox, but the layout may look quite awful. So does the code. – sztruks Oct 11 '18 at 19:05
• @sztruks Thanks! That wouldn't be too bad if I didn't have to use \vbox manually (I'm usually dealing with quite a few such pages at a time). Do you know how I could incorporate \vbox into any of the before/after/inbetween options or something similar? I didn't have much luck when I played around with that idea earlier. – ssokolen Oct 11 '18 at 19:34
• unfortunately not, I am just beginning my travel with TeX boxes… – sztruks Oct 11 '18 at 19:44

Does changing the spacing mode work for you?

\usemodule[visual]

\unprotect
% 0 = before/after
% 1 = between unless before
% 2 = between
\c_strc_itemgroups_spacing_mode=0
\protect

\setupitemize[2][before={\blank[samepage]}]

\starttext

\startitemize
\dorecurse{20}{
\item This is an exam/assignment question item: \fakewords{10}{20}

\startitemize
\dorecurse{3}{
\item subquestion or multiple choice answer: \fakewords{10}{20}
}
\stopitemize
}
\stopitemize

\stoptext


Click to enlarge picture:

• Weirdly enough, I don't seem to get the same output as you with either 2018.04.04 or 2015.05.18 texlive versions (for Arch and Ubuntu respectively). Does this solution require the latest beta? – ssokolen Nov 23 '18 at 19:08