3

I am working on big book and need to ensure that all citations have a white space before them. I tried

 \let\citep ~\citep

But that does not seem the right thing to do. Could you please help.

Cheers

2 Answers2

4

there are two things wrong with your attempt.

\let equates the specified command to the next single command. even though it may not look like one, ~ is in fact a command (for an unbreakable space). so you have just defined \citep to be an unbreakable space.

even if you had used the more appropriate approach -- \renewcommand{\citep}{~\citep} -- you would have run into the problem that, without "freezing" the original meaning of \citep, this would result in an unending loop.

a reliable approach is to define an entirely new command:

\newcommand{\mycitep}{~\citep}

here the original meaning of \citep is never compromised, and if you change your mind, it's easy to change the definition. this also allows you to use the original \citep if it is needed, for example, to start a sentence, where a preceding space would be inappropriate.

  • 1
    Isn't the space adding default if you load the cite package with the space option (really annoying if you want to use it in context where the sapce is not wanted). – daleif Dec 20 '13 at 16:13
  • @daleif -- that's why i suggested a new name. admittedly, i wasn't thinking of using a package. – barbara beeton Dec 20 '13 at 16:17
  • not easy when it is a tempalte providsed by a publisher. – daleif Dec 20 '13 at 16:54
  • @daleif -- good point. that's why (at ams) we do try to predict how macros might be "misused" before releasing them for general use. the payback is worth the extra effort up front. (and of course it's never possible to foresee everything.) – barbara beeton Dec 20 '13 at 19:18
3

As barbara explained, \let is not the right command to use. However, also the proposed solution is not very good, in my opinion.

Since \citep is provided by natbib, I'll assume it.

\documentclass{article}
\usepackage{natbib}
\usepackage{letltxmacro}

\LetLtxMacro{\ORIcitep}{\citep}
\DeclareRobustCommand{\citep}{\leavevmode\unskip~\ORIcitep}

In this way, \citep is defined to do the same as the original command, after removing a possible space before it and adding a tie instead. Without \unskip, an input like

word~\citep{key}

would result in two spaces.

Of course it doesn't make sense to use \citep at the start of a paragraph. So my advice is not to use such a redefinition, but to ensure ~ is typed before \citep when necessary.

See When to use \LetLtxMacro? for more information about \LetLtxMacro.

egreg
  • 1,121,712
  • unfortunately, if the redefined \citep starts a paragraph, there's an unwanted space at the beginning. – barbara beeton Dec 20 '13 at 16:20
  • @barbarabeeton I forgot to add natbib. Of course the unwanted space in front of the citation is unavoidable at the start of a paragraph, which is why I wouldn't recommend such an approach. A desired space in output should have a corresponding token in input. – egreg Dec 20 '13 at 16:23
  • i don't disagree that starting a paragraph with a citation is a bad thing, but that doesn't mean authors won't do it. (and i did \usepackage{natbib} when i tested it. you had a comment in your original answer that said you "assumed" it, and for once, i was careful enough to read the whole thing. i see you've edited a warning into the answer now.) – barbara beeton Dec 20 '13 at 19:14