[Tex/LaTex] How to break URLs when footnotes are on same line

footmiscfootnotesline-breakingparagraphsurls

Question Footnotes on the same line revealed that it is a good idea to use \usepackage[para]{footmisc}. However, this does not seem to work with URLs:

\documentclass{article} 
\usepackage{hyperref}
\usepackage[para]{footmisc}
\begin{document} 
test\footnote{\url{http://www.example.org/long-URL/long/long/long/long/long/long/long/long/long/long/long/long/long/long/long}}
\end{document}

undesired result

The given URL is not wrapped (but footnote 2 and 3 are on the same line). If footmisc is not loaded, the URL is wrapped perfectly. What can I do if I want to use footnotes with URLs next to each other?

More complex example (following answer https://tex.stackexchange.com/a/56706/9075):

\documentclass{article} 
\usepackage[para]{footmisc}
\usepackage{hyperref}

\def\myurl#1{\setbox0\vbox{\hsize.5\maxdimen
\url{#1}\par
\global\setbox1\lastbox}\unhbox1 }

\begin{document} 

test\footnote{\myurl{http://www.example.org/long-URL/long/long/long/long/long/long/long/long/long/long/long/long/long/long/long}}

ODE\footnote{\myurl{http://ode.apache.org/}}). 
SOAP/http\footnote{\myurl{http://www.w3.org/TR/soap12-part2/}} 
\end{document}

The output is as follows:

unexpected result

I'd like to have footnote 2 and 3 on the same line

Best Answer

To make it work with para automatically you need a modified version of \url

enter image description here

as noted in the comments, you the first version added parfillskip glue after each url which padded to the end of the line, This version removes that.

\documentclass{article} 
\usepackage[para]{footmisc}
\usepackage{hyperref}

\def\myurl#1{\setbox0\vbox{\hsize.5\maxdimen
\url{#1}\par
\setbox0\lastbox
\global\setbox1\hbox{\unhbox0\unskip\unskip\unpenalty}}\unhbox1 }

\begin{document} 
test\footnote{\myurl{http://www.example.org/long-URL/long/long/long/long/long/long/long/long/long/long/long/long/long/long/long}}

ODE\footnote{\myurl{http://ode.apache.org/}}). 
SOAP/http\footnote{\myurl{http://www.w3.org/TR/soap12-part2/}} 
\end{document}
Related Question