
如何定義一個命令來僅保留連結的域名,例如http://www.google.com/search?=bang僅提供 google.com 並將其顯示為 URL 參考的組織欄位?
非常感謝
答案1
這確實是一個不平凡的請求,我強烈建議手動填寫該organization
欄位(您最少的問題是組織名稱的大寫:您不想url = {http://nssdc.gsfc.nasa.gov/planetary/factsheet/moonfact.html}
顯示為organization = {nasa}
, but organization = {NASA}
)。
一些或多或少有用的解決方案作為biblatex
和 的概念證明biber
。
這個來源映射出現在序言中。
\DeclareSourcemap{
\maps[datatype=bibtex]{
\map[overwrite=false]{
\step[fieldsource=url, match=\regexp{^((?:f|ht)tps?://)?(?:www\.)?([^/]+)}, final]
\step[fieldset=organization, fieldvalue={$2}]
}
}
}
它嘗試從欄位中提取 URL 的網域部分url
並將其對應到該organization
欄位。由於擺脫子網域並不是一項簡單的任務,特別是如果您考慮到存在諸如 、 、 等 TLD .co.uk
,.info
因此.de
這些.com
仍然包含在內。
\documentclass{article}
\usepackage[style=authoryear, backend=biber]{biblatex}
\usepackage{hyperref}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@ELECTRONIC{MEMSnet,
title = {What is {MEMS}?},
url = {http://www.memsnet.org/mems/what_is.html},
urldate = {2013-12-01},
}
\end{filecontents}
\addbibresource{\jobname.bib}
\addbibresource{biblatex-examples.bib}
\DeclareSourcemap{
\maps[datatype=bibtex]{
\map[overwrite=false]{
\step[fieldsource=url, match=\regexp{^((?:f|ht)tps?://)?(?:www\.)?([^/]+)}, final]
\step[fieldset=organization, fieldvalue={$2}]
}
}
}
\begin{document}
\nocite{MEMSnet,wilde,markey}
\printbibliography
\end{document}
給出
上面提到的兩個問題都可以在這裡觀察到:人們可能希望看到MEMSnet
而不是memsnet.org
,並且CTAN
而不是tug.ctan.org
。