4

I'm using biblatex with a custom \citename command to display the familynames of authors in smallcaps. Somehow I always get a linebreak after using my \citename command. I tried using \unskip in the command or \ignorespaces after it but i still get a linebreak.

MWE using PDFlatex:

\documentclass{article}
\usepackage[style=authoryear]{biblatex}
\addbibresource{test.bib}

\newbibmacro{name:newformat}{%
   \namepartfamily
   \ifnumless{\value{listcount}}{\value{liststop}}{\addspace\textit{\textsc{and}}\addspace}
   {\addspace}
}

\DeclareNameFormat{newformat}{%
  \nameparts{#1}%
  \usebibmacro{name:newformat}%
  \usebibmacro{name:andothers}%
}

\DeclareCiteCommand{\citename}
  {\usebibmacro{prenote}}
  {\usebibmacro{citeindex}%
   \textsc{\printnames[newformat]{author}}%
   \unskip}
  {\usebibmacro{postnote}}

\begin{document}

\citename{sample}\ignorespaces are asking what is going on here.

\citename{sample2}\unskip still sees a linebreak.

\printbibliography

\end{document}

test.bib

@article{sample,
  author = {Doe, John and Smith, Jane},
  title = {Sample Title},
  journal = {Sample Journal},
  year = {2023},
}
@article{sample2,
  author = {Doe, John},
  title = {Sample Title 2},
  journal = {Sample Journal},
  year = {2023},
}

Thank you for helping me!

1
  • Welcome! Thanks for providing such a nice example!
    – cfr
    Commented Jun 19 at 1:23

1 Answer 1

3

The basic problem is that you are missing an argument from your declaration of the citation command, so Biblatex takes \usebibmacro{postnote} as the separator to be used between citations. You can see this most clearly if you add pre and post notes to your sample citations: the postnotes all disappear.

In addition, you are overwriting the standard \citename. While this may be intentional, I'd highly recommend not doing so - at least without setting up your alternative in a sufficiently sophisticated way to make an effective replacement. However, that is for you to decide. If you wish to dig pitfalls along your own path, by all means enjoy your obstacle course.

better behaving citations?

\begin{filecontents}[overwrite]{\jobname.bib}
@article{sample,
  author = {Doe, John and Smith, Jane},
  title = {Sample Title},
  journal = {Sample Journal},
  year = {2023},
}
@article{sample2,
  author = {Doe, John},
  title = {Sample Title 2},
  journal = {Sample Journal},
  year = {2023},
}
\end{filecontents}
\documentclass{article}
\usepackage[style=authoryear]{biblatex}
\addbibresource{\jobname.bib}

\newbibmacro{name:newformat}{%
  \textsc{\namepartfamily}%
  \ifnum\value{listcount}<\value{liststop}\addspace
    \textit{\textsc{and}}\addspace
  \else\addspace\fi}

\DeclareNameFormat{cite:nname}{%
  \usebibmacro{name:newformat}%
  \usebibmacro{name:andothers}%
}
\DeclareCiteCommand{\citenname}% probably not a good idea to obliterate \citename
% modified from \citeauthor in the biblatex.def
{\boolfalse{citetracker}%
  \boolfalse{pagetracker}%
  \usebibmacro{prenote}}
{\ifciteindex
  {\indexnames{labelname}}
  {}%
  \printnames[cite:nname]{author}}
{\multicitedelim}
{\usebibmacro{postnote}}

\newrobustcmd{\Citenname}{\bibsentence\citenname}
\DeclareMultiCiteCommand{\citennames}{\citenname}{}
\newrobustcmd{\Citennames}{\bibsentence\citennames}

\begin{document}
  
\citenname{sample} are asking what is going on here.

\citenname{sample2}  still sees a linebreak.

\printbibliography

\citenname{sample,sample2}
  
\end{document}
2
  • 1
    Thank you! I was so stumped by this. I really need to count my arguments in the future! I took your advice and renamed the command to \citenameSC. I'm very new to using \DeclareCiteCommand because I just started writing my thesis which has some very specific requirements.
    – Karl Heinz
    Commented Jun 19 at 6:34
  • @KarlHeinz It is easy to miss. I kept staring at the code, but it was only when I added pre and post notes that I started to have a clue. Something was obviously eating the postnotes .... If you are in North America, thesis format requirements are nuts.
    – cfr
    Commented Jun 19 at 20:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .