10

I have an external bib where I put a reference to an external URL.

@misc{myreference,
  author = {The Author},
  title = {The Title},
  howpublished = "\url{http://thisismyurl/2010/3/a-long-url-here}",
  year = {year}
}

When I compile, the URL (when displayed in Bibliography) exceeds the bounds of the page (set as customs). The URL is composed by different terms concatenated with - symbol. a-long-url-here can be the following:

abc-abc-abca-abc-ab-abc-abc-abc-a-abcabc-ab-abc-abc/

The bib is inserted in the following manner:

\bibliographystyle{IEEEbib}
\bibliography{bibliog}

Is there any mechanism to fix this behaviour? I checked Line breaking of URLs in bibliographies but I don't know how to use it in my situation.

Edit

For the sake of completeness, I use PdfLatex.

Lorenzo B
  • 427
  • Did you try the suggested \sloppy and \emergencystretch settings? – mafp Dec 28 '12 at 18:47
  • @mafp No. Where do I have to put these commands? Thanks. – Lorenzo B Dec 28 '12 at 18:52
  • 5
    since the url package allows breaks, it sounds like you are using hyperref, which doesn't allow them by default. if you specify the option \usepackage[breaklinks]{hyperref} you should get better results. of course, this is just a guess; i'm not familiar with the IEEEbib style, so it may apply some restrictions i'm not aware of. – barbara beeton Dec 28 '12 at 18:58
  • Indeed, try barbara's tip with \usepackage[breaklinks]{hyperref} first. Note that this will only work when you produce pdf output. – mafp Dec 28 '12 at 19:10
  • @barbarabeeton thanks for your reply. but that package does not work for me. – Lorenzo B Dec 28 '12 at 20:04
  • It gives me Option clash for package hyperref. – Lorenzo B Dec 28 '12 at 20:30
  • 3
    To avoid the option clash, you can type \hypersetup{breaklinks=true}. – Mico Dec 28 '12 at 20:51
  • @Mico no chance. I set \hypersetup{breaklinks=true} followed by \usepackage[breaklinks]{hyperref} but the error still remains the same. – Lorenzo B Dec 29 '12 at 09:04
  • 1
    Don't provide both of these instructions, but only the first one -- after the hyperref package has been loaded either directly by one of your own instructions or indirectly by one of the packages you load (or by the document class). – Mico Dec 30 '12 at 00:15
  • @Mico Thank you for your support but the url does not break correctly. Is there any option that I can use for url package? – Lorenzo B Dec 30 '12 at 10:44
  • Have you tried Barbara Beeton's suggestion, which was to load the url package with the hyphens option set: \usepackage[hyphens]{url}? Do load this package before loading hyperref. – Mico Dec 30 '12 at 19:10
  • @Mico Thanks for your reply. What packages do I have to use (if possible list them)? I'm a bit lost. – Lorenzo B Dec 30 '12 at 19:15
  • I've provided an answer with an MWE (minimum working example) that shows how you may get a URL string to break at hyphens. – Mico Dec 30 '12 at 21:35

2 Answers2

8

Assuming that you have a file named bibliog.bib with the contents given in your posting, the following MWE (minimum working example) generates a reference with the URL string broken at a hyphen. The key steps are (i) load the url package with the hyphens option and (ii) enable the breaklinks=true option of the hyperref package.

\documentclass{article}
\usepackage[hyphens]{url}
\usepackage{hyperref}
\hypersetup{colorlinks=true,breaklinks=true}
\setlength\textwidth{4in} % simulate a very narrow line width
\begin{document}
\nocite{*}
\bibliographystyle{IEEEtran} % *not* IEEEbib...
\bibliography{bibliog}
\end{document}

enter image description here

Mico
  • 506,678
0

Nothing worked mentioned here in my case. Finally \usepackage{xurl} worked in my case. I followed the following link answer Forcing a bibliography link with very long file name to stay within column width

Yuba
  • 1