7

I am trying to make a hyperlink in my bibliography referring the doi-url. The url begins with journal name and ends with the pages. Do to this I am using the code provided by Mateus Araújo in hyperlinks in biblatex. Unfortunately this also changes the style. For example, a normal reference looks likes this

enter image description here

But after adding the code do make the doi-hyperlink, it adds a dot after year and starts with a an uppercase letter.

enter image description here

I would like to remove the dot and start with a lowercase letter, but don't know how do that.

Here is a the code:

\documentclass{article}
\usepackage[backref=true]{biblatex}
\usepackage[colorlinks]{hyperref}
\bibliography{biblatex-examples}

\ExecuteBibliographyOptions{doi=false}
\DeclareFieldFormat{doilink}{
\iffieldundef{doi}{#1}
{\href{http://dx.doi.org/\thefield{doi}}{#1}}}

\DeclareBibliographyDriver{article}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{author/translator+others}%
  \setunit{\labelnamepunct}\newblock
  \usebibmacro{title}%
  \newunit
  \printlist{language}%
  \newunit\newblock
  \usebibmacro{byauthor}%
  \newunit\newblock
  \usebibmacro{bytranslator+others}%
  \newunit\newblock
  \printfield{version}%
  \newunit\newblock
  \usebibmacro{in:}%
  \href{http://dx.doi.org/\thefield{doi}}{%
  \usebibmacro{journal+issuetitle}%
  \newunit\newblock
  \usebibmacro{byeditor+others}%
  \newunit\newblock
  \usebibmacro{note+pages}}%
  \newunit\newblock
  \iftoggle{bbx:isbn}
   {\printfield{issn}}
   {}%
  \newunit\newblock
  \usebibmacro{doi+eprint+url}%
  \newunit\newblock
  \usebibmacro{addendum+pubstate}%
  \newunit\newblock
  \usebibmacro{pageref}%
  \usebibmacro{finentry}
  }

\begin{document}
\cite{kastenholz}
\printbibliography
\end{document}
2
  • You might be able to rephrase your question title so that it matches your questions better.
    – N.N.
    Sep 7, 2011 at 10:05
  • I hope the new title makes it clearer
    – maetra
    Sep 7, 2011 at 11:20

2 Answers 2

8

In the linked question is used another bibliography driver.

EDIT 2: Comment by maetra:

I recognized that using this together with any of the author-year styles results in an extra space after the link if no pages are defined. Maybe you know a solution?

Solution:

In the version 1.6 of biblatex is a small bug in the file authoryear.bbx. The style redefine the macro issue+date. The redefinition of the macro depends on the option mergedate. If the option is set to true or compact the redefinition is as follows:

\renewbibmacro*{issue+date}{%
  \iffieldundef{issue}
    {}
    {\printtext[parens]{\printfield{issue}}}
  \newunit}%

Before the last \newunit work there is a none escaped space which results in the extra space. So you have to do this:

\renewbibmacro*{issue+date}{%
  \iffieldundef{issue}
    {}
    {\printtext[parens]{\printfield{issue}}}%
  \newunit}%

This fixes the problem.

EDIT 1: Changed Code.

\documentclass{article}
\usepackage[backend=biber,backref=true]{biblatex}
\addbibresource{biblatex-examples.bib}

\usepackage[colorlinks]{hyperref}

\ExecuteBibliographyOptions{doi=false}
\ExecuteBibliographyOptions{doi=false}
\DeclareFieldFormat{doilink}{%
\iffieldundef{doi}{#1}%
{\href{http://dx.doi.org/\thefield{doi}}{#1}}}

\DeclareBibliographyDriver{article}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{author/translator+others}%
  \setunit{\labelnamepunct}\newblock
  \usebibmacro{title}%
  \newunit
  \printlist{language}%
  \newunit\newblock
  \usebibmacro{byauthor}%
  \newunit\newblock
  \usebibmacro{bytranslator+others}%
  \newunit\newblock
  \printfield{version}%
  \newunit\newblock
  \usebibmacro{in:}%
  \printtext[doilink]{%
  \usebibmacro{journal+issuetitle}%
  \newunit
  \usebibmacro{byeditor+others}%
  \newunit
  \usebibmacro{note+pages}%
  }%
  \newunit\newblock
  \iftoggle{bbx:isbn}
    {\printfield{issn}}
    {}%
  \newunit\newblock
  \usebibmacro{doi+eprint+url}%
  \newunit\newblock
  \usebibmacro{addendum+pubstate}%
  \setunit{\bibpagerefpunct}\newblock
  \usebibmacro{pageref}%
  \usebibmacro{finentry}}


\begin{document}
\cite{kastenholz}\qquad\cite{herrmann}\qquad\cite{sigfridsson}
\printbibliography
\end{document}

enter image description here

14
  • thanks Marco, this solves the problem of the period and the capital letter, unfortunately it adds two spaces after "In:"
    – maetra
    Sep 7, 2011 at 11:13
  • @maetra: The additional space based on the definition \DeclareFieldFormat{doilink}{. There I forgot to end the line with % Sep 7, 2011 at 11:39
  • this code is not working anymore, it seems as if you made too many changes
    – maetra
    Sep 7, 2011 at 11:59
  • 1
    @maetra: The code works well for me. Sep 7, 2011 at 12:01
  • @maetry: What's your problem. Has you recognised that I use backend=biber. I use biblatex v1.6. Sep 7, 2011 at 12:20
1

Marco's solution worked fine for me too. Just for some reason the year was missing in the references when I used his answer. So added these two lines to his code

\newunit
\space(\usebibmacro{date})%

to include the year as well. Also I used this post to make hyperlinks for urls or isbns whenever doi is not available. Below is the modified version of Marco's code:

\documentclass{article}
\usepackage[backend=biber,backref=true]{biblatex}
\addbibresource{biblatex-examples.bib}

\usepackage[colorlinks]{hyperref}


\ExecuteBibliographyOptions{doi=false}
\ExecuteBibliographyOptions{doi=false}
\DeclareFieldFormat{doilink}{%
  \iffieldundef{doi}{%
    \iffieldundef{url}{%
      \iffieldundef{isbn}{%
        \iffieldundef{issn}{%
          #1%
        }{%
          \href{http://books.google.com/books?vid=ISSN\thefield{issn}}{#1}%
        }%
      }{%
        \href{http://books.google.com/books?vid=ISBN\thefield{isbn}}{#1}%
      }%
    }{%
      \href{\thefield{url}}{#1}%
    }%
  }{%
    \href{http://dx.doi.org/\thefield{doi}}{#1}%
  }%
}
\DeclareBibliographyDriver{article}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{author/translator+others}%
  \setunit{\labelnamepunct}\newblock
  \usebibmacro{title}\addcomma\space%
  \newunit
  \printlist{language}%
  \newunit\newblock
  \usebibmacro{byauthor}%
  \newunit\newblock
  \usebibmacro{bytranslator+others}%
  \newunit\newblock
  \printfield{version}%
  \newunit\newblock
  \printtext[doilink]{%
  \usebibmacro{journal+issuetitle}%
  \newunit
  \usebibmacro{byeditor+others}%
  \newunit
  \usebibmacro{note+pages}%
  \newunit
  \space(\usebibmacro{date})%
  }%
  \newunit\newblock
  \iftoggle{bbx:isbn}
    {\printfield{issn}}
    {}%
  \newunit\newblock
  \usebibmacro{doi+eprint+url}%
  \newunit\newblock
  \usebibmacro{addendum+pubstate}%
  \setunit{\bibpagerefpunct}\newblock
  \usebibmacro{pageref}%
  \usebibmacro{finentry}}

\begin{document}
\cite{kastenholz}\qquad\cite{herrmann}\qquad\cite{sigfridsson}
\printbibliography
\end{document}

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.