[Tex/LaTex] A center environment for plain TeX

formattinghorizontal alignmentplain-tex

In TeX, one can center a single line of text with \centerline. How would one implement a center justification environment for a single long line of text in plain TeX without the addition of any packages. That is, the first line of TeX should justify to the center. Any wrapping text should also justify to the center.

Best Answer

\def\startcenter{%
  \par
  \begingroup
  \leftskip=0pt plus 1fil
  \rightskip=\leftskip
  \parindent=0pt
  \parfillskip=0pt
}
\def\stopcenter{%
  \par
  \endgroup
}
\long\def\centerpars#1{\startcenter#1\stopcenter}

You can now choose between

\startcenter
Some text to be centered
\stopcenter

and

\centerpars{Some text to be centered}

An empty line in the text will end the line.