
我想剪切 Bibtex 檔案中定義的 URL 標籤。例如,我想裁剪前綴“mailto:”,這樣就不會顯示它。但超連結仍然必須包含它。以下命令在文件環境中有效,但對於參考書目條目則失敗。他們需要特殊照顧嗎?
微量元素:
\documentclass{scrreprt}
\usepackage{hyperref}
\usepackage{xstring}
\let\oldUrl\url
\renewcommand{\url}[1]{
\StrBehind{#1}{:}[\tempa]
\StrBefore{#1}{:}[\tempb]
\IfBeginWith{\tempb}{mailto}
{\href{#1}{\nolinkurl{\tempa}}}
{\oldUrl{#1}}
}
\usepackage[
backend=biber,
style=alphabetic
]{biblatex}
\addbibresource{test.bib}
\begin{document}
\url{mailto:[email protected]}
\nocite{*}
\printbibliography
\end{document}
Bibtex 檔:
@MANUAL{ABC,
title = {Test Title},
author = {ABC},
url = {mailto:[email protected]}
}
輸出:
它確實適用於 note 標籤,但不適用於 url 標籤,因為在 note 標籤中使用了 url 巨集(透過使用 bibtex 引擎而不是 biber 引擎發現,因為 bibtex 不提供 url 標籤):
@MANUAL{ABC,
title = {Test Title},
author = {ABC},
url = {mailto:[email protected]}
note = {\url{mailto:[email protected]}}
}
我的第一個結論:biber 不使用 url 巨集來建立 hyperrefs,但是為什麼在 url 巨集的重新定義中 \IfBeginWith 巨集的 else 分支會起作用呢?
答案1
請參閱xstring
手冊,3.4 Catcode and starred macros
。
如果您想在其中使用宏,則必須使用帶有星號的測試宏版本。
\renewcommand{\url}[1]{
\StrBehind{#1}{:}[\tempa]
\StrBefore{#1}{:}[\tempb]
\IfBeginWith*{\tempb}{mailto}
{\href{#1}{\nolinkurl{\tempa}}}
{\oldUrl{#1}}
}