I want to align the last word of a paragraph to the right like this example from The TeXbook.
This works great with a justified paragraph, but fails with a \raggedright paragraph.
In case it's relevant, my specific example in the MWE example below includes a slightly more complicated paragraph setup for typesetting psalms based on code from this answer.
There are two issues with my current set up.
- The second to last word in the paragraph wraps on to the last line even when there is space for it on the previous line.
- The last word of the paragraph (Selah) is not set flush right.
I also want to avoid hyphenation.
\documentclass{article}
\usepackage{xparse}
\usepackage[showframe,textwidth=5.6cm,textheight=10cm]{geometry}
\parindent 0em
\ExplSyntaxOn
\dim_new:N \l__scripture_indent_dim
\dim_set:Nn \l__scripture_indent_dim { 1em }
\cs_new:Nn \scripture_vs:n
{
\textsuperscript {#1}
}
\cs_new:Nn \scripture_vs_overlap_left:n
{
\hbox_overlap_left:n
{
\scripture_vs:n {#1}
}
}
\cs_new:Nn \scripture_format_selah:n
{
\emph {#1}
}
\cs_new:Nn \scripture_selah:
{
{
\unskip
\nobreak
\hfil
\penalty 50
\skip_horizontal:N 2em
\hbox:n {}
\nobreak
\hfil
\scripture_format_selah:n { Selah }
\parfillskip = 0pt
\finalhyphendemerits = 0
\endgraf
\skip_vertical:n { -\baselineskip }
\leavevmode
}
}
\cs_new:Nn \scripture_vs_outdent_overlap_left:n
{
\skip_horizontal:N -\l__scripture_indent_dim
\scripture_vs_overlap_left:n {#1}
\skip_horizontal:N \l__scripture_indent_dim
}
\cs_new_protected:Nn \scripture_psalm_par:
{
\mode_if_vertical:TF
{
\cs_set_eq:NN \vs \scripture_vs_overlap_left:n
\noindent
}
{
\cs_set_eq:NN \vs \scripture_vs_outdent_overlap_left:n
\endgraf
}
\dim_set:Nn \hangindent { 4 \l__scripture_indent_dim }
}
\NewDocumentCommand \selah { }
{
\scripture_selah:
}
\NewDocumentEnvironment {psalm} { }
{
\raggedright
\cs_set_eq:NN \vs \scripture_vs_overlap_left:n
\cs_set_eq:NN \par \scripture_psalm_par:
\dim_set_eq:NN \leftskip \l__scripture_indent_dim
\dim_set_eq:NN \parindent \l__scripture_indent_dim
\obeylines
}
{ }
\ExplSyntaxOff
\begin{document}
\section*{What I get}
\begin{psalm}
\vs{1}\textsc{Lord}, how many are my foes!
How many rise up against me!
\vs{2}Many are saying of me,
‘God will not deliver him.’\selah\medskip
\vs{3}But you, \textsc{Lord}, are a shield around me,
my glory, the One who lifts my head high.
\vs{4}I call out to the Lord,
and he answers me from his holy mountain.\selah
\end{psalm}
\section*{What I'd like}
\hspace*{2em}`God will not deliver him.'\selah
\medskip
\hspace*{2em}and he answers me from his \\
\hspace*{5em}holy mountain.\selah
\end{document}


\hspace*is essentially doing the same as the\hbox:n{}\nobreak, so you're still using it. – David Purton Dec 18 '18 at 06:33\penalty -5which coaxes a line break (but not strongly). For example, it still produces the image above, but for #2, if you deletehimthenSelahjumps up to the same line as the text. – whatisit Dec 19 '18 at 02:44