%%
%% ---------------------------------------------------------------
%% erj.cbx --- A citation style of Economic Research Journal in china
%% modified from gb7714-2015ay for the request by ddswhu
%% Maintained by huzhenzhen
%% E-mail: hzzmail@163.com
%% Released under the LaTeX Project Public License v1.3c or later
%% ---------------------------------------------------------------
%%
%%������������������������������������biblatex���������������������
%%���������������������������������������������cite���textcite

\ProvidesFile{chinese-erj.cbx}[v1.0a a biblatex citation style for ERJ]

%==================================================
%������gb������
%==================================================
\RequireCitationStyle{gb7714-2015ay} %


%
%   ���������������������������������������������������������������
%   20220222,v1.0a,hzz
\DeclareBibliographyOption{gbcitepunctcn}[true]{%biblatex���������
  \ifstrequal{#1}{false}{\exegbpunctencite}{}}

\def\gbpunctmarkcite{���}%
\def\gbpunctsemicoloncite{���}%
\def\gbpunctparenlcite{���}%
\def\gbpunctparenrcite{���}
\def\exegbpunctencite{%
\def\gbpunctmarkcite{\addcomma\addspace}%
\def\gbpunctsemicoloncite{\addsemicolon\addspace}%
\def\gbpunctparenlcite{(}%
\def\gbpunctparenrcite{)}
}

%==================================================
%������������
%==================================================
\ExecuteBibliographyOptions{
    maxcitenames=2,
    mincitenames=1,
}

%==================================================
%������������������������������cite���textcite
%������������������
%==================================================
\renewcommand*{\multicitedelim}{\gbpunctsemicoloncite}%\addsemicolon\addspace���
\renewcommand*{\textcitedelim}{%
  \iffinalcitedelim
    {\ifnumgreater{\value{textcitetotal}}{2}
       {}{}%\iftextcitepunct{\finalandsemicolon}{\finalandcomma}
     \addspace\gbpunctmarkcite}%\addspace\bibstring{andincitecn}
    {\iftextcitepunct{\addsemicolon\space}{\addspace\gbpunctmarkcite}}%\addcomma
}%\space

\DeclareDelimFormat[textcite]{nameyeardelim}{\addspace}%\addcomma\space
\DeclareDelimFormat[textcite]{andothersdelim}{\iffieldequalstr{userf}{chinese}{}{\addspace}}%

%���������������\DeclareDelimFormat{andothersdelim}{}������������������������gb7714-2015������������������������biblatex���������������������������
%������������������������
\AtEveryCitekey{%
\iffieldequalstr{userf}{chinese}{\renewcommand*{\andothersdelim}{}}%\addthinspace
  {\renewcommand*{\andothersdelim}{\addspace}}%
}

%���������������������������date+extradate������extradate������2006a���2006b���������
%\DeclareDelimFormat*{compcitedelim}{\gbpunctmarkcite}%\addcomma\addspace
\newbibmacro*{cite:extradate}{%
  \iffieldundef{extradate}
    {}
    {\printtext[bibhyperref]{\addspace\printlabeldateextra}}}%\printfield{extradate}\printlabeldateextra \printfield{labelyear}\printfield{extradate}

%\AtEveryCite{%
%\let\parentext=\parentexttrack%
%\let\bibopenparen=���%
%\let\bibcloseparen=���}

%������������������
\DeclareCiteCommand{\cite}%[\mkbibparens]
  {\usebibmacro{cite:init}%
   \unspace\printtext{\gbpunctparenlcite}\usebibmacro{prenote}}%\addspace
  {\usebibmacro{citeindex}%
   \usebibmacro{cite}}
  {}
  {\usebibmacro{postnote}%
  \gbpunctparenrcite}%\addspace

%������
%\DeclareCiteCommand{\cite}[\mkbibparens]
%  {\usebibmacro{cite:init}%
%   \usebibmacro{prenote}}%)
%  {\usebibmacro{citeindex}%
%   \usebibmacro{cite}}
%  {}
%  {\usebibmacro{postnote}}

%
%������������������
%\DeclareCiteCommand{\cbx@textcite}
%  {\usebibmacro{cite:init}}
%  {\usebibmacro{citeindex}%
%   \usebibmacro{textcite}}
%  {}
%  {\usebibmacro{textcite:postnote}\addspace}

\newbibmacro*{textcite}{%
  \iffieldequals{namehash}{\cbx@lasthash}
    {\iffieldundef{shorthand}
       {\ifthenelse{\iffieldequals{labelyear}{\cbx@lastyear}\AND
                    \(\value{multicitecount}=0\OR\iffieldundef{postnote}\)}
          {\setunit{\addcomma}%
           \usebibmacro{cite:extradate}}
          {\setunit{\compcitedelim}%
           \usebibmacro{cite:labeldate+extradate}%
           \savefield{labelyear}{\cbx@lastyear}}}
       {\setunit{\compcitedelim}%
        \usebibmacro{cite:shorthand}%
        \global\undef\cbx@lastyear}}
    {\ifnameundef{labelname}
       {\iffieldundef{shorthand}
          {\usebibmacro{cite:label}%
           \setunit{%
             \global\booltrue{cbx:parens}%
             \printdelim{nonameyeardelim}\unspace\gbpunctparenlcite}%\bibopenparen
           \ifnumequal{\value{citecount}}{1}
             {\usebibmacro{prenote}}
             {}%
           \usebibmacro{cite:labeldate+extradate}}
          {\usebibmacro{cite:shorthand}}}
       {\printnames{labelname}%
        \setunit{%
          \global\booltrue{cbx:parens}%
          \printdelim{nameyeardelim}\unspace\gbpunctparenlcite}%\bibopenparen
        \ifnumequal{\value{citecount}}{1}
          {\usebibmacro{prenote}}
          {}%
        \iffieldundef{shorthand}
          {\iffieldundef{labelyear}
             {\usebibmacro{cite:label}}
             {\usebibmacro{cite:labeldate+extradate}}%
           \savefield{labelyear}{\cbx@lastyear}}
          {\usebibmacro{cite:shorthand}%
           \global\undef\cbx@lastyear}}%
     \stepcounter{textcitecount}%
     \savefield{namehash}{\cbx@lasthash}}%
  \setunit{%
    \ifbool{cbx:parens}
      {\gbpunctparenrcite\global\boolfalse{cbx:parens}}%\bibcloseparen
      {}%
    \textcitedelim}}

\newbibmacro*{textcite:postnote}{%
  \usebibmacro{postnote}%
  \ifthenelse{\value{multicitecount}=\value{multicitetotal}}
    {\setunit{}%
     \printtext{%
       \ifbool{cbx:parens}
         {\gbpunctparenrcite\global\boolfalse{cbx:parens}}%\bibcloseparen
         {}}}
    {\setunit{%
       \ifbool{cbx:parens}
         {\gbpunctparenrcite\global\boolfalse{cbx:parens}}%\bibcloseparen
         {}%
       \textcitedelim}}}

\let\citet=\textcite
\let\citep=\cite