1

When I use \hfill and in the previous line the last word is hyphenated, the \hfill doesn't work the same way as usual:

\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}

What should I write to get \hfill work like the first \hfill in the example?

egreg
  • 1,121,712
  • 2
    Welcome to TeX.SX! Your problem has nothing to do with hyphenation. Is http://tex.stackexchange.com/questions/91548/bump-right-aligned-text-to-next-line-iff-no-room helping? – egreg Dec 29 '13 at 17:34
  • alternatively to @egreg's link, you can try to reduce the occurrences of hyphenation by using the microtype package. In your mwe it works. – ArTourter Dec 29 '13 at 17:42
  • Thank you both for your answers. I write mostly in greek, so I use the babel package and the microtype package does't reduce the occurrences of hyphenation, I don't know why. The link you gave me is not helping with hypernation. I found today this http://tex.stackexchange.com/questions/9325/bump-right-aligned-text-to-next-line-if-no-room and @Jørgen Tesman describes the same problem with hypernation in his answer. – Bozelou M. Dec 30 '13 at 18:47

2 Answers2

2

The behaviour isn't really related to hypphenation, but I think you just want to avoid the final phrase breaking over a line so:

enter image description here

\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}

You could make a macro out of this (and address egreg's point) by

\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}

enter image description here

David Carlisle
  • 757,742
2

The first solution is a modification of my solution to Bump right-aligned text to next line iff no room

I show also David's solution, in order to see where it can fail.

\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}

enter image description here

egreg
  • 1,121,712