Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
    
I can cut the example down (preamble) \documentclass{article} \usepackage{soul} \usepackage{ragged2e} \begin{document} –  Joseph Wright Jul 17 at 19:04
1  
soul is a (horrible) hack. –  Martin Schröder Jul 17 at 20:22
1  
@MartinSchröder And nobody should use underlining. ;-) –  egreg Jul 17 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 at 20:48
1  
@BrianM.Hunt: Seriously: ConTeXt. :-) –  Martin Schröder Jul 18 at 9:14

1 Answer 1

up vote 5 down vote accepted

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
\g@addto@macro\SOUL@ulpreamble{%
  \@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}

Result

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.