1

Consider the code:

\documentclass{book}
\usepackage{soul}

\begin{document} \thispagestyle{empty} \large

How may I do this without the \textit{soul} package?\[7pt]

\ul{Text underlining with linebreaking; Text underlining with linebreaking; Text underlining with linebreaking; Text underlining with linebreaking; Text underlining with linebreaking; Text underlining with linebreaking;} \end{document}

which produces

enter image description here

QUESTION: How may I do this (line-break the underlining within a paragraph) without using the soul package?

Thank you.

DDS
  • 8,816
  • 4
  • 9
  • 36
  • 1
    "How do I do what a package does without the package?" Either write a replacement, or use an alternate package. The former is quite hard in this case. For the latter, there's lua-ul if you use LuaTeX. But, you could tell us at least why "without soul". – gusbrs Jul 12 '22 at 15:36
  • Try \usepackage{ulem} and \uline{<text>} as an alternative. – Simon Dispa Jul 12 '22 at 15:40
  • @SimonDispa That seems to do the job; but the paragraph justification in the MWE seems to be thrown off. – DDS Jul 12 '22 at 16:03
  • you need some macros, you can copy the content of soul.sty to your preamble, but why? – David Carlisle Jul 12 '22 at 16:03
  • Underfull \hbox (badness 10000) in paragraph at lines 8--9 :( – David Carlisle Jul 12 '22 at 16:04
  • @DavidCarlisle I have used this package in the past; I don't remember specifically what the issue(s) were, but whenever possible I try not to use it, rather than risk having a conflict with another package that does not result in an error---but causes unexpected output. – DDS Jul 12 '22 at 16:10
  • 1
    any code that underlines paragraph text is going to be highly invasive and clash with other macros in the document. "avoiding soul" won't change that. – David Carlisle Jul 12 '22 at 16:21
  • @DavidCarlisle Thank you. I did not know that. – DDS Jul 12 '22 at 16:29
  • Your best bet really is lua-ul if you use LuaLaTeX (just like @gusbrs already noted). Else your options boil down to ulem (no automatic hyphenation, manual hyphenation with \- works), soul (can break depending on content), or some TikZ solution or similar (assumes equally spaced lines, if that holds true is pretty good, go search on this very site). – Skillmon Jul 12 '22 at 17:29
  • @Skillmon Thank you for this information. – DDS Jul 12 '22 at 18:47
  • See https://tex.stackexchange.com/questions/126291/list-of-underlining-packages-pros-and-cons – Steven B. Segletes Jul 13 '22 at 13:32
  • @StevenB.Segletes Many thanks for pointing this out. – DDS Jul 13 '22 at 13:56

1 Answers1

2

Underlining in a manuscript signified to the printer to set the text in italics.

On a typewriter, this underlining was done by back-spacing and typing an underscore.

Greater emphasis (bold, say) could be signified by turning the platen half a "line" space upwards and typing an equals signs.

Those who had two-colour ink ribbons could use red, for greatest emphasis (=bold italics).

tt underline

The effect is not nearly so striking in the case of non-monospaced fonts, though.

non-mono

Ragged right:

ragged right

MWE

\documentclass{book}
\usepackage{xcolor}
\usepackage{soul}
\usepackage{xparse}

\ExplSyntaxOn

\cs_set:Npn \fc_funcunderline:n #1 {
% 1=character

\tl_if_blank:eTF { #1 } { \tl_set:Nn \l_tmpc_tl { \c_space_token } } % else: { \tl_set:Nn \l_tmpc_tl { #1 \llap { \g_tmpa_tl } } } \tl_use:N \l_tmpc_tl
}

%-------------------- Underliner \NewDocumentCommand \ull { o m } { % 1=character to use as marker % 2=text \IfNoValueTF { #1 } { \tl_gset:Nn \g_tmpa_tl { _ } } { \tl_gset:Nn \g_tmpa_tl { #1 } }

        \tl_set:Nn \l_tmpa_tl { #2 }

    \group_begin:               
        \ttfamily
        \exp_args:Nx
        \str_map_function:nN 
                { \l_tmpa_tl }
                \fc_funcunderline:n
    \group_end:             

}

\ExplSyntaxOff

\begin{document} \thispagestyle{empty} \large

How may I do this without the \textit{soul} package?

\colorbox{green!5}{\parbox{\textwidth}{\quad Text underlining with linebreaking; Text underlining with linebreaking; Text underlining with linebreaking; Text underlining with linebreaking; Text underlining with linebreaking; Text underlining with linebreaking;x.}}

\colorbox{red!5}{\vtop{\ul{Text underlining with linebreaking; Text underlining with linebreaking; Text underlining with linebreaking; Text underlining with linebreaking; Text underlining with linebreaking; Text underlining with linebreaking;x.}}}

\raggedright \paragraph{Emphasis} \ull{Text underlining with linebreaking; Text underlining with linebreaking; Text underlining with linebreaking; Text underlining with linebreaking; Text underlining with linebreaking; Text underlining with linebreaking;x.}

\paragraph{Greater Emphasis} \ull[\raisebox{-1.4ex}{=}]{Text underlining with linebreaking; Text underlining with linebreaking; Text underlining with linebreaking; Text underlining with linebreaking; Text underlining with linebreaking; Text underlining with linebreaking;x.}

\paragraph{Greatest Emphasis} \ull[\raisebox{-1.4ex}{\textcolor{red}{=}}]{Text underlining with linebreaking; Text underlining with linebreaking; Text underlining with linebreaking; Text underlining with linebreaking; Text underlining with linebreaking; Text underlining with linebreaking;x.}

\paragraph{Other} \ull[\raisebox{-1.1ex}{{\tiny x}}]{Text underlining with linebreaking; Text underlining with linebreaking; Text underlining with linebreaking; Text underlining with linebreaking; Text underlining with linebreaking; Text underlining with linebreaking;x.}

\end{document}


\llaping the spaces gives this effect:

spaces underlined

MWE

\documentclass{book}
\usepackage{xcolor}
\usepackage{soul}
\usepackage{xparse}

\ExplSyntaxOn

\cs_set:Npn \fc_funcunderline:n #1 {
% 1=character

\tl_if_blank:eTF { #1 } { \tl_set:Nn \l_tmpc_tl { \c_space_token \llap { \g_tmpa_tl } } } % else: { \tl_set:Nn \l_tmpc_tl { #1 \llap { \g_tmpa_tl } } } \tl_use:N \l_tmpc_tl
}

%-------------------- Underliner \NewDocumentCommand \ull { o m } { % 1=character to use as marker % 2=text \IfNoValueTF { #1 } { \tl_gset:Nn \g_tmpa_tl { _ } } { \tl_gset:Nn \g_tmpa_tl { #1 } }

        \tl_set:Nn \l_tmpa_tl { #2 }

    \group_begin:               
        \ttfamily
        \exp_args:Nx
        \str_map_function:nN 
                { \l_tmpa_tl }
                \fc_funcunderline:n
    \group_end:             

}

\ExplSyntaxOff

\begin{document} \thispagestyle{empty} \large

How may I do this without the \textit{soul} package?

\colorbox{green!5}{\parbox{\textwidth}{\quad Text underlining with linebreaking; Text underlining with linebreaking; Text underlining with linebreaking; Text underlining with linebreaking; Text underlining with linebreaking; Text underlining with linebreaking;x.}}

\colorbox{red!5}{\vtop{\ul{Text underlining with linebreaking; Text underlining with linebreaking; Text underlining with linebreaking; Text underlining with linebreaking; Text underlining with linebreaking; Text underlining with linebreaking;x.}}}

\raggedright \paragraph{Emphasis} \ull{Text underlining with linebreaking; Text underlining with linebreaking; Text underlining with linebreaking; Text underlining with linebreaking; Text underlining with linebreaking; Text underlining with linebreaking;x.}

\paragraph{Greater Emphasis} \ull[\raisebox{-1.4ex}{=}]{Text underlining with linebreaking; Text underlining with linebreaking; Text underlining with linebreaking; Text underlining with linebreaking; Text underlining with linebreaking; Text underlining with linebreaking;x.}

\paragraph{Greatest Emphasis} \ull[\raisebox{-1.4ex}{\textcolor{red}{=}}]{Text underlining with linebreaking; Text underlining with linebreaking; Text underlining with linebreaking; Text underlining with linebreaking; Text underlining with linebreaking; Text underlining with linebreaking;x.}

\paragraph{Other} \ull[\raisebox{-1.1ex}{{\tiny x}}]{Text underlining with linebreaking; Text underlining with linebreaking; Text underlining with linebreaking; Text underlining with linebreaking; Text underlining with linebreaking; Text underlining with linebreaking;x.}

\paragraph{rule} \ull[\raisebox{-1.0ex}{\rule{1.2ex}{1.2pt}}]{Text underlining with linebreaking; Text underlining with linebreaking; Text underlining with linebreaking; Text underlining with linebreaking; Text underlining with linebreaking; Text underlining with linebreaking;x.}

\end{document}

Non-monospaced:

non-mono


Conclusion: could be possible.

A thinner rule, slightly higher, would be the way to go, say.

Cicada
  • 10,129