1

The para setting in threeparttable (excerpt below) uses what David Carlisle calls "an interesting collection of penalties and glue" that I must sadly confess is beyond me. Could someone explain what is going on here as if I were a young child, or a golden retriever? :-)

Excerpt from threeparttable.sty:

\def\TPT@doparanotes{\par
   \prevdepth\z@ \TPT@hsize
   \TPTnoteSettings
   \parindent\z@ \pretolerance 8
   \linepenalty 200
   \renewcommand\item[1][]{\relax\ifhmode \begingroup
       \unskip
       \advance\hsize 10em % \hsize is scratch register, based on real hsize
       \penalty -45 \hskip\z@\@plus\hsize \penalty-19
       \hskip .15\hsize \penalty 9999 \hskip-.15\hsize
       \hskip .01\hsize\@plus-\hsize\@minus.01\hsize 
       \hskip 1em\@plus .3em
      \endgroup\fi
      \tnote{##1}\,\ignorespaces}%
   \let\TPToverlap\relax
   \def\endtablenotes{\par}%
}
Fredrik P
  • 1,386

1 Answers1

3

Starting in the middle.

\hskip .15\hsize \penalty 9999 \hskip-.15\hsize

The idiom hskip something, some penalty, hskip minus something is quite common and goes back before LaTeX described in the TeXBook.

The total space added here is nothing so if no linebreak happens then it's as if it wasnt there. If however a linebreak happens at the penalty (allowed but strongly discouraged in this 9999 example) then there is a skip of .15\hsize at the end of the first line (as this is not stretchy this forces the line to be short) then the line break at the penalty, then the second negative skip is discarded as all glue following a line break is discarded.

So if there is already a paragraph break before the item most of this is skipped, but if there is not and we are in h(orizontal) mode then

\unskip to remove any glue from a space before \item (we want to add this glue combination not a normal word space)

\penalty -45 a negative penalty indicating a good place to break if you can break straight after the previous item.

\hskip 0pt plus \hsize adding glue between 0pt and full width (will be discarded if the previous break was taken)

\penalty-19 still a good place to break, but not as good as the -45 option.

\hskip .15\hsize \penalty 9999 \hskip-.15\hsize as discussed this is a discouraged but allowable last choice break which will force the previous line to be short

\hskip .01\hsize plus-\hsize minus.01\hsize If the previous breaks were not taken add glue with stretch of -\hsize which cancels out the \hsize stretch added previously, also allow a bit of shrink.

\hskip 1em plus .3em if there has not been a linebreak (otherwise this will be discarded) add a space of 1em stretching to 1.3em if needed as minimum space before the actual item

\tnote{##1}\,\ignorespaces now whether this is a new paragraph or the same paragraph following the horizontal glue just added, add the text from \item[] then a thin space then ignore any space from spaces in the source file, then start with the actual text which follows \item.

David Carlisle
  • 757,742