0

I found something really strange when using newcommand in latex. I wrap two pieces of text that are often show up in my article, which are,

\newcommand{\etal}{et al.}
\newcommand{\stra}{$\mathcal{S}_A$}

where the first is the abbreviation and the other is a symbol. However, when I use these two macro definion and type the following

Sentence 1: Liu \etal \cite{liu2019} did something.
Sentence 2: Liu \etal did somthing.
Sentence 3: Liu add \stra to this process.

the results are

Sentence 1: Liu et al. [1] did something.

Sentence 2: Liu et al.did something.

Sentence 3: Liu add $\mathcal{S}_A$to this process.

As you can tell, the blank after commands in the last two sentences are lost, but the space in the first sentence still exists. I am wondering how can I solve this problem.

BTW, It is not a good practice to put an extra space in the command.

  • Especially https://tex.stackexchange.com/a/290504/38080 is worth reading, it is a masterwork on the "space after command" subject :-) – Rmano Oct 15 '20 at 05:00
  • The space appears in the first case possibly because you’re using the cite package. – egreg Oct 15 '20 at 07:44

1 Answers1

1

Spaces after commands that are made of letters are ignored. This allows you to type, e.g., \AE sop to get Æsop since munging the letters together would make LaTeX think that you were entering a command \AEsop and give you an undefined control sequence error.

For your examples, you need to add \ to the end of the command to let LaTeX know that you do want a space there. So your sentences would be:

Sentence 1: Liu \etal\ \cite{liu2019} did something.
Sentence 2: Liu \etal\ did somthing.
Sentence 3: Liu add \stra\ to this process.
Don Hosek
  • 14,078
  • @Hosek Thanks, the problem is solved. So, in the first sentence, the space is kept because there is another command follow behind? – Yuejiang_Li Oct 15 '20 at 03:29
  • @Yuejiang_Li spaces get ignored after an alphabetic command regardless of what follows. – Don Hosek Oct 15 '20 at 13:32