选择性破坏 biblatex 网址?

选择性破坏 biblatex 网址?

基于避免 URL 不雅分割,我有这个 MWE:

\documentclass{article}
\usepackage[backend=biber]{biblatex}
\usepackage{filecontents}
\usepackage{trace}
\usepackage{hyperref}
\begin{filecontents}{\jobname.bib}
@misc{A01,
  author = {Author, A. and Buthor, B.  },
  year = {2001},
  title = {Alpha aaa},
  url = {http://www.thewebsiteurl.com/ab/XC/PYR12337.pdf},
}
@misc{A02,
  author = {Authoq, A. and Buthoq, B.  },
  year = {2002},
  title = {Betaa bbb},
  url = {http://www.trythesesites.com/cx/AB/KXY0012C.pdf},
}
\end{filecontents}
\addbibresource{\jobname.bib}

\def\mybiburlval{0}% 0 is otherwise the default
% \def\mybiburlval{1}% uncomment this to set to 1

% hyphenation does not work in URLs:
%\hyphenation{the-website-url}
% so use as per:
% https://tex.stackexchange.com/questions/30857/avoiding-inelegant-splits-on-urls

% Set low penalties for breaks at numbers, uppercase letters and lowercase letters
\setcounter{biburlnumpenalty}{\mybiburlval}
\setcounter{biburlucpenalty}{\mybiburlval}
\setcounter{biburllcpenalty}{\mybiburlval}

% Define a category to selectively print entries with a higher lowercase penalty
\DeclareBibliographyCategory{badbreaks}
\addtocategory{badbreaks}{A01} % only A01 here

\AtEveryBibitem{%
  \ifcategory{badbreaks}
    {\defcounter{biburllcpenalty}{9000}}
    {}}

\begin{document}

\noindent
A: \fullcite{A01}

B: \fullcite{A02}

\printbibliography

\end{document}

使用 编译此文件,使用 Texlive 2014 冻结。以下是如何呈现此输出pdflatex test.tex && biber test && pdflatex test.tex && pdflatex test.tex的屏幕截图:evince

测试1.png

因此,大多数链接都会“泄漏”/“溢出”边缘,除了第二个链接,它在句号/点处断线。

现在取消注释该\def\mybiburlval{1}行,并再次重新编译;现在的输出是:

测试2.png

注意如何全部此处的链接在小写字母处会换行 - 即使我只向类别中添加了第一个 ( A01) 引用badbreaks;即使我将小写字母换行惩罚设置为最小可能值 (1)!

所以我的问题是 - 我如何选择性地选择 URL 中断仅有的对于属于该badbreaks类别的引用(在本例中仅为A01);否则,按照通常情况排版链接(即使它们溢出边缘)?

也许值得注意的是:

$ texdef -t latex -p biblatex -f setcounter
\setcounter is defined by (La)TeX.

\setcounter:
macro:#1#2->\@ifundefined {c@#1}{\@nocounterr {#1}}{\global \csname c@#1\endcsname #2\relax }

$ texdef -t latex -p biblatex -f defcounter
\defcounter first defined in "etoolbox.sty".

\defcounter:
\protected macro:#1#2->\ifcsundef {c@#1} {\etb@noglobal \@nocounterr {#1}}{\csname c@#1\endcsname \numexpr #2\relax }

因此,显然,\setcounter是全局的,而\defcounter不是(是局部的)——但我得到相同的输出(即,中断在任何地方非选择性地应用),即使我在 switch 中使用\setcounter而不是\defcounter——即使我在“else”部分专门设置了 0,如下所示:

\AtEveryBibitem{%
  \ifcategory{badbreaks}
    {\setcounter{biburllcpenalty}{9000}}
    {\setcounter{biburllcpenalty}{0}   }}

那么,我怎样才能有选择地将 URL 断言应用于小写字符——仅针对某些引用?

答案1

惩罚不用于 bibitem,而只用于在\biburlsetup书目开头执行的 bibitem。如果要更改某个 bibitem 的设置,则应再次调用 url 设置:

\AtEveryBibitem{%
  \ifcategory{badbreaks}
    {\defcounter{biburllcpenalty}{9000}\biburlsetup}
    {}}

使用 OP MWE( \def\mybiburlval{0}) 输出:

测试3.png

相关内容