Discussion:
\centerline{ } *with line breaks* in Plain TeX?
(too old to reply)
AES
2009-06-23 13:52:45 UTC
Permalink
I used to have a home-brewed Plain TeX macro pair \centerlines (note the
plural) and \clinebreak such that I could write

\centerlines{Some text \clinebreak more text \clinebreak
still more text \clinebreak . . . }

and the result would be "Some text" centered on one line; "more text"
centered on the next line; "still more text" centered below that; and so
on -- but I've lost it.

Is there an easy way to code a paragraph so that inserted \break's will
cause each resulting line to be centered (using Plain TeX)?

Thanks . . .
Enrico Gregorio
2009-06-23 19:29:20 UTC
Permalink
Post by AES
I used to have a home-brewed Plain TeX macro pair \centerlines (note the
plural) and \clinebreak such that I could write
\centerlines{Some text \clinebreak more text \clinebreak
still more text \clinebreak . . . }
and the result would be "Some text" centered on one line; "more text"
centered on the next line; "still more text" centered below that; and so
on -- but I've lost it.
Is there an easy way to code a paragraph so that inserted \break's will
cause each resulting line to be centered (using Plain TeX)?
Something like this?

\newbox\centerlinesbox
\def\centerlines{\afterassignment\startcenterlines
\setbox\centerlinesbox=\vbox}
\def\startcenterlines{\aftergroup\endcenterlines
\leftskip=0pt plus 1fil \rightskip=\leftskip
\parfillskip=0pt \parindent=0pt \strut\ignorespaces}
\def\endcenterlines{\par\box\centerlinesbox}
\def\clinebreak{\par}

Ciao
Enrico
Dan Luecking
2009-06-23 20:14:23 UTC
Permalink
Post by AES
I used to have a home-brewed Plain TeX macro pair \centerlines (note the
plural) and \clinebreak such that I could write
\centerlines{Some text \clinebreak more text \clinebreak
still more text \clinebreak . . . }
You can produce
1. a paragraph with lines centered,
2. a stack of boxes like
\centerline{Some text}
\centerline{still more text}
...
or
3. a \vbox with a paragraph inside with centered lines.

Which do you want?

For the first:
\def\clinebreak{\unskip\null\hfil\penalty-\@M\ignorespaces}}
\def\centerlines#1{%
\begingroup
\leftskip 0pt plus 0.5fil
\rightskip 0pt plus -0.5fil
\parfillskip 0pt plus 1fil\relax
#1\par
\endgroup}

For the second:
\def\clinebreak{\hss\egroup\hbox to \hsize\bgroup\hss}
\def\centerlines#1{\hbox to \hsize\bgroup\hss#1\hss\egroup}

For the third wrap a \vbox around the first (or the second).

Another possibility is to center an \halign with centered entries:
\let\clinebreak\crcr
\def\centerlines#1{%
\centerline{%
\vbox{
\halign{\hfil##\hfil\cr#1\crcr}
}%
}
}


Caveat: not tested.


Dan
To reply by email, change LookInSig to luecking

Loading...