1

Are there any similar packages (or color ulem) to the ulem package, with color, underline, sout, xout, dash underline, dot underline with color as parameter?

I found this Q&A about changing the color of special underlines with ulem months ago, and I like that solution, but I'd like:

  • color as parameter
  • sout, xout, dash underline and dot underline work well.
  • even works well with a paragraph

enter image description here


After Peter Wilson comment: enter image description here

\documentclass{article}
\usepackage{lipsum}  
\usepackage[normalem]{ulem}
\usepackage[names]{xcolor}
\usepackage{amsmath}
\makeatletter
    \newcommand{\culine}[2]{%
        \newcommand\temp@uline{\bgroup\markoverwith
            {\textcolor{#1}{\rule[-0.5ex]{2pt}{0.4pt}}}\ULon}%
        \temp@uline{#2}%
    }
    \newcommand{\cuuline}[2]{%
        \UL@protected\def\temp@uuline{\leavevmode \bgroup
            \UL@setULdepth
            \ifx\UL@on\UL@onin \advance\ULdepth2.8\p@\fi
            \markoverwith{\textcolor{#1}{\lower\ULdepth\hbox
                {\kern-.03em\vbox{\hrule width.2em\kern1\p@\hrule}\kern-.03em}}}%
        \ULon}%
        \temp@uuline{#2}%
    }
    \newcommand{\cuwave}[2]{%
        \UL@protected\def\temp@uwave{\leavevmode \bgroup
        \ifdim \ULdepth=\maxdimen \ULdepth 3.5\p@
        \else \advance\ULdepth2\p@
        \fi \markoverwith{\textcolor{#1}{\lower\ULdepth\hbox{\sixly \char58}}}\ULon}
        \font\sixly=lasy6 % does not re-load if already loaded, so no memory drain.
        \temp@uwave{#2}%
    }
    \newcommand{\csout}[2]{%
        \UL@protected\def\temp@sout{\leavevmode \bgroup
        \ifdim \ULdepth=\maxdimen \ULdepth 3.5\p@
        \else \advance\ULdepth2\p@
        \fi \markoverwith{\textcolor{#1}{\lower\ULdepth\hbox{\sixly \char58}}}\ULon}
        \font\sixly=lasy6 % does not re-load if already loaded, so no memory drain.
        \temp@sout{#2}%
    }
    \newcommand{\cxout}[2]{%
        \UL@protected\def\temp@uwave{\leavevmode \bgroup
        \ifdim \ULdepth=\maxdimen \ULdepth 3.5\p@
        \else \advance\ULdepth2\p@
        \fi \markoverwith{\textcolor{#1}{\lower\ULdepth\hbox{\sixly \char58}}}\ULon}
        \font\sixly=lasy6 % does not re-load if already loaded, so no memory drain.
        \temp@uwave{#2}%
    }
    \newcommand{\cdashuline}[2]{%
        \UL@protected\def\temp@uwave{\leavevmode \bgroup
        \ifdim \ULdepth=\maxdimen \ULdepth 3.5\p@
        \else \advance\ULdepth2\p@
        \fi \markoverwith{\textcolor{#1}{\lower\ULdepth\hbox{\sixly \char58}}}\ULon}
        \font\sixly=lasy6 % does not re-load if already loaded, so no memory drain.
        \temp@uwave{#2}%
    }
  \newcommand{\cdotuline}[2]{%
  \UL@protected\def\cdotuline{\leavevmode \bgroup 
    \UL@setULdepth
    \ifx\UL@on\UL@onin \advance\ULdepth2\p@\fi
    \markoverwith{\begingroup
       %\advance\ULdepth0.08ex 
       \lower\ULdepth\hbox{\kern.06em \textcolor{#1}{.}\kern.04em}%
       \endgroup}%
    \ULon}
    }
  \UL@protected\def\greendashuline{\leavevmode \bgroup 
    \UL@setULdepth
    \ifx\UL@on\UL@onin \advance\ULdepth2\p@\fi
    \markoverwith{\kern.13em
    \vtop{\color{green}\kern\ULdepth \hrule width .3em}%
    \kern.13em}\ULon}
\makeatother
%
\begin{document}
%
\textbf{With Color:}
    \culine{brown}{I am underlined in color.}
%    \culine{red}{\lipsum[1].}

    \cuuline{blue}{I am double underlined in color.}
%    \culine{green}{\lipsum[1].}

    \cuwave{teal}{I am underlined in waves.}
%    \cuwave{blue}{\lorem[1].}

    I am not underlined at all.

    \csout{orange}{I am SOUTED in color}

    \cxout{green}{I am XOUTED in color.}

    \cdashuline{cyan}{I am dash-underlined in color.}

    \cdotuline{red}{I am dot-underlined in color.}

\medskip
\par
\textbf{Without color: (works fine!)}
    \uline{I am underlined in color.}

    \uuline{I am double underlined in color.}

    \uwave{I am underlined in waves.}

    I am not underlined at all.

    \sout{I am SOUTED in color}

    \xout{I am XOUTED in color.}

    \dashuline{I am dash-underlined in color.}

    \dotuline{I am dot-underlined in color.}

\end{document}
6
  • 5
    use lualatex and the lua-ul package. Apr 1, 2023 at 13:48
  • 1
    You could also try the soul package if you don't use LuaLaTeX. Apr 1, 2023 at 13:53
  • Color as parameter is already supported by one of the answers there. Which one is missing exactly?
    – user202729
    Apr 1, 2023 at 15:02
  • 1
    Please provide an MWE that we can compile that shows your problem and how you tried to fix it. Apr 1, 2023 at 17:10
  • @PeterWilson I edited and added the mwe. Thank you.
    – Mika Ike
    Apr 1, 2023 at 19:12

1 Answer 1

3

Well, you should use the correct original definitions of the macros. If you use the \uwave defintion for your \cxout macro, of course you will get a the same wavy underline ... =)

Also, you should not use \newcommand insinde of your redefinitions, because this will raise an error if you try to use the newly defined macro more than once. Better stick to \UL@protected\def.

The only macro you cannot simply edit by inserting some \color command is that for \sout, but it is quite easy to reuse the definition of the \uline macro and shift the line using \raisebox.

\documentclass{article}
\usepackage{ulem}
\usepackage{xcolor}

\makeatletter
    \newcommand{\culine}[2]{%
        \UL@protected\def\temp@uline{\bgroup\markoverwith
            {\textcolor{#1}{\rule[-0.5ex]{2pt}{0.4pt}}}\ULon}%
        \temp@uline{#2}%
    }
    \newcommand{\cuuline}[2]{%
        \UL@protected\def\temp@uuline{\leavevmode \bgroup
            \UL@setULdepth
            \ifx\UL@on\UL@onin \advance\ULdepth2.8\p@\fi
            \markoverwith{\textcolor{#1}{\lower\ULdepth\hbox
                {\kern-.03em\vbox{\hrule width.2em\kern1\p@\hrule}\kern-.03em}}}%
        \ULon}%
        \temp@uuline{#2}%
    }
    \newcommand{\cuwave}[2]{%
        \UL@protected\def\temp@uwave{\leavevmode \bgroup
        \ifdim \ULdepth=\maxdimen \ULdepth 3.5\p@
        \else \advance\ULdepth2\p@
        \fi \markoverwith{\textcolor{#1}{\lower\ULdepth\hbox{\sixly \char58}}}\ULon}
        \font\sixly=lasy6 % does not re-load if already loaded, so no memory drain.
        \temp@uwave{#2}%
    }
    \newcommand{\csout}[2]{%
        \UL@protected\def\temp@sout{\bgroup\markoverwith
            {\textcolor{#1}{\raisebox{1.05ex}{\rule[-0.5ex]{2pt}{0.4pt}}}}\ULon}%
        \temp@sout{#2}%
    }
    \newcommand{\cxout}[2]{%
        \UL@protected\def\temp@xout{\leavevmode \bgroup
        \markoverwith{\color{#1}\hbox to.35em{\hss/\hss}}\ULon}%
        \temp@xout{#2}%
    }
    \newcommand{\cdashuline}[2]{%
        \UL@protected\def\temp@dashuline{\leavevmode \bgroup 
        \UL@setULdepth
        \ifx\UL@on\UL@onin \advance\ULdepth2\p@\fi
        \markoverwith{\kern.13em
        \vtop{\color{#1}\kern\ULdepth \hrule width .3em}%
        \kern.13em}\ULon}
        \temp@dashuline{#2}%
    }
    \newcommand{\cdotuline}[2]{%
        \UL@protected\def\temp@dotuline{\leavevmode \bgroup 
        \UL@setULdepth
        \ifx\UL@on\UL@onin \advance\ULdepth2\p@\fi
        \markoverwith{\begingroup
            %\advance\ULdepth0.08ex 
            \lower\ULdepth\hbox{\kern.06em \textcolor{#1}{.}\kern.04em}%
            \endgroup}%
        \ULon}%
        \temp@dotuline{#2}%
    }
\makeatother

\begin{document}

\textbf{With Color:}

    \culine{brown}{I am underlined in color.}

    \cuuline{blue}{I am double underlined in color.}

    \cuwave{teal}{I am underlined in waves.}

    I am not underlined at all.

    \csout{orange}{I am SOUTED in color}

    \cxout{green}{I am XOUTED in color.}

    \cdashuline{cyan}{I am dash-underlined in color.}

    \cdotuline{red}{I am dot-underlined in color.} 

\end{document}

enter image description here


A variant that allows for different thickness:

\documentclass{article}
\usepackage{ulem}
\usepackage{xcolor}

\makeatletter
    \newcommand{\cthickuline}[3][0.5pt]{%
        \UL@protected\def\temp@uline{\bgroup\markoverwith
            {\textcolor{#2}{\rule[-0.5ex]{2pt}{#1}}}\ULon}%
        \temp@uline{#3}%
    }
\makeatother

\begin{document}

\textbf{With Color:}

    \cthickuline[0.1pt]{red}{I am underlined in color.}

    \cthickuline{red}{I am underlined in color.}

    \cthickuline[1.2pt]{red}{I am underlined in color.}

\end{document}

enter image description here

3
  • 1
    Sorry, I overlooked \dashuline. Just corrected this one. Apr 1, 2023 at 19:38
  • For me is... Perfect solved. @jasper-habicht Two adds: 1.- I think it could be interesting a new ulem package with your options. Even with thick option. 2.- is possible put |lipsum[1] (with break lines) in a \uwave \uline \uuline?
    – Mika Ike
    Apr 1, 2023 at 19:40
  • 1
    @MikaIke As for the lipsum problem: see this answer. It seems that you can't use it directly, for reasons that are difficult to grasp for me as well ... Apr 1, 2023 at 19:43

You must log in to answer this question.

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