1

This question is very similar to

Special characters in DOI leading to invalid URLs

but the solution found in the above Q&A doesn't work with biblatex-chicago.

Specifically, I have to deal with DOIs with special characters: for example,

10.1175/1520-0485(1975)005<0300:CTWIAS>2.0.CO;2

But, the URL which directly corresponds to this DOI

https://doi.org/10.1175/1520-0485(1975)005<0300:CTWIAS>2.0.CO;2

includes invalid characters as a URL. How can one set things up so that such DOIs as this are correctly encoded when they are turned into URLs?

The solution found in the above Q&A was to use the doi package and

\doi{10.1175/1520-0485(1975)005<0300:CTWIAS>2.0.CO;2}

So, the solution was simple: Just \usepackage{doi}. This solution works in the traditional LaTeX + BibTeX way because bib styles tend to use the \doi macro.

As the following code demonstrates, however, this method doesn't work with biblatex-chicago. The hyperlinks it generates still contain invalid URLs, which some PDF viewers (like Mac's Preview) cannot handle. The code below also demonstrates that the \doi macro itself produces correctly encoded URLs. Apparently, biblatex-chicago doesn't use the \doi command.

\documentclass[11pt]{article}
\usepackage[doi=only]{biblatex-chicago}
\usepackage{doi}
\begin{filecontents}[overwrite,noheader]{tmp.bib}
@article{ref-with-odd-doi,
  title = {Coastal Trapped Waves in a Stratified Ocean},
  author = {Allen, J. S.},
  year = {1975},
  journal = {J. Phys. Oceanogr.},
  volume = {5},
  pages = {300--325},
  doi = {10.1175/1520-0485(1975)005<0300:CTWIAS>2.0.CO;2}
}
@article{ref-with-nice-doi,
  title = {Something},
  author = {Some Author},
  year = {1975},
  journal = {Some Journal},
  volume = {5},
  pages = {300--325},
  doi = {10.1016/j.dsr.2003.09.011}
}
\end{filecontents}
\bibliography{tmp}
\begin{document}
\noindent
\cite{ref-with-odd-doi}\\
\cite{ref-with-nice-doi}\\
\doi{10.1175/1520-0485(1975)005<0300:CTWIAS>2.0.CO;2}\\
\doi{10.1016/j.dsr.2003.09.011}\\
\printbibliography
\end{document}

1
  • 1
    while it would be possible to postprocess the doi to make it safe it would probably make more sense if biber would percent encode it, and add a doiraw field similar to the way it handles url. Oct 19, 2022 at 9:32

1 Answer 1

0

Imho the best would be if biber would handle doi like url and percent encode them directly. But you can also replace the problematic chars:

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage[doi=only]{biblatex-chicago}
\usepackage{doi}

\ExplSyntaxOn
\cs_new_protected:Npn \printdoi#1
 {
  \tl_set:Nn \l_tmpa_tl{#1}
  \tl_replace_all:Nnn\l_tmpa_tl {<}{\c_percent_str3C}
  \tl_replace_all:Nnn\l_tmpa_tl {>}{\c_percent_str3E}
  % expands with more if needed ...
  \href{\doiurl\l_tmpa_tl}{\nolinkurl{#1}}
 }
\ExplSyntaxOff
\DeclareFieldFormat{doi}{\printdoi{#1}}

\begin{filecontents}[overwrite,noheader]{tmp.bib}
@article{ref-with-odd-doi,
  title = {Coastal Trapped Waves in a Stratified Ocean},
  author = {Allen, J. S.},
  year = {1975},
  journal = {J. Phys. Oceanogr.},
  volume = {5},
  pages = {300--325},    
  doi = {10.1175/1520-0485(1975)005<0300:CTWIAS>2.0.CO;2}
}
@article{ref-with-nice-doi,
  title = {Something},
  author = {Some Author},
  year = {1975},
  journal = {Some Journal},
  volume = {5},
  pages = {300--325},
  doi = {10.1016/j.dsr.2003.09.011}
}
\end{filecontents}
\bibliography{tmp}
\begin{document}
%\noindent 
\cite{ref-with-odd-doi}\\
\cite{ref-with-nice-doi}

\doi{10.1175/1520-0485(1975)005<0300:CTWIAS>2.0.CO;2}\\
\doi{10.1175/1520-0485(1975)005<0300:CTWIAS>2.0.CO;2}

\printbibliography
\end{document}

You must log in to answer this question.

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