%% ---------------------------------------------------------------
%% biblatex-ieee --- A biblatex implementation of the IEEE
%%   bibliography style
%% Maintained by Joseph Wright
%% E-mail: joseph@texdev.net
%% Released under the LaTeX Project Public License v1.3c or later
%% See http://www.latex-project.org/lppl.txt
%% ---------------------------------------------------------------
%%

\ProvidesFile{ieee-comp.cbx}[2025-08-01 v1.4f biblatex citation style]

\RequireCitationStyle{numeric-comp}

\ExecuteBibliographyOptions{
    maxcitenames = 2,
    minnames     = 1,
    sorting      = none
}

% Putting brackets around each citation number is a two-part
% operation. First, remove them from around the whole citation by
% redeclaring here.
\DeclareCiteCommand{\cite}%
  {\usebibmacro{cite:init}%
   \bibopenbracket
   \usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \usebibmacro{cite:comp}}
  {}
  {\usebibmacro{cite:dump}%
   \usebibmacro{postnote}%
   \bibclosebracket
  }

\DeclareCiteCommand{\supercite}[\mkbibsuperscript]
  {\usebibmacro{cite:init}%
   \bibopenbracket
   \let\multicitedelim=\supercitedelim
   \let\multicitesubentrydelim=\supercitesubentrydelim
   \let\multiciterangedelim=\superciterangedelim
   \let\multicitesubentryrangedelim=\supercitesubentryrangedelim
   \iffieldundef{prenote}
     {}
     {\BibliographyWarning{Ignoring prenote argument}}%
   \iffieldundef{postnote}
     {}
     {\BibliographyWarning{Ignoring postnote argument}}}
  {\usebibmacro{citeindex}%
   \usebibmacro{cite:comp}}
  {}
  {\usebibmacro{cite:dump}%
   \bibclosebracket}

% The second step is to replace \multicitedelim and
% \multicitesubentrydelim with a version wrapped in
% the appropriate delimiter.
\renewcommand*{\do}[1]{%
  \expandafter\patchcmd\expandafter
    {\csname abx@macro@\detokenize{#1}\endcsname}%
    {\multicitedelim}
    {\bibclosebracket\multicitedelim\bibopenbracket}
    {}
    {%
      \PackageError{biblatex-ieee}{Failed to update citation style}\@ehc
    }%
  }
\docsvlist{cite:comp:end,cite:comp:inset,cite:comp:shand,cite:dump}

\renewcommand*{\do}[1]{%
  \expandafter\patchcmd\expandafter
    {\csname abx@macro@\detokenize{#1}\endcsname}%
    {\multicitesubentrydelim}
    {\bibclosebracket\multicitesubentrydelim\bibopenbracket}
    {}
    {%
      \PackageError{biblatex-ieee}{Failed to update citation style}\@ehc
    }%
  }
\docsvlist{cite:comp:inset,cite:dump:inset}


% There's also one \multiciterangedelim and one
% \multicitesubentryrangedelimto alter.
\expandafter\patchcmd\expandafter
  {\csname abx@macro@\detokenize{cite:dump}\endcsname}%
  {\multiciterangedelim}
  {\bibclosebracket\multiciterangedelim\bibopenbracket}
  {}
  {%
    \PackageError{biblatex-ieee}{Failed to update citation style}\@ehc
  }%

\expandafter\patchcmd\expandafter
  {\csname abx@macro@\detokenize{cite:dump:inset}\endcsname}%
  {\multicitesubentryrangedelim}
  {\bibclosebracket\multicitesubentryrangedelim\bibopenbracket}
  {}
  {%
    \PackageError{biblatex-ieee}{Failed to update citation style}\@ehc
  }%


% More bracket removal required
\DeclareMultiCiteCommand{\cites}{\cite}{\multicitedelim}

% print labelnumber for compressed set entries
\renewbibmacro*{cite:print:subentry:comp}{%
  \printtext[bibhyperref]{%
    \printfield{labelprefix}%
    \printfield{labelnumber}%
    \printfield{entrysetcount}}}

\renewbibmacro*{cite:print:last:subentry:comp}{%
  \printtext[bibhyperref:lastkey]{%
    \ifdef\cbx@lastprefix
      {\printtext[labelprefix]{\cbx@lastprefix}}
      {}%
    \printtext[labelnumber]{\cbx@lastnumber}%
    \ifdef\cbx@lastentrysetcount
      {\printtext[entrysetcount]{\cbx@lastentrysetcount}}
      {}}}

%%
%% Copyright (C) 2011-2013,2015-2021,2024,2025 by
%%   Joseph Wright <joseph@texdev.net>
%%
%% 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 files biblatex-ieee.bib,
%%                                 biblatex-ieee.tex,
%%                                 ieee.bbx,
%%                                 ieee.cbx,
%%                                 ieee-alphabetic.bbx,
%%                                 ieee-alphabetic.cbx,
%%                                 ieee-comp.cbx and
%%                                 magyar-ieee.lbx,
%%           and the derived files biblatex-ieee.pdf and
%%                                 biblatex-ieee-alphabetic.pdf.
%%
%%
%% End of file `ieee.cbx'.
