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}

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}
