Paragraph last line control

From Wiki
Revision as of 15:11, 8 June 2020 by Garulfo (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

In case of separating paragraphs by indenting the first line (instead of blank line), it allows influencing a minimum and maximum length of the last line. The former prevents gaps between the end of the line and next indented line. The latter avoids cases the last line ends at the rigth edge so the next paragraph has no clear distincion from the previous one.

1. the last line lenght should be greater than the left indent

   xxxxxxxxxxxxxxxx
   xxxx
     xxxxxxxxxxxxxx
   xxxxxxxxxxxxxxxx

2. the last line should be shorter than block width

   xxxxxxxxxxxxxxxx
   xxxxxxxxxxxxxx
     xxxxxxxxxxxxxx
   xxxxxxxxxxxxxxxx

It can be achieved by custom settings of \parfillskip command. https://www.tug.org/utilities/plain/cseq.html#parfillskip-rp

The first parameter is a minimal right indent which can eventually be enlarged by the value of the second parameter: \parfillskip <right-indent> plus <tolerance>

However, in case of unfavourable conditions the result can still yield to the length outside the allowed range[1], as can be seen on several pages in the following example. So this approach should never been taken as a universal solution.

\setupindenting[yes, 2em]
\setuptolerance[strict]

\newdimen\lastlineminlength
\newdimen\lastlinemingap

\lastlineminlength=3em
\lastlinemingap=1em

\parfillskip \lastlinemingap plus \dimexpr\availablehsize-\lastlineminlength-\lastlinemingap\relax

\edef\ward{\cldloadfile{ward}}

\starttext

\dorecurse{100}{
   \hsize\dimexpr\textwidth-#1mm\relax
   \ward{}okey \par
   \ward{}okey \par
   \page
}

\stoptext

__________

  1. Even if the second parameter is properly calculated, thanks to internal TeX processing the larger value may be used at the end.