梅威瑟:
测试.tex:
% !TeX program = xelatex
\documentclass[paper=A4,fontsize=12pt]{scrartcl}
\usepackage[left=3cm, right=3cm, bottom=3cm, top=3cm]{geometry}
\usepackage{fontspec}
\usepackage[backend=biber,style=authoryear,citestyle=authoryear]{biblatex}
\DeclareNameAlias{sortname}{last-first}
\DeclareNameAlias{default}{last-first}
\setcounter{biburllcpenalty}{7000}
\setcounter{biburlucpenalty}{9999}
\addbibresource{resources.bib}
\begin{document}
\cite{Test.2018}
\printbibliography
\end{document}
资源.bib:
@misc{Test.2018,
author = {{testauthor test author testauthor}},
year= {2018},
title = {{testfile test file testfile}},
url = {http://abcdefghijklmnopqrstuvwxy.com/phrrFK5dS1ztTjiaCmveRARXpGBtV01U%20B93FcrxkOVhj2CceIguNuUPpwDaUD4GjTTWh9cL30D6rLgWxapYlhegDXQGFlE0hao7B2YS227ca%20keoWHWNmQVKVcNOUFxfsCp0SwCElfTVtpMv6DKqiSwhWgO2zrHvstd4UNBo99UQBSCTkzL7lD2UyRLTRy6xXdJ}
}
由于 fontspec 包更改了 parindent,因此 URL 无法正确中断。我该如何修复这个问题?
\begingroup
\sloppy
\printbibliography
\endgroup
这使得 URL 看起来非常丑陋,第一行甚至没有对齐。这只是一个延伸到边框的奇怪字符。当 BibLaTeX 使用 Biber 原生支持 URL 时,我不想使用任何奇怪的解决方法,例如使用包url
并更改参考书目。
答案1
biblatex
3.13 实现了向 URL 添加可伸缩空间的方法,具体方法如下乌尔丽克·菲舍尔的回答, 看https://github.com/plk/biblatex/issues/850。
相关长度为\biburlnumskip
、\biburlucskip
和\biburllcskip
。
\documentclass[paper=A4,fontsize=12pt]{scrartcl}
\usepackage[left=3cm, right=3cm, bottom=3cm, top=3cm]{geometry}
\usepackage{fontspec}
\usepackage[backend=biber,style=authoryear]{biblatex}
\DeclareNameAlias{default}{family-given}
\DeclareNameAlias{sortname}{default}
\setcounter{biburllcpenalty}{100}
\setcounter{biburlucpenalty}{100}
\setcounter{biburlnumpenalty}{100}
\biburlnumskip=0mu plus 1mu\relax
\biburlucskip=0mu plus 1mu\relax
\biburllcskip=0mu plus 1mu\relax
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@misc{Test.2018,
author = {{testauthor test author testauthor}},
year = {2018},
title = {{testfile test file testfile}},
url = {http://abcdefghijklmnopqrstuvwxy.com/phrrFK5dS1ztTjiaCmveRARXpGBtV01U%20B93FcrxkOVhj2CceIguNuUPpwDaUD4GjTTWh9cL30D6rLgWxapYlhegDXQGFlE0hao7B2YS227ca%20keoWHWNmQVKVcNOUFxfsCp0SwCElfTVtpMv6DKqiSwhWgO2zrHvstd4UNBo99UQBSCTkzL7lD2UyRLTRy6xXdJ}
}
\end{filecontents}
\addbibresource{\jobname.bib}
\begin{document}
\cite{Test.2018}
\printbibliography
\end{document}
答案2
您可以插入一点可拉伸的空间:
\documentclass[paper=A4,fontsize=12pt]{scrartcl}
\usepackage[left=3cm, right=3cm, bottom=3cm, top=3cm]{geometry}
\usepackage{fontspec}
\usepackage[backend=biber,style=authoryear,citestyle=authoryear]{biblatex}
\DeclareNameAlias{sortname}{last-first}
\DeclareNameAlias{default}{last-first}
\setcounter{biburllcpenalty}{100}
\setcounter{biburlucpenalty}{100}
\setcounter{biburlnumpenalty}{100}
\addbibresource{resource.bib}
\renewcommand*{\biburlsetup}{%
\Urlmuskip=0mu plus 3mu\relax
\mathchardef\UrlBigBreakPenalty=100\relax
\mathchardef\UrlBreakPenalty=200\relax
\def\UrlBigBreaks{\do\:\do\-}%
\def\UrlBreaks{%
\do\.\do\@\do\/\do\\\do\!\do\_\do\|\do\;\do\>\do\]\do\)\do\}%
\do\,\do\?\do\'\do\+\do\=\do\#\do\$\do\&\do\*\do\^\do\"}%
\ifnumgreater{\value{biburlnumpenalty}}{0}
{\def\do##1{\appto\UrlSpecials{\do##1{\mathchar`##1 \mskip 0mu plus 1mu\penalty\value{biburlnumpenalty}}}}%
\do\1\do\2\do\3\do\4\do\5\do\6\do\7\do\8\do\9\do\0}
{}%
\ifnumgreater{\value{biburlucpenalty}}{0}
{\def\do##1{\appto\UrlSpecials{\do##1{\mathchar`##1 \mskip 0mu plus 1mu\penalty\value{biburlucpenalty}}}}%
\do\A\do\B\do\C\do\D\do\E\do\F\do\G\do\H\do\I\do\J
\do\K\do\L\do\M\do\N\do\O\do\P\do\Q\do\R\do\S\do\T
\do\U\do\V\do\W\do\X\do\Y\do\Z}
{}%
\ifnumgreater{\value{biburllcpenalty}}{0}
{\def\do##1{\appto\UrlSpecials{\do##1{\mathchar`##1 \mskip 0mu plus 1mu\penalty\value{biburllcpenalty}}}}%
\do\a\do\b\do\c\do\d\do\e\do\f\do\g\do\h\do\i\do\j
\do\k\do\l\do\m\do\n\do\o\do\p\do\q\do\r\do\s\do\t
\do\u\do\v\do\w\do\x\do\y\do\z}
{}%
\let\do=\noexpand}
\begin{document}
\cite{Test.2018}
\printbibliography
\end{document}