Based on Avoiding inelegant splits on URLs, I have this 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}
Compiled this with pdflatex test.tex && biber test && pdflatex test.tex && pdflatex test.tex
, using Texlive 2014 frozen. Here is a screenshot of how evince
renders this output:
So the links mostly "leak"/"spill over" the margin, except the second one, which is line-broken at a period/dot.
Now uncomment the \def\mybiburlval{1}
line, and recompile again; the output now is:
Notice how all links are line-broken here at lowercase characters - even if I've only added the first (A01
) citation to the badbreaks
category; and even if I've set the lower case breaking penalty to the smallest possible value (1)!
So my question is - how can I selectively choose to have a URL break only for the citations which are in the badbreaks
category (in this case, only A01
); and otherwise typeset links as in the usual case (even if they spill over the margin)?
Maybe of note would be to recall:
$ 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 }
So, apparently, \setcounter
is global, and \defcounter
is not (is local) - but I get the same output (i.e. breaking applied nonselectively everywhere), even if I use \setcounter
instead of \defcounter
in the switch - and even if I specifically set a 0 in the "else" part, as in:
\AtEveryBibitem{%
\ifcategory{badbreaks}
{\setcounter{biburllcpenalty}{9000}}
{\setcounter{biburllcpenalty}{0} }}
So how can I apply url breaking at lowercase characters selectively - only to some citations?