5

Background

Creating a document that can have zero-, two-, or three-column layouts, depending on user preferences. I would like to keep the content clean of \columnsets by redefining only the sections (both section and chapter pages have independent styles).

For example, this produces the desired outcome, but requires duplicating the \startcolumnset for each \startsection, which I'd like to avoid:

\definecolumnset[StyleColumns][n=2,
  %rule=on,
]

\startsection[title={Section1},reference=sec:section1,]
  \startcolumnset[StyleColumns]
    \placefigure[left]{}{%
    \externalfigure[7b104cc5c6.jpg][width=\textwidth]}

    This is a sentence that is really, really, really and very long.
  \stopcolumnset
\stopsection

\startsection[title={Section2},reference=sec:section2,]
  \startcolumnset[StyleColumns]
    \placefigure[left]{}{%
    \externalfigure[7b104cc5c6.jpg][width=\textwidth]}

    This is a sentence that is really, really, really and very long.
  \stopcolumnset
\stopsection

(The vertical rules don't work for me yet, but that's a separate issue.)

Problem

There are potentially hundreds of sections in the book that gets automatically generated. I would like to define whether or not multiple columns are used outside of the main content in a single location within the document (i.e., before the first \startbodymatter).

Forgiving my accent, I would like to do something such as:

% <CODE BLOCK>
\let\OldSection\section
\define\section{%
  \startsection
    \startcolumnset[StyleColumns]
      \OldSection
    \stopcolumnset
  \stopsection
% </CODE BLOCK>

\startsection[title={Section1},reference=sec:section1,]
  \placefigure[left]{}{%
  \externalfigure[7b104cc5c6.jpg][width=\textwidth]}
  This is a sentence that is really, really, really and very long.
\stopsection

\startsection[title={Section2},reference=sec:section2,]
  \placefigure[left]{}{%
  \externalfigure[7b104cc5c6.jpg][width=\textwidth]}
  This is a sentence that is really, really, really and very long.
\stopsection

That way when the document is generated, if the <CODE BLOCK> is not included then the document won't use multiple columns.

Alternative Approach

I considered using conditional modes, but that would lead to either messy or duplicated content.

Question

How do you create a document using ConTeXt such that the \startsection...\stopsection code blocks can be made columnar without actually embedding \startcolumnset[X]...\stopcolumnset within each section's code block?

Related

5

Use the after and aftersection keys to apply the column set for the given section. The after hook is injected between the section head and the content, aftersection at the end of the section. If column sets should not be applied to the entire document, you can define individual heads for the column text. Otherwise just redefine section using \setuphead[section].

\definecolumnset
  [StyleColumns]
  [n=2]

\definehead
  [ColumnSection]
  [section]
  [after={\startcolumnset[StyleColumns]},
   aftersection=\stopcolumnset]

\starttext
  \startColumnSection [title=Section 1]
    \dorecurse{4}{\input knuth\par}
  \stopColumnSection

  \startsection [title=Section 2]
    \dorecurse{4}{\input knuth\par}
  \stopsection
\stoptext
  • 2
    Note that beforesection is applied before the section heading, so strictly speaking the above is not equivalent to the OP. For that you would need to use after={\startcolumnset[StyleColumns]}, aftersection=\stopcolumnset, which, I admit, is a bit weird – Aditya Aug 21 '13 at 18:48

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.