# Does combining microtype with ragged right make any sense?

My impression when using microtype in a document that used \RaggedRight (everything said is probably true for \raggedright as well but who cares really ...) always was that all lines just get stretched, often to the point where the whole text looked distorted and ugly. Never did I see the enhancement in typographic quality and likely reduction in the number of lines that usually go along with justified text and microtype.

I tried to test this impression a little bit more systematically:

\documentclass{article}
\usepackage{microtype,ragged2e,lipsum}
\begin{document}
\RaggedRight
\lipsum[1-4]
\newpage
\microtypesetup{activate=false}
\lipsum[1-4]
\end{document}


The result is best inspected in a PDF viewer set to fit to page but to give an immediate impression, here are the two pages overlayed in different colors. Text with microtype is red, without is blue. As can be seen, except for the first line and each last line in a paragraph (and the fourth line which has a different line break altogether), microtype always stretches the lines (click to enlarge):

Is this generally true? If so, why? Maybe microtype didn't get the memo and still tries to justify the text, stretching it as far as it can? I thought microtype used the interword spacing though. That would mean, however, that even with ragged2e the typography of ragged text was seriously wanting.

In any case, if this really is the behavior of microtype in ragged paragraphs, why then doesn't microtype switch itself off in \RaggedRight, \RaggedLeft and \Centering paragraphs instead of leaving this to the (probably mostly unsuspecting) user?

Edit: Oh and sorry for the eye cancer. With red-blue 3D glasses you can seriously cut down on your LSD expenses though. You're welcome.

Edit 2: Hidden behind a preview image; this should alleviate the permanent pain in the eyes.

Interesting observation, really. The result you are seeing is indeed that microtype is stretching (most) lines and it isn't really surprising, but I don't think it could be called a fault of microtype that it isn't recognizing that it is in a ragged right context, because ragged2e is really working hard on hiding the fact.

Standard LaTeX is using a brute foce method with \raggedright by setting \rightskip to 0pt plus 1fil. This makes spaces at the right edge stretch arbitrarily without producing a line that shows a \badness that differs from zero. So TeX could in in fact put a single word on a line and it would still be considered fine by the paragraph breaking algorithm. The fact that paragraphs do not go overboard with such strange line breakings is only due to the fact that the algorithm will prefer shorter paragraphs on the whole, so it will tend to fill the lines (i.e, use lines with more text) if they have the same badness and the overall demerits of the paragraph are not increased by the different line breaking.

But this means that the paragraph can still by quite "ragged", e.g. there will be no hyphenation happening as hyphens normaly increase the badness.

In other words, without actually having it tested, my guess is that microtype will not show this behavior if you use \raggedright from LaTeX.

The ragged2e package, on the other hand is trying to produce less variation and allows for hyphenation to achieve this. The trick used in the package is to make the \rightskip not infinitly stretchable, but use something like 0pt plus 2em. Now this can still stretch abritrarily, but now it comes at a cost: if it goes beyond 2em the badness will start to increase. That in turn might trigger some hyphenation and generally will result in the paragraph algorithm attempting to keep the lines near to the 2em boundary.

As a result most of the lines produced look to microtype as if they have some badness that could be improved upon and as the interword spacings are fixed, what happens is that it applies font stretching to reduce it. And this is what you are seeing.

Now it is true that microtype could try to be more clever and identify that this is an attempt to do ragged right typesetting here, but getting this fool proof wouldn't be that easy. Perhaps looking at the stretchability of space might be an option, but then you can easily make up a ragged style that also allows for some tiny variation in the spaces so ...

Bottom line, you better turn microtype off during ragged right typesetting, at least the font stretching capability, other capabilities might still be worth having.

• Thanks, that was really insightful. I learned a lot. activate=false will switch off the protrusion and expansion features of microtype (which are the only ones enabled by default). Expansion is what's causing all the ugliness and while it's true that protrusion might still be useful, I seriously doubt that the difference is noticeable in ragged mode. But still, switching off only protrusion is probably the more sensible thing to do. Oh and you're right, for \raggedright, microtype doesn't seem to make any difference at all (except for different line breaks due to protrusion). – Christian Sep 20 '13 at 23:46
• @Christian protusion works both on both margins (depending on the value settings) because it is not just acting on things like hyphens, comma, and period but also on other characters. So it does have its value in ragged settings. Of course, on the right side it will not be visible. – Frank Mittelbach Sep 21 '13 at 6:19

Frank has already explained that microtype will stretch all lines (except for the occasional overfull one), because it considers them as loose. It does so because \rightskip only contains a stretch, but no shrink component. So, thinking this further does indeed lead to a scenario where using microtype with ragged text could make sense, namely by adding a shrink component to \rightskip, eg.:

\setlength\RaggedRightRightskip{1pt plus 2em minus 1pt} % default is: 0pt plus 2em


where the first and last component (1) must be equal, and (2) shouldn't be too big, as otherwise the right margin would tend to move to the left. This shrink component will allow microtype -- or rather pdftex's hz-algorithm -- to not only stretch, but also shrink the lines, resulting in a less ragged margin. While for longer lines this may even reach the point where ragged text would become indiscernible from justified text, for shorter lines it could give pdftex the necessary freedom to create pleasingly ragged (ie. not too much and not too little) text with less hyphenations.

• What the hz program does is a (fairly invisible) distortion of characters to achieve better alignment, but it is still a distortion and so my claim is that one should avoid it where possible. And all you achieve with the suggestion is that there is less raggedness in the paragraph. However, if the raggedness becomes minimal then the result is that the paragraph looks not ragged but badly justified so it might turn out to be even counterproductive. The other problem with the approach is that you would need to reduce the linewidth otherwise you have several lines sticking into the margin. – Frank Mittelbach Sep 21 '13 at 6:24
• See updated, qualified answer. Not sure about your last sentence, though: isn't this prevented by setting first and last component to the same width? – Robert Sep 21 '13 at 23:48
• @FrankMittelbach I think there's a misunderstanding here: the shrink component should be equal to the first component, not to the stretch. – Robert Sep 23 '13 at 3:09
• Robert, you are right, I overlooked that you actually talked about the main space not the plus part. I removed my comment. – Frank Mittelbach Sep 23 '13 at 5:59