% \iffalse meta-comment
%
% Copyright (C) 2019-2025 by Jan Hajer
% -----------------------------------
%
% This file may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3c
% of this license or (at your option) any later version.
% The latest version of this license is in:
%
% http://www.latex-project.org/lppl.txt
%
% and version 1.3c or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
% \fi
%
% \iffalse

%<package>\NeedsTeXFormat{LaTeX2e}[2021-11-15]
%<package>\ProvidesPackage{hep-bibliography}[2026/08/01 v1.5 HEP-Bibliography]
%<datamodel>\ProvidesFile{hep-bibliography.dbx}[2026/08/01 v1.5 HEP-Bibliography biblatex data model]
%<documentation>\ProvidesFile{hep-bibliography-documentation.tex}[2026/08/01 v1.5 HEP-Bibliography documentation]
%
%<*documentation>
\RequirePackage[l2tabu, orthodox]{nag}
\documentclass{ltxdoc}

\renewcommand*\theCodelineNo{\rmfamily\tstyle\footnotesize\arabic{CodelineNo}}
\AtBeginEnvironment{macrocode}{\renewcommand*{\ttdefault}{clmt}}
\renewcommand*{\MacroFont}{\codestyle}
\AtBeginDocument{\DeleteShortVerb{\|}}
\AtBeginDocument{\MakeShortVerb{\"}}
\EnableCrossrefs
\CodelineIndex
\RecordChanges

\usepackage{hologo}

\usepackage[parskip,oldstyle,font=10pt]{hep-paper}
\bibliography{bibliography}
\acronym{URL}{uniform resource locator}
%</documentation>

%<*driver>
\expandafter\newif\csname ifshort\endcsname
\shortfalse
\begin{document}
\DocInput{hep-bibliography-implementation.dtx}
\end{document}
%</driver>
%
% \fi
%
% \CheckSum{354}
%
% \CharacterTable
%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%   Digits        \0\1\2\3\4\5\6\7\8\9
%   Exclamation   \!     Double quote  \"     Hash (number) \#
%   Dollar        \$     Percent       \%     Ampersand     \&
%   Acute accent  \'     Left paren    \(     Right paren   \)
%   Asterisk      \*     Plus          \+     Comma         \,
%   Minus         \-     Point         \.     Solidus       \/
%   Colon         \:     Semicolon     \;     Less than     \<
%   Equals        \=     Greater than  \>     Question mark \?
%   Commercial at \@     Left bracket  \[     Backslash     \\
%   Right bracket \]     Circumflex    \^     Underscore    \_
%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%   Right brace   \}     Tilde         \~}
%
% \changes{v1.0}{2021/09/01}{Created the dedicated biblatex package with InspireHEP fields, source maps, errata handling, citation back-links, and HEP e-print formats.}
% \changes{v1.1}{2022/11/01}{Passed biblatex options before loading the package and corrected the SourceForge e-print alias.}
% \changes{v1.2}{2023/07/01}{Reworked bibliography back-links through citation targets, stripped leading zeros from page ranges, namespaced source-map and e-print helpers, added CDS and HEPData e-print formats, and refreshed documentation and README formatting.}
% \changes{v1.3}{2024/11/01}{Stopped globally wrapping \cs{printbibliography} in \cs{sloppy} and restored release metadata.}
% \changes{v1.4}{2025/09/01}{Applied starred command definitions consistently and expanded the bibliography test entry.}
% \changes{v1.5}{2026/08/01}{Raised the LaTeX format requirement, bumped release metadata, and expanded the abstract, user documentation, README, and examples to cover bibliography setup, InspireHEP fields, source maps, back-links, e-print formats, and errata.}
%
% \ifshort
%<*documentation>
% \fi
%
\GetFileInfo{hep-bibliography.sty}

\title{The \software{hep-bibliography} package\thanks{This document corresponds to \software{hep-bibliography}~\fileversion.}}
\subtitle{Bibliographies for high energy physics}
\author{Jan Hajer \email{jan.hajer@tecnico.ulisboa.pt}}
\date{\filedate}

% \ifshort
\begin{document}
% \fi

\newgeometry{vscale=.8, vmarginratio=3:4, includeheadfoot, left=11em, marginparwidth=4.6cm, marginparsep=3mm, right=7em}

\maketitle

\begin{abstract}
The \software{hep-bibliography} package configures \software{biblatex} for high-energy physics publications.
It adds the \software{InspireHEP} data fields used in HEP bibliographies, citation back-links from bibliography labels, source maps for common BibTeX variants, erratum handling, and eprint formats for arXiv, PubMed, code-hosting, and package repositories.
\end{abstract}

The package can be loaded via "\usepackage{hep-bibliography}".

\DescribeMacro{style}
The "style="\meta{name} option selects the \software{biblatex} style passed to "\RequirePackage{biblatex}".
The default is "numeric-comp".

\DescribeMacro{\bibliography}
\DescribeMacro{\printbibliography}
The \software{biblatex} package \cite{biblatex} is loaded for bibliography management.
The user has to add the line "\bibliography"\marg{my.bib} to the preamble of the document and "\printbibliography" at the end of the document.
The bibliography is generated by \software{Biber} \cite{biber}.
"biblatex" is extended to read the "collaboration" and "reportNumber" fields provided by \online{https://inspirehep.net}{inspirehep.net}, to normalise selected volume, issue, URL, and PubMed data, and to link bibliography labels back to the first citation.
Additionally, arXiv, PubMed, PubMed Central, \online{https://ctan.org}{ctan.org}, \online{https://github.com}{github.com}, \online{https://gitlab.com}{gitlab.com}, \online{https://bitbucket.org}{bitbucket.org}, \online{https://www.launchpad.net}{launchpad.net}, \online{https://sourceforge.net}{sourceforge.net}, and \online{https://hepforge.org}{hepforge.org} are valid "eprinttype"s.

\DescribeMacro{\online}
\DescribeMacro{\email}
The "\online"\marg{url}\marg{text} macro prints link text that becomes a hyperlink if \software{hyperref} is loaded.
The "\email"\marg{address} macro is a mail link wrapper using the same fallback.

\DescribeEnv{commalist}
The "commalist" environment typesets "\item"-separated entries as a comma-separated list with a final \enquote{and}.

\DescribeMacro{erratum}
Errata can be included using the "related" feature.
\begin{verbatim}
\article{key1,
  ...,
  relatedtype="erratum",
  related="key2",
}
\article{key2,
  ...,
}
\end{verbatim}

% \ifshort
\printbibliography

\end{document}
%
%</documentation>
% \fi
%
% \StopEventually{
% \printbibliography
% \PrintChanges
% }
%
% \appendix
%
% \section{Implementation}
%
%<*package>

% Load the \software{kvoptions} package \cite{kvoptions} and define a "hepbib" namespace.
%    \begin{macrocode}
\RequirePackage{kvoptions}
\SetupKeyvalOptions{
  family=hepbib,
  prefix=hepbib@
}
%    \end{macrocode}
%
% \begin{macro}{bibliography}
% Provide the "style" option for passing a "style" string to the \software{biblatex} package \cite{biblatex} or disabling the automatic loading of "biblatex".
%    \begin{macrocode}
\DeclareStringOption[numeric-comp]{style}
%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
\ProcessKeyvalOptions*
%    \end{macrocode}
%
% \begin{macro}{\online}
% \begin{macro}{\email}
% Define the "\online"\marg{text}\marg{url} macro combining the features of the "\href" and the "\url" macros.
% Define a macro for typesetting emails.
%    \begin{macrocode}
\providecommand*{\online}[2]{\texttt{#2}}%
\providecommand*{\hep@email}[1]{\online{mailto:#1}{#1}}
\providecommand*\email{\hep@email}
\AtBeginDocument{\@ifpackageloaded{hyperref}{%
    \renewcommand*{\online}[2]{\href{#1}{\nolinkurl{#2}}}%
  }{}
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{environment}{commalist}
% Define a commalist environment using the "xparse" package \cite{xparse}.
%    \begin{macrocode}
\RequirePackage{xparse}
\ExplSyntaxOn
\NewDocumentEnvironment{commalist}{O{\space}+b}{
  \hep@comma@list:n{#2}
}{#1}
\seq_new:N \hep@items@sequence
\cs_new_protected:Npn \hep@comma@list:n #1{
  \seq_set_split:Nnn \hep@items@sequence{\item}{#1}
  \seq_pop_left:NN \hep@items@sequence \l_tmpa_tl
  \seq_use:Nnnn \hep@items@sequence{~and~}{,~}{,~and~}
}
\ExplSyntaxOff
%    \end{macrocode}
% \end{environment}
%
%
% \begin{macro}{\bibliography}
% Load the \software{biblatex} package \cite{biblatex} with the datamodel defined in \cref{sec:data model}.
%    \begin{macrocode}
\PassOptionsToPackage{
  style=\hepbib@style,
  datamodel=hep-bibliography
}{biblatex}
\RequirePackage{biblatex}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{hep-bibliography}
% Provide the "\DeclareSortingTemplate" macro for older "biblatex" installations.
% Define a new sorting template that sorts only multi key "\cite" entries according to their date and leaves the rest of the bibliography entries in the order they appear in the text.
%    \begin{macrocode}
\providecommand*{\DeclareSortingTemplate}{\DeclareSortingScheme}
\DeclareSortingTemplate{hep-bibliography}{
  \sort{\citeorder}
  \sort[final]{\field{sortkey}}
  \sort{\field{sortyear} \field{year} \literal{9999}}
  \sort{\field{month}}
  \sort{\field{eprint} \field{doi}}
  \sort{\field{sorttitle} \field{title}}
  \sort{\field{subtitle} \field{volume}}
}
%    \end{macrocode}
% \end{macro}
%
% Use the new sorting scheme and abbreviat all first names.
%    \begin{macrocode}
\ExecuteBibliographyOptions{
  sorting=hep-bibliography,
  safeinputenc,
  giveninits=true,
  maxbibnames=7,
}
%    \end{macrocode}
%
%
% Redefine the "pages" filed such that leading zeros are stripped from the page numbers.
%    \begin{macrocode}
\newcommand*\hep@strip@zero[1]{\expandafter\hep@strip@zero@helper#1}
\newcommand*\hep@strip@zero@helper[1]{%
  \ifx0#1\expandafter\hep@strip@zero@helper\else#1\fi%
}
\DeclareFieldFormat{pages}{%
  \mkpageprefix[bookpagination][{\mknormrange[][\hep@strip@zero]}]{#1}%
}
%    \end{macrocode}
%
% Define an internal bibhypertarget.
%    \begin{macrocode}
\DeclareFieldFormat{bibhypertarget}{%
  \bibhypertarget{\thefield{entrykey}:\the\value{instcount}}{#1}%
}
%    \end{macrocode}
% Redefine the citation command to set the bibhypertarget and call the cite:save macro.
%    \begin{macrocode}
\renewbibmacro*{cite:comp}{%
  \printtext[bibhypertarget]{%
    \stepcounter{cbx@tempcntb}%
    \iffieldundef{shorthand}{%
      \ifbool{bbx:subentry}{%
        \iffieldundef{entrysetcount}{%
          \usebibmacro{cite:comp:comp}}{\usebibmacro{cite:comp:inset}%
        }%
      }{\usebibmacro{cite:comp:comp}}%
    }{\usebibmacro{cite:comp:shand}}%
  }%
  \usebibmacro{cite:save}%
}
%    \end{macrocode}
% Define the cite:safe macro
%    \begin{macrocode}
\newbibmacro*{cite:save}{%
  \ifcsundef{cbx@\thefield{entrykey}}{%
    \csxdef{cbx@\thefield{entrykey}}{\the\value{instcount}}%
  }{}%
}
%    \end{macrocode}
% Link from the bibliography to the first cite.
%    \begin{macrocode}
\newbibmacro{cbx:linktofirstcite}[1]{%
  \ifcsdef{cbx@\thefield{entrykey}}{%
    \bibhyperlink{%
      \thefield{entrykey}:\csuse{cbx@\thefield{entrykey}}%
    }{#1}%
  }{#1}%
}
%    \end{macrocode}
% Ensure table style numbers in the bibliography labels.
%    \begin{macrocode}
\providecommand*{\tstyle}{}
\DeclareFieldFormat{labelnumberwidth}{%
  \usebibmacro{cbx:linktofirstcite}{\mkbibbrackets{\tstyle#1}}%
}
%    \end{macrocode}
% Deactivate counting during caption measurement.
%    \begin{macrocode}
\AtBeginDocument{\@ifpackageloaded{caption}{%
  \g@addto@macro\caption@prepareslc{\let\blx@citeprint\relax}}{}%
}
%    \end{macrocode}
%
% Shrink the biblography in two column mode.
%    \begin{macrocode}
\if@twocolumn
  \AtBeginBibliography{\small}
  \setlength\biblabelsep{\labelsep}
\fi
%    \end{macrocode}
%
% \begin{macro}{translationof}
% Redefine the "translationof" string to fit better to documents without a original title.
%    \begin{macrocode}
\DefineBibliographyStrings{english}{translationof={Original}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{erratum}
% Add new bibliography string \enquote{Erratum} for the use in the "relatedtype" field.
%    \begin{macrocode}
\NewBibliographyString{erratum,erratums}
\DefineBibliographyStrings{english}{erratum={Erratum},erratums={Errata}}
\providecommand*{\relateddelimerratum}{\addsemicolon\space}
%    \end{macrocode}
% \end{macro}
%
% Activate the Oxford comma when using "british" and separate title and subtitle with a colon.
%    \begin{macrocode}
\DefineBibliographyExtras{british}{\def\finalandcomma{\addcomma}}
\renewcommand*{\subtitlepunct}{\addcolon\addspace}
%    \end{macrocode}
%
% \begin{macro}{\printbibliography}
% Allow the bibliography to be printed sloppy
%    \begin{macrocode}
% \let\hep@printbibliography\printbibliography
% \renewcommand*{\printbibliography}{{\sloppy\hep@printbibliography}}
%    \end{macrocode}
% \end{macro}

% \subsection{Sourcemap}
%
% \begin{macro}{\hep@reg@exp@one}
% \begin{macro}{\hep@reg@exp@two}
% \begin{macro}{\hep@reg@exp@url}
% \begin{macro}{\hep@reg@exp@pmc}
% Define regular expressions in order to deal with inconsistent journal title and volume naming as well as \URL protocols and the PMCID.
%    \begin{macrocode}
\newcommand*{\hep@reg@exp@one}{\regexp{\A(\p{L}+)?\d+(\p{L}+)?\Z}}
\newcommand*{\hep@reg@exp@two}{\regexp{\A(\p{L}+)?(\d+)(\p{L}+)?\Z}}
\newcommand*{\hep@reg@exp@url}{\regexp{\A(ht|f)tp(s)?:\/\/}}
\newcommand*{\hep@reg@exp@pmc}{\regexp{\A(PMC)?}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\DeclareSourcemap}
% Use the "\DeclareSourcemap" feature.
%    \begin{macrocode}
\DeclareSourcemap{%
  \maps[datatype=bibtex, overwrite=true]{%
%    \end{macrocode}
% \begin{macro}{collaboration}
% Read the collaboration information if present.
%    \begin{macrocode}
    \map{%
      \step[fieldsource=Collaboration, final=true]%
      \step[fieldset=collaboration, origfieldval, final=true]
    }%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{reportnumber}
% Read the pre-print information if present.
%    \begin{macrocode}
    \map{%
      \step[fieldsource=reportNumber, final=true]%
      \step[fieldset=reportnumber, origfieldval, final=true]
    }%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{journal}
% Move letters from the volume field to the journal field.
%    \begin{macrocode}
    \map[overwrite]{
      \pertype{article}
      \step[fieldsource=volume, match=\hep@reg@exp@one, final]
      \step[fieldsource=volume, match=\hep@reg@exp@two, replace={$2}]
      \step[fieldsource=journal, fieldtarget=journaltitle]
      \step[fieldset=journaltitle, fieldvalue={\space$1$2}, append=true]
    }
%    \end{macrocode}
% \end{macro}
% \begin{macro}{url}
% Remove the protocol from \URL.
%    \begin{macrocode}
    \map{
      \step[fieldsource=url, final=true]
      \step[fieldset=protocollessurl, origfieldval, final=true]
      \step[fieldsource=protocollessurl,
            match=\hep@reg@exp@url, replace={}]
    }
%    \end{macrocode}
% \end{macro}
% \begin{macro}{pmc}
% Remove the PMC from the PMCID.
%    \begin{macrocode}
    \map{
      \step[fieldsource=pmcid, final=true]
      \step[fieldset=pmc, origfieldval, final=true]
      \step[fieldsource=pmc, match=\hep@reg@exp@pmc, replace={}]
    }
  }%
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\letbibmacro}
% Provide the "\letbibmacro" macro for old "biblatex" installations.
%    \begin{macrocode}
\providecommand*{\letbibmacro}[2]{\csletcs{abx@macro@#1}{abx@macro@#2}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{collaboration}
% Execute the author macro even if only the collaboration information if present and override the author information with collaboration information if present.
%    \begin{macrocode}
\renewbibmacro*{author/translator+others}{%
  \ifboolexpr{
    test \ifuseauthor and (
      not test {\ifnameundef{author}} or
      not test {\iffieldundef{collaboration}}
    )
  }
  {\usebibmacro{author}}
  {\usebibmacro{translator+others}}
}
\letbibmacro{hep@bib@author}{author}
\renewbibmacro*{author}{%
  \iffieldundef{collaboration}{%
    \usebibmacro{hep@bib@author}}{\textit{\printfield{collaboration}}%
  }%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{In:}
% Remove spurious \enquote{In:} if no journal is present.
%    \begin{macrocode}
\renewbibmacro*{in:}{%
  \iffieldundef{journaltitle}{}{\printtext{\bibstring{in}\intitlepunct}}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{reportnumber}
% Print the "reportnumber" as commalist using the \software{relsize} package \cite{relsize}.
%    \begin{macrocode}
\RequirePackage{relsize}
\DeclareFieldFormat{reportnumber}{%
  \edef\commalistbody{\forcsvfield{%
    \egroup\noexpand\item\unexpanded{\bgroup\smaller[.5]\textsc}
  }{reportnumber}}%
  \expandafter\commalist\commalistbody\egroup\endcommalist%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{url}
% Show \URLs without the protocol.
%    \begin{macrocode}
\DeclareFieldFormat{url}{%
  \mkbibacro{URL}\addcolon\space\online{#1}{\thefield{protocollessurl}}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\hep@bib@online}
% Private "\hep@bib@online" macro
%    \begin{macrocode}
\newcommand*{\hep@bib@online}[2]{%
  \ifhyperref{\online{#1}{#2}}{\nolinkurl{#2}}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{pmid}
% \begin{macro}{pmcid}
% Present PubMed IDs.
%    \begin{macrocode}
\DeclareFieldFormat{pmid}{%
  \mkbibacro{PM}\addcolon\space%
  \hep@bib@online{https://www.ncbi.nlm.nih.gov/pubmed/#1}{#1}%
}
\DeclareFieldFormat{pmc}{%
  \mkbibacro{PMC}\addcolon\space%
  \hep@bib@online{https://www.ncbi.nlm.nih.gov/pmc/articles/PMC#1}{#1}%
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{pmcid}
% \begin{macro}{pmid}
% \begin{macro}{reportnumber}
% Add the pre-print and PubMed information if present.
%    \begin{macrocode}
\letbibmacro{hep-doi+eprint+url}{doi+eprint+url}
\renewbibmacro*{doi+eprint+url}{%
  \usebibmacro{hep-doi+eprint+url}
  \iffieldundef{pmc}{%
    \iffieldundef{pmid}{}{\printfield{pmid}\newunit}%
  }{\printfield{pmc}\newunit}
  \iffieldundef{reportnumber}{}{%
    \newunitpunct\textnumero\intitlepunct%
    \printfield{reportnumber}\newunit%
  }%
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}

% \subsection{Eprints}
%
% \begin{macro}{\hep@eprint}
% Private "\hep@eprint" macro
%    \begin{macrocode}
\NewDocumentCommand{\hep@eprint}{smm}{
  \DeclareFieldFormat{eprint:#2}{%
    \newcommand*{\@path}{\IfBooleanT{#1}{\thefield{eprintclass}/}##1}%
    #2\addcolon\space\hep@bib@online{#3/\@path}{\@path}%
  }%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{CDS}
% Add CERN Document server as a eprint option
%    \begin{macrocode}
\hep@eprint{CDS}{https://cds.cern.ch/record}
\DeclareFieldAlias{eprint:cds}{eprint:CDS}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{HEPData}
% Add the repository for publication-related High-Energy Physics data as a eprint option
%    \begin{macrocode}
\hep@eprint{HEPData}{https://www.hepdata.net/record}
\DeclareFieldAlias{eprint:hepdata}{eprint:HEPData}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{CTAN}
% Add CTAN as a eprint option
%    \begin{macrocode}
\hep@eprint{CTAN}{https://ctan.org/pkg}
\DeclareFieldAlias{eprint:ctan}{eprint:CTAN}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{GitHub}
% Add GitHub as a eprint option
%    \begin{macrocode}
\hep@eprint*{GitHub}{https://github.com}
\DeclareFieldAlias{eprint:github}{eprint:GitHub}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{GitLab}
% Add GitLab as a eprint option
%    \begin{macrocode}
\hep@eprint*{GitLab}{https://gitlab.com}
\DeclareFieldAlias{eprint:gitlab}{eprint:GitLab}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{Bitbucket}
% Add Bitbucket as a eprint option
%    \begin{macrocode}
\hep@eprint*{Bitbucket}{https://bitbucket.org}
\DeclareFieldAlias{eprint:bitbucket}{eprint:Bitbucket}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{Launchpad}
% Add Launchpad as a eprint option
%    \begin{macrocode}
\hep@eprint{Launchpad}{https://launchpad.net}
\DeclareFieldAlias{eprint:launchpad}{eprint:Launchpad}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{SourceForge}
% Add SourceForge as a eprint option
%    \begin{macrocode}
\hep@eprint{SourceForge}{https://sourceforge.net/projects}
\DeclareFieldAlias{eprint:sourceforge}{eprint:SourceForge}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{HEPForge}
% Add HEPForge as a eprint option
%    \begin{macrocode}
\DeclareFieldFormat{eprint:hepforge}{%
  HEPForge\addcolon\space\hep@bib@online{https://#1/hepforge.org}{#1}%
}
\DeclareFieldAlias{eprint:HEPForge}{eprint:hepforge}
%    \end{macrocode}
% \end{macro}
%
% Define bibstrings for reference names.
%    \begin{macrocode}
\NewBibliographyString{refname}
\NewBibliographyString{refsname}
\DefineBibliographyStrings{english}{%
  refname = {reference},
  refsname = {references}
}
%    \end{macrocode}
% \begin{macro}{\ccite}
% \begin{macro}{\Ccite}
% Define \emph{clever} citation macros.
% \begin{macrocode}
\DeclareCiteCommand{\ccite}{%
  \ifnum\thecitetotal=1
    \bibstring{refname}%
  \else%
    \bibstring{refsname}%
  \fi%
  \addnbspace\bibopenbracket%
  \usebibmacro{cite:init}\usebibmacro{prenote}%
}{\usebibmacro{citeindex}\usebibmacro{cite:comp}}{}{%
  \usebibmacro{cite:dump}\usebibmacro{postnote}%
  \bibclosebracket%
}

\newrobustcmd*{\Ccite}{\bibsentence\ccite}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%</package>
%
% \section{Biblatex datamodel file} \label{sec:data model}
%
%<*datamodel>
%
% \begin{macro}{collaboration}
% \begin{macro}{pmid}
% \begin{macro}{pmcid}
% \begin{macro}{pmc}
% \begin{macro}{reportnumber}
% \begin{macro}{protocollessurl}
% Define the "dbx" file containing the "hep-bibliography" datamodel.
%    \begin{macrocode}
\DeclareDatamodelFields[type=field, datatype=literal]{
  collaboration, pmid, pmcid, pmc,
}
\DeclareDatamodelFields[type=field, format=xsv, datatype=literal]{
  reportnumber,
}
\DeclareDatamodelFields[type=field, datatype=uri]{protocollessurl}
\DeclareDatamodelEntryfields{
  collaboration, pmid, pmcid, pmc, reportnumber, protocollessurl,
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
%</datamodel>
%
% \section{Test}
%
%<*test>
%    \begin{macrocode}
\documentclass[twocolumn,a4paper]{article}

\usepackage{hep-bibliography}

\begin{filecontents}{\jobname.bib}
@article{Ade:2015xua,
    author = "Ade, P. A. R. and others",
    collaboration = "Planck",
    title = "{Planck 2015 results. XIII. Cosmological parameters}",
    eprint = "1502.01589",
    archivePrefix = "arXiv",
    primaryClass = "astro-ph.CO",
    doi = "10.1051/0004-6361/201525830",
    journal = "Astron. Astrophys.",
    volume = "594",
    pages = "A13",
    year = "2016"
}

@article{Agashe:2014kda,
    author = "Olive, K. A. and others",
    collaboration = "Particle Data Group",
    title = "{Review of Particle Physics}",
    doi = "10.1088/1674-1137/38/9/090001",
    journal = "Chin. Phys. C",
    volume = "38",
    pages = "090001",
    year = "2014"
}

@article{Ade:2013zuv,
    author = "Ade, P. A. R. and others",
    collaboration = "Planck",
    title = "{Planck 2013 results. XVI. Cosmological parameters}",
    eprint = "1303.5076",
    archivePrefix = "arXiv",
    primaryClass = "astro-ph.CO",
    reportNumber = "CERN-PH-TH-2013-129",
    doi = "10.1051/0004-6361/201321591",
    journal = "Astron. Astrophys.",
    volume = "571",
    pages = "A16",
    year = "2014"
}

@article{Aad:2012tfa,
    author = "Aad, Georges and others",
    collaboration = "ATLAS",
    title = "{Observation of a new particle in the search for
    the Standard Model Higgs boson with the ATLAS detector at the LHC}",
    eprint = "1207.7214",
    archivePrefix = "arXiv",
    primaryClass = "hep-ex",
    reportNumber = "CERN-PH-EP-2012-218",
    doi = "10.1016/j.physletb.2012.08.020",
    journal = "Phys. Lett. B",
    volume = "716",
    pages = "1--29",
    year = "2012"
}

@article{Chatrchyan:2012ufa,
    author = "Chatrchyan, Serguei and others",
    collaboration = "CMS",
    title = "{Observation of a New Boson at a Mass of 125 GeV with the
    CMS Experiment at the LHC}",
    eprint = "1207.7235",
    archivePrefix = "arXiv",
    primaryClass = "hep-ex",
    reportNumber = "CMS-HIG-12-028, CERN-PH-EP-2012-220",
    doi = "10.1016/j.physletb.2012.08.021",
    journal = "Phys. Lett. B",
    volume = "716",
    pages = "30--61",
    year = "2012"
}

@article{Beringer:1900zz,
    author = "Beringer, J. and others",
    collaboration = "Particle Data Group",
    title = "{Review of Particle Physics (RPP)}",
    reportNumber = "SLAC-REPRINT-2014-001",
    doi = "10.1103/PhysRevD.86.010001",
    journal = "Phys. Rev. D",
    volume = "86",
    pages = "010001",
    year = "2012"
}

@article{Chatrchyan:2008aa,
    author = "Chatrchyan, S. and others",
    collaboration = "CMS",
    title = "{The CMS Experiment at the CERN LHC}",
    doi = "10.1088/1748-0221/3/08/S08004",
    journal = "JINST",
    volume = "3",
    pages = "S08004",
    year = "2008"
}

@article{Cacciari:2008gp,
    author = "Cacciari, Matteo and Salam, Gavin P. and Soyez, Gregory",
    title = "{The anti-$k_t$ jet clustering algorithm}",
    eprint = "0802.1189",
    archivePrefix = "arXiv",
    primaryClass = "hep-ph",
    reportNumber = "LPTHE-07-03",
    doi = "10.1088/1126-6708/2008/04/063",
    journal = "JHEP",
    volume = "04",
    pages = "063",
    year = "2008"
}

@article{Aad:2008zzm,
    author = "Aad, G. and others",
    collaboration = "ATLAS",
    title = "{The ATLAS Experiment at the CERN Large Hadron Collider}",
    doi = "10.1088/1748-0221/3/08/S08003",
    journal = "JINST",
    volume = "3",
    pages = "S08003",
    year = "2008"
}

@article{Sjostrand:2006za,
    author = "Sjostrand, Torbjorn and Mrenna, Stephen
    and Skands, Peter Z.",
    title = "{PYTHIA 6.4 Physics and Manual}",
    eprint = "hep-ph/0603175",
    archivePrefix = "arXiv",
    reportNumber = "FERMILAB-PUB-06-052-CD-T, LU-TP-06-13",
    doi = "10.1088/1126-6708/2006/05/026",
    journal = "JHEP",
    volume = "05",
    pages = "026",
    year = "2006"
}

@article{Spergel:2003cb,
    author = "Spergel, D. N. and others",
    collaboration = "WMAP",
    title = "{First year Wilkinson Microwave Anisotropy Probe (WMAP)
    observations: Determination of cosmological parameters}",
    eprint = "astro-ph/0302209",
    archivePrefix = "arXiv",
    doi = "10.1086/377226",
    journal = "Astrophys. J. Suppl.",
    volume = "148",
    pages = "175--194",
    year = "2003"
}

@article{Agostinelli:2002hh,
    author = "Agostinelli, S. and others",
    collaboration = "GEANT4",
    title = "{GEANT4--a simulation toolkit}",
    reportNumber = "SLAC-PUB-9350, FERMILAB-PUB-03-339,
    CERN-IT-2002-003",
    doi = "10.1016/S0168-9002(03)01368-8",
    journal = "Nucl. Instrum. Meth. A",
    volume = "506",
    pages = "250--303",
    year = "2003"
}

@article{Randall:1999ee,
    author = "Randall, Lisa and Sundrum, Raman",
    title = "{A Large mass hierarchy from a small extra dimension}",
    eprint = "hep-ph/9905221",
    archivePrefix = "arXiv",
    reportNumber = "MIT-CTP-2860, PUPT-1860, BUHEP-99-9",
    doi = "10.1103/PhysRevLett.83.3370",
    journal = "Phys. Rev. Lett.",
    volume = "83",
    pages = "3370--3373",
    year = "1999"
}

@article{Perlmutter:1998np,
    author = "Perlmutter, S. and others",
    collaboration = "Supernova Cosmology Project",
    title = "{Measurements of $\Omega$ and $\Lambda$ from 42 high
    redshift supernovae}",
    eprint = "astro-ph/9812133",
    archivePrefix = "arXiv",
    reportNumber = "LBNL-41801, LBL-41801",
    doi = "10.1086/307221",
    journal = "Astrophys. J.",
    volume = "517",
    pages = "565--586",
    year = "1999"
}

@article{Riess:1998cb,
    author = "Riess, Adam G. and others",
    collaboration = "Supernova Search Team",
    title = "{Observational evidence from supernovae for an accelerating
    universe and a cosmological constant}",
    eprint = "astro-ph/9805201",
    archivePrefix = "arXiv",
    doi = "10.1086/300499",
    journal = "Astron. J.",
    volume = "116",
    pages = "1009--1038",
    year = "1998"
}

@article{Witten:1998qj,
    author = "Witten, Edward",
    title = "{Anti-de Sitter space and holography}",
    eprint = "hep-th/9802150",
    archivePrefix = "arXiv",
    reportNumber = "IASSNS-HEP-98-15",
    doi = "10.4310/ATMP.1998.v2.n2.a2",
    journal = "Adv. Theor. Math. Phys.",
    volume = "2",
    pages = "253--291",
    year = "1998"
}

@article{Gubser:1998bc,
    author = "Gubser, S. S. and Klebanov, Igor R.
    and Polyakov, Alexander M.",
    title = "{Gauge theory correlators from noncritical string theory}",
    eprint = "hep-th/9802109",
    archivePrefix = "arXiv",
    reportNumber = "PUPT-1767",
    doi = "10.1016/S0370-2693(98)00377-3",
    journal = "Phys. Lett. B",
    volume = "428",
    pages = "105--114",
    year = "1998"
}

@article{Maldacena:1997re,
    author = "Maldacena, Juan Martin",
    title = "{The Large N limit of superconformal field
    theories and supergravity}",
    eprint = "hep-th/9711200",
    archivePrefix = "arXiv",
    reportNumber = "HUTP-97-A097, HUTP-98-A097",
    doi = "10.1023/A:1026654312961",
    journal = "Adv. Theor. Math. Phys.",
    volume = "2",
    pages = "231--252",
    year = "1998"
}

@article{Schlegel:1997yv,
    author = "Schlegel, David J. and Finkbeiner, Douglas P.
    and Davis, Marc",
    title = "{Maps of dust IR emission for use in estimation
    of reddening and CMBR foregrounds}",
    eprint = "astro-ph/9710327",
    archivePrefix = "arXiv",
    doi = "10.1086/305772",
    journal = "Astrophys. J.",
    volume = "500",
    pages = "525",
    year = "1998"
}

@article{Guth:1980zm,
    author = "Guth, Alan H.",
    editor = "Fang, Li-Zhi and Ruffini, R.",
    title = "{The Inflationary Universe: A Possible Solution
    to the Horizon and Flatness Problems}",
    reportNumber = "SLAC-PUB-2576",
    doi = "10.1103/PhysRevD.23.347",
    journal = "Phys. Rev. D",
    volume = "23",
    pages = "347--356",
    year = "1981"
}

@article{Altarelli:1977zs,
    author = "Altarelli, Guido and Parisi, G.",
    title = "{Asymptotic Freedom in Parton Language}",
    reportNumber = "LPTENS-77-6",
    doi = "10.1016/0550-3213(77)90384-4",
    journal = "Nucl. Phys. B",
    volume = "126",
    pages = "298--318",
    year = "1977"
}

@article{Hawking:1974sw,
    author = "Hawking, S. W.",
    editor = "Gibbons, G. W. and Hawking, S. W.",
    title = "{Particle Creation by Black Holes}",
    doi = "10.1007/BF02345020",
    journal = "Commun. Math. Phys.",
    volume = "43",
    pages = "199--220",
    year = "1975",
    related = "Hawking:1974sw-1",
    relatedtype = "erratum"
}

@article{Kobayashi:1973fv,
    author = "Kobayashi, Makoto and Maskawa, Toshihide",
    title = "{CP Violation in the Renormalizable Theory of
    Weak Interaction}",
    reportNumber = "KUNS-242",
    doi = "10.1143/PTP.49.652",
    journal = "Prog. Theor. Phys.",
    volume = "49",
    pages = "652--657",
    year = "1973"
}

@article{Weinberg:1967tq,
    author = "Weinberg, Steven",
    title = "{A Model of Leptons}",
    doi = "10.1103/PhysRevLett.19.1264",
    journal = "Phys. Rev. Lett.",
    volume = "19",
    pages = "1264--1266",
    year = "1967"
}

@article{Glashow:1961tr,
    author = "Glashow, S. L.",
    title = "{Partial Symmetries of Weak Interactions}",
    doi = "10.1016/0029-5582(61)90469-2",
    journal = "Nucl. Phys.",
    volume = "22",
    pages = "579--588",
    year = "1961"
}

@article{Hawking:1974sw-1,
    author = "Hawking, S. W.",
    journal = "Commun. Math. Phys.",
    volume = "46",
    pages = "206",
    year = "1976",
    options = {skipbib=true}
}

@article{test,
    author = "author",
    title = "title",
    journaltitle = "journal title",
    year = "2000",
    translator = "translator",
    annotator = "annotator",
    commentator = "commentator",
    subtitle = "subtitle",
    titleaddon = "titleaddon",
    editor = "editor",
    editora = "editora",
    editorb = "editorb",
    editorc = "editorc",
    journalsubtitle = "journalsubtitle",
    journaltitleaddon = "journaltitleaddon",
    issuetitle = "issuetitle",
    issuesubtitle = "issuesubtitle",
    issuetitleaddon = "issuetitleaddon",
    language = "language",
    origlanguage = "origlanguage",
    series = "series",
    volume = "volume",
    number = "number",
    eid = "eid",
    issue = "issue",
    month = "1",
    pages = "100",
    version = "1",
    note = "note",
    issn = "issn",
    addendum = "addendum",
    pubstate = "pubstate",
    doi = "doi",
    eprint = "eprint",
    eprintclass = "eprintclass",
    eprinttype = "eprinttype",
    url = "url",
    urldate = "2000",
}
\end{filecontents}
\bibliography{\jobname}
\nocite{*}
\usepackage{hyperref}

\begin{document}
\printbibliography
\end{document}
%    \end{macrocode}
%</test>
%
% \section{Readme}
%
%<*readme>
%
%    \begin{macrocode}
# The `hep-bibliography` package

Bibliographies for high energy physics

## Introduction

The `hep-bibliography` package configures `biblatex` for high-energy
physics publications. It adds the `InspireHEP` data fields used in HEP
bibliographies, source maps for common BibTeX variants, citation
back-links from bibliography labels, erratum handling, and eprint formats
for arXiv, PubMed, PubMed Central, code-hosting sites, and package
repositories.

The package can be loaded via `\usepackage{hep-bibliography}`.

## Author

Jan Hajer

## License

This file may be distributed and/or modified under the conditions of the
`LaTeX` Project Public License, either version 1.3c of this license or
(at your option) any later version. The latest version of this license is
in `http://www.latex-project.org/lppl.txt` and version 1.3c or later is
part of all distributions of LaTeX version 2005/12/01 or later.
%    \end{macrocode}
%
%</readme>
%
% \Finale

\endinput

% \PrintIndex
% makeindex -s gglo.ist -o hep-bibliography-implementation.gls hep-bibliography-implementation.glo
% makeindex -s gglo.ist -o hep-bibliography-implementation.ind hep-bibliography-implementation.idx
