ho-tex / doi

The small doi package for linking to doi.org
8 stars 2 forks source link

Formatting prefix and hyperlink #2

Open wmoreland opened 5 years ago

wmoreland commented 5 years ago

I'm struggling to make two changes to how the DOI is formatted by this package: 1) change the format of the prefix to use small caps; and 2) change the colour of the hyperlink.

  1. I tried to edit the \doitext command in doi.sty to: \newcommand{\doitext}{\textsc{doi: }} but when I compile my document I get an error associated with the .bbl file: Missing control sequence inserted. \newblock \doi{10.1002/andp.19053221004}
  2. I have set the options for the hyperref package to colour both links and citations blue but these options seem to be ignored by the doi package.

Does anyone have any suggestions? I've included my MWE file contents below. The doi.sty file is unchanged except for when I tried that one change described above.

Cheers!

Contents of my mwe.tex file: \documentclass[a4paper]{article} \usepackage{natbib} \usepackage{hyperref} \usepackage{doi} \hypersetup{colorlinks=true, citecolor=blue, linkcolor=blue} \begin{document} This is a test \citep{einstein}. \bibliographystyle{plainnat} \bibliography{mwe.bib} \end{document} Contents of my mwe.bib file: @article{einstein, author = "Albert Einstein", title = "{Zur Elektrodynamik bewegter K{\"o}rper}. ({German}) [{On} the electrodynamics of moving bodies]", journal = "Annalen der Physik", volume = "322", number = "10", pages = "891--921", year = "1905", DOI = "10.1002/andp.19053221004" }
moewew commented 5 years ago

It seems that \doitext is \edef-expanded when \doi is typeset.

https://github.com/ho-tex/doi/blob/28dbd16ca59a89fb0cbe49754803338e32d55dc0/doi.sty#L93

That does not work well for \textsc as it is not expandable. A workaround could be \noexpand, but it might be worth checking if it possible to get \doitext in unexpanded form here.

\documentclass[a4paper]{article}
\usepackage{natbib}
\usepackage{hyperref}
\usepackage{doi}

\renewcommand{\doitext}{\noexpand\textsc{doi:}}

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@article{appleby,
  author  = {Humphrey Appleby},
  title   = {On the Importance of the Civil Service},
  year    = {1980},
  journal = {Civil Service Journal},
  doi     = {10.2214/ajr.12.9928},
}
\end{filecontents}

\begin{document}
  This is a test \citep{appleby}.

  \bibliographystyle{plainnat}
  \bibliography{\jobname}
\end{document}