web.archive.org 的链接重定向到带有 % 字符的链接

web.archive.org 的链接重定向到带有 % 字符的链接

我正在尝试使用可由 biblatex(biber)和 bibtex 编译的代码,但它在参考书目中包含以下链接:

https://web.archive.org/web/20110412120322/http://www.allheadlinenews.com/briefs/articles/90043651?After%20hesitation%2C%20Jordan%20joins%20in%20Libya%20no-fly%20campaign

问题是 web.archive 重定向到反斜杠%字符/%而不是仅仅是 的内容%

梅威瑟:

主文本:

\documentclass{article}
\usepackage{array}
\usepackage{longtable}
\usepackage[utf8]{inputenc}
\usepackage{xcolor}

\xdef\UseBibLaTeX{1}
\usepackage[hyphens]{url}


\ifnum\UseBibLaTeX>0
\usepackage[
backend=biber,
style=alphabetic,
citestyle=authoryear,
natbib=true,
]{biblatex}
  \addbibresource{References.bib}
\else
  \usepackage{natbib}
  \renewcommand\harvardurl[1]{\textbf{URL:} \url{#1}}
\fi
  
\usepackage[colorlinks]{hyperref}

\begin{document}
Test \cite{cite01}

\begin{sloppypar}
\ifnum\UseBibLaTeX>0
  \printbibliography
\else
  \bibliographystyle{agsm}
  \bibliography{References}
\fi
\end{sloppypar}

\end{document}

参考文献.bib:

@article{cite01,
        title ={After hesitation, {Jordan} joins in {Libya} no-fly campaign},
        url ={https://web.archive.org/web/20110412120322/http://www.allheadlinenews.com/briefs/articles/90043651?After\%20hesitation\%2C\%20Jordan\%20joins\%20in\%20Libya\%20no-fly\%20campaign},
        urldate ={2020-08-04},
        month =Apr,
        author={{TML Staff}},
        journal={{All Headline News (AHN)}},
        year ={2011},
        day={06}
}

答案1

因为biblatex您不应该 (LaTeX-) 转义url字段中的任何 US-ASCII 字符。这意味着%应该保留%,而不应该转义为\%

BibTeX 的情况并不统一。最初的标准 BibTeX 样式可以追溯到 80 年代,那时 URL 尚未标准化,因此没有专用字段url。后来的 BibTeX 样式支持 URL,但具体实现方式有所不同。最多BibTeX 样式与urlorhyperref包交互,因此支持未转义的 URL 输入。然而,这可能不是所有样式的情况。但我不会以此为借口坚持%在 URL 中转义 s,相反,我会说这是这些样式的缺陷。

在这种情况下,解决方案很简单。

\renewcommand\harvardurl[1]{\textbf{URL:} \url{#1}}

使用

\renewcommand\harvardurl{\textbf{URL:} \url}

TeX 读取参数的方式使得\url处理特殊字符的技巧在用于另一个命令的参数时失效。(这与你在使用\verb或等宏时观察到的现象相同\lstinline。例如参见http://www.texfaq.org/FAQ-verbwithin如何在命令中传递使用 lstlisting 或 lstinline如何将 \verb 命令放入 \t​​extbf{} 块内?) 在新的定义中,我们巧妙地避免明确给出的\url论点,从而允许\url的魔法继续发挥作用。

\documentclass{article}
\usepackage{array}
\usepackage{longtable}
\usepackage[utf8]{inputenc}
\usepackage{xcolor}

\xdef\UseBibLaTeX{0}
\usepackage[hyphens]{url}


\ifnum\UseBibLaTeX>0
\usepackage[
backend=biber,
style=alphabetic,
citestyle=authoryear,
natbib=true,
]{biblatex}
  \addbibresource{\jobname.bib}
\else
  \usepackage{natbib}
  \renewcommand\harvardurl{\textbf{URL:} \url}
\fi
  
\usepackage[colorlinks]{hyperref}

\begin{filecontents}{\jobname.bib}
@article{cite01,
  title   = {After hesitation, {Jordan} joins in {Libya} no-fly campaign},
  url     = {https://web.archive.org/web/20110412120322/http://www.allheadlinenews.com/briefs/articles/90043651?After%20hesitation\%2C%20Jordan%20joins%20in%20Libya%20no-fly%20campaign},
  urldate = {2020-08-04},
  month   = Apr,
  author  = {{TML Staff}},
  journal = {All Headline News (AHN)},
  year    = {2011},
}
\end{filecontents}

\begin{document}
Test \cite{cite01}

\begin{sloppypar}
\ifnum\UseBibLaTeX>0
  \printbibliography
\else
  \bibliographystyle{agsm}
  \bibliography{\jobname}
\fi
\end{sloppypar}

\end{document}

正确显示的 URL 'https://web.archive.org/web/20110412120322/http://www.allheadlinenews.com/briefs/articles/90043651?After%20hesitation2C%20Jordan%20joins%20in%20Libya%20no-fly%20campaign'

相关内容