1

I am trying to strike out a long url, but it seems that I only can either break the url or strike it out, but not both.

I would like to do something like this:

\documentclass{article} \usepackage{url} \usepackage{ulem} \sout{\url{http://tex.stackexchange.com}}

but it does not break the url

2
  • 2
    Welcome to TeX.SX! Please provide an MWE which shows what you have tried and where you are having problems. Thanks.
    – LaRiFaRi
    Jan 22, 2015 at 11:23
  • 3
    @close voters: Please allow some more time for Peter to improve the question before voting to close as unclear. Jan 22, 2015 at 11:57

1 Answer 1

3

This simulates the url package by recursively breaking the input character by character, striking it out (in \ttfamily), applying \penalty0 to allow linebreaks. The strikeout is a modification to the censor package.

In this EDITED implementation, the characters /, -, and \_ can serve as linebreak points. (In the original implementation at the end of this post, any character in the \souturl argument could serve as a linebreak point)

\documentclass{article}
\usepackage[nopar]{lipsum}
\usepackage{censor}
%%%%%%%%%%%
\censorruleheight=.1ex %THICKNESS OF CENSOR RULE
\newlength\nextcharwidth
\makeatletter
\renewcommand\@cenword[1]{%
  \setlength{\nextcharwidth}{\widthof{#1}}%
  \censorrule{\nextcharwidth}%
  \kern -\nextcharwidth%
  #1}
\makeatother
\newcommand\souturl[1]{\bgroup\ttfamily%
  \censorruledepth=.55ex\souturlhelp#1\relax\relax\egroup}
\def\souturlhelp#1#2\relax{%
  \censor{#1}%
  \ifx#1/\penalty0\else%
    \ifx#1-\penalty0\else%
      \ifx#1\_\penalty0\else%
  \fi\fi\fi%
  \ifx\relax#2\relax\else\souturlhelp#2\relax\fi}
%%%%%%%%%%%
\begin{document}
\lipsum[1]
\souturl{%
http://tex.stackexchange.com/questions/224354/how-to-strike-out-an-url\_xyz%
}
\lipsum[2]
\end{document}

enter image description here

ORIGINAL SOLUTION that allows any character as a linebreak point

\documentclass{article}
\usepackage[nopar]{lipsum}
\usepackage{censor}
%%%%%%%%%%%
\censorruleheight=.1ex %THICKNESS OF CENSOR RULE
\newlength\nextcharwidth
\makeatletter
\renewcommand\@cenword[1]{%
  \setlength{\nextcharwidth}{\widthof{#1}}%
  \censorrule{\nextcharwidth}%
  \kern -\nextcharwidth%
  #1}
\makeatother
\newcommand\souturl[1]{\bgroup\ttfamily%
  \censorruledepth=.55ex\soutrefhelp#1\relax\relax\egroup}
\def\soutrefhelp#1#2\relax{%
  \censor{#1}\penalty0\ifx\relax#2\relax\else\soutrefhelp#2\relax\fi}
%%%%%%%%%%%
\begin{document}
\lipsum[1]
\souturl{%
http://tex.stackexchange.com/questions/224354/how-to-strike-out-an-url\_xyz%
}
\lipsum[2]
\end{document}

enter image description here

You must log in to answer this question.

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