# ragged2e breaks soul package \textbf{} spacing

If you compile the XeLaTeX below you will see the output is not-as-expected for the bold part of the text i.e. it is:

underline underline boldboldbold

In other words the spacing of the bold elements inside soul's \ul is seemingly non-existent. One would expect:

underline underline bold bold bold

I have narrowed down the issue to the ragged2d package when using the Minion Pro font (although it is reproducible with other fonts). The problem also occurs with macros such as \textit.

The following demonstrates the issue.

\documentclass{article}
\usepackage{soul}
\usepackage{ragged2e}

\begin{document}
\ul{underline underline \textbf{bold bold bold}}
\end{document}


Having identified the problem, I noted one workaround is using {\bfseries{}bold bold bold} but that sometimes leads to "Reconstruction failed" error, and in any case I am curious as to what is going on here.

Another workaround, seemingly more robust than bfseries, is to end then re-start the underlining so that the textbf encapsulates the ul i.e. \ul{underline underline }\textbf{\ul{bold bold bold}}. Whenever the font changes, then, we may end then re-start the underlining.

-
I can cut the example down (preamble) \documentclass{article} \usepackage{soul} \usepackage{ragged2e} \begin{document} –  Joseph Wright Jul 17 '14 at 19:04
soul is a (horrible) hack. –  Martin Schröder Jul 17 '14 at 20:22
@MartinSchröder And nobody should use underlining. ;-) –  egreg Jul 17 '14 at 20:47
soul tricks ragged2e into believing the bold font is a monospaced font. The problem shows with any font changing command in \ul - even with \textrm. Please file a bug with the author of the soul package. :-p –  Martin Schröder Jul 17 '14 at 20:48
@BrianM.Hunt: Seriously: ConTeXt. :-) –  Martin Schröder Jul 18 '14 at 9:14

The problem is an incompatibility of packages soul and ragged2e about the handling of \spaceskip.

Package soul saves the interword space settings of the font in the skip register \SOUL@spaceskip in \SOUL@start. In the preamble of the ul driver, \spaceskip is set to \SOUL@spaceskip. Later \spaceskip is used in \SOUL@uleveryspace for setting the space: \hskip\spaceskip.

Package ragged2e loads package everysel to add its interword space modifications to suppress the stretch component. However, it resets \spaceskip to zero, if ragging is not in force.

Now, a font switch to the bold font occurs inside the underlined text. If package ragged2e is loaded, then \spaceskip is set to zero. The everyspace handler of soul's underline driver then sets \hskip\spaceskip as interword space, that means no space, because \spaceskip is zero.

The following example tries to fix the issue for soul drivers ul and so:

\documentclass[oneside,12pt]{memoir}
% for bold typewriter font
\usepackage[T1]{fontenc}
\usepackage{lmodern}

\usepackage{soul}
\usepackage{ragged2e}

\usepackage{etoolbox}
\makeatletter
\newif\if@inside@soul
\newif\if@inside@soul@ul
\@inside@soul@ultrue
}
\patchcmd\SOUL@start{\SOUL@preamble}{\@inside@soultrue\SOUL@preamble}
{}{\errmessage{Cannot patch \protect\SOUL@start}}
\renewcommand{\@raggedtwoe@everyselectfont}{%
\if@raggedtwoe@spaceskip
\ifdim\fontdimen\thr@@\font=\z@\relax
\if@inside@soul
\if@inside@soul@ul
\spaceskip\fontdimen\tw@\font
\@minus\fontdimen4\font
\fi
\else
\spaceskip\z@
\fi
\else
\spaceskip\fontdimen\tw@\font
\fi
\else
\if@inside@soul
\if@inside@soul@ul
\spaceskip\fontdimen\tw@\font
\@plus\fontdimen\thr@@\font
\@minus\fontdimen4\font
\fi
\else
\spaceskip\z@
\fi
\fi
}
\makeatother

\begin{document}
\noindent
\ul{underline underline \textbf{bold bold bold}}\\
\so{letter spacing \textbf{bold bold bold}}

\RaggedRight\ttfamily
\ul{underline underline \textbf{bold bold bold}}\\
\so{letter spacing \textbf{bold bold bold}}

\end{document}


-