1

I am using the wave underline to highlight some text, but there is no function to make a double waveline. And I wish the underline could have line break automatically. Is there any methods to use \dwave(double wavy underline) as follow? For example, using \dwave{I am using the wave underline to highlight some text, but there is no function to make a line break. Each time the text was always underlined in a single line. Is there any methods to use \dwave and have the line break result?}

I want to have a effect like enter image description here

1 Answers1

4

Modifying the definition of uwave:

%! TEX program = lualatex
\documentclass{article}
\usepackage{ulem}
\begin{document}

\makeatletter

\iffalse % the following is the default definition of \uwave for comparison. Commented out. \protected\def\uwave{% \leavevmode \bgroup \ifdim \ULdepth =\maxdimen \ULdepth 3.5\p@ \else \advance \ULdepth 2\p@ \fi \markoverwith {\lower \ULdepth \hbox {\sixly \char 58}}% \ULon } \fi

% and this is the definition of dwave. \protected\def\dwave{% \leavevmode \bgroup \markoverwith {% \lower 3.5\p@ \hb@xt@ \z@{\sixly \char 58\hss}% \lower 5\p@ \hbox {\sixly \char 58}% }% \ULon }

\makeatother

\uwave{% I am using the wave underline to highlight some text, but there is no function to make a line break. Each time the text was always underlined in a single line. Is there any methods to use \textbackslash dwave and have the line break result?% }

\dwave{% I am using the wave underline to highlight some text, but there is no function to make a line break. Each time the text was always underlined in a single line. Is there any methods to use \textbackslash dwave and have the line break result?% }

\end{document}

output image

(documentation of primitive commands in TeXbook/TeX by Topic as usual.) Otherwise you can roughly guess how \markoverwith ... \ULon are meant to be used in the ulem documentation. Reading the code you can figure out that the original definition of uwave is used to make sure that nesting multiple emphasis will lower the outer definition, but nesting does not line-break properly anyway so we need to define a custom command.


Alternative solution using soulpos which has the advantage of supporting word-break (but takes one additional compilation pass):

%! TEX program = lualatex
\documentclass{article}
\usepackage{soulpos}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}
\begin{document}

\makeatletter

% this is taken straight from the documentation. \ulposdef{\uwave}{% \raisebox{-.75ex}{% \begin{tikzpicture}% \clip (0,-1pt) rectangle (\ulwidth,1pt); \draw[color=black!40, line width=.7pt, decorate, decoration= {snake, amplitude=.3pt, segment length=1mm,}] (0,0) -- +(\ulwidth+3pt,0); \end{tikzpicture}}}

% copied. \ulposdef{\dwave}{% \raisebox{-.9ex}{% \begin{tikzpicture}[mylinestyle/.style={ color=black, decorate, decoration={snake, amplitude=.3pt, segment length=1mm} }]% \clip (0,-1pt) rectangle (\ulwidth,3pt); \draw[mylinestyle] (0,0) -- +(\ulwidth+3pt,0); \draw[mylinestyle] (0,1.5pt) -- +(\ulwidth+3pt,0); \end{tikzpicture}}}

\makeatother

\uwave{% I am using the wave underline to highlight some text, but there is no function to make a line break. Each time the text was always underlined in a single line. Is there any methods to use \textbackslash dwave and have the line break result?% }

\dwave{% I am using the wave underline to highlight some text, but there is no function to make a line break. Each time the text was always underlined in a single line. Is there any methods to use \textbackslash dwave and have the line break result?% }

\end{document}

output of soulbox


Yet another alternative is to use lua-ul -- allows hyphenation, requires only one compilation pass, but requires LuaLaTeX:

%! TEX program = lualatex

\documentclass{article} \usepackage[a4paper, margin=4.5cm]{geometry} \usepackage{lua-ul}

\newunderlinetype\beginDoubleUnderWavy[\number\dimexpr1ex]{\cleaders\hbox{% \setlength\unitlength{.3ex}% \begin{picture}(4,0)(0,1) \qbezier(0,0)(1,1)(2,0) \qbezier(2,0)(3,-1)(4,0) % the original underline \qbezier(0,-1)(1,0)(2,-1) \qbezier(2,-1)(3,-2)(4,-1) % the underline below \end{picture}% }} \NewDocumentCommand\doubleUnderWavy{+m}{{\beginDoubleUnderWavy#1}}

\begin{document} \pagenumbering{gobble}

\doubleUnderWavy{% I am using the wave underline to highlight some text, but there is no function to make a line break. Each time the text was always underlined in a single line. Is there any methods to use \textbackslash dwave and have the line break result?% } \end{document}

Just copy the definition of \underWavy from the documentation of lua-ul and modify accordingly.

output image

user202729
  • 7,143