Skip to content

Instantly share code, notes, and snippets.

@SimonAB
Created February 22, 2020 18:08
Show Gist options
  • Save SimonAB/10531b52c75b4dad370744ea771c6460 to your computer and use it in GitHub Desktop.
Save SimonAB/10531b52c75b4dad370744ea771c6460 to your computer and use it in GitHub Desktop.
BibLaTeX compact style
%% ---------------------------------------------------------------
%% biblatex-compact
%% Version: 2020-02-22
%% ---------------------------------------------------------------
%%
\ProvidesFile{compact.bbx}
% Load the standard style to avoid copy-pasting unnecessary material
\RequireBibliographyStyle{numeric-comp}
% Additional options
\newtoggle{bbx:articletitle}
\DeclareBibliographyOption{articletitle}[true]{%
\settoggle{bbx:articletitle}{#1}%
}
% Alter settings that carry through from biblatex
\ExecuteBibliographyOptions{
articletitle = false ,
doi = false ,
giveninits ,
maxnames = 2 ,
maxcitenames = 2 ,
urldate = year ,
useprefix ,
}
\defbibenvironment{bibliography}
{\noindent}
{\unspace}
{\printtext[bold]{%
\printtext[labelnumberwidth]{%
% \printfield{labelprefix}%
\printfield{labelnumber}}}%
\addspace}
\renewbibmacro*{finentry}{\finentry\addspace}
% Modify the name format
\DeclareNameFormat{default}{%
\nameparts{#1}%
\usebibmacro{name:family}
{\namepartfamily}
{\namepartgiveni}
{\namepartprefix}
{\namepartsuffix}%
\usebibmacro{name:andothers}%
}
\renewbibmacro*{name:andothers}{%
\ifboolexpr{
test {\ifnumequal{\value{listcount}}{\value{liststop}}}
and
test \ifmorenames
}
{%
\ifnumgreater{\value{liststop}}{1}
{\finalandcomma}
{}%
\andothersdelim
\bibstring[\mkbibemph]{andothers}%
}
{}%
}
% Field formats for the bibliography environment
\DeclareFieldFormat{labelnumberwidth}{\mkbibbrackets{#1}}
% Custom field formats
\DeclareFieldFormat{edition}{%
\ifinteger{#1}
{\bibstring{edition}~#1}
{#1}%
}
\DeclareFieldFormat[inproceedings]{booktitle}{#1}
\DeclareFieldFormat{doi}{%
DOI\space
\ifhyperref
{\href{http://dx.doi.org/#1}{\nolinkurl{#1}}}
{\nolinkurl{#1}}%
}
\DeclareFieldFormat[article]{pages}{#1}
\DeclareFieldFormat[proceedings]{title}{#1}
\DeclareFieldFormat[article]{title}{#1\adddot\space\nopunct}
\DeclareFieldFormat[report]{title}{\mkbibquote{#1}}
\DeclareFieldFormat{url}{\url{#1}}
\DeclareFieldFormat{urldate}{#1}
\DeclareFieldFormat[article,periodical]{volume}{\mkbibbold{#1}}
% Simple modifications to punctuation, etc.
\renewcommand*{\finalnamedelim}{%
\ifcurrentname{labelname}
{%
\ifnumgreater{\value{liststop}}{2}
{\finalandcomma}
{}%
\addspace
\bibstring{and}%
\space
}
{\multinamedelim}%
}
\renewcommand*\intitlepunct{\addspace}
\renewcommand*\newunitpunct{\addcomma\space}
% Bibliography strings
\NewBibliographyString{presentedat}
\DefineBibliographyStrings{english}{
editor = Ed\adddot ,
editors = Eds\adddot ,
patentus = US Patent ,
presentedat = presented at the\addspace ,
}
% Bibliography macros
\renewbibmacro*{event+venue+date}{%
\printfield{eventtitle}%
\ifboolexpr{
test {\iffieldundef{venue}}
and
test {\iffieldundef{eventyear}}
}
{}
{%
\printfield{venue}%
\newunit
\iffieldundef{eventyear}
{%
\printdate
\clearfield{year}%
}
{%
\printeventdate
\clearfield{eventyear}%
}%
}%
\newunit
}
\renewbibmacro*{institution+location+date}{%
\ifboolexpr{
test {\iflistundef{institution}}
and
test {\iflistundef{location}}
and
test {\iffieldundef{edition}}
and
test {\iffieldundef{date}}
}
{}
{%
\nopunct
\printtext[parens]{%
\printlist{institution}%
\newunit
\printlist{location}%
\newunit
\printfield{edition}%
\newunit
\usebibmacro{date}%
}%
}%
}
\renewbibmacro*{journal+issuetitle}{%
\usebibmacro{journal}%
\setunit*{\addspace}%
\iffieldundef{series}
{}
{%
\newunit
\printfield{series}%
\setunit{\addspace}%
}%
\printfield{volume}%
\newunit
\usebibmacro{issue}%
\newunit
}
\renewbibmacro*{publisher+location+date}{%
\ifboolexpr{
test {\iflistundef{publisher}}
and
test {\iflistundef{location}}
and
test {\iffieldundef{edition}}
and
test {\iffieldundef{date}}
}
{}
{%
\nopunct
\printtext[parens]{%
\printlist{publisher}%
\newunit
\printlist{location}%
\newunit
\printfield{edition}%
\newunit
\usebibmacro{date}%
}%
}%
}
\renewbibmacro*{url+urldate}{%
\iffieldundef{url}
{}
{%
\printtext[parens]{%
\usebibmacro{urldate}%
\setunit*{\addsemicolon\space}%
\usebibmacro{url}%
}}}
% New bibliography drivers, using the required order of fields. These
% are mainly copied from standard.bbx then modified.
\DeclareBibliographyDriver{article}{%
\usebibmacro{bibindex}%
\usebibmacro{begentry}%
\usebibmacro{author/translator+others}%
\setunit{\labelnamepunct}\newblock
\iftoggle{bbx:articletitle}
{\usebibmacro{title}}
{}%
\newunit
\printlist{language}%
\newunit\newblock
\usebibmacro{byauthor}%
\newunit\newblock
\usebibmacro{bytranslator+others}%
\newunit\newblock
\printfield{version}%
\newunit\newblock
\usebibmacro{journal+issuetitle}%
\newunit
\usebibmacro{byeditor+others}%
\newunit
\usebibmacro{note+pages}%
\newunit
\iftoggle{bbx:isbn}
{\printfield{issn}}
{}%
\newunit\newblock
\usebibmacro{doi+eprint+url}%
\setunit{\addspace}\newblock
\iffieldundef{year}
{\printfield{howpublished}}
{\usebibmacro{issue+date}}%
\newunit\newblock
\usebibmacro{addendum+pubstate}%
\setunit{\bibpagerefpunct}\newblock
\usebibmacro{pageref}%
\newunit\newblock
\iftoggle{bbx:related}
{\usebibmacro{related:init}%
\usebibmacro{related}}
{}%
\usebibmacro{finentry}%
}
\DeclareBibliographyDriver{book}{%
\usebibmacro{bibindex}%
\usebibmacro{begentry}%
\usebibmacro{author/editor+others/translator+others}%
\setunit{\labelnamepunct}\newblock
\usebibmacro{maintitle+title}%
\newunit
\printlist{language}%
\newunit\newblock
\usebibmacro{byauthor}%
\newunit\newblock
\usebibmacro{byeditor+others}%
\newunit\newblock
\printfield{volumes}%
\newunit\newblock
\newunit\newblock
\printfield{note}%
\newunit\newblock
\usebibmacro{publisher+location+date}%
\newunit\newblock
\printfield{volume}
\newunit
\usebibmacro{chapter+pages}%
\newunit
\printfield{pagetotal}%
\newunit\newblock
\iftoggle{bbx:isbn}
{\printfield{isbn}}
{}%
\newunit\newblock
\usebibmacro{doi+eprint+url}%
\newunit\newblock
\usebibmacro{addendum+pubstate}%
\setunit{\bibpagerefpunct}\newblock
\usebibmacro{pageref}%
\newunit\newblock
\iftoggle{bbx:related}
{\usebibmacro{related:init}%
\usebibmacro{related}}
{}%
\usebibmacro{finentry}%
}
\DeclareBibliographyDriver{collection}{%
\usebibmacro{bibindex}%
\usebibmacro{begentry}%
\usebibmacro{editor+others}%
\setunit{\labelnamepunct}\newblock
\usebibmacro{maintitle+title}%
\newunit
\printlist{language}%
\newunit\newblock
\usebibmacro{byeditor+others}%
\newunit\newblock
\printfield{volumes}%
\newunit\newblock
\printfield{note}%
\newunit\newblock
\usebibmacro{publisher+location+date}%
\newunit\newblock
\printfield{volume}
\newunit
\usebibmacro{chapter+pages}%
\newunit
\printfield{pagetotal}%
\newunit\newblock
\iftoggle{bbx:isbn}
{\printfield{isbn}}
{}%
\newunit\newblock
\usebibmacro{doi+eprint+url}%
\newunit\newblock
\usebibmacro{addendum+pubstate}%
\setunit{\bibpagerefpunct}\newblock
\usebibmacro{pageref}%
\newunit\newblock
\iftoggle{bbx:related}
{\usebibmacro{related:init}%
\usebibmacro{related}}
{}%
\usebibmacro{finentry}%
}
\DeclareBibliographyDriver{inbook}{%
\usebibmacro{bibindex}%
\usebibmacro{begentry}%
\usebibmacro{author/translator+others}%
\setunit{\labelnamepunct}\newblock
\printlist{language}%
\newunit\newblock
\usebibmacro{byauthor}%
\newunit\newblock
\usebibmacro{in:}%
\usebibmacro{bybookauthor}%
\setunit*{\newunitpunct}\newblock
\usebibmacro{maintitle+booktitle}%
\newunit\newblock
\usebibmacro{byeditor+others}%
\newunit\newblock
\printfield{volumes}%
\newunit\newblock
\printfield{note}%
\newunit\newblock
\usebibmacro{publisher+location+date}%
\newunit\newblock
\printfield{volume}
\newunit
\usebibmacro{chapter+pages}%
\newunit\newblock
\iftoggle{bbx:isbn}
{\printfield{isbn}}
{}%
\newunit\newblock
\usebibmacro{doi+eprint+url}%
\newunit\newblock
\usebibmacro{addendum+pubstate}%
\setunit{\bibpagerefpunct}\newblock
\usebibmacro{pageref}%
\newunit\newblock
\iftoggle{bbx:related}
{\usebibmacro{related:init}%
\usebibmacro{related}}
{}%
\usebibmacro{finentry}%
}
\DeclareBibliographyDriver{incollection}{%
\usebibmacro{bibindex}%
\usebibmacro{begentry}%
\usebibmacro{author/translator+others}%
\setunit{\labelnamepunct}\newblock
\printlist{language}%
\newunit\newblock
\usebibmacro{byauthor}%
\newunit\newblock
\usebibmacro{in:}%
\usebibmacro{maintitle+booktitle}%
\newunit\newblock
\usebibmacro{byeditor+others}%
\newunit\newblock
\printfield{volumes}%
\newunit\newblock
\printfield{note}%
\newunit\newblock
\usebibmacro{publisher+location+date}%
\newunit\newblock
\printfield{volume}
\newunit
\usebibmacro{chapter+pages}%
\newunit\newblock
\iftoggle{bbx:isbn}
{\printfield{isbn}}
{}%
\newunit\newblock
\usebibmacro{doi+eprint+url}%
\newunit\newblock
\usebibmacro{addendum+pubstate}%
\setunit{\bibpagerefpunct}\newblock
\usebibmacro{pageref}%
\newunit\newblock
\iftoggle{bbx:related}
{\usebibmacro{related:init}%
\usebibmacro{related}}
{}%
\usebibmacro{finentry}%
}
\DeclareBibliographyDriver{inproceedings}{%
\usebibmacro{bibindex}%
\usebibmacro{begentry}%
\usebibmacro{author/translator+others}%
\setunit{\labelnamepunct}\newblock
\printlist{language}%
\newunit\newblock
\usebibmacro{byauthor}%
\newunit\newblock
\bibstring{presentedat}%
\usebibmacro{maintitle+booktitle}%
\newunit\newblock
\usebibmacro{byeditor+others}%
\newunit\newblock
\iffieldundef{maintitle}
{\printfield{volume}%
\printfield{part}}
{}%
\newunit
\printfield{volumes}%
\newunit\newblock
\printfield{note}%
\newunit\newblock
\usebibmacro{event+venue+date}%
\newunit\newblock
\usebibmacro{chapter+pages}%
\newunit\newblock
\iftoggle{bbx:isbn}
{\printfield{isbn}}
{}%
\newunit\newblock
\usebibmacro{doi+eprint+url}%
\newunit\newblock
\usebibmacro{addendum+pubstate}%
\setunit{\bibpagerefpunct}\newblock
\usebibmacro{pageref}%
\newunit\newblock
\iftoggle{bbx:related}
{\usebibmacro{related:init}%
\usebibmacro{related}}
{}%
\usebibmacro{finentry}%
}
\DeclareBibliographyDriver{online}{%
\usebibmacro{bibindex}%
\usebibmacro{begentry}%
\usebibmacro{author/editor+others/translator+others}%
\setunit{\labelnamepunct}\newblock
\usebibmacro{title}%
\newunit
\printlist{language}%
\newunit\newblock
\usebibmacro{byauthor}%
\newunit\newblock
\usebibmacro{byeditor+others}%
\newunit\newblock
\printfield{version}%
\newunit
\printfield{note}%
\newunit\newblock
\printlist{organization}%
\newunit\newblock
\iftoggle{bbx:eprint}
{\usebibmacro{eprint}}
{}%
\nopunct
\usebibmacro{url+urldate}%
\newunit\newblock
\usebibmacro{addendum+pubstate}%
\setunit{\bibpagerefpunct}\newblock
\usebibmacro{pageref}%
\newunit\newblock
\usebibmacro{related}%
\usebibmacro{finentry}%
}
\DeclareBibliographyDriver{patent}{%
\usebibmacro{bibindex}%
\usebibmacro{begentry}%
\usebibmacro{author}%
\setunit{\labelnamepunct}\newblock
\printlist{language}%
\newunit\newblock
\usebibmacro{byauthor}%
\newunit\newblock
\printfield{type}%
\newunit
\printfield{number}%
\iflistundef{location}
{}
{\setunit*{\addspace}%
\printtext[parens]{%
\printlist[][-\value{listtotal}]{location}}}%
\newunit\newblock
\printfield{note}%
\newunit\newblock
\usebibmacro{doi+eprint+url}%
\newunit
\nopunct
\printfield[parens]{year}%
\newunit\newblock
\usebibmacro{addendum+pubstate}%
\setunit{\bibpagerefpunct}\newblock
\usebibmacro{pageref}%
\newunit\newblock
\iftoggle{bbx:related}
{\usebibmacro{related:init}%
\usebibmacro{related}}
{}%
\usebibmacro{finentry}%
}
\DeclareBibliographyDriver{periodical}{%
\usebibmacro{bibindex}%
\usebibmacro{begentry}%
\printfield{issuetitle}%
\newunit
\usebibmacro{author/editor+others/translator+others}%
\setunit{\labelnamepunct}\newblock
\usebibmacro{maintitle+title}%
\newunit
\printlist{language}%
\newunit\newblock
\usebibmacro{byauthor}%
\newunit\newblock
\usebibmacro{byeditor+others}%
\newunit\newblock
\printfield{volumes}%
\newunit\newblock
\newunit\newblock
\printfield{note}%
\newunit\newblock
\usebibmacro{publisher+location+date}%
\newunit\newblock
\printfield{volume}
\newunit
\usebibmacro{chapter+pages}%
\newunit
\printfield{pagetotal}%
\newunit\newblock
\iftoggle{bbx:isbn}
{\printfield{isbn}}
{}%
\newunit\newblock
\usebibmacro{addendum+pubstate}%
\setunit{\bibpagerefpunct}\newblock
\usebibmacro{pageref}%
\newunit\newblock
\iftoggle{bbx:related}
{\usebibmacro{related:init}%
\usebibmacro{related}}
{}%
\usebibmacro{finentry}%
}
\DeclareBibliographyDriver{thesis}{%
\usebibmacro{bibindex}%
\usebibmacro{begentry}%
\usebibmacro{author}%
\setunit{\labelnamepunct}\newblock
\printlist{language}%
\newunit\newblock
\usebibmacro{byauthor}%
\newunit\newblock
\printfield{note}%
\newunit\newblock
\printfield{type}%
\newunit\newblock
\printlist{institution}%
\newunit
\printdate
\newunit\newblock
\usebibmacro{chapter+pages}%
\newunit
\printfield{pagetotal}%
\newunit\newblock
\usebibmacro{doi+eprint+url}%
\newunit\newblock
\usebibmacro{addendum+pubstate}%
\setunit{\bibpagerefpunct}\newblock
\usebibmacro{pageref}%
\newunit\newblock
\iftoggle{bbx:related}
{\usebibmacro{related:init}%
\usebibmacro{related}}
{}%
\usebibmacro{finentry}%
}
%%
%% Copyright (C) 2010-2013,2016,2018 by
%% Joseph Wright <joseph.wright@morningstar2.co.uk>
%%
%% It may be distributed and/or modified under the conditions of
%% the LaTeX Project Public License (LPPL), either version 1.3c of
%% this license or (at your option) any later version. The latest
%% version of this license is in the file:
%%
%% http://www.latex-project.org/lppl.txt
%%
%% This work is "maintained" (as per LPPL maintenance status) by
%% Joseph Wright.
%%
%% This work consists of the file biblatex-science.bib,
%% biblatex-science.tex,
%% science.bbx and
%% science.cbx,
%% and the derived file biblatex-science.pdf.
%%
%%
%% End of file `science.bbx'.
%% ---------------------------------------------------------------
%% biblatex-compact
%% Version: 2020-02-22
%% ---------------------------------------------------------------
%%
\ProvidesFile{compact.cbx}
\RequireCitationStyle{numeric-comp}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment