10

Word allows for all kinds of font formatting:

enter image description here

The above example combines strike-through/strike-out (like this) and underlining. I'd like to be able to do the same, but neither ulem nor soul allows for this in a convenient way.

  • ulem:

    enter image description here

    \documentclass{article}
    \usepackage[a6paper,showframe]{geometry}% Just for this example
    \usepackage{ulem}
    \begin{document}
    Lorem ipsum dolor sit amet, \sout{consectetur adipiscing elit. 
    Praesent} in nisi magna. Mauris \sout{auctor gravida} fermentum. 
    Proin enim \uline{massa, \sout{\textbf{lobortis in} ligula} vel, convallis} fermentum 
    nulla. \uline{Nam in mattis nulla}. Vestibulum vel \uline{auctor orci. 
    Praesent \textit{\textbf{ornare, eros} ac} euismod} congue, turpis est facilisis 
    nisi, a sollicitudin massa lectus imperdiet tellus. Duis at 
    tempor velit. \sout{Nulla \uline{gravida}, dolor in cursus}. 
    \end{document}
    
  • soul:

    The soul documentation explicitly states that "nesting soul commands don't work":

    enter image description here

    As such, the following example does not compile without errors:

    \documentclass{article}
    \usepackage[a6paper,showframe]{geometry}% Just for this example
    \usepackage{soul}
    \begin{document}
    Lorem ipsum dolor sit amet, \st{consectetur adipiscing elit. 
    Praesent} in nisi magna. Mauris \st{auctor gravida} fermentum. 
    Proin enim \ul{massa, \st{\textbf{lobortis in} ligula} vel, convallis} fermentum 
    nulla. \ul{Nam in mattis nulla}. Vestibulum vel \ul{auctor orci. 
    Praesent \textit{\textbf{ornare, eros} ac} euismod} congue, turpis est facilisis 
    nisi, a sollicitudin massa lectus imperdiet tellus. Duis at 
    tempor velit. \st{Nulla \ul{gravida}, dolor in cursus}. 
    \end{document}
    

Ideally I'd like to be able to use these font "effect" macros interchangeably: strike-out inside underline, or underline inside strike-out with no impact on the use of fonts (like italic or bold). Here's the output from Word:

enter image description here

(See also the followup question: Underline + strike-through using soul)

2
  • @HenriMenke: Good question! I'm processing output from a custom-made interface where users (lawyers) can specify any number of formatting options. These styles may be specific to a jurisdiction, so I would have very little control over what is considered standard practice for formatting. I would never encourage striking out and underlining some bold italic piece of text...
    – Werner
    May 8, 2014 at 18:06
  • For your first sentence; no it doesn't it just stacks letters next to each other :)
    – percusse
    May 8, 2014 at 18:06

2 Answers 2

6

Here is an adaptation to Martin's answer at Cool Text Highlighting in LaTeX where I have defined \tikzst based on Martin's \tikzul.

This shows examples of

  • strike out and underlining
  • strike out and highlighting

enter image description here

Note:

  • Usually, \tikzmark solutions require two runs. As there are nested uses of \tikzmark, this require at three runs. (Thanks @Werner for pointing this out).

    The additional run is required as the nested tikzmark's locations depends on the location of the parent's \tikzmark. So, the first run stabilizes the location of the "outer" \tikzmark, the second stabilizes the location of the "inner" \tikzmark, and the third to do the actual drawing.

  • The \tikzmark is from Adding a large brace next to a body of text.

Code:

\documentclass[twoside,11pt]{book}

\usepackage{zref-abspage}
\usepackage{zref-user}
\usepackage{tikz}
\usepackage{atbegshi}
\usetikzlibrary{calc,decorations.pathmorphing}

\makeatletter
\newcommand{\currentsidemargin}{%
  \ifodd\zref@extract{textarea-\thetextarea}{abspage}%
    \oddsidemargin%
  \else%
    \evensidemargin%
  \fi%
}

\newcounter{textarea}
\newcommand{\settextarea}{%
   \stepcounter{textarea}%
   \zlabel{textarea-\thetextarea}%
   \begin{tikzpicture}[overlay,remember picture]
    % Helper nodes
    \path (current page.north west) ++(\hoffset, -\voffset)
        node[anchor=north west, shape=rectangle, inner sep=0, minimum width=\paperwidth, minimum height=\paperheight]
        (pagearea) {};
    \path (pagearea.north west) ++(1in+\currentsidemargin,-1in-\topmargin-\headheight-\headsep)
        node[anchor=north west, shape=rectangle, inner sep=0, minimum width=\textwidth, minimum height=\textheight]
        (textarea) {};
  \end{tikzpicture}%
}


\usepackage{lipsum}
\newcommand\xlipsum[1][]{{\let\par\relax\lipsum*[#1]}}

\tikzset{tikzul/.style={yshift=-.75\dp\strutbox}}

\newcounter{tikzul}%
\newcommand\tikzul[1][]{%
    \begingroup
    \global\tikzullinewidth\linewidth
    \def\tikzulsetting{[#1]}%
    \stepcounter{tikzul}%
    \settextarea
    \zlabel{tikzul-begin-\thetikzul}%
    \tikz[overlay,remember picture,tikzul] \coordinate (tikzul-\thetikzul) at (0,0);% Modified \tikzmark macro
    \ifnum\zref@extract{tikzul-begin-\thetikzul}{abspage}=\zref@extract{tikzul-end-\thetikzul}{abspage}
    \else
        \AtBeginShipoutNext{\tikzul@endpage{#1}}%
    \fi
    \bgroup
    \def\par{\ifhmode\unskip\fi\egroup\par\@ifnextchar\noindent{\noindent\tikzul[#1]}{\tikzul[#1]\bgroup}}%
    \aftergroup\endtikzul
    \let\@let@token=%
}
\newlength\tikzullinewidth


\def\tikzul@endpage#1{%
\setbox\AtBeginShipoutBox\hbox{%
\box\AtBeginShipoutBox
\hbox{%
\begin{tikzpicture}[overlay,remember picture,tikzul]
\draw[#1]
    let \p1 = (tikzul-\thetikzul), \p2 = ([xshift=\tikzullinewidth+\@totalleftmargin]textarea.south west) in
    \ifdim\dimexpr\y1-\y2<.5\baselineskip
        (\x1,\y1) -- (\x2,\y1)
    \else
        let \p3 = ([xshift=\@totalleftmargin]textarea.west) in
        (\x1,\y1) -- +(\tikzullinewidth-\x1+\x3,0)
        % (\x3,\y2) -- (\x2,\y2)
        (\x3,\y1)
       \myloop{\y1-\y2+.5\baselineskip}{%
           ++(0,-\baselineskip) -- +(\tikzullinewidth,0)
       }%
    \fi
;
\end{tikzpicture}%
}}%
}%


\def\endtikzul{%
    \zlabel{tikzul-end-\thetikzul}%
    \ifnum\zref@extract{tikzul-begin-\thetikzul}{abspage}=\zref@extract{tikzul-end-\thetikzul}{abspage}
    \begin{tikzpicture}[overlay,remember picture,tikzul]
        \expandafter\draw\tikzulsetting
            let \p1 = (tikzul-\thetikzul), \p2 = (0,0) in
            \ifdim\y1=\y2
                (\x1,\y1) -- (\x2,\y2)
            \else
                let \p3 = ([xshift=\@totalleftmargin]textarea.west), \p4 = ([xshift=-\rightmargin]textarea.east) in
                (\x1,\y1) -- +(\tikzullinewidth-\x1+\x3,0)
                (\x3,\y2) -- (\x2,\y2)
                (\x3,\y1)
                \myloop{\y1-\y2}{%
                    ++(0,-\baselineskip) -- +(\tikzullinewidth,0)
                }%
            \fi
        ;
    \end{tikzpicture}%
    \else
    \settextarea
    \begin{tikzpicture}[overlay,remember picture,tikzul]
        \expandafter\draw\tikzulsetting
            let \p1 = ([xshift=\@totalleftmargin,yshift=-.5\baselineskip]textarea.north west), \p2 = (0,0) in
            \ifdim\dimexpr\y1-\y2<.5\baselineskip
                (\x1,\y2) -- (\x2,\y2)
            \else
                let \p3 = ([xshift=\@totalleftmargin]textarea.west), \p4 = ([xshift=-\rightmargin]textarea.east) in
                (\x3,\y2) -- (\x2,\y2)
                (\x3,\y2)
                \myloop{\y1-\y2}{%
                    ++(0,+\baselineskip) -- +(\tikzullinewidth,0)
                }
            \fi
        ;
    \end{tikzpicture}%
    \fi
    \endgroup
}

% -------------------------------------------------------------- Additions by Peter Grill

\tikzset{tikzst/.style={yshift=0.5\dp\strutbox}}

\newcounter{tikzst}%
\newcommand\tikzst[1][]{%
    \begingroup
    \global\tikzstlinewidth\linewidth
    \def\tikzstsetting{[#1]}%
    \stepcounter{tikzst}%
    \settextarea
    \zlabel{tikzst-begin-\thetikzst}%
    \tikz[overlay,remember picture,tikzst] \coordinate (tikzst-\thetikzst) at (0,0);% Modified \tikzmark macro
    \ifnum\zref@extract{tikzst-begin-\thetikzst}{abspage}=\zref@extract{tikzst-end-\thetikzst}{abspage}
    \else
        \AtBeginShipoutNext{\tikzst@endpage{#1}}%
    \fi
    \bgroup
    \def\par{\ifhmode\unskip\fi\egroup\par\@ifnextchar\noindent{\noindent\tikzst[#1]}{\tikzst[#1]\bgroup}}%
    \aftergroup\endtikzst
    \let\@let@token=%
}
\newlength\tikzstlinewidth


\def\tikzst@endpage#1{%
\setbox\AtBeginShipoutBox\hbox{%
\box\AtBeginShipoutBox
\hbox{%
\begin{tikzpicture}[overlay,remember picture,tikzst]
\draw[#1]
    let \p1 = (tikzst-\thetikzst), \p2 = ([xshift=\tikzstlinewidth+\@totalleftmargin]textarea.south west) in
    \ifdim\dimexpr\y1-\y2<.5\baselineskip
        (\x1,\y1) -- (\x2,\y1)
    \else
        let \p3 = ([xshift=\@totalleftmargin]textarea.west) in
        (\x1,\y1) -- +(\tikzstlinewidth-\x1+\x3,0)
        % (\x3,\y2) -- (\x2,\y2)
        (\x3,\y1)
       \myloop{\y1-\y2+.5\baselineskip}{%
           ++(0,-\baselineskip) -- +(\tikzstlinewidth,0)
       }%
    \fi
;
\end{tikzpicture}%
}}%
}%


\def\endtikzst{%
    \zlabel{tikzst-end-\thetikzst}%
    \ifnum\zref@extract{tikzst-begin-\thetikzst}{abspage}=\zref@extract{tikzst-end-\thetikzst}{abspage}
    \begin{tikzpicture}[overlay,remember picture,tikzst]
        \expandafter\draw\tikzstsetting
            let \p1 = (tikzst-\thetikzst), \p2 = (0,0) in
            \ifdim\y1=\y2
                (\x1,\y1) -- (\x2,\y2)
            \else
                let \p3 = ([xshift=\@totalleftmargin]textarea.west), \p4 = ([xshift=-\rightmargin]textarea.east) in
                (\x1,\y1) -- +(\tikzstlinewidth-\x1+\x3,0)
                (\x3,\y2) -- (\x2,\y2)
                (\x3,\y1)
                \myloop{\y1-\y2}{%
                    ++(0,-\baselineskip) -- +(\tikzstlinewidth,0)
                }%
            \fi
        ;
    \end{tikzpicture}%
    \else
    \settextarea
    \begin{tikzpicture}[overlay,remember picture,tikzst]
        \expandafter\draw\tikzstsetting
            let \p1 = ([xshift=\@totalleftmargin,yshift=-.5\baselineskip]textarea.north west), \p2 = (0,0) in
            \ifdim\dimexpr\y1-\y2<.5\baselineskip
                (\x1,\y2) -- (\x2,\y2)
            \else
                let \p3 = ([xshift=\@totalleftmargin]textarea.west), \p4 = ([xshift=-\rightmargin]textarea.east) in
                (\x3,\y2) -- (\x2,\y2)
                (\x3,\y2)
                \myloop{\y1-\y2}{%
                    ++(0,+\baselineskip) -- +(\tikzstlinewidth,0)
                }
            \fi
        ;
    \end{tikzpicture}%
    \fi
    \endgroup
}
% --------------------------------------------------------------

\def\myloop#1#2#3{%
    #3%
    \ifdim\dimexpr#1>1.1\baselineskip
        #2%
        \expandafter\myloop\expandafter{\the\dimexpr#1-\baselineskip\relax}{#2}%
    \fi
}

\makeatother

\begin{document}

text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text \tikzul[red]{text text text text \tikzst[black, ultra thick]{text text text text text
text text text text text text text text} text text text
text text text text} text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text

{\tikzset{tikzul/.style={yshift=1ex}}

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit,
vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida
mauris. Nam arcu libero, nonummy eget, consectetuer id, vulputate a, magna.
Donec vehicula augue eu neque. Pellentesque habitant morbi tristique senectus
et netus et malesuada fames ac turpis egestas. Mauris ut leo. Cras viverra
metus rhoncus sem. Nulla et lectus vestibulum urna fringilla ultrices. Phasellus
eu tellus sit amet tortor gravida placerat. Integer sapien est, iaculis in, pretium
quis, viverra ac, nunc. Praesent eget sem vel leo ultrices bibendum. \tikzul[line width=1.5\ht\strutbox,semitransparent,yellow]{Aenean
faucibus. Morbi dolor nulla, \tikzst[black, ultra thick]{malesuada eu, pulvinar at, mollis ac, nulla. Curabitur auctor semper nulla. Donec varius orci eget risus. Duis nibh mi, congue
eu, accumsan eleifend, sagittis quis}, diam. Duis eget orci sit amet orci dignissim
rutrum.}
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
test
}

\begin{quote}
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text \tikzul[red]{text text text \tikzst[black, ultra thick]{text text text text text text
text text text text text text text text text text text
text text text text text text text} text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text text text} text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
\end{quote}

{\tikzset{tikzul/.style={yshift=.5ex}}

\begin{quote}
text text text text text text text text text text text
text text text text text text text text text text text
\begin{quote}
text text text text text text text text text text text
text text \tikzul[green]{text text \tikzst[black, ultra thick]{text text text text text text text
text text text text text text text text text text text
text text text text 
text text text text text text text}
text text text text text text text text text text text
text text text text text text text text text text text
text text text text} text text text text text text text
\end{quote}
text text text text text text text text text text text
text text text text text text text text text text text
\end{quote}

\large
new text text text text text text text text text text text
text text \tikzul[red]{first text text text text \tikzst[black, ultra thick]{text text text text
teXt teXt teXt teXt teXt teXt teXt teXt teXt teXt teXt
teXt teXt teXt} teXt teXt teXt teXt teXt teXt teXt teXt
teXt teXt teXt last} teXt teXt teXt teXt teXt teXt teXt
text text text text text text text text text text text
text text text text text text text text text text text

text text text text text text text text text text text
text text text text text text text text text text text
text text \tikzul[red]{text text text text text text text text text
text text\par\noindent text text text text text text text text text
text text text text} text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
}

\begin{itemize}
    \item \tikzul{test test test} test
    \item test \tikzul{test test test} test
    \item aa \tikzul{test test test} test
    \item b \tikzul{test test 
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
        test} test
\end{itemize}

text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text
text text \tikzul[red]{text text text text text text text text text
text text

 text text text text text text text text text
text text text text} text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text

text text text text text text text text text text text
text text text text text text text text text text text
text text \tikzul[red]{text text text text text text text text text
text text

\noindent text text text text text text text text text
\par text text text text} text text text text text text text
text text text text text text text text text text text
text text text text text text text text text text text


\end{document}
1
  • 1
    ...actually, at the first go-around, you need 3 compilations. This may be as a result of the nested commands.
    – Werner
    May 8, 2014 at 19:26
0

There are several options -- all of the below supports line break:

These solutions does not support line break:

For completion, below is a solution using ulem instead (adapt from my answer defining \dwave) -- ulem does not have the "uniform horizontal" restriction, but does not support hyphenation either:

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

\makeatletter
\protected\def\ulinesout{%
    \leavevmode \bgroup
    \UL@setULdepth
    \markoverwith {%
        \rlap{\rule[.55ex]{2pt}{0.4pt}}%
        \rule[-\ULdepth]{2pt}{0.4pt}%  \rule[-.673ex]{2pt}{0.4pt}
    }%
    \ULon 
}
\makeatother
\begin{document}

\uline{a}\ulinesout{b}\sout{c}

\uline{Producing a colored underline or strike-through is }\ulinesout{not supported by
regular uline}\sout{ or sout, but it is quite easy to colorize using the
markoverwith mechanism}

\end{document}

As remarked in ulem documentation, this is not a "truly flexible" rule, but it feels impossible in this case, and this draws the rule by repeating lots of small pieces.

ulem documentation

This drawback is the same as that of the solution in the soul package linked above.

You must log in to answer this question.

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