16

One functionality of BibDesk that is nice is the ability to click on a link at the end of the Doi entry field, which will open up the link http://dx.doi.org/DOI-HERE in a browser.

enter image description here

One problem I've just run into with bibliography styles that display DOIs in the References section (e.g., unified) is that a Doi entry that contains an underscore will be printed as a subscript in the References section.

For example, this code:

\documentclass{article}

\usepackage{natbib}

\begin{document}

\citet{chomsky1977b}
\citet{chomsky1977b-test}

\bibliographystyle{unified}
\bibliography{master}

\end{document}

produces this output

enter image description here

where chomsky1977b is

@article{chomsky1977b,
    Author = {Chomsky, Noam and Lasnik, Howard},
    Doi = {10.1007/978-94-015-6859-3_4},
    Journal = {Linguistic Inquiry},
    Keywords = {control theory, syntax},
    Number = {3},
    Pages = {425-504},
    Title = {Filters and Control},
    Volume = {8},
    Year = {1977}}

and chomsky1997b-test is

@article{chomsky1977b-test,
    Author = {Chomsky, Noam and Lasnik, Howard},
    Doi = {10.1007/978-94-015-6859-3{\_}4},
    Journal = {Linguistic Inquiry},
    Keywords = {control theory, syntax},
    Number = {3},
    Pages = {425-504},
    Title = {Filters and Control},
    Volume = {8},
    Year = {1977}}

Of course, the Doi entry in chomsky1997b-test breaks the BibDesk functionality of opening the link in a browser, as it opens http://dx.doi.org/10.1007/978-94-015-6859-3{\_}4 rather than http://dx.doi.org/10.1007/978-94-015-6859-3_4.

Is there a way to retain this functionality yet still ensure that the DOI is printed correctly in the References section when using a style that prints the DOI?

15

For your particular example (of the unified.bst) style, it suffices to add the following line to your preamble (and load the hyperref package)

\newcommand{\doi}[1]{\textsc{doi}: \href{http://dx.doi.org/#1}{\nolinkurl{#1}}}

The MWE

\documentclass{article}

\usepackage{natbib}
\usepackage{hyperref}

\begin{filecontents}{\jobname.bib}
@article{chomsky1977b,
    Author = {Chomsky, Noam and Lasnik, Howard},
    Doi = {10.1007/978-94-015-6859-3_4},
    Journal = {Linguistic Inquiry},
    Keywords = {control theory, syntax},
    Number = {3},
    Pages = {425-504},
    Title = {Filters and Control},
    Volume = {8},
    Year = {1977}}
\end{filecontents}

\newcommand{\doi}[1]{\textsc{doi}: \href{http://dx.doi.org/#1}{\nolinkurl{#1}}}

\begin{document}

\citet{chomsky1977b}

\bibliographystyle{unified}
\bibliography{\jobname}

\end{document}

then yields enter image description here

| improve this answer | |
  • 2
    One has to note though that while this solution works in this particular example, it cannot be universally applied. It really depends on how printing the DOI is implemented in the .bst file. One certainly has to have a look at the .bst file to find out whether printing is implemented via a dedicated command (as was done here with \doi{foo}) or directly; in the latter case it will (probably) be necessary to edit the .bst file. – moewe Dec 20 '13 at 14:00
  • This is nice, but only if using the unified style. For conferences where styles are given and cannot be modified, there is no easy fix. – peschü Apr 20 '16 at 7:42
  • @peschü That's pretty much what my comment above said as well. If you have a conference style that you can't modify you would probably expect that that style gives the required output... – moewe Apr 20 '16 at 12:51
7

If you look at your .bst, i.e. the BibTeX style file, there should be a function formating the DOI output.

There you could use \hreffrom the hyperref package and \detokenize as mentioned here or here, you can do something like

FUNCTION {format.doilink}
{ duplicate$ empty$
{ pop$ "" }
{ doi empty$
    { skip$ }
    { "{,\ doi:~\href{http://dx.doi.org/" * doi * "}{\detokenize{" * doi * "}}}" * }
  if$
}
if$
}

which is based on the naming used in style files of the elsevier BibTeX files, so your function in the .bst file might differ in naming. The function above pouts a “doi:” in front, as your example suggests. So you could just search your style file for that and change the output after that.

| improve this answer | |
  • + 1, though I think I will accept the other answer, as it does not require modifying the .bst file. Also, as a side note, for some reason I have to load \usepackage[T1]{fontenc} when compiling, otherwise \detokenize{_} is rendered as what seems to be U+05C4. One last note, I assume you mean hyperref and not hyperlink? – Adam Liter Dec 20 '13 at 0:40
  • 1
    Yep, I should've added an MWE, of course you neet T1and of course i meant hyperref. I edited my answer. The advantage of this solution, it also works for styles not using a \doi command (mine had not even an idea of handling doi entries. But of course, editing a .bst might not be that much fun ;) – Ronny Dec 20 '13 at 6:17
  • So it seems. I just asked about that here. I didn't realize OT1 was the default for LaTeX. Silly me. Anyway, thanks again for the answer! – Adam Liter Dec 20 '13 at 6:22
3

There is a nice solution to similar issue by Roly in Missing $ inserted issue, who recommends to use \usepackage[strings]{underscore}.

The package arranges that, while in text, ‘_’ itself behaves as \textunderscore (the behaviour of _ in maths mode is not affected).

| improve this answer | |

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.