# [pdftex] Getting the correct word spacing after Macros.

The Thanh Han hanthethanh at fptnet.com
Wed Jun 12 00:31:36 CEST 2002

On Tue, Jun 11, 2002 at 09:27:05AM +0000, Michael Chapman wrote:
>
> Apologies in advance, this is more Latex than pdfLatex, but I have difficulty
> finding keywords to search the archives for what must(?) be a trivial
> question.
>
> I have a document with several dozen complicated words/phrases. To
> trivialise, if I were to set:
>
> \newcommand{\USA}{United States of America}
>
> is there an easy way of making the command so a space is (automatically)
> inserted if the next character is a letter or number, but no space is
> inserted if the next character is punctuation.
> (E.gg. 	It happened in United States of America.
> 	In the United States of America it is common for people ....)
>
> Have thought of a regular expression search of the file and/or trying to get
> into if/then programming of Latex, but I feel I must be re-inventing the
> wheel ... !

I use the following macro for abbreviations:

\def\<#1>{%
\expandafter\ifx\csname<#1>\endcsname\relax
\errmessage{abbreviation <#1> undefined!}
\else
\csname<#1>\endcsname
\fi
}
\def\abbr#1#2{%
\expandafter\def\csname<#1>\endcsname{#2}%
}

\abbr{THANH}{H\an Th\^e\llap{\raise 0.5ex\hbox{\'{}}} Th\anh}
\abbr{HZ}{\textit{hz}}
\abbr{KF}{\textit{kf\kern-.05em}}
\abbr{KR}{\textit{K$\varrho$}}
\abbr{EK}{\textit{{\Large$\varepsilon$\kern-.1em}k}}
\abbr{JP}{\textit{jp}}
\abbr{MF}{\MF}
\abbr{CMR}{CMR}
\abbr{CMSS}{CMSS}
\abbr{MM}{Multiple Master}
\abbr{T1}{Type\nobreak\,1}
\abbr{PFB}{PFB}
\abbr{CM}{Computer Modern}
\abbr{TEX}{\TeX}
\abbr{LATEX}{\LaTeX}
\abbr{PDFTEX}{pdf\TeX}
\abbr{URW}{URW}
\abbr{ASCII}{ASCII}
\abbr{DTP}{DTP}
\abbr{DVI}{DVI}
\abbr{PS}{PS}
\abbr{TFM}{TFM}
\abbr{PDF}{PDF}
\abbr{HJ}{H\kern.1em\&\kern.1emJ}
\abbr{UNIX}{UNIX}
\abbr{AMIGA}{Amiga}
\abbr{DOS}{DOS}
\abbr{MAC}{Macintosh}
\abbr{C}{C}
\abbr{TRUETYPE}{TrueType}
\abbr{WIN32}{Win32}
\abbr{FPTEX}{fp\TeX}
\abbr{TETEX}{te\TeX}
\abbr{MIKTEX}{Mik\TeX}
\abbr{CMACTEX}{CMac\TeX}
\abbr{AFM}{AFM}
\abbr{MMTOOLS}{MMTOOLS}
\abbr{VNR}{VNR}
\abbr{CS}{CS}
\abbr{HTML}{HTML}
\abbr{WWW}{WWW}
\abbr{ID}{InDesign}
\abbr{3B2}{3B2}
\abbr{...}{\dots}
\abbr{OMEGA}{$\Omega$}
\abbr{ETEX}{$\varepsilon$-\TeX}
\abbr{NTS}{NTS}
\abbr{LF}{\textrm{\it letter\!\_\kern.1emfit}}
\abbr{SGML}{SGML}
\abbr{XML}{XML}
\abbr{NTG}{NTG}
\abbr{DANTE}{DANTE}
\abbr{GUST}{GUST}
\abbr{GUT}{GUTenberg}
\abbr{TUG}{TUG}
\abbr{BS}{\char92}
\abbr{TFTOPL}{TFtoPL}
\abbr{PDFETEX}{pdf\<ETEX>}
\abbr{ZLIB}{ZLIB}
\abbr{LIBPNG}{LIBPNG}
\abbr{LIBTIFF}{LIBTIFF}
\abbr{XPDF}{XPDF}
\abbr{MIRKA}{Miroslava Mis\'akov\'a}
\abbr{PERL}{Perl}
\abbr{MMINSTANCE}{MMInstance}
\abbr{PERL}{Perl}
\abbr{LINUX}{Linux}
\abbr{PASCAL}{Pascal}

and write ie \<TEX> instead of \TeX\ or \TeX{}. I also have some macro for the
editor I use (vim) so I don't have to write '\<TEX>' but only 'tex' and some
shortcurt to turn it to \<TEX> (in my case <C-X><C-K>). This is much faster than any
of sequences '\<TEX>', '\TeX\ ' or '\TeX{}'. Addding a new abbreviation is
as trivial as

\abbr{USA}{United States of America}

HTH,
Thanh