[Tex/LaTex] Avoid indenting one-liner paragraphs

indentationparagraphs

Some weeks ago I've found here a thread about how to accomplish not indenting paragraphs when they consists on only one line. I can't find this thread now.

What I want is that \parindent only applies to paragraphs with two or more lines, the same as issuing \noindent before those one-liner paragraphs but in an automatic way.

Best Answer

If you're willing to wrap your document in a \vbox, the following seems to work. (So, this is only good for one page.)

\vbox{\let\Par=\par
      \parindent=20pt
      \def\par{\Par
               \ifnum  \prevgraf=1 
                  \setbox0=\lastbox  
                  \nointerlineskip
                  \moveleft \parindent\copy0    \fi}%

    One line.

    Two lines blah    blah  
    blah  blah  blah  blah  blah  
    blah  blah  blah  blah  blah  
    blah  blah  blah  blah  blah  
    blah  blah  blah  blah  blah  
    blah  blah  blah  blah  blah  

         }

        \bye

"\prevgraf" is a primitive TeX integer variable that gives the number of lines in the last, or current, paragraph.

"\lastbox" is another primitive command that removes the last \vbox or \hbox on the current vertical or horizontal list and this box then becomes the \lastbox. It can't be used in vertical mode but can be used in internal vertical mode; hence the need to wrap things in a vbox.

I don't know if something similar, using \prevgraf, can be done in vertical mode.

The above was intended for Plain TeX, but it should work anywhere as it uses only primitive control sequences (I think).