Instantly share code, notes, and snippets.

Embed
What would you like to do?
biblatex style to be able to use the numeric style in one section and the alphabetic in another
% This is an unholy mashup of the numeric.bbx and alphabetic.bbx files from
% the standard biblatex distribution, made so we can switch between numeric
% style for the main body and alphabetic style for the appendix.
\ProvidesFile{alphanumeric-hybrid.bbx}
[\abx@bbxid]
\RequireBibliographyStyle{standard}
\ExecuteBibliographyOptions{labelalpha,labelnumber,sorting=anyt}
% To use the alphabetic section in one refsection, \setbool{bbx:alpha}{true} at the start;
% to switch back, \setbool{bbx:alpha}{false}.
\providebool{bbx:alpha}
\DeclareNameAlias{author}{default}
\DeclareNameAlias{editor}{default}
\DeclareNameAlias{translator}{default}
\DeclareFieldFormat{labelalphawidth}{\mkbibbrackets{#1}}
\DeclareFieldFormat{labelnumberwidth}{\mkbibbrackets{#1}}
\DeclareFieldFormat{shorthandwidth}{\mkbibbrackets{#1}}
\defbibenvironment{bibliography}
{\list
{\ifbool{bbx:alpha}{%
\printtext[labelalphawidth]{%
\printfield{prefixnumber}%
\printfield{labelalpha}%
\printfield{extraalpha}%
}%
}{%
\printtext[labelnumberwidth]{%
\printfield{prefixnumber}%
\printfield{labelnumber}%
}%
}}
{\setlength{\labelwidth}{\ifbool{bbx:alpha}{\labelalphawidth}{\labelnumberwidth}}%
\setlength{\leftmargin}{\labelwidth}%
\setlength{\labelsep}{\biblabelsep}%
\addtolength{\leftmargin}{\labelsep}%
\setlength{\itemsep}{\bibitemsep}%
\setlength{\parsep}{\bibparsep}}%
\ifbool{bbx:alpha}{%
\renewcommand*{\makelabel}[1]{##1\hss}%
}{%
\renewcommand*{\makelabel}[1]{\hss##1}%
}}
{\endlist}
{\item}
\defbibenvironment{shorthands}
{\list
{\printfield[shorthandwidth]{shorthand}}
{\setlength{\labelwidth}{\shorthandwidth}%
\setlength{\leftmargin}{\labelwidth}%
\setlength{\labelsep}{\biblabelsep}%
\addtolength{\leftmargin}{\labelsep}%
\setlength{\itemsep}{\bibitemsep}%
\setlength{\parsep}{\bibparsep}%
\ifbool{bbx:alpha}{%
\renewcommand*{\makelabel}[1]{##1\hss}%
}{%
\renewcommand*{\makelabel}[1]{\hss##1}%
}}}
{\endlist}
{\item}
\endinput
\ProvidesFile{alphanumeric-hybrid.cbx}
[\abx@cbxid]
\ExecuteBibliographyOptions{labelalpha,labelnumber,autocite=inline}
\renewcommand*{\multicitedelim}{\ifbool{bbx:alpha}{\addsemicolon}{\addcomma}\space}
\renewcommand*{\iffinalcitedelim}{%
\ifnumequal{\value{textcitecount}}{\value{textcitetotal}-1}}
\providebool{bbx:alpha}
\newbool{cbx:parens}
\newbibmacro*{cite}{%
\printtext[bibhyperref]{%
\printfield{prefixnumber}%
\ifbool{bbx:alpha}{%
\printfield{labelalpha}%
\printfield{extraalpha}%
}{%
\printfield{labelnumber}%
}}}
\newbibmacro*{textcite}{%
\iffieldequals{namehash}{\cbx@lasthash}
{\setunit{\multicitedelim}}
{\ifnameundef{labelname}
{\printfield[citetitle]{labeltitle}}
{\printnames{labelname}}%
\setunit{%
\global\booltrue{cbx:parens}%
\addspace\bibopenbracket}%
\stepcounter{textcitecount}%
\savefield{namehash}{\cbx@lasthash}}%
\ifnumequal{\value{citecount}}{1}
{\usebibmacro{prenote}}
{}%
\usebibmacro{cite}%
\setunit{%
\ifbool{cbx:parens}
{\bibcloseparen\global\boolfalse{cbx:parens}}
{}%
\textcitedelim}}
\newbibmacro*{textcite:init}{%
\ifnumless{\value{multicitecount}}{2}
{\global\boolfalse{cbx:parens}%
\global\undef\cbx@lasthash}
{\global\undef\cbx@lasthash}}
\newbibmacro*{textcite:postnote}{%
\usebibmacro{postnote}%
\ifthenelse{\value{multicitecount}=\value{multicitetotal}}
{\setunit{}%
\printtext{%
\ifbool{cbx:parens}
{\bibcloseparen\global\boolfalse{cbx:parens}}
{}}}
{\setunit{%
\ifbool{cbx:parens}
{\bibcloseparen\global\boolfalse{cbx:parens}}
{}%
\textcitedelim}}}
\DeclareCiteCommand{\cite}[\mkbibbrackets]
{\usebibmacro{prenote}}
{\usebibmacro{citeindex}%
\usebibmacro{cite}}
{\multicitedelim}
{\usebibmacro{postnote}}
\DeclareCiteCommand{\parencite}[\mkbibbrackets]
{\usebibmacro{prenote}}
{\usebibmacro{citeindex}%
\usebibmacro{cite}}
{\multicitedelim}
{\usebibmacro{postnote}}
\DeclareCiteCommand{\footcite}[\mkbibfootnote]
{\usebibmacro{prenote}}
{\usebibmacro{citeindex}%
\usebibmacro{cite}}
{\multicitedelim}
{\usebibmacro{postnote}}
\DeclareCiteCommand{\footcitetext}[\mkbibfootnotetext]
{\usebibmacro{prenote}}
{\usebibmacro{citeindex}%
\usebibmacro{cite}}
{\multicitedelim}
{\usebibmacro{postnote}}
\DeclareCiteCommand{\smartcite}[\iffootnote\mkbibbrackets\mkbibfootnote]
{\usebibmacro{prenote}}
{\usebibmacro{citeindex}%
\usebibmacro{cite}}
{\multicitedelim}
{\usebibmacro{postnote}}
\DeclareCiteCommand{\cbx@textcite}
{\usebibmacro{textcite:init}}
{\usebibmacro{citeindex}%
\usebibmacro{textcite}}
{}
{\usebibmacro{textcite:postnote}}
\DeclareCiteCommand{\textcite}[\cbx@textcite@init\cbx@textcite]
{\gdef\cbx@savedkeys{}%
\citetrackerfalse%
\pagetrackerfalse%
\DeferNextCitekeyHook%
\usebibmacro{textcite:init}}
{\ifthenelse{\iffirstcitekey\AND\value{multicitetotal}>0}
{\protected@xappto\cbx@savedcites{()(\thefield{multipostnote})}%
\global\clearfield{multipostnote}}
{}%
\xappto\cbx@savedkeys{\thefield{entrykey},}%
\iffieldequals{namehash}{\cbx@lasthash}
{}
{\stepcounter{textcitetotal}%
\savefield{namehash}{\cbx@lasthash}}}
{}
{\protected@xappto\cbx@savedcites{%
[\thefield{prenote}][\thefield{postnote}]{\cbx@savedkeys}}}
\newrobustcmd{\cbx@textcite@init}[2]{%
\setcounter{textcitetotal}{0}%
\setcounter{textcitecount}{0}%
\def\cbx@savedcites{#1}#2\cbx@savedcites\empty}
\DeclareMultiCiteCommand{\cbx@textcites}{\cbx@textcite}{}
\DeclareMultiCiteCommand{\textcites}[\cbx@textcites@init\cbx@textcites]{\textcite}{}
\let\cbx@textcites@init\cbx@textcite@init
\pretocmd{\cbx@textcites@init}{\UseNextMultiCiteHook}{}{}
\DeclareMultiCiteCommand{\cites}[\mkbibbrackets]{\cite}{\multicitedelim}
\DeclareMultiCiteCommand{\parencites}[\mkbibbrackets]{\parencite}{\multicitedelim}
\DeclareMultiCiteCommand{\smartcites}[\iffootnote\mkbibbrackets\mkbibfootnote]
{\smartcite}{\multicitedelim}
\endinput
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment