3

I'm using the table of contents mikep described: ConTeXt: Can I exclude entries from a placelist table of contents?.

I was inspired to style the sections in the table of contents by Max Chernoff's answer: Context: a custom chapter title.

In the table of contents, I want a horizontal layout, with each section name and it's page number to be on the same line. My MWE achieves this, but there are 3 problems:

1 - A section can extend into the right margin. I want a line break before Another~section~looooooooong · 3.

2 - My macro myTOC inserts a \hskip 10mm after every section name & number in the table of contents. Can I prevent this for the last one before a new chapter?

3 - I have put tildes between words in a section name so the name doesn't line break in the table of contents. Is there a way to use spaces and not have a break? TOC

\showframe
\define[3]\myTOC{{#2}~·~{#3}\hskip 10mm}%   Write a section TOC entry

\setuphead[part][placehead=yes, number=no,] \definehead[mypart][part][number=no,] \setuphead[chapter][sectionsegments={chapter:section},] \setuphead[section][sectionsegments={chapter:section},]

\setuplist[part][style={\bfa}, pagenumber=no,]
\setuplist[chapter][style={\bf}, pagenumber=no,]
\setuplist[chapter,section][headnumber=no,] \setuplist[section][command=\myTOC,alternative=command,] %\setuplist[section][alternative=d,] \setupcombinedlist[content][list={part,chapter,section}]

\starttext

\unhyphenated{ {\raggedright % no bad line breaks in horizontal \completecontent }} \chapter[title={Introduction chapter}] \section[title=Section~one]\samplefile{douglas} \section[title=Section~two]\samplefile{douglas} \section[title=Third~section]\samplefile{douglas} \section[title=Another~section~looooooooong]\samplefile{douglas} \section[title=Yet~another~section]\samplefile{douglas} \section[title=A~following~section]\samplefile{douglas} \stoptext

Stanley
  • 371

1 Answers1

2

You shall never need to insert manual tildes like that. To keep stuff together, put it into a box (also with some strut after barbara's comment):

\define[3]\myTOC{\dontleavehmode\hbox{\begstrut #2 · #3\endstrut}\hskip 10mm}%

Also, instead of the \unhyphenated and \raggedright, you can try

\startalign[flushleft,broad]
\completecontent
\stopalign

Thus, with

\showframe

\setuphead[part][placehead=yes,number=no,] \definehead[mypart][part][number=no,] \setuphead[chapter][sectionsegments={chapter:section},] \setuphead[section][sectionsegments={chapter:section},]

\setuplist[part][style={\bfa}, pagenumber=no,]
\setuplist[chapter][style={\bf}, pagenumber=no,]
\setuplist[chapter,section][headnumber=no,]

\define[3]\myTOC{\dontleavehmode\hbox{\begstrut #2 · #3\endstrut}\hskip 10mm}%

\setuplist[section][ alternative=command, command=\myTOC, ]

\setupcombinedlist[content][list={part,chapter,section}]

\starttext \startalign[flushleft,broad] \completecontent \stopalign

\chapter[title={Introduction chapter}] \section[title=Section one]\samplefile{douglas} \section[title=Section two]\samplefile{douglas} \section[title=Third section]\samplefile{douglas} \section[title=Another section looooooooong]\samplefile{douglas} \section[title=Yet another section]\samplefile{douglas} \section[title=A following section]\samplefile{douglas} \stoptext

I get the following output:

table of contents

If we show boxes and struts (\showboxes and \showstruts) it looks like this:

with boxes and struts

Image from the old answer without the strut:

table of contents

mickep
  • 8,685