biblatex icon indicating copy to clipboard operation
biblatex copied to clipboard

Customize \textcite with superscript reference number

Open etclub opened this issue 5 years ago • 4 comments

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.

etclub avatar Jan 28 '21 03:01 etclub

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 avatar Jan 28 '21 07:01 moewew

@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.

etclub avatar Jan 29 '21 14:01 etclub

@moewew I also found that

  1. removing \makesuperscriptdelims from your textcite macro does not make any difference, as if \makesuperscriptdelims is useless, which is out of my expectation.
  2. removing \mkbibsuperscript from your textcite macro removes the spurious space, but results in normal reference number.

etclub avatar Jan 30 '21 02:01 etclub

@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.

etclub avatar Feb 02 '21 03:02 etclub