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.

12
  • 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, 2022 at 15:36
  • Try \usepackage{ulem} and \uline{<text>} as an alternative. Jul 12, 2022 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, 2022 at 16:03
  • you need some macros, you can copy the content of soul.sty to your preamble, but why? Jul 12, 2022 at 16:03
  • 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. Jul 12, 2022 at 16:21

1 Answer 1

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .