Problema com \hfill e hifenização

Problema com \hfill e hifenização

Quando uso \hfille na linha anterior a última palavra é hifenizada, \hfillnão funciona da mesma forma de costume:

\documentclass[a4paper, 12pt]{book}
\begin{document}

Spellings attempt to transcribe the sounds of the language into 
alphabetic letters, but phonetic spellings are exceptions   \hfill go to library

AA Spellings attempt to transcribe the sounds of the language into 
alphabetic letters, but phonetic spellings  \hfill go to library

\end{document}

O que devo escrever para conseguir \hfillum trabalho como o primeiro \hfilldo exemplo?

Responder1

A primeira solução é uma modificação da minha solução paraColoque o texto alinhado à direita na próxima linha se não houver espaço

Mostro também a solução de David, para ver onde ela pode falhar.

\documentclass[a4paper, 12pt,draft]{book} % draft for showing the overfull boxes

\newcommand*{\gotoend}[1]{%
  \unskip
  {\nobreak\hfill\penalty50\ \null\nobreak
   \hfill\mbox{#1}%
   \parfillskip=0pt \finalhyphendemerits=0 \par}
}

%% David's version
\newcommand*{\Dgotoend}[1]{\unskip\hspace*{\fill}\mbox{ #1}}


\begin{document}

Spellings attempt to transcribe the sounds of the language into 
alphabetic letters, but phonetic spellings are exceptions \gotoend{go to library}

AA Spellings attempt to transcribe the sounds of the language into 
alphabetic letters, but phonetic spellings \gotoend{go to library}

AA Spellings attempt to transcribe the sounds of the language into 
alphabetic letters, but AA phonetic spellings are just bigger 
exceptions \gotoend{go to library}

David's version:

Spellings attempt to transcribe the sounds of the language into 
alphabetic letters, but phonetic spellings are exceptions \Dgotoend{go to library}

AA Spellings attempt to transcribe the sounds of the language into 
alphabetic letters, but phonetic spellings \Dgotoend{go to library}

AA Spellings attempt to transcribe the sounds of the language into 
alphabetic letters, but AA phonetic spellings are just bigger exceptions \Dgotoend{go to library}

\end{document}

insira a descrição da imagem aqui

Responder2

O comportamento não está realmente relacionado à hifenização, mas acho que você só quer evitar que a frase final ultrapasse uma linha, então:

insira a descrição da imagem aqui

\documentclass[a4paper, 12pt]{book}
\begin{document}

Spellings attempt to transcribe the sounds of the language into 
alphabetic letters, but phonetic spellings are exceptions\hspace*{\fill}\mbox{ go to library}

AA Spellings attempt to transcribe the sounds of the language into 
alphabetic letters, but phonetic spellings\hspace*{\fill}\mbox{ go to library}

\end{document}

Você poderia fazer uma macro com isso (e abordar o ponto de egreg)

\documentclass[a4paper, 12pt,draft]{book} % draft for showing the overfull boxes


%% David's version
\newcommand*{\Dgotoend}[1]{\unskip\hfill\penalty9999\hspace*{\fill}\mbox{ #1}}


\begin{document}


David's version:

Spellings attempt to transcribe the sounds of the language into 
alphabetic letters, but phonetic spellings are exceptions \Dgotoend{go to library}

AA Spellings attempt to transcribe the sounds of the language into 
alphabetic letters, but phonetic spellings \Dgotoend{go to library}

AA Spellings attempt to transcribe the sounds of the language into 
alphabetic letters, but AA phonetic spellings are just bigger exceptions \Dgotoend{go to library}

\end{document}

insira a descrição da imagem aqui

informação relacionada