8

Sometimes with \raggedright, if a line is too long, but only slighly so, it will be shrunk instead of broken up. Here is an example:

\documentclass{article}
\raggedright
\begin{document}
This is a line that is shrunk to fit the page width despite the use of raggedright. 
This is a line that is shrunk to fit the page width despite the use of \ldots
\end{document}

Is there a way to prevent this? In particular, I want all text in my document to be ragged right, and I want to make sure that everywhere in the document, text is never shrunk (neither stretched, but this is never an issue with ragged-right text).

Werner
  • 603,163

2 Answers2

7

You could fix the inter-word spacing using some ideas from Fixed-width interword space:

enter image description here

\documentclass{article}
\raggedright
\begin{document}
This is a line that is shrunk to fit the page width despite the use of raggedright.

This is a line that is shrunk to fit the page width despite the use of \ldots

\begingroup
\spaceskip=1\fontdimen2\font
\xspaceskip=0pt\relax % just to be sure
This is a line that is shrunk to fit the page width despite the use of raggedright.

This is a line that is shrunk to fit the page width despite the use of \ldots
\endgroup

\end{document}
Werner
  • 603,163
  • This doesn't exactly answer my question. The proposed solution fixes spaces to one size for every font type and size in the document. – RaggedRight Feb 07 '14 at 03:11
  • @RaggedRight: Sure. If you wish, one can add the specifics to \normalfont. However, I've grouped in the example, limiting the scope. If this answer doesn't solve your bigger problem, perhaps consider asking a follow-up question. – Werner Feb 07 '14 at 03:32
1

I think I have found a possible answer to my own question. Apparently, TeX uses \pretolerance and \tolerance to decide if line breaking is acceptable. Setting \pretolerance = 0 seems to produce the desired behaviour (setting \tolerance = 0 does not). I am not sure how this works, or whether it will still work for other, more complicated examples, but it seems like an optimal solution for this simple example.

  • There is some discussion about \pretolerance in the TeX Book (Chapter 14: How TeX Breaks Paragraphs into Lines, p 96; alternatively, search for \pretolerance in texbook.tex). – Werner Feb 07 '14 at 00:55
  • Setting \pretolerance to 0 imposes stricter limits on badness of lines; it doesn't really guarantee that shrinking of interword spaces is avoided. – egreg Feb 07 '14 at 01:03