[Tex/LaTex] Creating a macro that can selectively format capital letters

capitalizationformattingmacrossmall-caps

For a project my partner and I are working on, our text includes a great number of words in mixed lowercase and smallcaps:

an example

We're currently doing this with a rather clunky macro:

\newcommand{\famword}[5]{%
    #1\textsc{#2}#3\textsc{#4}#5}

This allows us to have two "clusters" of smallcaps within a word like this:

\famword{a}{k}{i}{l}{ulat}

which is just good enough to function without wasting too much of our time. However, since we're inputting a lot of words like this what we'd really like to do is have a macro where we could type the command like this:

\famword{aKiLulat}

and have it automatically convert the capital letters within the command to smallcaps in the document. We've searched for answers on this stack exchange and found a few solutions to adjacent issues, but none that addresses this particular problem.

As an addendum, some of these words contain the "Latin capital letter glottal stop" character Ɂ. Our existing macro deals with this character fine (as far as I can tell it just leaves it unaltered), but just in case any solution exists that would break on this non-ascii character, it won't do.

Does anybody know if this is doable?

Best Answer

When using modern fonts in conjunction with LuaLaTeX or XeLaTeX, one is (sometimes) able to delegate this this to the font, since OpenType Layout defines a font feature c2sc that translates capital letters to small cap letters. Unfortunately, Latin Modern does not contain this feature. When available, one can activate this via fontspec feature Letters=UppercaseSmallCaps. Example:

\documentclass{article}
\usepackage{fontspec}
\setmainfont{Stix Two Text} % Font with c2sc feature and italic SC
\newcommand\famword[1]{{\addfontfeatures{Letters=UppercaseSmallCaps}#1}}

\begin{document}
\famword{aKiLulat}

\itshape \famword{aKiLulat}
\end{document}

enter image description here