Skip to content

Commit

Permalink
Merge pull request #103 from moewew/nptextcite
Browse files Browse the repository at this point in the history
Rework \textcite and \nptextcite
  • Loading branch information
plk authored Apr 30, 2020
2 parents ef84fcf + ca58703 commit cc709e4
Showing 1 changed file with 160 additions and 96 deletions.
256 changes: 160 additions & 96 deletions tex/latex/biblatex-apa/cbx/apa.cbx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
%% version 2005/12/01 or later.
%%
%% This work has the LPPL maintenance status `maintained'.
%%
%%
%% The Current Maintainer of this work is Philip Kime.

\ProvidesFile{apa.cbx}[2020/04/26\space v9.10\space APA biblatex citation style]
Expand Down Expand Up @@ -43,44 +43,11 @@
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% (APA 8.17) ampersand separator in parenthetical cites

\newtoggle{apa:inpcite}

\DeclareDelimFormat[parencite]{finalnamedelim}
{\ifnum\value{liststop}>2 \finalandcomma\fi\addspace\&\space}

\DeclareCiteCommand{\parencite}[\mkbibparens]
{\usebibmacro{cite:init}%
\usebibmacro{prenote}%
\toggletrue{apa:inpcite}}
{\usebibmacro{citeindex}%
\usebibmacro{cite}%
\usebibmacro{cite:post}}
{}
{\usebibmacro{postnote}%
\togglefalse{apa:inpcite}}

\DeclareCiteCommand*{\parencite}[\mkbibparens]
{\usebibmacro{cite:init}%
\usebibmacro{prenote}%
\toggletrue{apa:inpcite}}
{\usebibmacro{citeindex}%
\usebibmacro{citeyear}%
\usebibmacro{cite:post}%
\togglefalse{apa:inpcite}}
{}
{\usebibmacro{postnote}}

%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% (APA 8.10) Suffices are not shown in citations
% (APA 8.17) 3+ authors have "et al."
% (APA 8.20) Initials only for primary author and only when not unique across all *primary* authors

\newbibmacro*{labelname:doname}[8]{%
\ifboolexpr{test {\ifnumcomp{\value{listcount}}{>}{1}}
or
Expand Down Expand Up @@ -183,7 +150,7 @@
% X and Y and Z (2009)
% X and W and V (2010)
%
% which have the same namehash due to minnames visibility truncation to 1
% which have the same namehash due to minnames visibility truncation to 1
% would be printed incorrectly as
% \cite{one, two} -> X, Y & Z 2009, 2010
\newbibmacro*{cite}{%
Expand Down Expand Up @@ -212,25 +179,25 @@
\savefield{fullhash}{\cbx@lasthash}}}%
\setunit{\multicitedelim}}

\renewcommand*{\iffinalcitedelim}{%
\ifnumequal{\value{textcitecount}}{\value{textcitetotal}-1}}

\newbibmacro*{textcite}{%
\iffieldequals{fullhash}{\cbx@lasthash}
% Compact cite - more than one thing for same author
{\setunit{\compcitedelim}%
\usebibmacro{cite:plabelyear+extradate}}
% New cite
{%
\ifbool{cbx:parens}
{\bibcloseparen\global\boolfalse{cbx:parens}}
{}%
\setunit{\compcitedelim}%
\ifnameundef{labelname}
% No author/editor
{\ifbool{cbx:parens}
{\bibcloseparen\global\boolfalse{cbx:parens}}
{}%
\setunit{\textcitedelim}%
\ifnameundef{labelname}
% No author/editor
{\iffieldundef{shorthand}%
% Cite using title
{\usebibmacro{cite:noname}%
\setunit{\ifbool{cbx:np}%
{\printdelim{nameyeardelim}}%
{\global\booltrue{cbx:parens}\addspace\bibopenparen}}%
\setunit{\global\booltrue{cbx:parens}\addspace\bibopenparen}%
\usebibmacro{cite:plabelyear+extradate}}
% Cite using shorthand
{\usebibmacro{cite:shorthand}}}
Expand All @@ -246,19 +213,23 @@
{\printnames[labelname]{author}}
{\printnames[labelname]{groupauthor}}}}%
% Year
\setunit{\ifbool{cbx:np}
{\printdelim{nameyeardelim}}
{\global\booltrue{cbx:parens}\addspace\bibopenparen}}%
\setunit{\global\booltrue{cbx:parens}\addspace\bibopenparen}%
% Put the shortauthor inside the year brackets if necessary
\ifnameundef{shortauthor}
{}
{\cbx@apa@ifnamesaved
{}
{\printnames{shortauthor}\setunit{\printdelim{nameyeardelim}}}}%
{\printnames{shortauthor}%
\setunit{\printdelim{nameyeardelim}}}}%
% Print prenote (belongs to first cite)
\ifnumequal{\value{citecount}}{1}
{\usebibmacro{prenote}}
{}%
% Actual year printing
\usebibmacro{cite:plabelyear+extradate}%
% Save name hash for checks later
\savefield{fullhash}{\cbx@lasthash}}}}
\savefield{fullhash}{\cbx@lasthash}}%
\stepcounter{textcitecount}}}

\newbibmacro*{cite:plabelyear+extradate}{%
\iffieldundef{labelyear}{}
Expand Down Expand Up @@ -370,7 +341,7 @@
{\biblclstring{repealed}\setunit{\addspace}\printeventdate}
{}}
{}}

%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Expand All @@ -385,39 +356,13 @@
{\ifcurrentfield{shorthand}
{\mkbibemph{#1}}
{#1}}}

%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% (APA 8.11) No parens round year for cites when the cite is in
% parentheses. Use new command \nptextcite for such cites.

\DeclareDelimFormat[nptextcite]{finalnamedelim}
{\ifnum\value{liststop}>2 \finalandcomma\fi\addspace\&\space}

\DeclareMultiCiteCommand{\nptextcites}{\nptextcite}{\setunit{\multicitedelim}}

\DeclareCiteCommand{\nptextcite}
{\usebibmacro{cite:init}%
\usebibmacro{prenote}}
{\usebibmacro{citeindex}%
\global\booltrue{cbx:np}%
\usebibmacro{textcite}%
\usebibmacro{cite:post}%
\global\boolfalse{cbx:np}}%
{}
{\iffieldundef{postnote}
{}
{\printdelim{nameyeardelim}%
\printfield{postnote}}}

%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% No shorthand
%
%
\newbibmacro*{citeyear}{%
\iffieldundef{labelyear}
{\usebibmacro{cite:init}}
Expand Down Expand Up @@ -469,7 +414,6 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newbool{cbx:parens} % boolean to say we're inside parens
\newbool{cbx:np} % boolean to say we're using a non-parentheses text cite

\newbibmacro*{textcite:postnote}{%
\usebibmacro{postnote}%
Expand Down Expand Up @@ -498,6 +442,15 @@
{\printfield{labelyear}%
\printfield{extradate}}}

\DeclareCiteCommand{\citeauthor}
{\usebibmacro{cite:init}%
\usebibmacro{prenote}}
{\usebibmacro{citeindex}%
\usebibmacro{cite:author}%
\usebibmacro{cite:post}}
{}
{\usebibmacro{postnote}}

\DeclareCiteCommand{\citeyear}
{\boolfalse{citetracker}%
\boolfalse{pagetracker}%
Expand All @@ -515,6 +468,8 @@
{}
{\usebibmacro{postnote}}

\DeclareMultiCiteCommand{\cites}{\cite}{\setunit{\multicitedelim}}

\DeclareCiteCommand*{\cite}
{\usebibmacro{cite:init}%
\usebibmacro{prenote}}
Expand All @@ -524,32 +479,116 @@
{}
{\usebibmacro{postnote}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% (APA 8.17) ampersand separator in parenthetical cites

\newtoggle{apa:inpcite}

\DeclareDelimFormat[parencite]{finalnamedelim}
{\ifnum\value{liststop}>2 \finalandcomma\fi\addspace\&\space}

\DeclareCiteCommand{\parencite}[\mkbibparens]
{\usebibmacro{cite:init}%
\usebibmacro{prenote}%
\toggletrue{apa:inpcite}}
{\usebibmacro{citeindex}%
\usebibmacro{cite}%
\usebibmacro{cite:post}}
{}
{\usebibmacro{postnote}%
\togglefalse{apa:inpcite}}

\DeclareMultiCiteCommand{\parencites}[\mkbibparens]{\parencite}
{\setunit{\multicitedelim}}

\DeclareCiteCommand*{\parencite}[\mkbibparens]
{\usebibmacro{cite:init}%
\usebibmacro{prenote}%
\toggletrue{apa:inpcite}}
{\usebibmacro{citeindex}%
\usebibmacro{citeyear}%
\usebibmacro{cite:post}%
\togglefalse{apa:inpcite}}
{}
{\usebibmacro{postnote}}

%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% (APA 8.11) No parens round year for cites when the cite is in
% parentheses. Use new command \nptextcite for such cites.

\DeclareDelimFormat[nptextcite]{finalnamedelim}
{\ifnum\value{liststop}>2 \finalandcomma\fi\addspace\&\space}

\DeclareCiteCommand{\nptextcite}
{\usebibmacro{cite:init}%
\usebibmacro{prenote}%
\toggletrue{apa:inpcite}}
{\usebibmacro{citeindex}%
\usebibmacro{cite}%
\usebibmacro{cite:post}}
{}
{\usebibmacro{postnote}%
\togglefalse{apa:inpcite}}

\DeclareMultiCiteCommand{\nptextcites}{\nptextcite}
{\setunit{\multicitedelim}}

\DeclareCiteCommand*{\nptextcite}
{\usebibmacro{cite:init}%
\usebibmacro{prenote}%
\toggletrue{apa:inpcite}}
{\usebibmacro{citeindex}%
\usebibmacro{citeyear}%
\usebibmacro{cite:post}%
\togglefalse{apa:inpcite}}
{}
{\usebibmacro{postnote}}

%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\DeclareCiteCommand{\footcite}[\mkbibfootnote]
{\bibsentence
\usebibmacro{cite:init}%
{\usebibmacro{cite:init}%
\usebibmacro{prenote}}
{\usebibmacro{citeindex}%
\usebibmacro{cite}%
\usebibmacro{cite:post}}
{}
{\usebibmacro{postnote}}

\DeclareMultiCiteCommand{\textcites}{\textcite}{\setunit{\compcitedelim}}
\DeclareMultiCiteCommand{\cites}{\cite}{\setunit{\multicitedelim}}
\DeclareMultiCiteCommand{\parencites}[\mkbibparens]{\parencite}
{\setunit{\multicitedelim}}
\DeclareMultiCiteCommand{\footcites}[\mkbibfootnote]{\footcite}
{\setunit{\multicitedelim}}

\DeclareCiteCommand{\footcitetext}[\mkbibfootnotetext]
{\usebibmacro{cite:init}%
\usebibmacro{prenote}}
{\usebibmacro{citeindex}%
\usebibmacro{cite}%
\usebibmacro{cite:post}}
{}
{\usebibmacro{postnote}}

\DeclareMultiCiteCommand{\footcitetexts}[\mkbibfootnotetext]
{\footcitetext}{\setunit{\multicitedelim}}

\DeclareCiteCommand{\smartcite}[\iffootnote\mkbibparens\mkbibfootnote]
{\usebibmacro{cite:init}%
\usebibmacro{prenote}}
{\usebibmacro{citeindex}%
\usebibmacro{cite}}
{}
{\usebibmacro{postnote}}

\DeclareMultiCiteCommand{\smartcites}[\iffootnote\mkbibparens\mkbibfootnote]
{\smartcite}{\setunit{\multicitedelim}}

\newtoggle{apa:intcite}

\DeclareCiteCommand{\textcite}
\DeclareCiteCommand{\cbx@textcite}
{\usebibmacro{cite:init}%
\usebibmacro{prenote}%
\toggletrue{apa:intcite}}
{\usebibmacro{citeindex}%
\usebibmacro{textcite}%
Expand All @@ -558,13 +597,38 @@
{}
{\usebibmacro{textcite:postnote}}

\DeclareCiteCommand{\citeauthor}
{\usebibmacro{cite:init}%
\usebibmacro{prenote}}
{\usebibmacro{citeindex}%
\usebibmacro{cite:author}%
\usebibmacro{cite:post}}
\DeclareCiteCommand{\textcite}[\cbx@textcite@init\cbx@textcite]
{\gdef\cbx@savedkeys{}%
\citetrackerfalse%
\pagetrackerfalse%
\DeferNextCitekeyHook%
\usebibmacro{cite: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}}}
{}
{\usebibmacro{postnote}}
{\protected@xappto\cbx@savedcites{%
[\thefield{prenote}][\thefield{postnote}]{\cbx@savedkeys}}}

% textcite has nested \DeclareCiteCommand definitions for textcite and we want to use
% the normal textcite context
\DeclareDelimcontextAlias{cbx@textcite}{textcite}

\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}{}{}

\endinput

0 comments on commit cc709e4

Please sign in to comment.