3

I want the output as below:

(1) An online journal article with a DOI enter image description here

(2) A website enter image description here

(3) A journal article enter image description here

I want to do a citing for An online journal article with a DOI using the format below:

enter image description here

My Output is:

enter image description here

I am using:

% An online journal article with a DOI using @article
@article{Test2,
    author = {Kovalchuk, Y. and Stewart, R. and Broadbent, M. and Hubbard, T. J. P. and Dobson, R. J. B.},
    title  = {Analysis of diagnoses extracted from electronic health records in a large mental health case register},
    journal = {Plus One},
    volume = "12",
    number = "2",
    date   = {2017},
    DOI = "http://dx.doi.org/10.1371/journal.pone.0171526",
}

If I use @online.

% An online journal article with a DOI using @Online
@online{Test1,
    author = {Kovalchuk, Y. and Stewart, R. and Broadbent, M. and Hubbard, T. J. P. and Dobson, R. J. B.},
    title  = {Analysis of diagnoses extracted from electronic health records in a large mental health case register},
    journal = {Plus One},
    volume = "12",
    number = "2",
    date   = {2017},
    url    = {http://dx.doi.org/10.1371/journal.pone.0171526},
}

The output below where the title become italic which I do not want for citing a website. enter image description here

My Full MWE:

\documentclass{article}
\usepackage{xpatch}
% \usepackage[style = authoryear-comp, maxnames = 99]{biblatex}

\usepackage[backend=biber, 
% style=authoryear, 
 style=authoryear-comp,
% citestyle=authoryear, 
dashed=false,
maxcitenames=2,
maxbibnames=99,
giveninits,
alldates=comp,
dateabbrev=false,
uniquename=init]{biblatex}

% to make volume (number), eg. 4(2)
\newcommand*{\volnumdelim}{}
\DeclareFieldFormat[article,periodical]{number}{\mkbibparens{#1}}

\renewbibmacro*{volume+number+eid}{%
  \printfield{volume}%
  \setunit*{\volnumdelim}%
  \printfield{number}%
  \setunit{\addcomma\space}%
  \printfield{eid}}

\newcommand*{\jourvoldelim}{\addcomma\space}
\newcommand*{\jourserdelim}{\newunitpunct}
\newcommand*{\servoldelim}{\jourvoldelim}
\newcommand*{\volnumdatedelim}{\addspace}

\renewbibmacro*{journal+issuetitle}{%
  \usebibmacro{journal}%
  \setunit*{\jourvoldelim}%
  \iffieldundef{series}
    {}
    {\setunit*{\jourserdelim}%
     \printfield{series}%
     \setunit{\servoldelim}}%
  \usebibmacro{volume+number+eid}%
  \setunit{\volnumdatedelim}%
  \usebibmacro{issue+date}%
  \setunit{\addcolon\space}%
  \usebibmacro{issue}%
  \newunit}  
% to make volume (number), eg. 4(2)
\DeclareNameAlias{sortname}{family-given} %for second and third author name
\DeclareFieldFormat{postnote}{\printtext[bibhyperref]{#1}}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage[english]{babel}
\usepackage{csquotes}



\addto\captionsenglish{
\renewcommand{\listfigurename}{\textsf{List of Figures}}
\renewcommand{\listtablename}{\textsf{List of Tables}}
}

% Flag for whether to add front matter to TOC
\newtoggle{fulltoc}
\toggletrue{fulltoc}  % Change to \togglefalse{fulltoc} to remove front matter
\renewcommand{\contentsname}{Table of Contents}


\usepackage[unicode,colorlinks,citecolor=blue]{hyperref}


% for a chapter edited by a book
\usepackage{xpatch}
% \renewcommand*{\finalnamedelim}{\addspace\&\space} 
% \renewcommand*{\intitlepunct}{\space} (to become In:)
\renewcommand{\labelnamepunct}{\space} %to delete . after (1997)
% \DeclareFieldFormat[article, incollection, unpublished]{pages}{#1} % to add in PP. (page)
\DeclareFieldFormat[article, incollection, unpublished]{title}{#1}
% \renewcommand{\bibpagespunct}{\ifentrytype{article}{\addcolon}{\addperiod\addspace}} %cancel out this in order to add in PP. (page)


% for title italic
% \DeclareFieldFormat*{title}{\mkbibemph{#1}} %for title italic in all format (conference, paper..)
\DeclareFieldFormat*{title}{#1} %for conference title delete ".."
\DeclareFieldFormat[incollection]{title}{\mkbibemph{#1}} %for incollecion title italic ONLY
\DeclareFieldFormat[thesis]{title}{\mkbibemph{#1}} %for phdthesis title italic ONLY
% for title italic

% to delete "In:" for article
\renewbibmacro{in:}{%
  \ifentrytype{article}{}{\printtext{\bibstring{in}\intitlepunct}}}
% to delete "In:" for article


% for delete comma after Author A and Aurhor b
\DefineBibliographyExtras{english}{%
   \let\finalandcomma\empty
   \let\finalandsemicolon\empty
 }
\renewcommand{\compcitedelim}{\space\&\space}
\DeclareNameAlias{editorin}{given-family}

\newbibmacro*{byeditor:in}{%
  \ifnameundef{editor}
    {}
    {\printnames[editorin]{editor}%
     \setunit{\addcomma\space}%
     \usebibmacro{editorstrg}%
     \clearname{editor}}}     


\DeclareDelimFormat[textcite]{postnotedelim}{\addcolon\space}
\DeclareDelimFormat[parencite]{postnotedelim}{\addcolon\space}

% \DeclareFieldFormat{postnote}{#1}
\DeclareFieldFormat{postnote}{\printtext[bibhyperref]{#1}}
\DeclareFieldFormat{multipostnote}{#1}


% for references 's studies (year)
\renewcommand*{\nameyeardelim}{\addcomma\space}
\newcommand{\mycite}[1]{\citeauthor{#1}'s \citeyear{#1}}

\DeclareCiteCommand{\citeauthor}
  {\boolfalse{citetracker}%
   \boolfalse{pagetracker}%
   \usebibmacro{prenote}}
  {\ifciteindex
     {\indexnames{labelname}}
     {}%
   \printtext[bibhyperref]{\printnames{labelname}}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\citeyear} % <======================================
    {}
    {(\bibhyperref{\printdate})}
    {\multicitedelim}
    {}

\DeclareCiteCommand{\parencite}[\mkbibparens]
  {\renewcommand*{\postnotedelim}{\addcolon\space}%
   \usebibmacro{cite:init}%
   \usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \printtext[bibhyperref]{\usebibmacro{cite}}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\cbx@textcite}
  {\renewcommand*{\postnotedelim}{\addsemicolon\space}%
   \usebibmacro{cite:init}}
  {\usebibmacro{citeindex}%
   \usebibmacro{textcite}}
  {}
  {\usebibmacro{textcite:postnote}}  



\makeatletter
\let\abx@macro@textciteOrig\abx@macro@textcite
\renewbibmacro{textcite}{% <============================================
   \bibhyperref{%
   \let\bibhyperref\relax\relax%
   \abx@macro@textciteOrig%
   }%
}%
\makeatother
% for references 's studies (year)





\DeclareFieldFormat{url}{Available at\addcolon\space\url{#1}}
\DeclareFieldFormat{urldate}{\mkbibbrackets{\bibstring{urlseen}\space#1}}
\DeclareFieldFormat[online]{title}{\mkbibemph{#1}}
\DefineBibliographyStrings{english}{%
  urlseen = {Accessed},
}

\DefineBibliographyExtras{english}{%
  \protected\def\mkdaterangecomp{%
    \mkdaterangetrunc{long}}%
  \protected\def\mkdaterangeterse{%
    \mkdaterangetrunc{short}}%
  \protected\def\mkdaterangecompextra{%
    \mkdaterangetruncextra{long}}%
  \protected\def\mkdaterangeterseextra{%
    \mkdaterangetruncextra{short}}%
  \protected\def\mkbibdatelong#1#2#3{%
    \iffieldundef{#3}
      {}
      {\thefield{#3}%
       \iffieldundef{#2}{}{\nobreakspace}}%
    \iffieldundef{#2}
      {}
      {\mkbibmonth{\thefield{#2}}%
       \iffieldundef{#1}{}{\space}}%
    \iffieldbibstring{#1}
      {\bibstring{\thefield{#1}}}
      {\dateeraprintpre{#1}\stripzeros{\thefield{#1}}}}%
}





\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}


% An online journal article with a DOI using @Online
@online{Test1,
    author = {Kovalchuk, Y. and Stewart, R. and Broadbent, M. and Hubbard, T. J. P. and Dobson, R. J. B.},
    title  = {Analysis of diagnoses extracted from electronic health records in a large mental health case register},
    journal = {Plus One},
    volume = "12",
    number = "2",
    date   = {2017},
    url    = {http://dx.doi.org/10.1371/journal.pone.0171526},
}

% An online journal article with a DOI using @article
@article{Test2,
    author = {Kovalchuk, Y. and Stewart, R. and Broadbent, M. and Hubbard, T. J. P. and Dobson, R. J. B.},
    title  = {Analysis of diagnoses extracted from electronic health records in a large mental health case register},
    journal = {Plus One},
    volume = "12",
    number = "2",
    date   = {2017},
    DOI = "http://dx.doi.org/10.1371/journal.pone.0171526",
}

%M Maintain this format Website
@online{Maintain1,
    author = {World Health Organization},
    title  = {Global Health Observatory Data Repository},
    date   = {2014},
    url    = {http://www.who.int/gho/database/en/},
    urldate = {2014-12-23},
}

% Maintaine this format for Journal
@article{Maintain2,
  title={The building information modelling trajectory in facilities management: a review},
  author={Parn, E. A. and Edwards, D. J. and Sing, M. C. P.},
  journal={Automation in Construction},
  volume={75},
  pages={45--55},
  year={2017},
}

\end{filecontents*}

\addbibresource{\jobname.bib}

\begin{document}
\nocite{WinNT}

This is a ABC done by \textcite{Test1}.
book \parencite{Test2}
\textcite{Maintain1}
\textcite{Maintain2}

\printbibliography
\end{document}

where output: enter image description here

Thanks.

aan
  • 2,663
  • 1
    Please note that the doi field should only contain the DOI and not the whole resolver URL, so it should be doi = {10.1371/journal.pone.0171526}, and not doi = {http://dx.doi.org/10.1371/journal.pone.0171526},. If for some reason you want to give the full URL, you should use the url field. – moewe Oct 08 '19 at 16:07
  • Sorry, I don't quite get what you mean. In any case my suggestion was purely a point about sensible semantic input (the doi field takes only the DOI part, if you want the full URL with the resolved, then use url), I did not want to suggest that changing things as described would automatically make the "Available at" appear. The entry type is also largely independent of the actual display of the DOI. You should choose the type that makes sense: A paper that appeared in a journal would be an @article, a simple website an @online, ... – moewe Oct 09 '19 at 06:06
  • 1
    ... a database entry could be @dataset, if things fit no category you can take @misc. The entry with the DOI 10.1371/journal.pone.0171526 is certainly an @article. – moewe Oct 09 '19 at 06:07

1 Answers1

6

This question was already answered here: How to change "url" to "Available at" for citing a website in BibLatex?

I could change the DOI format by using the same process:

\DeclareFieldFormat{doi}{Available at\addcolon\space\url{#1}}

For the "no italic" part, I was inspired by the question described here: How to put & symbol in reference as paper title. I tried \& and the previous post. You need to redefine so that biblatex does not emphasize the text:

\DeclareFieldFormat[online]{title}{#1}

Final result:

enter image description here

EDIT

Alternative proposed by @moewe in the comments:

\DeclareFieldFormat{doi}{\bibstring{urlfrom}\addcolon\space\url{#1}}

This way you use a unique string for all formats that you would like to redefine. If you want to modify that string:

\DefineBibliographyStrings{english}{%
    urlfrom = {Available at}
}

To get all articles with italic titles you can use your previous commands:

\DeclareFieldFormat[article]{title}{\mkbibemph{#1}}

Last but not least, the "World Health Organization" has no family name. It is like a corporation so you must tell bib(la)tex to not parse the name. It's done by putting an additional pair of { }, like this:

author = {{World Health Organization}},
  • 1
    It would be a bit nicer to use a bibstring here. The bibstring urlfrom would come to mind, its usual English definition is available from, but that can of course be changed with \DefineBibliographyStrings. – moewe Oct 08 '19 at 15:58
  • 2
    Redefining the bibstring alone indeed does not help, you'd need something like \DeclareFieldFormat{doi}{\bibstring{urlfrom}\addcolon\space\url{#1}} in addition, since it is not used by the DOI field format by default. – moewe Oct 08 '19 at 16:06
  • @AlexandreQuenon, Sorry. But then for the 3rd referencing, it suppose the title of the website is italic.Global Health Observatory Data Repository. Available, but is not italic. But the 1st reference, I want toitalicfortitleaccording theHarvard referencing for An online journal article with a DOI. – aan Oct 08 '19 at 16:10
  • @aan I checked your reference. it is not an article but a database. Are you sure about the referencing format? – Alexandre Quenon Oct 08 '19 at 16:16
  • @AlexandreQuenon, are you referring to 3rd referencing? If yes, it is an article. At page 47 of Harvard Referencing link here https://bcuassets.blob.core.windows.net/docs/BCU%20Harvard%20Referencing%20Guidelines%20Version%201st%20September%202019%20v3.pdf – aan Oct 08 '19 at 16:22
  • @AlexandreQuenon thanks. So I only add in \DeclareFieldFormat{doi}{Available at\addcolon\space\url{#1}} and use @article it will works pefectly for my 3 reference 1. An online journal article; 2. A website; 3. A journal article. – aan Oct 08 '19 at 16:43
  • 2
    @aan Please don't ask about several, only tangentially related issues per question (https://tex.meta.stackexchange.com/q/7425/35864). The question of the string before the DOI is completely independent of any italics in the field format. Split those questions up. – moewe Oct 09 '19 at 06:02
  • @AlexandreQuenon the World Health Organization is an authorship of a wesbite. Sorry, i couldn't understand your edit part. Maybe I got confused. – aan Oct 09 '19 at 15:10
  • @aan if you have a close look at your 3rd reference, it is written "Organization, W.H." instead of "Workd Health Organization". To avoid this behavior is the purpose of the second pair of {} inside the authorfield. – Alexandre Quenon Oct 09 '19 at 15:12
  • @aan if you are satisfied with the explanations and the solution, could you please accept the answer? – Alexandre Quenon Oct 10 '19 at 05:55
  • @AlexandreQuenon I will. I am still checking with Overleaf and keep unable to compile. It said Timed out. Sorry, your compile took too long to run and timed out. This may be due to a large number of high-res images, or complicated diagrams.. Just give me few more days and I will get back here. Or remind me again please – aan Oct 15 '19 at 16:10