This question based on this answer.
Found letter missing when it occurs next to dash, as per the below MWE:
\documentclass{article}
\usepackage{readarray}
\usepackage{ifthen}
\newcounter{index}\setcounter{index}{0}
\def\firstletters#1{%
\getargsC{#1}%
\whiledo{\theindex<\narg}{%
\stepcounter{index}%
\edef\nextword{\csname arg\romannumeral\theindex\endcsname}%
\expandafter\getfirst\nextword\relax%
}%
}
\def\getfirst#1#2\relax{#1}
\begin{document}
\firstletters{This is a test of the Emergency Broadcast System. This-Test. for sample. This T.}
\end{document}
Best Answer
The
datatool
package provides\DTLinitials
. For example:This automatically inserts a period after each initial, but that can be prevented by redefining
\DTLafterinitials
,\DTLbetweeninitials
and\DTLafterinitialbeforehyphen
to do nothing.If you need the initials in an expandable context, you first need to use
\DTLstoreinitials
, which will save the initials in the command provided in the second argument:Edit: if you also want to remove the hyphen from the initials, just redefine
\DTLinitialhyphen
to do nothing as well:Edit2: Note that
\DTLinitials
is designed primarily for names (its original purpose was for use with the abbreviated bibliography style provided bydatabib
) so it assumes its argument is a series of letters separated by spaces or hyphens. Additionally from the manual:So, as per your comment below:
Or use XeLaTeX or LuaLaTeX with UTF-8 characters. This is similar to the limitations on
\makefirstuc
(frommfirstuc
)Also from the
datatool
manual:This means that, say
will produce m.a. not M.a.