TeX - LaTeX Asked by Ñako on March 22, 2021
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:
labelprefix
from the citation range if the citations follow the integer sequence of natural numbers, for example, tech. 1-3
instead of tech. 1-tech.3
labelprefix
in the case of combination of single with range citations or different non-consecutive citation ranges, for instance, tech. 1, 3-4
instead of tech. 1, tech. 3-4
or tech. 1-2, 4-6
instead of tech. 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]{%
ifdefcbx@lastprefix
%{printtext[labelprefix]{cbx@lastprefix}} %deleted
{} % added
{}%
printtext[labelnumber]{cbx@lastnumber}
}}
{}%
setcounter{cbx@tempcnta}{0}%
globalundefcbx@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]{%
ifdefcbx@lastprefix
% {printtext[labelprefix]{cbx@lastprefix}} %deleted
{} % added
{}%
printtext[labelnumber]{cbx@lastnumber}
}}
{}%
setcounter{cbx@tempcnta}{0}%
globalundefcbx@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]{##1hss}}
{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}
You may want to try the following solution. It requires severe rewriting of internal commands, but the style you want is quite different from what numeric-comp
normally does.
documentclass{article}
usepackage[utf8]{inputenc}
usepackage[T1]{fontenc}
usepackage[backend=biber,
style=numeric-comp,
labelalpha, defernumbers,
locallabelwidth]{biblatex}
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]
}
}
}
renewcommand*{multicitedelim}{addsemicolonspace}
letbibmacro{cite:num:comp}{cite:comp}
newbibmacro{cite:alpha}{%
printtext[bibhyperref]{%
printfield{labelprefix}%
printfield{labelalpha}%
printfield{extraalpha}%
ifbool{bbx:subentry}
{printfield{entrysetcount}}
{}}}
renewbibmacro*{cite:comp}{%
ifkeyword{primary}
{usebibmacro{cite:dump}%
ifnumgreater{value{cbx@tempcntb}}{-1}
{multicitedelim}
{iffirstcitekey
{}
{multicitedelim}}%
usebibmacro{cite:alpha}%
iflastcitekeylocal
{}
{multicitedelim}%
setcounter{cbx@tempcnta}{0}%
setcounter{cbx@tempcntb}{-2}}
{usebibmacro{cite:num:comp}}}
makeatletter
newcommand*iflastcitekeylocal{%
ifnumequalc@citecountc@citetotal}
renewbibmacro*{cite:init}{%
globalboolfalse{cbx:parens}%
globalundefcbx@lasthash
globalundefcbx@lastnumber
globalundefcbx@lastprefix
globalundefcbx@secondtolastprefix
setcounter{cbx@tempcnta}{0}%
setcounter{cbx@tempcntb}{-2}}
newcommand*{ifsamelabelprefix}{%
iffieldundef{labelprefix}
{ifundefcbx@lastprefix}
{iffieldequals{labelprefix}{cbx@lastprefix}}}
renewbibmacro*{cite:comp:comp}{%
renewcommand*{multicitedelim}{addcommaspace}%
ifsamelabelprefix
{ifnumequal{thefield{labelnumber}}{value{cbx@tempcntb}}
{savefield{entrykey}{cbx@lastkey}%
savefield{labelnumber}{cbx@lastnumber}%
addtocounter{cbx@tempcnta}{1}}
{ifnumequal{thefield{labelnumber}}{value{cbx@tempcntb}-1}
{}
{usebibmacro{cite:dump}%
ifnumgreater{value{cbx@tempcntb}}{-1}
{multicitedelim}
{}%
printtext[bibhyperref]{%
iffieldequals{labelprefix}{cbx@lastprefix}
{}
{printfield{labelprefix}}%
printfield{labelnumber}}}}}
{usebibmacro{cite:comp:end}}%
setcounter{cbx@tempcntb}{thefield{labelnumber}}%
globalletcbx@secondtolastprefixcbx@lastprefix
savefield{labelprefix}{cbx@lastprefix}}
renewbibmacro*{cite:dump}{%
ifnumgreater{value{cbx@tempcnta}}{0}
{ifnumgreater{value{cbx@tempcnta}}{1}
{bibrangedash}
{multicitedelim}%
bibhyperref[cbx@lastkey]{%
ifdefcbx@lastprefix
{ifdefequalcbx@lastprefixcbx@secondtolastprefix
{}
{printtext[labelprefix]{cbx@lastprefix}}}
{}%
printtext[labelnumber]{cbx@lastnumber}}}
{}%
setcounter{cbx@tempcnta}{0}}
makeatother
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]{##1hss}}
{endlist}
{item}
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}
addbibresource{biblatextest1.bib}
addbibresource{biblatextest2.bib}
begin{document}
The first two citations autocite{LinkD07,LinkC01}
and autocite{BookB10,BookB11,BookB09}.
Mixing both primary and secondary autocite{LinkD08,LinkD04,LinkD05,BookB10,BookB11,BookB09}.
The others are autocite{LinkC01,LinkD08,LinkD05,LinkD06,LinkD07}
as well as autocite{LinkC01,LinkD04,LinkD05,LinkD07,LinkD08, LinkD09}
and autocite{BookA03}.
printbibliography[env=bibliographyALPHA, title=Bibliography, keyword=primary]
newrefcontext[labelprefix=techstringadddotspace]
printbibliography[title=References, keyword=secondary, resetnumbers]
end{document}
Correct answer by moewe on March 22, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP