# How and when does hyphenation in beamer slides work?

I don't understand how beamer handles hyphenation. Consider the following example:

\documentclass{beamer}
\begin{document}

\begin{frame}
\frametitle{Without hyphenation}
Latex is the stable dispersion (emulsion) of polymer microparticles in an aqueous medium. Latexes may be natural or synthetic. Latex as found in nature is a milky fluid found in 10\% of all flowering plants (angiosperms). It is a complex emulsion consisting of proteins, alkaloids, starches, sugars, oils, tannins, resins, and gums that coagulates on exposure to air. It is usually exuded after tissue injury. In most plants, latex is white, but some have yellow, orange, or scarlet latex. Since the 17th century, latex has been used as a term for the fluid substance in plants. It serves mainly as defense against herbivorous insects.
\end{frame}

\begin{frame}
\frametitle{With hyphenation}
\begin{overprint}
\onslide<1>
Latex is the stable dispersion (emulsion) of polymer microparticles in an aqueous medium. Latexes may be natural or synthetic. Latex as found in nature is a milky fluid found in 10\% of all flowering plants (angiosperms). It is a complex emulsion consisting of proteins, alkaloids, starches, sugars, oils, tannins, resins, and gums that coagulates on exposure to air. It is usually exuded after tissue injury. In most plants, latex is white, but some have yellow, orange, or scarlet latex. Since the 17th century, latex has been used as a term for the fluid substance in plants. It serves mainly as defense against herbivorous insects.
\end{overprint}
\end{frame}

\end{document}


On the first slide, text will not be hyphenated, whereas it will be on the second. How can I make hyphenation happen on slides without overprint blocks?

-

## migrated from stackoverflow.comNov 18 '12 at 13:08

This question came from our site for professional and enthusiast programmers.

Welcome to TeX.sx! Your post was migrated here from another stackexchange site. Please register on this site, too, and make sure that both accounts are associated with each other (by using the same OpenID), otherwise you won't be able to comment on or accept answers or edit your question. –  lockstep Nov 18 '12 at 13:49

The text on the first slide seems to use \raggedright (or beamers equivalent thereof) which inhibits hyphenation. The text on the second slide uses \onslide which internally uses a minipage which in turn will cause the text to be typeset justified which in turn allows hyphenation. ;-)

If you want ragged right text plus hypenation for both slides, add the following to your preamble:

\usepackage{ragged2e}
\RaggedRight

\makeatletter
\def\@minipagerestore{\RaggedRight}
\makeatother


If, on the other hand, you want justified text for both slides, the following preamble code does the trick:

\usepackage{ragged2e}
\justifying

-

This doesn't look like intended behaviour from the beamer class, but it is caused by different values of \rightskip. Placing \showthe\rightskip on the first slide or before the \onslide command in the second file shows (in the log file) that the value is

> 0.0pt plus 1.0fil.


which discourages hyphenation in favour of a ragged right text. On the other hand on the second slide after \onslide<1> the value of \rightskip is

> 0.0pt.


so the text is now set justified to the (left and) right margins, and hyphenation gets used.

To get justified text in the first frame with hyphenation, you need to set \rightskip before the frame starts. You can put \setlength{\rightskip}{0pt} in your preamble to affect all frames. If you just want the first frame to be like this then you can enclosed the setting in a group containing the frame, as in the following example, where we see hyphenation in effect for the first frame, ragged right at the beginning of the second frame and then hyphenation after the \onframe. The third slide shows the opposite effect, by addding the fill back into the \rightskip to regain ragged right after the \onslide.

\documentclass{beamer}
\begin{document}

\bgroup
\setlength{\rightskip}{0pt}

\begin{frame}
\frametitle{With hyphenation}

Latex is the stable dispersion (emulsion) of polymer microparticles
in an aqueous medium. Latexes may be natural or synthetic. Latex as
found in nature is a milky fluid found in 10\% of all flowering
plants (angiosperms). It is a complex emulsion consisting of
proteins, alkaloids, starches, sugars, oils, tannins, resins, and
gums that coagulates on exposure to air. It is usually exuded after
tissue injury. In most plants, latex is white, but some have yellow,
orange, or scarlet latex. Since the 17th century, latex has been
used as a term for the fluid substance in plants. It serves mainly
as defense against herbivorous insects.
\end{frame}
\egroup

\begin{frame}
\frametitle{With and without hyphenation}
\begin{overprint}
Latex is the stable dispersion (emulsion) of polymer
microparticles in an aqueous medium. Latexes may be natural or
synthetic. Latex as found in nature is a milky fluid found in 10\%
of all flowering plants (angiosperms). It is a complex emulsion
consisting of proteins, alkaloids, starches, sugars, oils, tannins,
resins, and gums that coagulates on exposure to air. It is usually
exuded after tissue injury.
\onslide<1> Latex is the stable dispersion (emulsion) of polymer
microparticles in an aqueous medium. Latexes may be natural or
synthetic. Latex as found in nature is a milky fluid found in 10\%
of all flowering plants (angiosperms). It is a complex emulsion
consisting of proteins, alkaloids, starches, sugars, oils, tannins,
resins, and gums that coagulates on exposure to air. It is usually
exuded after tissue injury. In most plants, latex is white, but some
have yellow, orange, or scarlet latex. Since the 17th century, latex
has been used as a term for the fluid substance in plants. It serves
mainly as defense against herbivorous insects.
\end{overprint}
\end{frame}

\begin{frame}
\frametitle{Without hyphenation}
\begin{overprint}
Latex is the stable dispersion (emulsion) of polymer
microparticles in an aqueous medium. Latexes may be natural or
synthetic. Latex as found in nature is a milky fluid found in 10\%
of all flowering plants (angiosperms). It is a complex emulsion
consisting of proteins, alkaloids, starches, sugars, oils, tannins,
resins, and gums that coagulates on exposure to air. It is usually
exuded after tissue injury.
\onslide<1> \setlength{\rightskip}{0pt plus 1fil}Latex is the stable
dispersion (emulsion) of polymer
microparticles in an aqueous medium. Latexes may be natural or
synthetic. Latex as found in nature is a milky fluid found in 10\%
of all flowering plants (angiosperms). It is a complex emulsion
consisting of proteins, alkaloids, starches, sugars, oils, tannins,
resins, and gums that coagulates on exposure to air. It is usually
exuded after tissue injury. In most plants, latex is white, but some
have yellow, orange, or scarlet latex. Since the 17th century, latex
has been used as a term for the fluid substance in plants. It serves
mainly as defense against herbivorous insects.
\end{overprint}
\end{frame}

\end{document}


-
+1 for the explanation, but I believe that the lack of hyphenation is the intended behavior. –  egreg Nov 18 '12 at 13:49
@egreg Thanks. What I meant as unintened behaviour is the change of margin caused by the \onslide command. –  Andrew Swann Nov 18 '12 at 14:07