Created
July 26, 2023 10:43
-
-
Save MichalPt/f1bbf4d27b6f735191eb0bc945914e7c to your computer and use it in GitHub Desktop.
DOI package for abbrvnat.bst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\NeedsTeXFormat{LaTeX2e} | |
\ProvidesPackage{doi}[2018/09/09 handle doi numbers] | |
\RequirePackage{hyperref} | |
%% To change the default prefix, redefine this command within your own code. | |
%% It takes no argument, which is different from the doipubmed package. | |
%\newcommand{\doitext}{} | |
%% To change the default DOI URL resoloution URL, redefine this command | |
%% within your own code. | |
%% Previous versions of this package always used http://dx.doi.org/ but | |
%% The preferred address is now as given here, https://doi.org/ | |
\newcommand{\doiurl}{https://doi.org/} | |
%% The meat of the code. | |
%% The first command opens a group, and changes a few catcodes. | |
\newcommand*{\doi}{% | |
\begingroup | |
\lccode`\~=`\#\relax | |
\lowercase{\def~{\#}}% | |
\lccode`\~=`\_\relax | |
\lowercase{\def~{\_}}% | |
\lccode`\~=`\<\relax | |
\lowercase{\def~{\textless}}% | |
\lccode`\~=`\>\relax | |
\lowercase{\def~{\textgreater}}% | |
\lccode`\~=0\relax | |
\catcode`\#=\active | |
\catcode`\_=\active | |
\catcode`\<=\active | |
\catcode`\>=\active | |
\@doi | |
} | |
%% This is the actual command which processes the argument, with the catcodes | |
%% set in the previous command | |
%% it closes the group, and spits out the url. | |
\def\@doi#1{% | |
\let\#\relax | |
\let\_\relax | |
\let\textless\relax | |
\let\textgreater\relax | |
\edef\x{\toks0={{\doiurl#1}}}% | |
\x | |
\edef\#{\@percentchar23}% | |
\edef\_{_}% | |
\edef\x{\toks2={\noexpand\href{\doiurl#1}}}% | |
\x | |
\edef\x{\endgroup\the\toks2 \the\toks0}% | |
\x | |
} | |
%% That's all folks. | |
\endinput |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment