Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

This question already has an answer here:

So I'm trying to come up with some good, general definitions for latin abbreviations in my TeX template...

What I did up to now is this:

\usepackage{xspace}
\newcommand{\etc}{etc.\xspace}

..which works fine for spacing, but does not solve the problem of "blah etc.." at the end of a sentence when I use the macro like blah \etc.. So I had a look around and found the nice solution in this answer here, which I slightly modified to:

\usepackage{expl3}
\ExplSyntaxOn
\newcommand{\appendFullStop}[1]{
  \peek_meaning:NTF . {% Same as \@ifnextchar
    #1\@}%
  { \peek_catcode:NTF a {% Check whether next char has same catcode as \'a, i.e., is a letter
      #1.\@ }%
    {#1.\@}}}
\ExplSyntaxOff
% Omit final dot from each definition, it is added automatically when needed!
\newcommand{\etc}{\appendFullStop{etc}}

Now, this works fine for punctuation, meaning that ..blah \etc. is actually compiled to "..blah etc." and not "etc..". BUT I now again have the spacing problem...

So I thought to solve this by merging the two approaches. But changing the last line in the above snippet to

\newcommand{\etc}{\appendFullStop{etc}\xspace}

breaks the punctuation thing again...

I am lost on this, any help would be really appreciated!


Example of the second code snippet not handling spacing:

\documentclass{article}
%\usepackage{xspace}

% Define a macro to look ahead one character and append a full-stop
\usepackage{expl3}
\ExplSyntaxOn
\newcommand{\appendFullStop}[1]{
  \peek_meaning:NTF . {% Same as \@ifnextchar
    #1\@}%
  { \peek_catcode:NTF a {% Check whether next char has same catcode as \'a, i.e., is a letter
      #1.\@ }%
    {#1.\@}}}
\ExplSyntaxOff
% Define the style for latin abbreviations
% Omit final dot from each definition, it is added automatically when needed!
\newcommand{\etc}{\appendFullStop{etc}}

\begin{document}
Test \etc in the middle. \\
After comma \etc, we test as well. \\
Finally at the end of a sentence \etc. \\
\end{document}
share|improve this question
    
The code is meant to handle the spacing problem, through the "\@" it inserts: it treats "\etc. And" differently to "\etc and", because the "\@. " it inserts makes the space after the "." wider, in this sentence ending case, while the other occurrences of "\@" narrow the following space. Could you post an example where this isn't working correctly? –  Charles Stewart Feb 14 '13 at 10:07
    
See above. I'm talking about the first of the three test sentences. –  fgysin Feb 14 '13 at 12:31
add comment

marked as duplicate by mafp, Kurt, Paul Gaborit, lockstep, Speravir Feb 19 '13 at 1:36

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2 Answers

The following change to the macro seems to fix the problem (I added some text to your example to show off end-of-sentence punctuation):

\documentclass{article}
%\usepackage{xspace}

% Define a macro to look ahead one character and append a full-stop
\usepackage{expl3}
\ExplSyntaxOn
\newcommand{\appendFullStop}[1]{
  \peek_meaning:NTF . {% Same as \@ifnextchar
    #1\@}%
  { \peek_catcode:NTF a {% Check whether next char has same catcode as \'a, i.e., is a letter
      #1.\@\ }%
    {#1.\@}}}
\ExplSyntaxOff
% Define the style for latin abbreviations
% Omit final dot from each definition, it is added automatically when needed!
\newcommand{\etc}{\appendFullStop{etc}}

\begin{document}
Test \etc in the middle. \\
After comma \etc, we test as well. \\
Finally at the end of a sentence \etc. Two. Three. \\
\end{document}

The space following the second case (for the abbreviation being followed by a letter) was being gobbled, which does not happen with \ - I think this is an expl3 syntax thing, since spaces are usually not signifianct then; I'm surprised I did not notice this before when I tested it.

This is very much a hack. For instance, it does not handle sentence-ending punctuation other than . correctly. Until someone implements The Right Thing, beware when using this sort of macro. Also, it seems overkill to load the expl3 macros for such a tiny thing as testing catcodes, but no doubt this will seem quite natural a few years from now.

Name of macro: I prefer \latinabbrev, since it gestures at the particular functionality we want; the name alone suggests the quite different \def\appendFullStop#1{#1\@.} is good implementation.

share|improve this answer
    
Such a tiny detail. Thanks. :) –  fgysin Feb 14 '13 at 13:15
    
Concerning the macro name: guess you are right, I just used 'latinabbrev' to also include some styling (I like using \emph{...} or \textsl{...} for latin abbreviations). :) –  fgysin Feb 14 '13 at 13:17
add comment

Ok, in a attempt to find the solution, here a combination. I decided to use the \xspace package to avoid manually dealing with the whole spacing thing - in my experience \xspace is actually pretty good at that...

Version 1

Suppresses the period at the end of a sentence if the next character is a ..

\usepackage{expl3}
\usepackage{xspace}
\ExplSyntaxOn
\newcommand{\latinabbrev}[1]{
  \peek_meaning:NTF .
  {#1\xspace}
  {
    #1.\xspace
  }
}
\ExplSyntaxOff
\newcommand{\etc}{\latinabbrev{etc}}

Version 2

Supresses the period if the next character is a ., ! or ?. I am not sure if this is typographically sound, at least I have no sources that go either way. If you're interested in a discussion, I posted a question on english.stackexchange here.

\usepackage{expl3}
\usepackage{xspace}
\ExplSyntaxOn
\newcommand{\latinabbrev}[1]{
  \peek_meaning:NTF .
  {#1\xspace}
  {
    \peek_meaning:NTF !
    {#1\xspace}
    { 
      \peek_meaning:NTF ?
      {#1\xspace}
      { 
        #1.\xspace
      }
    }
  }
}
\ExplSyntaxOff
\newcommand{\etc}{\latinabbrev{etc}}

If you have any suggestions, please join the discussion...

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.