8

Background

Regarding floats in columns, the wiki states:

By default, a title will be moved down to appear below a float, it will not be "wrapped" around a float like normal text.

Problem

The section title disappears, instead of being moved below the float. Ultimately, I'm trying to produce the following two layouts without changing the content (between \starttext and \stoptext):

Layouts

As an aside, it is important that the content need not change as there are other layouts that use the same document structure. If content changes can be made universal such that the other layouts remain unaffected, for example by adding a new namespace and command, then that will work. This might resemble:

\definenamespace[Photograph][
  type=module,
  name=Photograph,
  parent=Photograph,
  setup=list,
  version=1.0,
  style=yes,
  command=list,
]

% ...
\starttext
  \setupInsertPhotograph[
    author=Full Name,
    homepage=http://authorname.com/about.html,
    source=http://flickr.com/authorname/sunset.jpg,
  ]
  % Calls "placefigure" and "externalfigure" using the setup parameters.
  \InsertPhotograph
% ...
\stoptext

Then the \InsertPhotograph macro could be used to customize how the photograph is typeset, independently of the layout.

Code

So far, I have the following code:

\setupalign[hz,tolerant,]

\setuphead[chapter][footer=empty,]
\setuphead[section][page=yes,]

\setuphead[subsection][
  before={\vskip0.5em},
  after={\vskip0.5em},
]

\setuphead[chapter,section,subsection][header=none,number=no,]

\defineitemgroup[Preparation]
\setupitemgroup[Preparation][each][packed][
  before={\empty},
]

\setupexternalfigures[width=\hsize,]

\definecolumnset[BookColumns][n=2]
\definecolumnsetspan[BookColumnSpan][n=2]

\starttext
  \startchapter[title=Chapter One]
  \page
  \startcolumnset[BookColumns]
    \startsection[title=Section One]
      % This could be \InsertPhotograph instead of \placefigure...
      \placefigure[tblr]{}{\externalfigure[fake][]}

      \startsubsection[title=Subsection]
      \input douglas
      \stopsubsection
      \startsubsection[title=Preparation]
      \startPreparation
      \dorecurse{4} { \startitem Pour liquid helium into flask. \stopitem }
      \stopPreparation
      \stopsubsection
    \stopsection
    \startsection[title=Section Two]
      \dorecurse{4} { \input knuth }
    \stopsection
  \stopcolumnset
  \stopchapter
\stoptext

Question

How can the photograph float to the left of the section title when a figure is present, whilst the section title spans the page when no figure is present?

5

Here I present a solution which uses the second optional argument of the sectioning commands.

The values can be retrieved with the command \structureuservariable. First, a custom head alternative is defined which checks if the figure key is present. If it is, it includes the figure and the section head, otherwise only the section head is included. Then the section head is set up to use the custom head alternative.

\setupexternalfigures
  [location=default]

\defineframed
  [headframe]
  [width=\textwidth,
   frame=off]

\defineheadalternative
  [graphiccolumn]
  [renderingsetup=graphiccolumn]

\startsetups [graphiccolumn]
  \headsetupspacing
  \doifsomethingelse
    {\structureuservariable{figure}}
    {\headframe
      {\externalfigure[\structureuservariable{figure}]\hfill
       \headnumbercontent\space\headtextcontent}}
    {\headnumbercontent\space\headtextcontent}
\stopsetups

\setuphead
  [section]
  [alternative=graphiccolumn]

\starttext
  \startsection [title=Alpha] [figure=cow]
    \input ward
  \stopsection

  \startsection [title=Beta]
    \input ward
  \stopsection

  \startsection [title=Gamma] [figure=hacker]
    \input ward
  \stopsection
\stoptext

result

2

Creating a custom section to indicate when a photograph is present (sectionpicture) allows for that section to be wrapped in a two-column mode and its title made empty. This preserves the structure of the document allowing for a wide variety of layout possibilities.

It might also be possible to use:

\def\trueref{true}
\startsection[title=Section One][picture=\trueref]
  \Photograph
  % ...
\stopsection

However, I could not get that approach to work. Instead, the code following the preview almost produces the correct result.

Preview:

Result

Code:

\setuppapersize[letter][letter]
\setuplayout[width=fit,]
\setupalign[hz,tolerant,]

\setuphead[chapter,section,subsection][header=none,number=no,]

\setuphead[chapter][footer=empty,after=\page,]
\setuphead[section][page=yes,]

\setuphead[subsection][
  before={\vskip0.5em},
  after={\vskip0.5em},
  page=no,
]

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

\definehead[sectionpicture][section][
  placehead=empty,
  before={\startcolumns[n=2,]},
  after={\vskip-1em},
]

\defineitemgroup[Preparation]
\setupitemgroup[Preparation][each][packed][
  before={\empty},
]

\setupexternalfigures[
  width=\hsize,
  location={none,left,high},
]

\definenamespace[Photograph][
  type=module,
  name=Photograph,
  parent=Photograph,
  setup=list,
  version=1.0,
  style=yes,
  command=list,
]

% Define parameters within the Photograph namespace.
\setupPhotograph[
  author=,
  homepage=,
  source=,
  % Pass along the current section title into the Photograph macro.
  sectiontitle={\namedstructurevariable{section}{title}},
  attribution=photo:,
  cite={%
    \Word{\Photographparameter{attribution}} %
    \Photographparameter{author}},
]

\setupcaptions[location=,]
\definefloat[photograph][photographs][figure]

\showframe

% Defines how the photograph is used.
\def\Photograph{%
  \placephotograph[top,left,force]{}{\externalfigure[fake][]}
  \columnbreak
  {\switchtobodyfont[24pt]\Photographparameter{sectiontitle}} \par \\
  \Photographparameter{cite}
  \stopcolumns
}

\starttext
  \startchapter[title=Chapter One]
    \startsectionpicture[title=Section One]
      \Photograph

      \startsubsection[title=Subsection]
      \input douglas
      \stopsubsection

      \startsubsection[title=Preparation]
      \startPreparation
      \dorecurse{3} { \startitem Pour liquid helium into flask. \stopitem }
      \stopPreparation
      \stopsubsection
    \stopsectionpicture

    \startsection[title=Section Two]
      \startsubsection[title=Subsection]
      \input knuth
      \stopsubsection

      \startsubsection[title=Preparation]
      \startPreparation
      \dorecurse{3} { \startitem Pour CO$_2$ into beaker. \stopitem }
      \stopPreparation
      \stopsubsection
    \stopsection
  \stopchapter
\stoptext

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.