12

I ran across the problem of underfull \hbox when I want to typeset a long url(long enough to fill two lines) in the footnote. Here is my MWE:

\documentclass{article}
\usepackage{hyperref}
\usepackage{ragged2e}

\begin{document}

We use this dataset
\footnote{\url{http://archive.ics.uci.edu/ml/datasets/Parkinson+Speech+Dataset+with++Multiple+Types+of+Sound+Recordings\#}}
for experimentation.
\end{document} 

After searching the web, this post suggests using \RaggedRight from the ragged2e package. But I think the \RaggedRightdoes not "really" solve this problem, it just hides the "underfull \hbox" warning. Below is the produced footnote of the above MWE: enter image description here

After using the \RaggedRight command, i.e., change from

\footnote{\url{http://archive.ics.uci.edu/ml/datasets/Parkinson+Speech+Dataset+with++Multiple+Types+of+Sound+Recordings\#}}

in the MWE to

\footnote{\RaggedRight\url{http://archive.ics.uci.edu/ml/datasets/Parkinson+Speech+Dataset+with++Multiple+Types+of+Sound+Recordings\#}}

. The warning disappears. But the produced footnote is (in my opinion) the same as before, see the image below: enter image description here

My question is, how to "really" solve this problem? In my naive thought, why not LaTeX move some charcters from the second line, say the characters "+Multipl", to the empty space in the end of first line. After all, url are just a series of charcters, why not stuff the first line with some charcters from the second line to make full use of first line? Or there are some hidden facts which are very complicated?

Any answers or pointer to answers are appreciated!

jdhao
  • 711

3 Answers3

9

Rather than breaking mid-word, you can re-introduce some stretch space around the break characters (. and / here) I use

\Urlmuskip=0mu  plus 10mu

which allows more than enough flexibility in this case.

enter image description here

\documentclass{article}
\usepackage{hyperref}

\Urlmuskip=0mu  plus 10mu
\begin{document}

We use this dataset
\footnote{\url{http://archive.ics.uci.edu/ml/datasets/Parkinson+Speech+Dataset+with++Multiple+Types+of+Sound+Recordings\#}}
for experimentation.

\vfill

\noindent X\dotfill X
\end{document} 
David Carlisle
  • 757,742
7

\url tries hard to break the url only at "sensible" places. But if you don't like this you can allow \url to break everywhere:

\documentclass{article}
\usepackage{hyperref}

\makeatletter
\g@addto@macro{\UrlBreaks}{%
\do\/\do\a\do\b\do\c\do\d\do\e\do\f%
\do\g\do\h\do\i\do\j\do\k\do\l\do\m%
\do\n\do\o\do\p\do\q\do\r\do\s\do\t%
\do\u\do\v\do\w\do\x\do\y\do\z%
\do\A\do\B\do\C\do\D\do\E\do\F\do\G%
\do\H\do\I\do\J\do\K\do\L\do\M\do\N%
\do\O\do\P\do\Q\do\R\do\S\do\T\do\U%
\do\V\do\W\do\X\do\Y\do\Z}
\makeatother
\begin{document}

We use this dataset
\footnote{\url{http://archive.ics.uci.edu/ml/datasets/Parkinson+Speech+Dataset+with++Multiple+Types+of+Sound+Recordings\#}}
for experimentation.
\end{document} 

enter image description here

Be aware that as there are no stretchable spaces the line is still a bit underfull.

Ulrike Fischer
  • 327,261
  • might not microtype help by slightly deforming the characters in the string? (not saying that it's a good idea ...) – barbara beeton Nov 17 '16 at 15:11
  • 1
    @Ulrike Fischer, why are there still underfull warning when the first line is seemingly fully used? – jdhao Nov 17 '16 at 15:29
  • @barbarabeeton: Perhaps, but not by default (microtype imho doesn't expand typewriter fonts, beside this url uses math spacing). – Ulrike Fischer Nov 17 '16 at 15:34
  • @ the code in the preamble is a bit long (no offence), is there a more elegant way to do that? By the way, any pointer to how the calculation of badness works(the badness is still 10000, not changed) – jdhao Nov 17 '16 at 15:37
  • You can active font expansion for the typewriter if you want to get rid of the underfull hbox: \usepackage{microtype}\UseMicrotypeSet [expansion] {alltext}. – Ulrike Fischer Nov 17 '16 at 16:09
  • @Hao -- Length and elegance in code do not necessarily have a one-to-one correspondence. hyperref.sty itself is nearly 9000 lines long. But there's nothing to prevent you from putting the code inbetween the \makeat...commands into your own .sty file that you load after hyperref.... – jon Nov 17 '16 at 19:00
  • @UlrikeFischer, \usepackage{microtype}\UseMicrotypeSet [expansion] {alltext} does not solve the problem. There are still "underfull \hbox" warning. – jdhao Nov 18 '16 at 07:48
1

A solution that worked for me was to replace \url with \href. However, if your URL does not contain any breakable character (e.g. -), you will have to help it find by inserting some \hspace{0pt} (zero-width space) at strategic locations.

In your case, I added one after each '+'.

\footnote{\href{http://archive.ics.uci.edu/ml/datasets/Parkinson+Speech+Dataset+with+Multiple+Types+of+Sound+Recordings\#}{http://archive.ics.uci.edu/ml/datasets/Parkinson+\hspace{0pt}Speech+\hspace{0pt}Dataset+\hspace{0pt}with+\hspace{0pt}Multiple+\hspace{0pt}Types+\hspace{0pt}of+\hspace{0pt}Sound+\hspace{0pt}Recordings\#}}
  • The url can not be split into two lines if it is too long to fit in one line. Have you checked your answer? – jdhao Feb 02 '18 at 08:19
  • Thanks for the kind feedback. As mentioned above, I indeed checked it and it worked well on my own case. However I did notice that my URL happened to contains breakable chars (-) and that it would not work if an URL does not. In this case, one will have to insert some \hspace{0pt} at strategic locations in the text part. I updated my answer. – Quentin Roy Feb 02 '18 at 08:31
  • I think it is a bit awkward to manually adjust the url. If we have several url to process, it would be tedious and error-prone. – jdhao Feb 02 '18 at 08:37
  • If I may, we’re talking about word processing not programming. This is latex not C or python :) – Quentin Roy Jun 09 '18 at 22:02