# Typeset just the first letter in a group

How can I typeset (print) just the first letter of a group of text?

For instance, how does biblatex or bibtex determine the first initials of a name?

MWE to get started:

\documentclass[]{article}

\begin{document}

This prints \firstinit{just the first letter}.

My hero is \firstinit{John} \firstinit{Paul} Jones.

\end{document}


The routine \justfirst needs its argument not in braces, but terminated by a known quantity. Thus, \firstinit conspires with \justfirst, unbeknownst to the user, to provide it just so, with a \relax as the terminator, because it is unlikely to show up in user text.

\documentclass[]{article}
\def\firstinit#1{\justfirst#1\relax}
\def\justfirst#1#2\relax{#1}

\begin{document}

This prints \firstinit{just the first letter}.

My hero is \firstinit{John} \firstinit{Paul} Jones.

\end{document}


Of course, if you meant for multi-worded phrases to output the first letter of each word, that is slightly more difficult. REVISED to take advantage of recursion; RE-REVISED to eliminate use of packages. RE-RE-REVISED to prevent defeat by a "llama".

\documentclass[]{article}
\def\firstinit#1{\justfirst#1 \relax\relax}
\def\justfirst#1#2 #3\relax{#1\if\relax#3\else{} \justfirst#3\relax\fi}
\begin{document}
This prints \firstinit{just the first llama in the list}.

My hero is \firstinit{John} \firstinit{Paul} Jones.
\end{document}


• Very nice. I was mostly interested in the first case; The edit on the second version is much nicer in the code, and also seems like the spacing is better in typesetting. – cslstr Mar 20 '14 at 2:29
• Being defeated by a llama deserves a second upvote! – Chris H Mar 20 '14 at 10:16
• @ChrisH Well, it was either that, or else implement a [Chilean] package option. – Steven B. Segletes Mar 20 '14 at 10:27