![BibLaTeX 脚注引用缩短长 URL](https://linux22.com/image/372569/BibLaTeX%20%E8%84%9A%E6%B3%A8%E5%BC%95%E7%94%A8%E7%BC%A9%E7%9F%AD%E9%95%BF%20URL.png)
是否可以自动缩短脚注中的长 URL(例如缩短至 20 个字符)并在其后添加“...”?是否还可以修剪 TLD 后的 URL?
以下有两个示例:
现在引用:
Footcite 应该是(或多或少):
这是我的 MWE:
\documentclass{scrartcl}
\usepackage[backend=biber, sorting=nyt, maxcitenames=2, maxbibnames=2, firstinits=true, isbn=false, doi=false, url=false, style=authoryear, dashed=false]{biblatex}
\renewcommand*{\multinamedelim}{\slash\space} % Delimiter should be a "/"
\appto{\biburlsetup}{\renewcommand*{\UrlFont}{\normalfont}} % show URL w/o color
\begin{filecontents}{bib_data.bib}
@online{gs1_aisbl_epc_2016,
title = {{{EPC Information Services}} ({{EPCIS}}) {{Standard Release}} 1.2},
url = {https://www.gs1.org/sites/default/files/docs/epc/EPCIS-Standard-1.2-r-2016-09-29.pdf},
urldate = {2018-03-09},
date = {2016-09},
author = {{GS1 AISBL}},
}
\end{filecontents}
\addbibresource{bib_data.bib}
\DeclareCiteCommand{\footciteonline}[\mkbibfootnote]
{\usebibmacro{prenote}}
{\usebibmacro{citeindex}
\printnames{author}
(\printfield{year})
\newunit\newblock
\printfield{title}
\newunit\newblock
\usebibmacro{url+urldate}
\newunit\newblock
\setunit{\labelnamepunct}
}
{\addsemicolon\space}
{\usebibmacro{postnote}}
\begin{document}
Lorem Ipsum.\footciteonline{gs1_aisbl_epc_2016}
\printbibliography
\end{document}
感谢您的帮助。
如果您需要更多信息,请与我们联系。
答案1
以下代码使用 Biber 的源映射,通过 RegExp 提取包含 50 个或更多字符的 URL 的 TLD。然后将 TLD 写入字段verba
。\footciteonline
然后设置为打印来自的缩短 URL(verba
如果可用),而不是来自的长 URL url
。
\documentclass{scrartcl}
\usepackage[backend=biber, style=authoryear, dashed=false, maxcitenames=2, maxbibnames=2, giveninits=true, uniquename=init, isbn=false, doi=false, url=false]{biblatex}
\usepackage{hyperref}
\renewcommand*{\multinamedelim}{\slash\space} % Delimiter should be a "/"
\appto{\biburlsetup}{\renewcommand*{\UrlFont}{\normalfont}} % show URL w/o color
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@online{gs1_aisbl_epc_2016,
title = {{{EPC Information Services}} ({{EPCIS}}) {{Standard Release}} 1.2},
url = {https://www.gs1.org/sites/default/files/docs/epc/EPCIS-Standard-1.2-r-2016-09-29.pdf},
urldate = {2018-03-09},
date = {2016-09},
author = {{GS1 AISBL}},
}
@online{Bundesamt2016,
address = {Wiesbaden},
author = {{Statistisches Bundesamt}},
institution = {Statistisches Bundesamt},
title = {Bildungsstand der Bevölkerung},
date = {2016-11},% date ist besser als year und month
url = {https://www.destatis.de/GPStatistik/receive/DEHeft_heft_00057188},
}
@online{elk:bronto,
address = {London},
author = {Anne Elk},
institution = {University of Monthy},
title = {On the Theory of Brontosauruses},
date = {1972},
url = {http://www.example.edu/~elk/bronto.pdf},
}
\end{filecontents}
\addbibresource{\jobname.bib}
\DeclareCiteCommand{\footciteonline}[\mkbibfootnote]
{\usebibmacro{prenote}}
{\usedriver
{\renewbibmacro*{url}{\iffieldundef{verba}{\printfield{url}}{\printfield{verba}}}}
{\thefield{entrytype}}}
{\addsemicolon\space}
{\usebibmacro{postnote}}
\DeclareSourcemap{
\maps[datatype=bibtex]{
\map{
\step[fieldsource=url, match=\regexp{.{50,}}, final]
\step[fieldset=verba, origfieldval]
\step[fieldsource=verba, match=\regexp{\A(ht|f)tp(s)?:\/\/([^/]+).*}, replace=\regexp{$1tp$2://$3/...}]
}
}
}
\DeclareFieldFormat{verba}{%
\mkbibacro{URL}\addcolon\space
\ifhyperref
{\href{\thefield{url}}{\nolinkurl{#1}}}
{\nolinkurl{#1}}}
\begin{document}
Lorem\footciteonline{gs1_aisbl_epc_2016} Ipsum\footciteonline{Bundesamt2016} dolor\footciteonline{elk:bronto} sit amet.
\printbibliography
\end{document}