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
2
  • It isn't exactly what you want, but this code comes fairly close (sample output). I'll maybe write a proper answer later if I get some time. Commented Dec 16, 2022 at 2:57
  • Wow, that seems like magic. In the sense of an advanced technology ... I'd like to use it just for handling the widows & orphans.
    – Stanley
    Commented Dec 16, 2022 at 8:15

1 Answer 1

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

3
  • 2
    Maybe it's just my screen or my eyes, but the line "Introduction chapter" appears to be closer to the next line than the three lines of the entry are to each other. Commented Dec 16, 2022 at 21:12
  • 1
    I think you are right. I think a strut will do.
    – mickep
    Commented Dec 16, 2022 at 21:20
  • Thanks, that's perfect
    – Stanley
    Commented Dec 17, 2022 at 4:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .