Based on the solutions to Biblatex: Two bibliographies with different styles and sortings II and Biblatex: Two bibliographies with different styles and sortings II Part 2 given by
gusbrs and
moewe, respectively, I would like to add the option labelprefix to the style numeric-comp with the following behavior:
- Delete the second
labelprefixfrom the citation range if the citations follow the integer sequence of natural numbers, for example,tech. 1-3instead oftech. 1-tech.3 - Also delete
labelprefixin the case of combination of single with range citations or different non-consecutive citation ranges, for instance,tech. 1, 3-4instead oftech. 1, tech. 3-4ortech. 1-2, 4-6instead oftech. 1-2, tech. 4-6
The first point can be achieved redifining the cite:dump macro of numeric.comp.cbx, i.e., deleting \printtext[labelprefix]{\cbx@lastprefix}:
\renewbibmacro*{cite:dump}{%
\ifnumgreater{\value{cbx@tempcnta}}{0}
{\ifnumgreater{\value{cbx@tempcnta}}{1}
{\bibrangedash}
{\multicitedelim}%
\bibhyperref[\cbx@lastkey]{%
\ifdef\cbx@lastprefix
%{\printtext[labelprefix]{\cbx@lastprefix}} %deleted
{} % added
{}%
\printtext[labelnumber]{\cbx@lastnumber}
}}
{}%
\setcounter{cbx@tempcnta}{0}%
\global\undef\cbx@lastprefix}
What about the second one? Any ideas?
MWE:
\documentclass{article}
\usepackage{filecontents}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\begin{filecontents}{biblatextest1.bib}
@BOOK{BookA03,
author = {Author Ät{"a}},
title = {Some Title},
publisher = {Some Publisher},
year = 2003,
}
@BOOK{BookB02,
author = {Author Bb"{a}},
title = {Some Title},
publisher = {Some Publisher},
year = 2002,
}
@BOOK{BookB09,
author = {Author Jjj},
title = {Some Title},
publisher = {Some Publisher},
year = 2002,
}
@BOOK{BookB10,
author = {Author Kkk},
title = {Some Title},
publisher = {Some Publisher},
year = 2002,
}
@BOOK{BookB11,
author = {Author Lll},
title = {Some Title},
publisher = {Some Publisher},
year = 2002,
}
\end{filecontents}
\begin{filecontents}{biblatextest2.bib}
@MISC{LinkC01,
author = {Author Ccc},
title = {Some Title},
year = 2004,
url = {www.test1.com/bild.jpg},
}
@MISC{LinkD04,
author = {Author Ddd},
title = {Some Title},
year = 2001,
url = {www.test2.com/bild.jpg},
}
@MISC{LinkD05,
author = {Author Eee},
title = {Some Title},
year = 2004,
url = {www.test3.com/bild.jpg},
}
@MISC{LinkD06,
author = {Author Fff},
title = {Some Title},
year = 2001,
url = {www.test4.com/bild.jpg},
}
@MISC{LinkD07,
author = {Author Ggg},
title = {Some Title},
year = 2004,
url = {www.test5.com/bild.jpg},
}
@MISC{LinkD08,
author = {Author Hhh},
title = {Some Title},
year = 2001,
url = {www.test6.com/bild.jpg},
}
@MISC{LinkD09,
author = {Author Iii},
title = {Some Title},
year = 2001,
url = {www.test6.com/bild.jpg},
}
\end{filecontents}
\usepackage[style = numeric-comp, labelalpha, defernumbers,backend = biber]{biblatex}
\addbibresource{biblatextest1.bib}
\addbibresource{biblatextest2.bib}
\usepackage[colorlinks=true,citecolor=blue,urlcolor=red]{hyperref}
%Append keywords to identify different bibliography entries.
\DeclareSourcemap{
\maps[datatype=bibtex, overwrite]{
\map{
\perdatasource{biblatextest1.bib}
\step[fieldset=KEYWORDS, fieldvalue=primary]
}
\map{
\perdatasource{biblatextest2.bib}
\step[fieldset=KEYWORDS, fieldvalue=secondary]
}
}
}
\makeatletter
\newcommand{\labelalphatoshorthand}{%
\csdef{abx@field@shorthand}{%
\thefield{labelprefix}\thefield{labelalpha}\thefield{extraalpha}}}
%
\renewbibmacro{cite:dump}{%
\ifnumgreater{\value{cbx@tempcnta}}{0}
{\ifnumgreater{\value{cbx@tempcnta}}{1}
{\bibrangedash}
{\multicitedelim}%
\bibhyperref[\cbx@lastkey]{%
\ifdef\cbx@lastprefix
% {\printtext[labelprefix]{\cbx@lastprefix}} %deleted
{} % added
{}%
\printtext[labelnumber]{\cbx@lastnumber}
}}
{}%
\setcounter{cbx@tempcnta}{0}%
\global\undef\cbx@lastprefix} %
\makeatother
\AtEveryCitekey{\ifkeyword{primary}{\labelalphatoshorthand}{}}
\DeclareFieldFormat{labelalphawidth}{\mkbibbrackets{#1}}
\defbibenvironment{bibliographyALPHA}
{\list
{\printtext[labelalphawidth]{%
\printfield{labelprefix}%
\printfield{labelalpha}%
\printfield{extraalpha}}}
{\setlength{\labelwidth}{\labelalphawidth}%
\setlength{\leftmargin}{\labelwidth}%
\setlength{\labelsep}{\biblabelsep}%
\addtolength{\leftmargin}{\labelsep}%
\setlength{\itemsep}{\bibitemsep}%
\setlength{\parsep}{\bibparsep}}%
\renewcommand*{\makelabel}[1]{##1\hss}}
{\endlist}
{\item}
\begin{document}
The first two citations \cite{LinkD07,LinkC01} and \cite{BookB10,BookB11,BookB09}.
Mixing both primary and secondary \cite{LinkD08,LinkD04,LinkD05,BookB10,BookB11,BookB09}.
The others are \cite{LinkC01,LinkD08,LinkD05,LinkD06,LinkD07} as well as \cite{LinkC01,LinkD04,LinkD05,LinkD07,LinkD08, LinkD09}
and \cite{BookA03}.
\printbibliography[env=bibliographyALPHA, title=Bibliography, keyword=primary]
\newrefcontext[labelprefix=tech.\space]
\printbibliography[title=References, keyword=secondary, resetnumbers]
\end{document}

![The first two citations [tech. 1, 5] and [Jjj02, Kkk02, Lll02].//Mixing both primary and secondary [tech. 2, 3, 6, Jjj02, Kkk02, Lll02].//The others are [tech. 1, 3–6] as well as [tech. 1–3, 5–7] and [Ätä03].](../../images/d6cead3e92c8aedf122ebf1965ad5a8a.webp)
BookB09in the filebiblatextest1.bib, then Aaa02 is placed before tech. 2, 3, 6 without comma or space between them. I have tried to add\addcomma\spaceafter.\usebibmacro{cite:alpha}Unfortunately, it places a comma also at the end of thealphacitations. It seems that a if-else statement is needed. – Ñako Aug 06 '20 at 22:09\renewcommand*{\multicitedelim}{\addsemicolon\space}) and comma in thenumeric-compcases: [tech. 1,5] or [tech. 1,3-6] or [tech. 1-3,5-7] – Ñako Aug 07 '20 at 16:16\cites, too. Usually, I use it to cite sources and pages:\cites[page n°]{source_1}...[page n°]{source_n}. For example,\cites[2-15]{BookB09}[3,5,23]{BookB10}with Aaa the author name ofBookB09produces: [Aaa02; pp. 2–15, Kkk02, pp. 3, 5, 23]. A semicolon after the first author Aaa and then commas. What I want is a semicolon after the page numbers: [Aaa02, pp. 2–15; Kkk02, pp. 3, 5, 23]. Is there also a solution for this? Thanks in advance – Ñako Aug 07 '20 at 19:29numeric-compinbiblatex3.15 [not yet released] (which probably will require quite some changes to this answer anyway), but with the currentbiblatexit looks a bit ... involved. I'll see what I can do. But probably not today (my time). – moewe Aug 07 '20 at 19:47biblatex3.15. – moewe Aug 08 '20 at 16:01\citeor\autocitebut unfortunately not with\cites. For example:\cites[2--15]{BookB09}[3,5,23]{BookB10}[1--6]{BookB11}with Aaa the author name ofBookB09produces: [Aaa02; pp. 2–15; Kkk02; pp. 3, 5, 23; Lll02, pp. 1–6]. It places a non desired semicolon betweenauthor nameandpagesexcept in the last entry. Maybe I can open a new question with the\citesissue or just wait tobiblatex3.15. What do you think? – Ñako Aug 08 '20 at 21:21\citeof about 3 lines (multiple authors all inalphastyle) overflow the text margins. The effect is considerable when replacing all\spacewith\addthinspace. It didn´t happen before rewriting of internal commands, i.e., with your current solution.\usepackage{breakcites}or\emergencystretchor\allowbreakor\sloppydon´t give the desired output. Is there also a solution for this? Thanks in advance. – Ñako Aug 18 '20 at 13:13