2

Background

The following screen shot shows four uneven columns, which is the desired result:

Uneven Columns

Problem

The beforesection and aftersection options to the setuphead command don't seem to have any effect, which results in the following:

Unresponsive beforesection and aftersection options

Code

Reproduce the problem using:

\usemodule[newcolumnsets]

\definecolumnset[BookColumns][n=4]
\setupcolumnset[BookColumns:1][width=6in]
\setupcolumnset[BookColumns:2][width=4in]
\setupcolumnset[BookColumns:3][width=4in]
\setupcolumnset[BookColumns:4][width=4in]

\setuphead[chapter][
  beforesection={\startcolumnset[BookColumns]},
  aftersection={\stopcolumnset},
]

\definepapersize[BookPaperSize][
  width=24in,
  height=12in,
]

\setuppapersize[BookPaperSize]

\starttext
  \chapter[title={Chapter Title}]

  \dorecurse{5}{\input knuth \input lorem}
\stoptext

The uneven columns can be generated by changing the body to use \startcolumnset and \stopcolumnset directly:

  \startcolumnset[BookColumns]
    \chapter[title={Chapter Title}]

    \dorecurse{5}{\input knuth \input lorem}
  \stopcolumnset

Ideas

I tried redefining the chapter element as:

\let\oldchapter\chapter
\unexpanded\def\chapter{\dosingleempty\newchapter}
\def\chapter[#1]{\startcolumnset[BookColumns]\oldchapter[#1]\stopcolumnset}

This did not work. What does work is a series of sed calls:

sed -i 's/^\\chapter\(.*\)/\\stopcolumnset\n\\startcolumnset[BookColumns]\n\\chapter\1/' body.tex
sed -i '1d' body.tex
echo "\\stopcolumnset" >> body.tex

Calling sed is not the "ConTeXt way", of course.

A different question shows using beforesection and aftersection with mixedcolumns:

\setuphead[subsection][
  beforesection={\startmixedcolumns[n=2,balance=no,]},
  aftersection={\stopmixedcolumns},
  page=no,
]

Question

How would you ensure that the \startcolumnset and \stopcolumnset commands bracket every chapter without modifying the body? (That is, apply column sets for each chapter only by changing the setups.)

Related

Related questions include:

Dave Jarvis
  • 11,809
  • 2
    For beforesection and aftersection you have to use \startchapter and \stopchapter instead of \chapter. – Henri Menke Jul 20 '19 at 03:29
  • 2
    Yes, you can generate \start...\stopsection with pandoc. I implemented this because you asked me to do it at some point: https://github.com/jgm/pandoc/pull/4295 – Henri Menke Jul 20 '19 at 03:40
  • You also need \setuplayout[grid=yes] for the new columnsets. Otherwise floats will be misplaced and column balancing breaks. – Henri Menke Jul 20 '19 at 03:48

1 Answers1

1

The sections must be balanced with \start and \stop commands (such as \startsection and \stopsection or \startchapter and \stopchapter) before using the beforesection and aftersection options. For example:

\setuphead[section][
  beforesection={\startcolumnset[BookColumns]},
  aftersection={\stopcolumnset},
]

When using pandoc's top-level-division option, it produces \chapter commands:

pandoc --top-level-division=chapter ...

By changing the command-line argument to --section-divs, pandoc produces \startsection, \startsubsection, \startsubsubsection and equivalent \stop commands:

pandoc --section-divs ...

Combining the two arguments produces \startchapter and \stopchapter, which also allows beforesection and aftersection to work:

pandoc --top-level-division=chapter --section-divs ...
Dave Jarvis
  • 11,809