[Tex/LaTex] URL not showing correctly in latex IEEEtrans (both URL and Hyperref packages not working)

bibtexurl

I am working on a article using IEEEtrans template in overleaf, but I just noticed that a technical report reference with a URL doesn't compile correctly:

%Smith2040
@electronic{Smith2040,

 author   = "Smith, Matthew Nitch",

title     = "The number of cars worldwide is set to double by 2040",

url       = "\url{https://www.weforum.org/agenda/2016/04/the-number-of-cars-worldwide-is-set-to-double-by-2040}"
}

the url is printed as is, with \url{} also.

I get the aforementioned problem when using \usepackage{url}.
But, when using \usepackage{hyperref} I get fatal error.

Fatal error when using Hyperref package
is there a solution?

Best Answer

When using the IEEEtran bibliography style and the hyperref package, it's a mistake to encase the contents of the url field in a \url{...} wrapper. You should just write

url = "https://www.weforum.org/agenda/2016/04/the-number-of-cars-worldwide-is-set-to-double-by-2040",

enter image description here

Incidentally, I think it would be a really good idea for you to backfill the year and organization fields of this entry.

The following example loads the xurl package, rather than the url package. The only difference is that the former allows linebreaks inside a formatted URL string at any letter.

\RequirePackage{filecontents}
\begin{filecontents}{testbib.bib}
@electronic{Smith2040,
  author= "Smith, Matthew Nitch",
  title = "The number of cars worldwide is set to double by 2040",
  year  = 2016,
  organization = "World Economic Forum",
  url   = "https://www.weforum.org/agenda/2016/04/the-number-of-cars-worldwide-is-set-to-double-by-2040" 
}
\end{filecontents}

\documentclass{IEEEtran}
\bibliographystyle{IEEEtran}
\usepackage[spaces,hyphens]{xurl} % allow arbitrary line breaks in a formatted URL string
\usepackage[colorlinks,allcolors=blue]{hyperref}

\begin{document}
\cite{Smith2040}
\bibliography{testbib}
\end{document}
Related Question