316 TUGboat, Volume 33 (2012), No. 3 Stubborn leaders and juggling boxes: A slightly unusual table of contents Boris Veytsman Abstract A macro for typesetting an unusual table of contents is introduced. The history of development of this macro is described in detail showing the refinement of requirements and refactoring of the code. The T E X boxes, their measuring and inspection are discussed. 1 Introduction Many publishers that accept manuscripts in T E X or L A T E X put their styles on CTAN; see the (certainly in- complete) list at http://www.ctan.org/keyword/ publishers. However, when a journal uses T E X in- ternally, there are also macros not publicly released. These macros are used in typesetting covers, journal title pages, issue and volume tables of contents, in- dices etc. They are specific to the journal. Without major changes they can be used only by the people who want to create another one with exactly the same look and feel. For some reason this practice is frowned upon by the publishers. Still, sometimes the tricks in these macros might be of interest to T E Xnicians. Thus extracting them and publishing separately seems to be worth doing. I recently released the package (Veytsman, 2012) for typesetting articles for the journal Res Philo- sophica, http://www.resphilosophica.org. I also wrote a package to typeset the covers and technical information for the journal. In this article I describe a somewhat non-trivial macro used in the table of contents of the journal. An important (maybe the most important) part of the work of a programmer is the understanding of the requirements. Thus I would like to tell the history of this macro: how it was designed and re-designed after studying the samples. 2 The problem and a na¨ ıve solution The entries of the journal’s table of contents were typeset like the ones in Figure 1: the article title, then the dots connecting the entry to the page num- ber, following by the page number itself, and the au- thors on the next line in italics. The dots are called leaders in T E X. L A T E X has a nice macro \dotfill which makes infinitely stretchable leaders. 1 With this macro our T E X source looks like this: 1 While most of our code works in plain T E X, we do use some L A T E Xisms like \dotfill, \itshape, etc., which are easy to emulate in other formats. Article title ............................... 5 A. U. Thor Figure 1: A simple TOC entry Article title ............................... 5 A. U. Thor A very very very very very very long article title ....................................... 9 A. N. Other Figure 2: Failure of the na¨ ıve solution % #1 is the title, #2 is the author(s) % #3 is the page number \def\settocentry#1#2#3{\par #1\space\dotfill\space#3\par \textit{#2}\par\medskip} \parskip=0pt\parindent=0pt \settocentry{Article title}{A. U. Thor}{5} The problem is solved! Unfortunately, it is not so simple. What hap- pens if the article title is very long? The result is shown in Figure 2. The leaders start from the second line of the title, separating it from the author, which just does not look right. This situation occurs not infrequently because the width of the journal pages is rather small (6 in.). An examination of the samples showed that the designer wanted (1) the title and the authors to occupy no more than 60% of the text width, and (2) the leaders to always start from the first line of the entry, even if the title occupied two or more lines. Of course, there are some arguments against this design. One can object to the fact that the title is “broken” by the leaders. On the other hand, the eye looking for a title or authors moves in the vertical direction and probably disregards the intervening leaders, so this objection might not be too strong after all. Anyway, this was the design which I was given to implement. 3 A less na¨ ıve solution A less na¨ ıve idea is the following. Let us typeset the title in a box of certain width, say \entrywidth, with the baseline at the first line. If it occupies one line, we throw away the box and use the solution from the previous section. However, if it occupies two or more lines (which we can check by measuring its depth), we align it with the leaders and page number. To make our code simpler, let us split the main macro into two parts: setting the title and setting the authors. We also put the page into a global Boris Veytsman