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}