Text FormattingUnderlining with hyphens and ligatures

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
johnjamessmith0
Posts: 37
Joined: Sun Mar 29, 2009 1:41 am

Underlining with hyphens and ligatures

Post by johnjamessmith0 »

I am looking for a way to underline text without otherwise affecting wrapping at the end of lines, hyphenation, and ligatures. Text in \underline{} does not seem to wrap properly. Text in \ul{} from the soul package, unfortunately, is always underlined below the descender height even when there are no letters with descenders and seems to admit ligatures based on context (?). A minimal example comparing non-underlined, \ul{}, and \underline{} text:

Code: Select all

\documentclass{article}

\usepackage{soul}

\begin{document}

\section{Normal text}

ff ffi fi fl

Difficulty Difficulty Difficulty Difficulty Difficulty Difficulty Difficulty Difficulty Difficulty Difficulty

\emph{Working fine.}

\section{Underlined text}

\underline{ff ffi fi fl}

\emph{Working fine.}

\underline{Difficulty Difficulty Difficulty Difficulty Difficulty Difficulty Difficulty Difficulty Difficulty Difficulty}

\emph{Not wrapping.}

\section{Underlined text with special package}

\ul{ff ffi fi fl} 

\emph{Slightly ugly underline, but `ffi' ligature working fine.}

\ul{Difficulty Difficulty Difficulty Difficulty Difficulty Difficulty Difficulty Difficulty Difficulty Difficulty} 

\emph{Wrapping fine, `ffi' ligature not working (huh?).}

\end{document}
Help! Thanks in advance.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
johnjamessmith0
Posts: 37
Joined: Sun Mar 29, 2009 1:41 am

Underlining with hyphens and ligatures

Post by johnjamessmith0 »

I just found out about the ulem package, which has its flaws, too:

Code: Select all

\documentclass{article}

\usepackage{soul}
\usepackage{ulem}
\normalem

\begin{document}

\section{Normal text}

ff ffi fi fl

Difficulty Difficulty Difficulty Difficulty Difficulty Difficulty Difficulty Difficulty Difficulty Difficulty

\emph{Working fine.}

\section{Underlined text}

\underline{ff ffi fi fl}

\emph{Working fine.}

\underline{Difficulty Difficulty Difficulty Difficulty Difficulty Difficulty Difficulty Difficulty Difficulty Difficulty}

\emph{Not wrapping. The above is a bad box.}

\section{Underlined text with `soul' package}

\ul{ff ffi fi fl} 

\emph{Slightly ugly underline, but `ffi' ligature working fine.}

\ul{Difficulty Difficulty Difficulty Difficulty Difficulty Difficulty Difficulty Difficulty Difficulty Difficulty} 

\emph{Wrapping fine, `ffi' ligature not working (huh?).}

\section{Underlined text with `ulem' package}

\uline{ff ffi fi fl} 

\emph{Slightly ugly underline.}

\uline{Difficulty Difficulty Difficulty Difficulty Difficulty Difficulty Difficulty Difficulty Difficulty Difficulty} 

\emph{Ligatures fine. Non-hyphenatable, apparently. The above is a bad box.}

\end{document}
Post Reply