1

I'm using apacite to produce the bibliography. I'm also using this line of code \newcommand*{\doi}[1]{\href{http://dx.doi.org/#1}{#1}} before \begin{document} to hyperlink the DOI string which works perfectly. It was taken from here and I had to change it a little bit since the apacite prints out "doi: "

The problem is, in the bibliography there is a white space between the colon and the string which shouldn't be there according to APA style.

As an example I get doi: 10.1348/014466604X18523 in the bibliography which should be doi:10.1348/014466604X18523.

I tried to play with apacite.bst but I couldn't figure it out. How can I fix this, preferably in the main .tex file?

2 Answers 2

1

The space is there in the .bbl file already

\begin{APACrefDOI} \doi{10.1348/014466604X18523} \end{APACrefDOI}

So you could edit the .bst file not to add a space, or we can add \ignorespaces to the APACrefDOI environment.

\documentclass[british]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{hyperref}
\usepackage{apacite}% load apacite after hyperref, see §8.2 of the apacite manual

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@article{appleby,
  author  = {Humphrey Appleby},
  title   = {On the Importance of the Civil Service},
  year    = {1980},
  doi     = {10.1348/014466604X18523},
}
\end{filecontents}

\newcommand*{\doi}[1]{\href{https://doi.org/#1}{#1}}
\makeatletter
\renewenvironment{APACrefDOI}{%
  \global\let\old@doi\doi
  \if@doi
    \doiprefix
  \else
    \global\let\doi\@gobble
  \fi
  \ignorespaces
  }{\global\let\doi\old@doi }
\makeatother

\begin{document}
\cite{appleby}
\bibliographystyle{apacite}
\bibliography{\jobname}
\end{document}

enter image description here


If you prefer to modify the .bst file, you need to follow the steps below.

  1. Locate apacite.bst on your machine for example by typing kpsewhich apacite.bst.
  2. Copy the file to a place where LaTeX can find it (https://texfaq.org/FAQ-inst-wlcf), the directory of your document will do just fine, and rename it to apacite-nspdoi.bst, say. Note that the license of apacite.bst requires you to change the name of the file if you modify it.
  3. Open apacite-nspdoi.bst and insert a header with the new file name and the current date
  4. Find FUNCTION {begin.end.doi.env} and replace the entire function with

    FUNCTION {begin.end.doi.env}
    { "\begin{APACrefDOI}"% removed trailing space here
      " \end{APACrefDOI} "
    }
    

    Where the only change to the original is that you delete the last space in "\begin{APACrefDOI} " to make it "\begin{APACrefDOI}".

  5. Save the file and use \bibliography{apacite-nspdoi} in your document.

Alternatively you can get apacite-nspdoi.bst from https://gist.github.com/moewew/520dbd08e1a7a3129a8838d5e6be34a3

\documentclass[british]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{hyperref}
\usepackage{apacite}% load apacite after hyperref, see §8.2 of the apacite manual

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@article{appleby,
  author  = {Humphrey Appleby},
  title   = {On the Importance of the Civil Service},
  year    = {1980},
  doi     = {10.1348/014466604X18523},
}
\end{filecontents}

\newcommand*{\doi}[1]{\href{https://doi.org/#1}{#1}}

\begin{document}
\cite{appleby}
\bibliographystyle{apacite-nspdoi}
\bibliography{\jobname}
\end{document}

The output is as above.

1

APA style guide re. DOI's is here. If you want to use the style where you have "https://doi.org/XXXXXX" and you want it to be a clickable link from your .pdf than you can add the following to your preamble.

\usepackage[natbibapa]{apacite}
\usepackage{hyperref}
\makeatletter
\newcommand*{\doi}[1]{\href{https://doi.org/#1}{https://doi.org/#1}}
\renewcommand{\doiprefix}{}
\makeatother

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .