Customize \textcite with superscript reference number
I tried the method at https://tex.stackexchange.com/questions/162309/biblatex-nature-textcite-with-superscript-reference-number But it does not work when I have multiple citations of one author. Only the first citation shows with superscript reference number. And then I tried
\DeclareCiteCommand{\textcite}[\mkbibsuperscript]
{\usebibmacro{cite:init}%
\let\multicitedelim=\textcitedelim
\iffieldundef{prenote}
{}
{\BibliographyWarning{Ignoring prenote argument}}%
\iffieldundef{postnote}
{}
{\BibliographyWarning{Ignoring postnote argument}}}%
{\usebibmacro{citeindex}%
\usebibmacro{cite:comp}}
{}
{\usebibmacro{cite:dump}}
Everything works except the author name is gone away. I tried searching as far as I can but got no answer. So I asked here.
I saw the TeX.SX question at https://tex.stackexchange.com/q/580501/35864 and looked into a solution, but it is a bit trickier than one might think or hope.
I got as far as
\documentclass{article}
\usepackage[style=nature]{biblatex}
\makeatletter
\newcommand*{\makesuperscriptdelims}{%
\let\multicitedelim=\supercitedelim
\let\multicitesubentrydelim=\supercitesubentrydelim
\let\multiciterangedelim=\superciterangedelim
\let\multicitesubentryrangedelim=\supercitesubentryrangedelim
}
\renewbibmacro*{textcite}{%
\iffieldequals{namehash}{\cbx@lasthash}
{\mkbibsuperscript{\makesuperscriptdelims\usebibmacro{cite:comp}}}
{\mkbibsuperscript{\makesuperscriptdelims\usebibmacro{cite:dump}%
\ifbool{cbx:parens}
{\bibclosebracket\global\boolfalse{cbx:parens}}
{}}%
\iffirstcitekey
{}
{\setunit{\textcitedelim}}%
\usebibmacro{cite:init}%
\ifnameundef{labelname}
{\printfield[citetitle]{labeltitle}}
{\printnames{labelname}}%
\setunit*{}%
\mkbibsuperscript{\makesuperscriptdelims%
\bibopenbracket\global\booltrue{cbx:parens}%
\usebibmacro{cite:comp}%
}%
\stepcounter{textcitecount}%
\savefield{namehash}{\cbx@lasthash}}%
\ifnumequal{\value{citecount}}{\value{citetotal}}
{\setunit{}%
\mkbibsuperscript{\makesuperscriptdelims%
\usebibmacro{cite:dump}%
\ifbool{cbx:parens}
{\bibclosebracket\global\boolfalse{cbx:parens}}
{}}}
{}}
\DeclareCiteCommand{\cbx@textcite}
{\usebibmacro{cite:init}}
{\usebibmacro{citeindex}%
\usebibmacro{textcite}}
{}
{}
\makeatother
\begin{filecontents}{\jobname.bib}
@article{a1,
AUTHOR = {Author},
TITLE = {A sample paper},
JOURNAL = {Sample journal},
VOLUME = {1},
YEAR = {2013},
NUMBER = {1},
PAGES = {1--2},
}
@misc{a2,
AUTHOR = {Author},
TITLE = {A sample paper},
YEAR = {2013},
}
@misc{a3,
AUTHOR = {Author},
TITLE = {A sample paper},
YEAR = {2013},
}
\end{filecontents}
\addbibresource{\jobname.bib}
\begin{document}
\textcite{a1,a2,a3}
\textcite{a1,a2}
\textcite{a1}
\end{document}
but there is still a spurious space I can't seem to get rid of.
Conceptually, placing the superscript in several separate \mkbibsuperscripts also does not feel right (and posibly has kerning implications), but the current implementation of the citation style assumes that it can just write the output out immediately, so a larger overall change might be needed if one wanted to change that.
@moewew Thank you for your effort. Yeah, there is a spurious space.
To your reference,
I found https://github.com/josephwright/biblatex-ieee/blob/main/ieee.cbx was quite close to my requirement.
I tried modifying it to place several separate \mkbibsuperscripts, but I failed.
@moewew I also found that
- removing
\makesuperscriptdelimsfrom yourtextcitemacro does not make any difference, as if\makesuperscriptdelimsis useless, which is out of my expectation. - removing
\mkbibsuperscriptfrom yourtextcitemacro removes the spurious space, but results in normal reference number.
@moewew If you test it with
\begin{document}
\textcite{a1,a2,a3}TEST
\end{document}
you will find that it introduces another spurious space just before TEST.
Hope those information will help you.