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

Paul Isambert zappathustra at free.fr
Mon Sep 19 10:40:36 CEST 2011


Le 19/09/2011 10:14, Wilfried Kirschenmann a écrit :
> Hi,
> I would like to write a command \toRight{#1} allowing me to align a 
> piece of thext to be flushed the right at the end of a justified 
> paragraph, creating a nex line of necessary.

\def\toRight#1{{\unskip\nobreak\hfil\penalty50
     \hskip2em\hbox{}\nobreak\hfil #1
     \parfillskip=0pt \finalhyphendemerits=0 \par}}

Explained in the _TeXbook_, page 106:

     If a line break occurs at the \penalty50, the \hskip2em will 
disappear and the empty
     \hbox will occur at the beginning of a line, followed by \hfil 
glue. This yields two lines
     whose badness is zero; the first of these lines is assessed a 
penalty of 50. But if no line
     break occurs at the \penalty50, there will be glue of 2 em plus 2 
fil between the review
     and the name; this yields one line of badness zero. TeX will try 
both alternatives,
     to see which leads to the fewest total demerits. The one-line 
solution will usually be
     preferred if it is feasible.

(The `review' is your paragraph and the `name' is your argument to 
\toRight.)

Best,
Paul
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://tug.org/pipermail/texhax/attachments/20110919/6d4a5ae8/attachment.html>


More information about the texhax mailing list