Last active
January 4, 2024 21:19
-
-
Save yymao/eefa0bc6d881675b7e3c4bb7bee2b843 to your computer and use it in GitHub Desktop.
hyperlink-year-only-natbib-patch
This file contains hidden or 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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
% hyperlink-year-only-natbib-patch.tex | |
% Gist URL: https://gist.github.com/yymao/eefa0bc6d881675b7e3c4bb7bee2b843 | |
% Raw URL: https://gist.githubusercontent.com/yymao/eefa0bc6d881675b7e3c4bb7bee2b843/raw/hyperlink-year-only-natbib-patch.tex | |
% Implementation taken from https://tex.stackexchange.com/a/27311 | |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
\RequirePackage{hyperref} | |
\RequirePackage{natbib} | |
\RequirePackage{etoolbox} | |
\makeatletter | |
% Patch case where name and year are separated by aysep | |
\patchcmd{\NAT@citex} | |
{\@citea\NAT@hyper@{% | |
\NAT@nmfmt{\NAT@nm}% | |
\hyper@natlinkbreak{\NAT@aysep\NAT@spacechar}{\@citeb\@extra@b@citeb}% | |
\NAT@date}} | |
{\@citea\NAT@nmfmt{\NAT@nm}% | |
\NAT@aysep\NAT@spacechar\NAT@hyper@{\NAT@date}}{}{} | |
% Patch case where name and year are separated by opening bracket | |
\patchcmd{\NAT@citex} | |
{\@citea\NAT@hyper@{% | |
\NAT@nmfmt{\NAT@nm}% | |
\hyper@natlinkbreak{\NAT@spacechar\NAT@@open\if*#1*\else#1\NAT@spacechar\fi}% | |
{\@citeb\@extra@b@citeb}% | |
\NAT@date}} | |
{\@citea\NAT@nmfmt{\NAT@nm}% | |
\NAT@spacechar\NAT@@open\if*#1*\else#1\NAT@spacechar\fi\NAT@hyper@{\NAT@date}} | |
{}{} | |
\makeatother |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment