# Cannot compile bibliography with URL in it

I'm writing my first document in LaTeX and I'm using natbib for the bibliography and dcu as the style.

This is what I've written:

@misc{et,
author = "Engineering Toolbox",
year = "2003",
title = "Young's Modulus - Tensile and Yield Strength for common Materials",
URL = "\url{https://www.engineeringtoolbox.com/young-modulus-d_417.html}",
note = "[online]"
}


This is what I get when I try to compile it. I've used the url package with \usepackage{url} in the .tex file, and putting the URL in \url{} in the .bib file. It doesn't work with or without \url{} and I don't know what to do.

Also I've put [online] in note because the actual style I'm trying to replicate requires it but I don't know if it will appear correctly as I haven't seen the file compile yet. The [online] is supposed to come after the title.

• You don't need to add an additional \url{...} in the url field URL = "https://www.engineeringtoolbox.com/young-modulus-d_417.html", is enough. But you will need to tell natbib about using \url in a slightly different way: tex.stackexchange.com/q/9445/35864 – moewe Mar 30 at 22:15
• I see there that they needed to tell \harvardurl to actually use \url{} but I don't know how to apply that to this problem because I'm not using \harvardurl. – oyylumo Mar 30 at 22:23
• The dcu style I found on CTAN (ctan.org/tex-archive/macros/latex/contrib/harvard) uses the command \harvardurl to typeset its URL, so if you are using that style you are using \harvardurl. Did you try the suggested answer to the linked question? Did it not help? – moewe Mar 30 at 22:29
• Write author = "{Engineering Toolbox}", (see tex.stackexchange.com/q/10808/35864). Personally I think the monotype font is not a bad idea for URLs and don't think it is weird at all, but YMMV. You could try \urlstyle{same} to get the normal surrounding font. The linked answer also suggests a way to change the font for the URLs back to italics, which is roughly what you would have gotten without the code. – moewe Mar 30 at 22:52

• Since you're using the dcu bibliography style, which is part of the harvard citation management package, you should load the har2nat package to optimize interoperability with the natbib package. Doing so is especially important if you plan on using the hyperref package as well.

• The dcu bib style recognizes a field called url. Hence, no need to encase the URL string in a \url{..} "wrapper".

• If you don't like the default behavior of \harvardurl, just follow @moewe's advice and issue the directive

\renewcommand{\harvardurl}[1]{\url{#1}} % per @moewe's suggestion

• Since the author of the piece is a "corporate" entity, be sure to encase its contents in an extra pair of curly braces. This will prevent BibTeX from parsing the name as having first-name component "Electrical" and surname component "Toolbox".

\RequirePackage{filecontents}
\begin{filecontents}{mybib.bib}
@misc{et,
author = "{Engineering Toolbox}",
year   = "2003",
title  = "Young's Modulus -- {Tensile} and Yield Strength for common Materials",
url    = "https://www.engineeringtoolbox.com/young-modulus-d_417.html",
xnote  = "[online]"
}
\end{filecontents}

\documentclass{article}
\usepackage[T1]{fontenc}
\setcitestyle{aysep={,}}
\bibliographystyle{dcu}
\renewcommand{\harvardurl}[1]{\url{#1}} % per @moewe's suggestion
\usepackage{xurl}

• Is har2nat really necessary for hyperref? The source code looks like the package would basically only make some harvard commands available that would otherwise not be defined by natbib and changes the behaviour of \cite and \citeyear a bit. If one uses only natbib commands, then har2nat does not seem to offer much. – moewe Mar 31 at 12:24
• @moewe - See Why do hyperref and harvard not work together properly? (and especially my answer...), and also this answer. Quoting myself [!]: "[T]he har2nat package 'translates' harvard-package citation commands (such as \citeasnoun) to equivalent natbib-package citation commands. That way, you can keep using the harvard-package citation commands while getting all the benefits of the good interplay between the natbib and hyperref packages." – Mico Mar 31 at 12:41
• @moewe - For sure, I would only ever load the har2nat package when I'm forced to work with a bibliography style provided by the harvard citation management package. – Mico Mar 31 at 12:43