1

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.

  • 1
    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
  • 1
    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
  • 1
    Did you run BibTeX and LaTeX again after applying the changes in the .bib file? How did adding the curly braces not help? The bold URL: is causes by the \textbf{URL:} in the redefinition of \harvardul. Try something like \renewcommand{\harvardurl}[1]{URL:~\url{#1}} or \renewcommand{\harvardurl}[1]{\url{#1}} – moewe Mar 30 at 23:00
1

Some suggestions and comments:

  • 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".

enter image description here

\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}
\usepackage{har2nat} % loads 'natbib' automatically
\setcitestyle{aysep={,}}
\bibliographystyle{dcu}
\renewcommand{\harvardurl}[1]{\url{#1}} % per @moewe's suggestion
\usepackage{xurl}
\usepackage[colorlinks,allcolors=blue]{hyperref} % optional

\begin{document}
\citep{et}
\bibliography{mybib}
\end{document}
  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.