111

In this answer, \@ is used after a period and before an \xspace, presumably to indicate that the preceding period (in "etc.") was not sentence-final.

In these tips, \@ is used before a period and after capital letters, to indicate that the preceding capital letters are sentence final.

Since \@ is rather difficult to search for online, I thought I'd try to ask here: what exactly does \@ do, and how do you use it properly/consistently? For instance, how should you input the following farcical sentence?

Languages like JS, HTML, etc. were not used by King Henry III.

EDIT: I'm accepting Barbara's answer below as it (and the comments on it) indicate the initial intent of \@: "the period which follows is sentence-final". Its counterpart is \  (slash-space), which says "the period which precedes is sentence-medial". Egreg's answer explains in far more detail exactly how \@ and \spacefactor work to cause the effects seen by \@ and \  after lower- and upper-case letters and punctuation. Both are very helpful answers.

Two correct answers to my made-up sentence above is

Languages like JS, HTML, etc.\ were not used by King Henry III\@.
Languages like JS, HTML, etc.\@ were not used by King Henry III\@.

The former is arguably "better style", while the latter demonstrably produces the correct result even if it seems less consistent about placement of \@ versus periods. And a safe but slightly redundant answer blindly adds \@ before every comma:

Languages like JS\@, HTML\@, etc.\ were not used by King Henry III\@.

This last one is amenable to macro-izing: \def\acronym#1{\textbf{#1}\@\xspace} (or whatever style you'd prefer), where the \xspace disappears if the next character is punctuation, and the \@ ensures that subsequent punctuation thinks it follows a lowercase word and not an uppercase initial.

0

4 Answers 4

73

i find the cited answer rather confusing, if not out-and-out backwards. \@ before punctuation says that the period does fall at the end of a sentence. to quote from the latex manual (p.170):

\@ Causes an "end-of-sentence" space after punctuation when typed before the punctuation character. Needed only if the character preceding the punctuation character is not a lowercase letter or a number.

so your farcical sentence is input as

Languages like JS, HTML, etc.\ were not used by King Henry III\@.

only one \@, and that after a capital I.

Update:
I have been reminded, rather ignominiously, that \@ is not defined in classic TeX. If used, the result is "! Undefined control sequence." (The corresponding command for TeX to render an end-of-sentence space following a period following an uppercase letter is \null.) \@ is LaTeX only.

21
  • 7
    @Martin -- obviously i can't argue that @egreg's answer is wrong, since it demonstrably produces the desired result. but perhaps you will be sympathetic to my contention that it is misguided, since it embodies exactly the trickery that causes beginners to reject (la)tex as being too arcane. i find it much more defensible to recommend \ for something that doesn't end a sentence, and \@ for something that does. Commented Jul 7, 2011 at 18:53
  • 2
    Yes , I agree with you. \@ and the underlying \spacefactor also confused me as an advanced user. I personally stopped a while ago to use \ie and write i.e.\ instead. It also avoids all the hassle with \xspace and the definition of a new macro. Commented Jul 7, 2011 at 18:59
  • 3
    @barbara: after etc. there should be \ .
    – egreg
    Commented Jul 8, 2011 at 22:29
  • 3
    @Pouya -- the manual is available only in print; it is the original manual LaTeX: A Document Preparation System, User's Guide and Reference Manual, by Leslie Lamport, 2nd edition, Addison-Wesley, 1994. if you're a tug member, a discount is available through the tug bookstore. Commented Jun 9, 2014 at 14:22
  • 4
    Animations of the different styles by Joachim Breitner: joachim-breitner.de/blog/731-e_g__in_TeX Commented Oct 13, 2017 at 13:51
38

The macro simply says

\spacefactor 1000

Under \nonfrenchspacing, capital letters set the space factor to 999 and, by rule, the space factor never jumps from a value less than 1000 to a value greater than 1000. On the other hand, a comma sets the space factor to 1250, the period to 3000 and so on for other punctuation signs.

So with JS,, the space factor after the comma is 1000

J (999) S (999) , (1250->1000)

while with JS,\@ one has

J (999) S (999) , (1250->1000) \@ (1000)

and with JS\@, we get

J (999) S (999) \@ (1000) , (1250)

so that the right syntax is the latter.

Let's consider e.g.,, e.g.\@ and e.g\@.:

e (1000) . (3000) g (1000) . (3000) , (1250)
e (1000) . (3000) g (1000) . (3000) \@ (1000)
e (1000) . (3000) g (1000) \@ (1000) . (3000)

so the right syntax is the middle one. However, a comma just after the second period would make \@ unnecessary.

You should type your phrase as

Languages like JS\@, HTML\@, etc.\@ were not used by King Henry III\@.

otherwise the space after the commas would not expand (factor 1.25) and the space after etc. would (factor 3000), which is not desired.

The simplest thing is to go \frenchspacing and forget about this.

3
  • So the code in my answer is fine? (Besides the use of \xspace, which you don't like if I remember correctly) Commented Jul 7, 2011 at 18:33
  • 5
    @Martin Yes, e.g.\@\xspace is correct, barring \xspace, of course. :-)
    – egreg
    Commented Jul 7, 2011 at 19:17
  • 2
    The last example with JS, HTML, etc., and Henry III absolutely convinced me to use \frenchspacing from now on. Thanks and [+1] !!!
    – user4929
    Commented Apr 9, 2020 at 22:45
33

For novices, a simple mnemonic rule is: \@ is an invisible (zero-width) lowercase letter.

LaTeX considers a sequence <lowercase letter> <punctuation sign> <space> as end of a phrase and adds extra space for readability: in That's all. Thanks, LaTeX adds more space after all.. Otherwise it doesn't add extra space after the punctuation sign: in A. Einstein, the period does not end a sentence because the preceding letter is uppercase; in pi = 3.14, the period does not end a sentence because the next character is not a space.

However, this rule sometimes fails:

(1) Apple Inc. sells phones

here, LaTeX thinks the period ends a sentence and wrongly adds an extra space.

(2) My school scores were all A. Einstein would be proud of me!

here, LaTeX does not realize that the period ends a sentence and does not add the expected space.

You can correct this using an invisible lowercase letter \@:

(1) Apple Inc.\@ sells phones 

here, the period does not end a sentence because it is no longer followed by a space.

(2) My school scores were all A\@. Einstein would be proud of me!

here, the period does end a sentence because it is preceded by the "lowercase letter" \@.

This applies not only to a period but to commas, etc.: Score a, score b, score c. is OK, but with uppercase the correct use is Score A\@, score B\@, score C\@. for LaTeX to realize that each comma ends a phrase (since it goes after a lowercase "letter" \@).

(This simplistic mnemonic explanation is not exactly technically correct: see technical details in other answers.) To summarize: \@. ends a sentence and results in a small extra space after the period, whereas .\@ does not end a sentence and is used to prevent this extra space after the period.

3
  • 3
    Good metaphor! But I would like to memorize \@ slightly different—as "a zero-width lowercase letter". :-)
    – Eli4ph
    Commented Oct 13, 2020 at 7:40
  • 1
    Classic TeX does not define \@; this is exclusive to LaTeX. While it is true that a lowercase letter does have the effect you describe, it is inaccurate to say that \@ will have this effect with TeX alone -- instead, the result will be "Undefined control sequence." Please change this to LaTeX. Commented Oct 14, 2020 at 0:52
  • This mnemonic is absolutely enlightening! I can finally make sense of this arcane hack! No need to dive into implementation details and space factors and what-not.
    – Maëlan
    Commented May 10, 2022 at 21:26
15

This is an old question and this is not so much an answer, but an overly long comment.

The \@ before the commas (as is shown in egreg's excellent answer) is not redundant. TeX's treatment of \spacefactor is straight-forward, but obscure.

The TeXbook and TeX by Topic have all the details—and most of this is taken from TeX by Topic—but essentially the following happens. When TeX inserts a space between words, the amount of space inserted depends on several factors. The key factors are the current font parameters 2, 3, 4, and 7, along with \spaceskip, \xspaceskip, and \spacefactor. \spaceskip and \xspaceskip are used to override the font parameters. As they're rarely used, let's ignore them here.

Normally, when a space is inserted, it has a natural width (font parameter 2), a stretch component (font parameter 3) and a shrink component (font parameter 4). The \spacefactor modifies this: The stretch component is multiplied by \spacefactor/1000 whereas the shrink component is divided by \spacefactor/1000.

When \spacefactor is at least 2000, then TeX increases the natural width of the space by font parameter 7. This is done to have wider spaces between sentences.

Each character added to the a line has an associated space factor code, \sfcode. The \spacefactor is set after each character as follows. Let n be the \sfcode for the character.

  • If the n = 0, \spacefactor is unchanged. (This enables punctuation like parentheses and brackets to not affect the \spacefactor.)
  • If n > 1000 and \spacefactor < 1000, then the \spacefactor is set to 1000. (This slightly confusing behavior enables D. Knuth to use a normal space.)
  • Otherwise, \spacefactor is set to n.

Finally, the \spacefactor is set to 1000 at the beginning of paragraphs (including after \indent or \noindent), as well as after \vrule, an accent, or a box in horizontal mode.

So, with that in mind, let's consider some consequences of this using Computer Modern 10pt roman fonts.

  1. Spaces have an unmodified (by \spacefactor) glue of "3.33333pt plus 1.66666pt minus 1.11111pt" which is to say their natural width is 3.33333pt but can stretch by an additional 1.66666pt (without penalty) and shrink by 1.11111pt.
  2. Spaces following lower case letters (which have \sfcode 1000) have exactly the glue listed above.
  3. Spaces following upper case letters (which have \sfcode 999) have glue 3.33333pt plus 1.66498pt minus 1.11221pt. This is imperceptibly different from spaces following lower case letters.
  4. Spaces following commas (which have \sfcode 1250) which themselves follow a lower case letter (e.g., the space in foo, bar) have glue 3.33333pt plus 2.08331pt minus 0.88889pt.
  5. Spaces following periods (which have \sfcode 3000) which themselves follow a lower case letter (e.g., the space in foo. bar) have glue 4.44444pt plus 4.99997pt minus 0.37036pt. Note that the natural width has been augmented by font parameter 7 because \sfcode >= 2000.
  6. Spaces following periods (or commas) which themselves follow an upper case letter have the same glue as in 1.

Let's now consider the three short paragraphs in the following LaTeX document.

\documentclass{article}
\tracingoutput=1
\showboxbreadth=1000
\showboxdepth=1000

\begin{document}
Languages like JS, HTML, etc. were not used by King Henry III. Next.

Languages like JS, HTML, etc.\ were not used by King Henry III\@. Next.

Languages like JS\@, HTML\@, etc.\ were not used by King Henry III\@. Next.
\end{document}

Note that I've instructed TeX to write out what each page of output looks like to the log file. This output is pretty verbose, but you can see each box, glue, and character. For example, the first paragraph consists of this.

...\hbox(6.94444+1.94444)x345.0, glue set 16.08281fil
....\hbox(0.0+0.0)x15.0
....\OT1/cmr/m/n/10 L
....\OT1/cmr/m/n/10 a
....\OT1/cmr/m/n/10 n
....\OT1/cmr/m/n/10 g
....\OT1/cmr/m/n/10 u
....\OT1/cmr/m/n/10 a
....\OT1/cmr/m/n/10 g
....\OT1/cmr/m/n/10 e
....\OT1/cmr/m/n/10 s
....\glue 3.33333 plus 1.66666 minus 1.11111
....\OT1/cmr/m/n/10 l
....\OT1/cmr/m/n/10 i
....\OT1/cmr/m/n/10 k
....\kern-0.27779
....\OT1/cmr/m/n/10 e
....\glue 3.33333 plus 1.66666 minus 1.11111
....\OT1/cmr/m/n/10 J
....\OT1/cmr/m/n/10 S
....\OT1/cmr/m/n/10 ,
....\glue 3.33333 plus 1.66666 minus 1.11111
....\OT1/cmr/m/n/10 H
....\OT1/cmr/m/n/10 T
....\OT1/cmr/m/n/10 M
....\OT1/cmr/m/n/10 L
....\OT1/cmr/m/n/10 ,
....\glue 3.33333 plus 1.66666 minus 1.11111
....\OT1/cmr/m/n/10 e
....\OT1/cmr/m/n/10 t
....\OT1/cmr/m/n/10 c
....\OT1/cmr/m/n/10 .
....\glue 4.44444 plus 4.99997 minus 0.37036
....\OT1/cmr/m/n/10 w
....\kern-0.27779
....\OT1/cmr/m/n/10 e
....\OT1/cmr/m/n/10 r
....\OT1/cmr/m/n/10 e
....\glue 3.33333 plus 1.66666 minus 1.11111
....\OT1/cmr/m/n/10 n
....\OT1/cmr/m/n/10 o
....\OT1/cmr/m/n/10 t
....\glue 3.33333 plus 1.66666 minus 1.11111
....\OT1/cmr/m/n/10 u
....\OT1/cmr/m/n/10 s
....\OT1/cmr/m/n/10 e
....\OT1/cmr/m/n/10 d
....\glue 3.33333 plus 1.66666 minus 1.11111
....\OT1/cmr/m/n/10 b
....\kern-0.27779
....\OT1/cmr/m/n/10 y
....\glue 3.33333 plus 1.66666 minus 1.11111
....\OT1/cmr/m/n/10 K
....\OT1/cmr/m/n/10 i
....\OT1/cmr/m/n/10 n
....\OT1/cmr/m/n/10 g
....\glue 3.33333 plus 1.66666 minus 1.11111
....\OT1/cmr/m/n/10 H
....\OT1/cmr/m/n/10 e
....\OT1/cmr/m/n/10 n
....\OT1/cmr/m/n/10 r
....\OT1/cmr/m/n/10 y
....\glue 3.33333 plus 1.66666 minus 1.11111
....\OT1/cmr/m/n/10 I
....\kern0.27779
....\OT1/cmr/m/n/10 I
....\kern0.27779
....\OT1/cmr/m/n/10 I
....\OT1/cmr/m/n/10 .
....\glue 3.33333 plus 1.66666 minus 1.11111
....\OT1/cmr/m/n/10 N
....\OT1/cmr/m/n/10 e
....\OT1/cmr/m/n/10 x
....\OT1/cmr/m/n/10 t
....\OT1/cmr/m/n/10 .
....\penalty 10000
....\glue(\parfillskip) 0.0 plus 1.0fil
....\glue(\rightskip) 0.0

There's a lot of interesting stuff here which I'm going to skip over to focus on the key points.

  • The glue set after JS, and HTML, are normal spaces: \glue 3.33333 plus 1.66666 minus 1.11111
  • The glue set after etc. is an inter-sentence space: \glue 4.44444 plus 4.99997 minus 0.37036
  • The glue set after III. is a normal space.

This is precisely what we'd expect by following the rules given above.

The minimum one should do to fix these problems is the second paragraph:

  • The glue set after JS, and HTML, are still normal spaces.
  • The glue set after etc.\ is a normal space.
  • The glue set after III\@. is an inter-sentence space.

The correct thing to do is what egreg said and given in the third paragraph:

  • The glue set after JS\@, and HTML\@, are \glue 3.33333 plus 2.08331 minus 0.88889.
  • The glue set after etc.\ is a normal space.
  • The glue set after III\@. is an inter-sentence space.

What does this matter? Imagine you had written Ruby, JS, and HTML\@. instead. We might expect (and would certainly want) the space following Ruby, and the space following JS, to be the same. Unfortunately, following the rules detailed above, this doesn't happen.

...\hbox(6.94444+1.94444)x345.0, glue set 232.08315fil
....\hbox(0.0+0.0)x15.0
....\OT1/cmr/m/n/10 R
....\OT1/cmr/m/n/10 u
....\OT1/cmr/m/n/10 b
....\kern-0.27779
....\OT1/cmr/m/n/10 y
....\kern-0.83334
....\OT1/cmr/m/n/10 ,
....\glue 3.33333 plus 2.08331 minus 0.88889
....\OT1/cmr/m/n/10 H
....\OT1/cmr/m/n/10 T
....\OT1/cmr/m/n/10 M
....\OT1/cmr/m/n/10 L
....\OT1/cmr/m/n/10 ,
....\glue 3.33333 plus 1.66666 minus 1.11111
....\OT1/cmr/m/n/10 a
....\OT1/cmr/m/n/10 n
....\OT1/cmr/m/n/10 d
....\glue 3.33333 plus 1.66666 minus 1.11111
....\OT1/cmr/m/n/10 J
....\OT1/cmr/m/n/10 S
....\OT1/cmr/m/n/10 .
....\penalty 10000
....\glue(\parfillskip) 0.0 plus 1.0fil
....\glue(\rightskip) 0.0

In this format, it's readily apparent that the two spaces after the commas have different stretch and shrink components. Writing, Ruby, JS\@, and HTML\@. has the correct behavior.

egreg writes, "The simplest thing is to go \frenchspacing and forget about this." It's certainly true that that is the simplest thing to do, but unless it's common to typeset all spaces with the same base width in your language/journal/whatever, I recommend not doing that.

3
  • You write about the example "Ruby, JS, and HTML." but the log output you display typesets "Ruby, HTML, and JS." Also, doesn't using "Ruby, JS\@, and ..." force inter-sentence-spacing after "JS," rather than inter-word spacing which is rather what one expects? Sure, the space after "Ruby," and "JS," is the same, but shouldn't it be forced to be both inter-word spacing rather than inter-sentence?
    – ljrk
    Commented Dec 27, 2018 at 16:51
  • You're right about Ruby, HTML, and JS. As for \@, causing an inter-sentence space, no it won't. \@ just sets the \spacefactor to 1000 so that the following comma (which has \sfcode greater than 1000) will set \spacefactor to that value. Without it, \spacefactor will be 999 at the comma and which change to 1000 rather than the corresponding \sfcode.
    – TH.
    Commented Dec 29, 2018 at 4:42
  • 2
    Yep, that's what I figured. So basically you use \@ every after capital letter when it's followed by punctuation but not as part of an abbreviation, i.e. when it could have as well been a lower-case letter. And you use '\ ' or '\@' after the punctuation if you are not at the end of the sentence but end it with some lowercase letter followed by a period.
    – ljrk
    Commented Dec 29, 2018 at 11:41

You must log in to answer this question.

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