# Avoid indenting one-liner paragraphs

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.

• Hi! Why would you want that? I can't see a reason for this behavior, and I think that if I understood what it's meant for maybe I could suggest something else to do instead. – pst Jun 4 '15 at 6:39
• Sometimes if "paragraphs" are short (one line) they look ugly with indentation and I add \noindent to remove its indentation leaving all paragraphs with normal indentation. I saw a question about that with more than one answer. Now I want to implement it and can't find the thread... – Emilio Lazo Jun 4 '15 at 6:45
• A style that indents paragraphs is often used in conjunction with no extra vertical space before a paragraph. In that case, no indentation would make a one-line paragraph no longer be recognisable. Just a caveat. – Christian Lindig Jun 4 '15 at 7:02
• @ChristianLindig yes, sure, thanks; however I'm removing the indentation with caution... Sometimes I start an itemize or enumerate environment with just before a paragraph describing what these items are; this paragraph is usually one line. Also I'm writing a DTX file and almost on every \DescribeMacro I put \noindentbefore. – Emilio Lazo Jun 4 '15 at 7:13
• You say "with caution", but that doesn't apply to the automatic solution you are asking for, right? Will your one-liner be recognizable as a paragraph if the previous paragraph happens to end with a full line? If the short text before your itemize is like a header for it, maybe you could make it into \paragraph{...} instead? (Regardless of whether it fits on a line or is slightly longer.) – pst Jun 4 '15 at 7:32

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).

• Thank you. It worked also in LaTeX. Can't be extended to be breakable in pages? Defining an environment in which the whole document can be wrapped, perhaps? – Emilio Lazo Jun 8 '15 at 18:46
• @EmilioLazo This should work: \setbox1=\vbox{ stuff in vbox above } \unvbox1 (This is a bit silly IMO :) ) You might want to use an unused box register though: \newbox\Mybox \setbox\Mybox = ... – David Mitra Jun 8 '15 at 18:55