1

I defined a custom name + year + title footnote format, but for some reason there is a leading space before the superscript. Where is it coming from?

The command looks like this:

\DeclareNameFormat{lastnameonly}{\namepartfamily}
\DeclareCiteCommand{\myfootcite}{}{%
    \footnote{%
        \printnames[lastnameonly]{author} (\printfield{year}), \printfield{title}
    }
}{}{}

Output:

enter image description here

MWE:

\documentclass{article}

\usepackage[backend=biber]{biblatex}
\bibliography{references.bib}
\begin{filecontents}{references.bib}
@article{smith01,
  author = {Smith, John},
  year = {2001},
  title = {Article title}
}
\end{filecontents}

%% Custom command giving a mysterious space
\DeclareNameFormat{lastnameonly}{\namepartfamily}
\DeclareCiteCommand{\myfootcite}{}{%
    \footnote{%
        \printnames[lastnameonly]{author} (\printfield{year}), \printfield{title}
    }
}{}{}

\begin{document}
There is a space \myfootcite{smith01}
\end{document}
4
  • 1
    Well, you add a space between space and \myfootcite ;-)
    – user31729
    Commented Apr 17, 2017 at 16:56
  • Ah yes, I guess I'm curious how \footcite deletes the preceding space then, and how to do that for my command with \footnote?
    – kennysong
    Commented Apr 17, 2017 at 17:01
  • 1
    you might try using \unskip at the beginning of \myfootcite. Commented Apr 17, 2017 at 17:08
  • @barbarabeeton Aha! Very simple, thank you. Make it an answer and I will accept?
    – kennysong
    Commented Apr 17, 2017 at 17:10

1 Answer 1

3

the easy thing to do is add \unskip at the beginning of the \myfootcite definition:

%% Custom command giving a mysterious space
\DeclareNameFormat{lastnameonly}{\namepartfamily}
\DeclareCiteCommand{\myfootcite}{}{%
    \unskip
    \footnote{%
        \printnames[lastnameonly]{author} (\printfield{year}), \printfield{title}% <--
    }% <--
}{}{}

this has the effect of removing the space that immediately precedes the insertion of the command when it's applied.

the inverse of this is \ignorespaces, which will, as it says, ignore any spaces that immediately follow a command that includes it at the end.

these two commands earn their keep when careless input includes spaces at the beginning or end of some string that is to be used in a position where "clean" spacing matters, like a running head, or preceding a footnote as the example here shows.

there were also spurious spaces, removed with a % in the spots marked with <--.

1
  • 1
    While this of course helps (and indeed is how \footcite gets rid of preceding spcaes), defining a custom command for biblatex like this (i.e. by lumping together several high-level commands) is just plain wrong and leads to all kinds of problems. (Aside from spaces, there is missing support for pre- and post-notes, and for multiple citations. A command like this can also lead to problems with citation trackers.)
    – moewe
    Commented Apr 18, 2017 at 12:38

You must log in to answer this question.

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