1

I define an underline (based on the following site: https://alexwlchan.net/2017/10/latex-underlines/).

This was my initial code:

\usepackage{ulem}
\renewcommand{\ULdepth}{1.8pt}
\contourlength{0.8pt}
\newcommand{\myuline}[1]{%
  \uline{\phantom{#1}}%
  \llap{\contour{white}{#1}}%
}

The problem with the code is that it doesn't allow linebreaks nor hyphenations if I underline a lot of text. I made some research and found that \phantom and \contour could be the problem, so I replace \phantom with \textcolor in white, and add the following (to allow contour break lines):

\usepackage{ulem}
\renewcommand{\ULdepth}{1.8pt}
\contourlength{0.8pt}

% contour each word to allow linebreaks \RequirePackage{xparse} \ExplSyntaxOn \NewDocumentCommand{\MIR}{m} { \seq_set_split:Nnn \l_tmpa_seq { ~ } { #1 } \seq_map_inline:Nn \l_tmpa_seq { \contour{white}{##1} ~ } \unskip } \ExplSyntaxOff

% define underline \newcommand{\myuline}[1]{% \uline{\textcolor{white}{#1}}% \llap{\contour{white}{#1}}% }

but this didn't solve my problem, and now I realized that \llap doesn't allow linebreaks nor hyphenation too ... then, I don't know how can I solve the problem. Please help.

hllspwn
  • 47
  • 4

1 Answers1

1

Modifying what you have, you can use the following

\usepackage{contour}
\usepackage[normalem]{ulem}
\renewcommand{\ULdepth}{1.8pt}
\contourlength{0.8pt}

\newcommand{\myuline}[1]{% \uline{\phantom{#1}}% \llap{\contour{white}{#1}}% }

% myuline on each word to allow linebreaks \RequirePackage{xparse} \ExplSyntaxOn \NewDocumentCommand{\myulineX}{m} { \seq_set_split:Nnn \l_tmpa_seq { ~ } { #1 } \seq_map_inline:Nn \l_tmpa_seq { \myuline{##1} ~ } \unskip } \ExplSyntaxOff

Then you can get alexwlchan's nice underlines that you want, and also get them to work across line-breaks. Use it like:

\myulineX{Now the \texttt{myulineX} text will have nice underlines that avoid
  descenders, and also don't cause issues with line-breaking.}

to get:

example

However, the underlines don't continue through spaces between words. If that's an issue, I don't know how to solve that (also see comment here to the same effect, I think).

postylem
  • 276