% mla.cbx, v2.1a 2022/02/22 * compatible with biblatex 3.16
% Maintained at <https://github.com/jmclawson/biblatex-mla>.
%
% Feel free to improve, redistribute, and adapt to your own ends. Please share improvements back to the project on GitHub or to James Clawson: <clawson@gmail.com>.
%
% This material is subject to the LaTeX Project Public License. See http://www.ctan.org/tex-archive/help/Catalogue/licenses.lppl.html for the details of that license.

\ProvidesFile{mla.cbx}[2022/02/22 v2.1a biblatex citation style]

\RequireCitationStyle{mla-footnotes}

\newboolean{cbx@firstlonghand}%
\DeclareBibliographyOption{firstlonghand}[true]{\setboolean{cbx@firstlonghand}{#1}}
\newboolean{cbx@nofullfootnote}%
\DeclareBibliographyOption{nofullfootnote}[true]{\setboolean{cbx@nofullfootnote}{#1}}

\DeclareBibliographyOption{mancitepar}[true]{%
  \ifstrequal{#1}{true}{%
    \let\mypkg@@everypar\everypar
    \newtoks\mypkg@everypar
    \mypkg@everypar\expandafter{\the\everypar}
    \mypkg@@everypar{\mypkgs@ownstuff\the\mypkg@everypar}
    \def\mypkgs@ownstuff{%
    \mancite}%
    \let\everypar\mypkg@everypar
  }{}}

\DeclareBibliographyOption{footnoterulestrict}[true]{%
  \let\splitfootnoterule\footnoterule
  \renewcommand\footnoterule{}%
  \advance\skip\footins 4\p@\@plus2\p@\relax
  \gdef\split@prev{0}
  \let\pagefootnoterule\footnoterule
  \def\footnoterule{\relax
    \ifnum\split@prev=\z@
    \pagefootnoterule
    \else
    \splitfootnoterule
    \fi
    \xdef\split@prev{\the\insertpenalties}%
  }}

\ExecuteBibliographyOptions{citetracker=true,ibidtracker=constrict,opcittracker=constrict,singletitle,autocite=inline,uniquename=init,hyperref=true,useprefix=true,firstlonghand,annotation=false,loccittracker=strict,noremoteinfo=true,date=comp,urldate=long,mancitepar=false,datezeros=false,datecirca=true,dateuncertain=true,eprint=true,abbreviate=false}%

\newbool{cbx@named}%
\newbool{cbx@mlafootnotes}%
\newbool{cbx@hyperpages}%

\newbool{cbx@mladraft}%
\DeclareBibliographyOption{mladraft}[true]{%
  \setboolean{cbx@mladraft}{#1}}

\urlstyle{same}

\newbibmacro*{cite:init}{%
  \global\let\cbx@tempa=\empty
  \global\undef\cbx@lasthash}

\renewcommand*{\citereset}{%
  \usebibmacro{cite:reset}
  \@ifstar
    {}
    {\global\cslet{blx@bsee@\the\c@refsection}\@empty
     \global\cslet{blx@fsee@\the\c@refsection}\@empty
     \blx@ibidreset@force
     \blx@idemreset@force
     \blx@opcitreset@force
     \blx@loccitreset@force}
	 \global\undef\bbx@lasthash}% 2.1 last part added

% 2.1 adding citeauthor tracking for full / partial names
\newrobustcmd*{\cbx@nametracker@global}[1]{%
    \xifinlistcs{#1}{cbx@bseen@names@\the\c@refsection}
    {}
    {\listcsxadd{cbx@bseen@names@\the\c@refsection}{#1}}}

\newrobustcmd*{\cbx@nametracker@context}[1]{%
    \iftoggle{blx@footnote}
    {\xifinlistcs{#1}{cbx@fseen@names@\the\c@refsection}
        {}
        {\listcsxadd{cbx@fseen@names@\the\c@refsection}{#1}}}
    {\xifinlistcs{#1}{cbx@bseen@names@\the\c@refsection}
        {}
        {\listcsxadd{cbx@bseen@names@\the\c@refsection}{#1}}}}

\newrobustcmd*{\cbx@ifnameseen@global}[1]{%
    \xifinlistcs{#1}{cbx@bseen@names@\the\c@refsection}}

\newrobustcmd*{\cbx@ifnameseen@context}[1]{%
    \iftoggle{blx@footnote}%
    {\xifinlistcs{#1}{cbx@fseen@names@\the\c@refsection}}%
    {\xifinlistcs{#1}{cbx@bseen@names@\the\c@refsection}}}

\DeclareBibliographyOption[string]{nametracker}[true]{%
    \ifcsdef{blx@opt@nametracker@#1}
    {\csuse{blx@opt@nametracker@#1}}
    {\blx@err@invopt{nametracker=#1}{}}}

\def\blx@opt@nametracker@global{%
    \let\cbx@ifnameseen\cbx@ifnameseen@global
    \let\cbx@nametracker\cbx@nametracker@global}

\let\blx@opt@nametracker@true\blx@opt@nametracker@global

\def\blx@opt@nametracker@false{%
    \protected\long\def\cbx@ifnameseen##1##2##3{##3}%
    \let\cbx@nametracker\relax}

\def\blx@opt@nametracker@context{%
    \let\cbx@ifnameseen\cbx@ifnameseen@context
    \let\cbx@nametracker\cbx@nametracker@context}

\appto\blx@secinit{%
    \ifcsundef{cbx@bseen@names@\the\c@refsection}
    {\global\cslet{cbx@bseen@names@\the\c@refsection}\@empty}
    {}%
    \ifcsundef{cbx@fseen@names@\the\c@refsection}
    {\global\cslet{cbx@fseen@names@\the\c@refsection}\@empty}
    {}}

\ExecuteBibliographyOptions{nametracker=context}
% 2.1 adding citeauthor tracking for full / partial names

\InitializeCitationStyle{%
  \usebibmacro{cite:reset}%
  \@expandtwoargs\in@{,draft,}{,\@classoptionslist,}%
  \ifin@%
    \ExecuteBibliographyOptions{mladraft}% draft option present
  \fi
  \long\def\mlasymbolfootnote#1{\begingroup\def%
    \thefootnote{\fnsymbol{footnote}}\footnote[0]{#1}\endgroup}%
  \newcounter{mladraftnote}%
  \global\cslet{cbx@bseen@names@\the\c@refsection}\@empty%
  \global\cslet{cbx@fseen@names@\the\c@refsection}\@empty}

\OnManualCitation{%
  \usebibmacro{cite:reset}%
  \global\let\cbx@lastpostnote=\empty}

\newbibmacro*{cite:reset}{%
  \global\undef\cbx@lasthash}%

\newbibmacro*{cite:save}{%
  \savefield{entrykey}{\cbx@lastkey}%
  \savefield{namehash}{\cbx@lasthash}%
  \savefieldcs{entrykey}{cbx@lastkey@\thefield{namehash}}%
  \csxdef{cbx@lastcite@\thefield{entrykey}}{\the\value{instcount}}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%% In-Line Citations %%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newbibmacro*{cite:mla}{%
 \bibhypertarget{cite\the\value{instcount}}{%
    \ifciteseen%
      {\usebibmacro{cite:mla:seen}}
      {\usebibmacro{cite:mla:unseen}\usebibmacro{cite:save}}%
  \global\boolfalse{cbx@mlafootnotes}}}

\newbibmacro*{cite:mla:unseen}{%
  \ifbool{cbx@firstlonghand}
    {\usebibmacro{cite:mla:noshorthand}}%
    {\usebibmacro{cite:mla:seen}}}

\newbibmacro*{cite:mla:seen}{%
  \iffieldundef{shorthand}%
    {\usebibmacro{cite:mla:noshorthand}}%
    {\usebibmacro{cite:mla:shorthand}%
      \savefield{namehash}{\cbx@lasthash}}}

\newbibmacro*{cite:mla:noshorthand}{%
  \ifciteibid%
    {\ifbool{cbx@mlafootnotes}%
      {\usebibmacro{cite:mla:noibid}\usebibmacro{cite:save}}%
      {\usebibmacro{cite:ibid}}}%
    {\usebibmacro{cite:mla:noibid}\usebibmacro{cite:save}}}%

\newbibmacro*{cite:mla:noibid}%
  {\global\boolfalse{cbx@hyperpages}%
  \ifthenelse{\iffieldequals{namehash}{\cbx@lasthash}}%
     {\usebibmacro{cite:idem}%
      \usebibmacro{cite:mla:title}}%
     {\ifnameundef{labelname}%
        {\global\boolfalse{cbx@named}\usebibmacro{cite:mla:title}}%
        {\ifthenelse{\iffieldequalstr{entrytype}{incollection} \or \iffieldequalstr{entrytype}{inreference} \or \iffieldequalstr{entrytype}{review}}%
           {\ifnameundef{author}%
               {\global\boolfalse{cbx@named}%
                \usebibmacro{cite:mla:title}}%
               {\usebibmacro{cite:name}%
                \usebibmacro{cite:mla:title}\setunit{\addspace}}}%
           {\usebibmacro{cite:name}%
            \usebibmacro{cite:mla:title}}}}}%

\newbibmacro*{cite:mla:shorthand}{%
  \ifciteibid%
    {\ifbool{cbx@mlafootnotes}%
      {\printtext[bibhyperref]{%
        \printfield[citetitle:\strfield{entrytype}]{shorthand}}\setunit{\addspace}}%
      {\usebibmacro{cite:ibid}}}%
    {\global\boolfalse{cbx@hyperpages}\printtext[bibhyperref]{%
      \printfield[citetitle:\strfield{entrytype}]{shorthand}}\setunit{\addspace}}}

\newbibmacro*{cite:name}{%
 \ifsingletitle%
  {\ifbool{cbx@totalnames}%
    {\printtext[bibhyperref]{\printnames[][-\value{listtotal}]{labelname}}}%
	{\printtext[bibhyperref]{\printnames{labelname}}}%
   \savefield{namehash}{\cbx@lasthash}%
   \global\booltrue{cbx@named}}%
  {\printnames{labelname}%
    \savefield{namehash}{\cbx@lasthash}%
    \global\booltrue{cbx@named}}}%

\newbibmacro*{just:title:it}{%
  \iffieldequalstr{entrytype}{mlasource}%
    {\iffieldundef{titletype}%
	  {\iffieldundef{titlea}%
	    {\printtext[bibhyperref]{\printfield[mla:complete]{labeltitle}}}%
	    {\printtext[bibhyperref]{\printfield[mla:part]{labeltitle}}}}%
	  {\printtext[bibhyperref]{\printfield[mla:\thefield{titletype}]{labeltitle}}}}%
	{\ifthenelse{\(\iffieldequalstr{entrytype}{unpublished}\OR\iffieldequalstr{entrytype}{misc}\)%
    \AND\NOT\iffieldundef{entrysubtype}}% 2.0 added clear (next line)
	  {\printtext[bibhyperref]{\printfield[citetitle:\strfield{entrysubtype}]{labeltitle}}\clearfield{title}}%
	  {\iffieldequalstr{entrysubtype}{untitled}%
	    {\printtext[bibhyperref]{\printfield[noformat]{labeltitle}}}%
		{\iffieldequalstr{entrytype}{online}% 2.1 format online titles by entrysubtype
		  {\printtext[bibhyperref]{\printfield[citetitle:online:\strfield{entrysubtype}]{labeltitle}}}
		  {\printtext[bibhyperref]{\printfield[citetitle:\strfield{entrytype}]{labeltitle}}}}}}}

\newbibmacro*{cite:mla:title}{%
  \ifnameundef{labelname}%
    {\usebibmacro{just:title:it}}%
    {\ifsingletitle%
      {}%
      {\usebibmacro{cite:mla:title:internal}}}%
  \ifthenelse{\iffieldequalstr{entrytype}{review}%
      \and\ifnameundef{author}%
      \and\iffieldundef{title}}%
    {\printtext[bibhyperref]%
      {\printtext{\bibcpstring{reviewof}%
	   \setunit{\addspace}%
	   \printfield{booktitle}}}}%
    {}%
	\setunit{\addspace}}%

\newbibmacro*{cite:mla:title:internal}{%
  \ifbool{cbx@named}{\setunit{\addcomma\addspace}}{}%
  \iffieldundef{title}%
    {\iffieldequalstr{entrytype}{review}%
      {\printtext[bibhyperref]%
        {\printtext{\bibcpstring{reviewof}%
  	   \setunit{\addspace}%
  	   \printfield{booktitle}}}}%
      {\ifthenelse{\iffieldequalstr{entrytype}{suppbook}%
         \OR\iffieldequalstr{entrytype}{suppcollection}}%
        {\printtext[bibhyperref]{%
         \printfield[mla:capital]{entrysubtype}}}%
        {\iffieldundef{booktitle}% 2.0 fallback to print booktitle
		  {}%
		  {\printfield{booktitle}}%
		}}}%
    {\usebibmacro{just:title:it}}}%

%%%%%%%%%%% for ibid, idem, opcit %%%%%%%%

\newbibmacro*{cite:idem}{%
  \ifsingletitle%
    {\usebibmacro{cite:name}}%
    {\global\boolfalse{cbx@named}}}

\newbibmacro*{cite:opcit}{%
  \usebibmacro{cite:mla:title}\setunit{\addspace}}

\newbibmacro*{cite:ibid}{%
  \iffieldundef{postnote}%
    {\usebibmacro{cite:mla:noibid}}% 2.0 - check: add check here to see whether author should be printed?
    {\global\booltrue{cbx@hyperpages}}%
  \usebibmacro{cite:save}%
  \iffieldundef{prenote}%
    {}%
    {}}% 2.0 removed confusing attempt to disambiguate with prenotes

\renewcommand*{\postnotedelim}{\addspace}%

\renewbibmacro*{postnote}{%
  \iffieldundef{postnote}%
    {}%
	{\ifbool{cbx@hyperpages}%
      {\printtext[bibhyperref]{\printfield[ibidpostnote]{postnote}}}%
      {\printfield[ibidpostnote]{postnote}}}}%

\newbibmacro*{locpostnote}{%
  \ifbool{cbx@mladraft}%
    {\ifbool{cbx@hyperpages}%
      {\printtext[mlarepeatedcites]{%
        \printtext[bibhyperref]{\printfield[ibidpostnote]{postnote}}}}%
      {\printtext[mlarepeatedcites]{%
        \printfield[ibidpostnote]{postnote}}}%
    \ifthenelse{\value{mladraftnote}<2}%
        {\mlasymbolfootnote{\addtocounter{mladraftnote}{4}%
           $\clubsuit$ It is best to cite once at the end %
           of a passage quoting a single page range.}}%
        {}}%
    {\usebibmacro{postnote}}}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%% Format Declarations %%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\DeclareFieldFormat{citetitle:article}{\mkbibquote{#1}}
\DeclareFieldFormat{citetitle:book}{\mkbibemph{#1}}
\DeclareFieldFormat{citetitle:bookinbook}{\mkbibemph{#1}}% NEW in 2.0
\DeclareFieldFormat{citetitle:booklet}{\mkbibemph{#1}}%
\DeclareFieldFormat{citetitle:collection}{\mkbibemph{#1}}%
\DeclareFieldFormat{citetitle:dataset}{\mkbibquote{#1}}% NEW in 2.1
\DeclareFieldFormat{citetitle:image}{#1}% 2.1 finally styled right
\DeclareFieldFormat{citetitle:inbook}{\mkbibquote{#1}}% NEW in 2.0
\DeclareFieldFormat{citetitle:incollection}{\mkbibquote{#1}}
\DeclareFieldFormat{citetitle:inproceedings}{\mkbibquote{#1}}
\DeclareFieldFormat{citetitle:inreference}{\mkbibquote{#1}}
\DeclareFieldFormat{citetitle:misc}{#1}% 2.1 finally styled right
\DeclareFieldFormat{citetitle:mvbook}{\mkbibemph{#1}}% NEW in 2.0
\DeclareFieldFormat{citetitle:online}{\mkbibquote{#1}}%
\DeclareFieldFormat{citetitle:online:website}{\mkbibemph{#1}}%
\DeclareFieldFormat{citetitle:performance}{\mkbibemph{#1}}% NEW in 2.1
\DeclareFieldFormat{citetitle:reference}{\mkbibemph{#1}}%
\DeclareFieldFormat{citetitle:review}{\mkbibquote{#1}}%
\DeclareFieldFormat{citetitle:software}{\mkbibemph{#1}}% NEW in 2.1
\DeclareFieldFormat{citetitle:thesis}{\mkbibquote{#1}}
\DeclareFieldFormat{citetitle:unpublished}{\mkbibquote{#1}}% fixme still needs work for unstyled types
\DeclareFieldFormat{citetitle:video}{\mkbibemph{#1}}
\DeclareFieldFormat{mla:lowercase}{\MakeLowercase{#1}}%
\DeclareFieldFormat[mlasource]{mla:unstyled}{#1\unspace}%
\DeclareFieldFormat[mlasource]{mla:complete}{\mkbibemph{#1}\unspace}%
\DeclareFieldFormat[mlasource]{mla:part}{\mkbibquote{#1}}%
\DeclareFieldFormat{ibidpostnote}{#1}%
\DeclareFieldFormat{footpostnote}{#1}%
\DeclareFieldFormat{mlarepeatedcites}{\fbox{#1}%
  \marginpar{\hfill\footnotesize{$\clubsuit$}}}%


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%% Cite Commands %%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\renewbibmacro*{prenote}{%
  \iffieldundef{prenote}%
    {\global\undef\cbx@lastprenote}%
    {\printfield{prenote}%
     \prenotedelim%
     \ifthenelse{\iffieldequals{prenote}{\cbx@lastprenote} \and \iffieldequals{entrykey}{\cbx@lastkey}}%
       {}%
       {}%\usebibmacro{cite:reset}}% 2.0 remove "clever" ibid reset with prenotes
     \savefield{prenote}{\cbx@lastprenote}}}

\DeclareCiteCommand{\parencite}[\mkbibparens]
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \usebibmacro{cite:mla}}
  {\multicitedelim}
  {\ifthenelse{\iffieldequals{postnote}{\cbx@lastpostnote} \and \iffieldequals{entrykey}{\cbx@lastkey}}%
    {\usebibmacro{locpostnote}}%
    {\usebibmacro{postnote}}%
  \savefield{postnote}{\cbx@lastpostnote}}%

\DeclareCiteCommand*{\parencite}[\mkbibparens]
  {\global\undef\cbx@lasthash\usebibmacro{prenote}}%
  {\usebibmacro{citeindex}%
   \usebibmacro{cite:mla:starred:title}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\newbibmacro{mla:prenote:see}{% Suggested by moewe on StackExchange
  \iffootnote
    {\iffieldundef{prenote}
       {\global\undef\cbx@lastprenote
        \printtext{See\addspace}}
       {\usebibmacro{prenote}}}
    {}}

\DeclareCiteCommand{\cite}%
  {\usebibmacro{mla:prenote:see}}%
  {\usebibmacro{citeindex}%
   \usebibmacro{cite:mla}}%
  {\multicitedelim}%
  {\usebibmacro{postnote}}
  
\DeclareCiteCommand{\textcite}%
  {\usebibmacro{mla:prenote:see}}%
  {\usebibmacro{citeindex}%
   \usebibmacro{cite:mla}}%
  {\multicitedelim}%
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\headlesscite}%
  {\usebibmacro{mla:prenote:see}}%
  {\usebibmacro{citeindex}%
   \usebibmacro{cite:mla:starred:title}}
  {\multicitedelim}%
  {\usebibmacro{postnote}}

\DeclareCiteCommand*{\cite}%
  {\usebibmacro{mla:prenote:see}}%
  {\usebibmacro{citeindex}%
   \usebibmacro{cite:mla:starred:title}}
  {\multicitedelim}%
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\footcite}[\mkbibfootnote]
  {\bibsentence%
   \usebibmacro{cite:init}%
   \usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \global\booltrue{cbx@mlafootnotes}%
   \renewcommand*{\newunitpunct}{\addcomma\space}%
   \usebibmacro{cite:mla:foot}}
  {\multicitedelim}
  {\usebibmacro{mla:foot:postnote}}

\DeclareCiteCommand{\fullcite}
  {\usebibmacro{mla:prenote:see}}%
  {\usebibmacro{citeindex}%
   \usebibmacro{cite:mla:title}}
  {}%
  {\usebibmacro{postnote}}

\DeclareCiteCommand{\headlessfullcite}
  {\usebibmacro{mla:prenote:see}}%
  {\usebibmacro{citeindex}%
   \usebibmacro{cite:mla:starred:title}}
  {}%
  {\usebibmacro{postnote}}

\newbibmacro{mla:fullcite:prenote}{%
\citereset\renewbibmacro*{author}{%
  \ifthenelse{\ifuseauthor\AND\NOT\ifnameundef{author}}
    {\DeclareNameAlias{author}{default}\ifthenelse{\iffieldequals{namehash}{\cbx@lasthash}\AND\NOT
                 \iffirstonpage}
       {\mbox{\mlanamedash\unspace\newunitpunct}}
       {\printnames{author}%
        \savefield{namehash}{\cbx@lasthash}}}
    {\let\cbx@lasthash\undefined}}}
 
 \DeclareCiteCommand{\smartcite}[\iffootnote\mkbibparens\mkbibfootnote]% 2.0 changed to align with footcite
   {\bibsentence%
    \usebibmacro{cite:init}%
    \usebibmacro{prenote}}
   {\usebibmacro{citeindex}%
    \global\booltrue{cbx@mlafootnotes}%
    \renewcommand*{\newunitpunct}{\addcomma\space}%
    \usebibmacro{cite:mla:foot}}
   {\multicitedelim}
   {\usebibmacro{mla:foot:postnote}}
   
\DeclareCiteCommand{\titleandsubtitle}
  {\boolfalse{citetracker}%
   \boolfalse{pagetracker}%
   \usebibmacro{prenote}}
  {\indexfield{indextitle}%
   \printtext[bibhyperref]{\printtext[citetitle]{% 2.0 added hyperref
     \printfield[noformat]{title}%
     \iffieldundef{subtitle}{}{\subtitlepunct}%
     \printfield[noformat]{subtitle}}}}%
  {\multicitedelim}
  {\usebibmacro{postnote}}
  
\DeclareCiteCommand{\citeauthor}%
  {\usebibmacro{prenote}}
  {\ifciteindex
     {\indexnames{labelname}}
     {}%
   \printnames[citeauthor]{labelname}}%
  {\multicitedelim}
  {\usebibmacro{postnote}\usebibmacro{cite:save}}
  
\DeclareCiteCommand*{\citeauthor}% print just the surname
  {\usebibmacro{prenote}}
  {\ifciteindex
     {\indexnames{labelname}}
     {}%
   \printnames[citeauthorstar]{labelname}}%
  {\multicitedelim}
  {\usebibmacro{postnote}\usebibmacro{cite:save}}

% 2.1 tracking seen names for citeauthor
\DeclareNameFormat{citeauthor}{%
  \cbx@ifnameseen{\thefield{hash}}
    {\ifcase\value{uniquename}%
       \usebibmacro{name:family}
        {\namepartfamily}
        {\namepartgiven}
        {\namepartprefix}
        {\namepartsuffix}%
     \or
       \ifuseprefix
         {\usebibmacro{name:given-family}
            {\namepartfamily}
            {\namepartgiveni}
            {\namepartprefix}
            {\namepartsuffixi}}
         {\usebibmacro{name:given-family}
            {\namepartfamily}
            {\namepartgiveni}
            {\namepartprefixi}
            {\namepartsuffixi}}%
     \or
       \usebibmacro{name:given-family}
         {\namepartfamily}
         {\namepartgiven}
         {\namepartprefix}
         {\namepartsuffix}%
     \fi}
    {\usebibmacro{name:given-family}
       {\namepartfamily}
       {\namepartgiven}
       {\namepartprefix}
       {\namepartsuffix}%
     \cbx@nametracker{\thefield{hash}}}%
  \usebibmacro{name:andothers}}

\DeclareNameFormat{citeauthorstar}{%
  \ifcase\value{uniquename}%
    \usebibmacro{name:family}
      {\namepartfamily}
      {\namepartgiven}
      {\namepartprefix}
      {\namepartsuffix}%
  \or
    \ifuseprefix
      {\usebibmacro{name:given-family}
         {\namepartfamily}
         {\namepartgiveni}
         {\namepartprefix}
         {\namepartsuffixi}}
      {\usebibmacro{name:given-family}
         {\namepartfamily}
         {\namepartgiveni}
         {\namepartprefixi}
         {\namepartsuffixi}}%
  \or
    \usebibmacro{name:given-family}
      {\namepartfamily}
      {\namepartgiven}
      {\namepartprefix}
      {\namepartsuffix}%
  \fi
  \cbx@ifnameseen{\thefield{hash}}
    {}
    {\cbx@nametracker{\thefield{hash}}}%
  \usebibmacro{name:andothers}}
% 2.1 tracking seen names for citeauthor

\DeclareCiteCommand{\citetitle}
  {\boolfalse{citetracker}%
   \boolfalse{pagetracker}%
   \usebibmacro{prenote}}
  {\ifciteindex
     {\indexfield{indextitle}}
     {}%
   \usebibmacro{just:title:it}}% 2.1 simplified
  {\multicitedelim}
  {\usebibmacro{postnote}}

\DeclareCiteCommand*{\citetitle}
  {\boolfalse{citetracker}%
   \boolfalse{pagetracker}%
   \usebibmacro{prenote}}
  {\ifciteindex
     {\indexfield{indextitle}}
     {}%
   \usebibmacro{just:title:it}}% 2.1 simplified
  {\multicitedelim}
  {\usebibmacro{postnote}}

\newbibmacro*{cite:mla:starred:title}{%
  \ifciteibid
    {\iffieldundef{postnote}
      {\usebibmacro{cite:mla:title:alone}}
      {\global\booltrue{cbx@hyperpages}}}
    {\iffieldundef{shorthand}
      {\ifsingletitle%
          {\iffieldundef{postnote}
                  {\usebibmacro{cite:mla:title:alone}}
                  {\global\booltrue{cbx@hyperpages}}}%
          {\usebibmacro{cite:mla:title:alone}\setunit{\addspace}}}
      {\usebibmacro{cite:mla:shorthand}}}}

\newbibmacro*{cite:mla:title:alone}{%
  \printtext[bibhyperref]{% suggested by StackExchange user Audrey
  \ifthenelse{%
    \iffieldequalstr{entrytype}{unpublished}\AND\NOT\iffieldundef{entrysubtype}%
	}%
	{\printfield[citetitle:\strfield{entrysubtype}]{labeltitle}}%
	{\ifthenelse{\iffieldequalstr{entrytype}{suppbook}\and\iffieldundef{title}}%
    	{\printtext[bibhyperref]{%
		  \printfield[mla:capital]{entrysubtype}}}%
    	{\printfield[citetitle:\strfield{entrytype}]{labeltitle}}}%
  }%
}


\endinput