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.

Mico
  • 506,678
oyylumo
  • 13
  • 2
  • 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: https://tex.stackexchange.com/q/9445/35864 – moewe Mar 30 '19 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 '19 at 22:23
  • The dcu style I found on CTAN (https://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 '19 at 22:29
  • I tried it and it worked :) Unfortunately it shortens "Engineering Toolbox" to "Toolbox, E." and the URL: https://... is in a weird font. Is there an easy fix for that? – oyylumo Mar 30 '19 at 22:48
  • 1
    Write author = "{Engineering Toolbox}", (see https://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 '19 at 22:52
  • Putting "{Engineering Toolbox}" did not work. And I think the monotype font for the URL is good, but the part that says URL: is in a weird bold Times New Roman looking font which I don't like. Also I thought putting \emph{} around the title would make it italic but it isn't doing that. – oyylumo Mar 30 '19 at 22:56
  • 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 '19 at 23:00
  • First: Since you’re using the dcu bibliography style, you really should use the har2nat package. Second: After adding an extra pair of curly braces in the author field, did you first delete all six files (including the bbl file) and second perform a full recompile cycle (LaTeX, BibTeX, and LaTeX twice more)? – Mico Mar 30 '19 at 23:00
  • moewe, I did recompile LaTeX, BibTeX, LaTeX x2 and it still said "Toolbox, E." and Mico, what are the six files and what is a bbl file? (This is my first LaTeX document) Also what does har2nat do? – oyylumo Mar 30 '19 at 23:12
  • never mind, I hadn't saved the .bib file :s

    Thank you very much for the help both of you :)

    – oyylumo Mar 30 '19 at 23:19
  • Sorry, my iphone software auto-corrected [right!] "aux" to "six". I didn't notice in time. The har2nat provides improved compatibility of bibliography styles (such as dcu) that are part of the harvard citation management package with natbib. – Mico Mar 30 '19 at 23:26
  • Try changing URL into HOWPUBLISHED. It works for me. – Arnaud Mortier Mar 30 '19 at 23:46

1 Answers1

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}
Mico
  • 506,678
  • 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 '19 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 '19 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 '19 at 12:43