# [texhax] have a piece of thest ragged right à the end of a paragraph

Steve Schwartz s.schwartz at imperial.ac.uk
Mon Sep 19 14:15:41 CEST 2011

On Mon, 2011-09-19 at 12:07 +0100, Philip TAYLOR (Webmaster, Ret'd)
wrote:
> > \def\toRight#1{{\unskip\nobreak\hfil\penalty50
> >     \hskip2em\hbox{}\nobreak\hfil #1
> >     \parfillskip=0pt \finalhyphendemerits=0 \par}}
> >
> > Explained in the _TeXbook_, page 106:
>
> I am unconvinced that the solution is optimal, although
> it is undoubtedly robust.  I tried it with a number of
> paragraphs of ever-increasing length to see how it
> coped with all possible situations, and found the
> following anomaly :

Hmmm. I tried this with Phil's \pushright macro that I got on this list
some time ago, and it does the same thing more or less, with the same
"anomaly" [actually, there is a small difference that has to do with
where when executing the macro the linebreak is introduced if needed,
i.e., before or after the \hskip2em, but that doesn't really matter.

I think the only anomaly here might be that 2em's are wider than you
might think. An em is the width of an "M". I append a modification (in
latex to use framebox) to illustrate this. I think Phil's improvement is
really just the result of replacing something of width 2em by an
interword space which (a) is stretchable (I think) and (b) a lot
smaller.

Steve

\documentclass{article}
\usepackage[margin=1in]{geometry}

\begin{document}

% RightJustifiedLastLine

\parindent = 0 pt
\parskip = \baselineskip

\def \HardRight #1%
{%
{\unskip \nobreak \hfil \penalty 50 \framebox[2em]{}\hbox
{}\nobreak \hfil #1%
\parfillskip = 0 pt \finalhyphendemerits = 0 \par
}%
}

Now is the time for all good men to end their paragraphs with a
right-justified last line,
Now is the time for all good men to end their paragraphs with a
right-justified last line,
Now is the time for all good men to end their paragraphs with a
right-justified last line,
Now is the time for all good men to end their paragraphs with a
right-justified last line,
Now is the time for all good men to end their paragraphs with a
right-justified last line,
Now is the time for all good men to end their paragraphs with a
right-justified last line,
Now is the time for all good men to end their paragraphs with a
right-justified last line,
Now is the time for all good men to end their paragraphs with a
right-justified last lineeeeee
\HardRight {and this is the text with which we wish to end it.}

Now is the time for all good men to end their paragraphs with a
right-justified last line,
Now is the time for all good men to end their paragraphs with a
right-justified last line,
Now is the time for all good men to end their paragraphs with a
right-justified last line,
Now is the time for all good men to end their paragraphs with a
right-justified last line,
Now is the time for all good men to end their paragraphs with a
right-justified last line,
Now is the time for all good men to end their paragraphs with a
right-justified last line,
Now is the time for all good men to end their paragraphs with a
right-justified last line,
Now is the time for all good men to end their paragraphs with a
right-justified last lineeeeeee
\HardRight {and this is the text with which we wish to end it.}

\framebox[2em]{.}\par
\framebox[2em]{mm}\par
\framebox[2em]{MM}\par
\framebox[2em]{mmm}\par

\end{document}

--
+-------------------------------------------------------------------+
Professor Steven J Schwartz        Phone: +44-(0)20-7594-7660
Head, Space & Atmospheric Physics  Fax:   +44-(0)20-7594-7772
The Blackett Laboratory            E-mail: s.schwartz at imperial.ac.uk
Imperial College London            Office: Huxley 6M67A
London SW7 2AZ, U.K.               Web: www.sp.ph.ic.ac.uk/~sjs
+-------------------------------------------------------------------+