[Tex/LaTex] Trying to create an underlined, wrapped link

linksunderline

I'm parsing user HTML to LaTeX templates. The HTML comes from a rich text editor, so of course the incoming HTML syntax can be almost anything. There's one case that breaks LaTeX that I have to handle.

<u><a href="http://www.google.com">text</a></u>

This HTML, which I do not control, is parsed by a neutral parser into LaTeX templates. It might become something like:

\ul{\url{http://www.google.com}}

Due to the nature of the input, and the nature of the parser, I must assume I have some sort of underline tag wrapping some sort of link tag. This is a required constraint for answering this question. I do not have direct control over the input, and the parser is neutral. I can control what the parser outputs per per tag, such as <u> input can be compiled into \uline, but I cannot change the structure of the AST.

See what happens when I include the ulem package and wrap the link with \uline:

\usepackage{ulem}

Text: \uline{\url{http://test.com/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/}}

Now the link is underlined, but does not wrap:

non broken link

This is despite the ulem documentation saying "Unlike regular underlining, ulem allows line breaks".

I have also tried using the soul package and the \ul command:

\usepackage{soul}

Text: \ul{\url{http://test.com/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/}}

Which chokes with the error:

! Argument of \hyper@n@rmalise has an extra }.
l.9 ...ne-text/uline-text/uline-text/uline-text/}}

I do not directly control the creation of the LaTeX source code, so I cannot directly modify the order of the tags. Please read this question carefully before voting. I am not asking how to underline a link tag.

Best Answer

the pdf link annotation itself can render an underline.

\documentclass[letterpaper, 10pt]{article}

\usepackage[letterpaper, margin=1in]{geometry}
\usepackage[breaklinks]{hyperref}

\hypersetup{urlbordercolor=0 0 0,pdfborderstyle={/S/U/W 1}}

\begin{document}


Text: \url{http://test.com/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/}

\par \end{document}

enter image description here

see also


As requested, using the above to underline or not depending on an outer command:

enter image description here

\documentclass[letterpaper, 10pt]{article}

\usepackage[letterpaper, margin=1in]{geometry}
\usepackage[breaklinks]{hyperref}

\hypersetup{urlbordercolor=0 0 0,pdfborderstyle={/W 0}}


\def\uwibble#1{{\hypersetup{pdfborderstyle={/S/U/W 1}}#1}}

\begin{document}


Text: \url{http://test.com/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/}

Text: \uwibble{\url{http://test.com/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/}}

Text: \url{http://test.com/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/}

Text: \uwibble{\url{http://test.com/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/}}

\end{document}

and... enter image description here

\documentclass[letterpaper, 10pt]{article}

\usepackage[letterpaper, margin=1in]{geometry}
\usepackage[breaklinks]{hyperref}
\usepackage{ulem}
\hypersetup{urlbordercolor=0 0 0,pdfborderstyle={/W 0}}


\def\uwibble#1{{\xuwibble#1\relax\relax\xxuwibble{#1}}}
\def\xuwibble#1#2\xxuwibble{%
\def\z{[#1][#2]}\show\z
\ifx\url#1%
\hypersetup{pdfborderstyle={/S/U/W 1}}%
\else
\expandafter\uline
\fi}

\begin{document}


Text: \url{http://test.com/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/}

Text: \uwibble{\url{http://test.com/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/}}

Text: \url{http://test.com/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/}

Text: \uwibble{\url{http://test.com/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/}}

Text: \uwibble{something not a url} zzzz

\end{document}
Related Question