Closed stone-zeng closed 6 years ago
实际上这个问题还要再复杂一些。由于 URL 中的可能会有 %
、#
等特殊字符,直接忽略 \href
的第一个参数有的时候并不可行。hyperref
宏包是做了一定处理的。如果要修改 \href
,使它成为不带超链接的纯文本,大概可以这样操作:
% 需要 natbib 和 hyperref
\def\bibpreamble{%
\let\GB@href\href
\let\href\GB@nolink@href
\def\doi##1{DOI: \GB@href{http://dx.doi.org/##1}{##1}}}
\DeclareRobustCommand*\GB@nolink@href{%
\begingroup
\hyper@normalise\GB@href@aux}
\begingroup
\catcode`\$=6
\catcode`\#=12
\gdef\GB@href@aux$1{\expandafter\GB@href@split$1##\\}
\gdef\GB@href@split$1#$2#$3\\$4{$4\endgroup}
\endgroup
这里暂且忽略 \href
的可选参数,也不管 \href
在参数中时对 #
的特殊处理。主要改动是 \href@split
:
% hyperref 中的原始定义
\gdef\href@split$1#$2#$3\\$4{%
\hyper@@link{$1}{$2}{$4}%
\endgroup
}%
之前的代码删去 \hyper@@link
,但保留 #4
,从而关闭了超链接。
url
的基础上再加 hyperref
。我当时只是简单处理了一下,没考虑你提到的 \href
问题。我现在觉得,本 project 作为一个通用的 bst 还是应该从简处理,不应该依赖上 hyperref 这么大的宏包。当然你的方案很漂亮,不过我觉得还是去掉 title 的超链接吧。
加个选项会更好一点吧。
另外之前发的代码只有 \href
本身和 \hyper@normalise
是 hyperref
提供的。\href
用在 \doi
里面,但 DOI 没什么特殊字符,可以直接弄;\hyper@normalise
的话会麻烦一点,要把相关代码(基本上在 hyperref.pdf
第 16 节)全部复制过来。总之其实是可以不依赖 hyperref
的。
Fixed in 506f154 .
啊,搞错了
On 11 Dec 2017, at 7:42 AM, muzimuzhi notifications@github.com wrote:
链接是否填错了?解决这个 issue 的是提交 506f154 https://github.com/zepinglee/gbt7714-bibtex-style/commit/506f1540792884a22a2085761f87a575f7628110 — You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/zepinglee/gbt7714-bibtex-style/issues/21#issuecomment-350591673, or mute the thread https://github.com/notifications/unsubscribe-auth/ALuLBlnQV0zThzb2OsESv2gs3pEuXKp0ks5s_GxsgaJpZM4QD_Bk.
@Stone-Zeng 我想了一下,如果要加个选项,大概要实现
\RequirePackage{url}
\newcommand\gbturl[1]{\newblock\url{#1}.}
\newcommand\gbtdoi[1]{\newblock DOI: \url{#1}.}
但是这样的 \gbturl{abc%20def}
还不能正确处理,请教一下有办法允许参数接受 %
等字符吗?
目前带有 URL 的条目会被自动添加超链接:
觉得再用
\href
给文献加上链接有些多余,毕竟后面还会有 URL。当然实际用的时候,可以给
\bibliography
打一下补丁来禁用\href
: