Background
Trying to determine whether a column break must be inserted on a two-column page. There are multiple sections on the page. Before the last section on the page, I want to insert a column break, but only if within the first column and only if there is sufficient space in the second column (i.e., without forcing a page break).
Problem
The following code illustrates the problem:
\starttext
\startcolumns[n=2, balance=no]
\startsection[title=Section1]
\input knuth
\stopsection
\startsection[title=Section2]
\input zapf
\stopsection
\column
\startsection[title=Section3]
\input knuth
\stopsection
\stopcolumns
\stoptext
The \column break should not be applied because section 3 is in the second column, which causes an undesired page break. To clarify, the condition to determine whether or not to break the column should be independent of the text itself. For example, something like:
\setuphead[chapter][
before={\startcolumns[n=2, balance=no,]},
after={\stopcolumns},
]
% If the section is the last section in the chapter
% *and* the section is not in the last column *and*
% inserting a column break does not cause pagination...
\setuphead[section][
before={%
\if_last_section{%
\if_not_last_column{%
\if_fits_in_last_column_without_pagination{\columnbreak}
}
}
},
]
\starttext
\startchapter
\startsection[title=Section1]
\input knuth
\stopsection
\startsection[title=Section2]
\input zapf
\stopsection
\startsection[title=Section3]
\input knuth
\stopsection
\stopchapter
\stoptext
Question
How do you force ConTeXt to insert a column break if a section is in the first column, but not if the section is in the second column?
Related
Very similar question for LaTeX:
Using LaTeX, the following code -- part of the document class -- helped dynamically determine whether or not a column break should be present:
\def\columnbreakunlesslast{%
\docolaction{\typeout{in first column}\inlastfalse}%
{\typeout{in middle column}\inlasttrue}%
{\typeout{in last column}\inlasttrue}%
\unless \ifinlast \columnbreak \fi
}
This allowed documents to be written such that manually inserting column breaks was not necessary.





\pageand\page[disable]will accomplish it (of course, wherever you wish to force the page break). Either way, irrespective whether\columnis applied. – doed Oct 08 '13 at 07:16\docolaction{\typeout{in first column}to determine whether the text is still in the first column. I'm looking for something like that. – Dave Jarvis Oct 08 '13 at 18:14mccolactionmay be deployed with user-generated content. Leave out that\columnbreakunlesslastin LaTeX and see what happens. For that matter Here is with\columnbreakinstead, which accomplishes the same thing. – doed Oct 17 '13 at 12:24mccolactiondated 7/7/2013, the\columnbreakunlesslastmust be tweaked manually, or else it won't work. – doed Oct 17 '13 at 12:54columnbreakunlesslastwas tweaked (as shown in the question), but it was tweaked in the document class file, not within any document. – Dave Jarvis Oct 17 '13 at 16:15mccolactionallowed documents not to have a\columnbreakunlesslast? For the sake of clarity, unless you include\columnbreakunlesslastin the document, whether 'user-generated' or not, it won't break the columns as originally intended. – doed Oct 18 '13 at 11:13mccolaction, until after you linked the similarly related LaTeX question. But upon closer look , you can try this out in ConTeXt. For example,\vfil\unpenalty\vbox \input bla bla bla, with the addition of say,\columnbreakor a\vfilll, and see how it becomes easily stretchable and shrinkable. In LaTeX for example, let\lipsumsubstitute\input. And as you can see, as of this writing, this is unlikely attainable in LaTeX. – doed Oct 18 '13 at 11:15\columbreakmust be conditionally applied outside of\starttext. I have clarified the intent with an example. – Dave Jarvis Oct 18 '13 at 16:34