Creating a macro that can selectively format capital letters
The tokcycle
package (https://www.ctan.org/pkg/tokcycle) can be used for this.
\documentclass{article}
\usepackage{tokcycle}
\newcommand\famword[1]{%
\resettokcycle%
\Characterdirective{\ifcat A##1\ifnum`##1<`Z\addcytoks{%
\textsc{\char\numexpr32+`##1\relax}}\else
\addcytoks{##1}\fi\else\addcytoks{##1}\fi}%
\tokcyclexpress{#1}%
\the\cytoks%
}
\begin{document}
\famword{aKiLulat or even aK\textit{iLulat}!}
\end{document}
As I commented, to get italic small caps, you need a font that supports it, such as \usepackage{newtxtext}
:
If one prefers an invocation that is more environment-based, rather than macro-based, there is this:
\documentclass{article}
\usepackage{tokcycle}
\tokcycleenvironment\famword%
{\ifcat A##1\ifnum`##1<`Z\addcytoks{%
\textsc{\char\numexpr32+`##1\relax}}\else
\addcytoks{##1}\fi\else\addcytoks{##1}\fi}% <-CHARACTERS
{\processtoks{##1}}% <-GROUPS
{\addcytoks{##1}}% <-MACROS
{\addcytoks{##1}}% <-SPACES
\begin{document}
\famword aKiLulat or even aK\textit{iLulat}!\endfamword
\end{document}
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}
Here's a LuaLaTeX-based solution. It consists of (a) a main Lua function called uc2sc
(short for "uppercase to smallcaps", I suppose) and an auxiliary Lua function called makesc
which, together, do most of the work and (b) a LaTeX macro called \famword
that acts as a wrapper for the uc2sc
function. The Lua functions employ Lua's versatile built-in string.gsub
and string.lower
functions.
% !TEX TS-program = lualatex
\documentclass{article}
\usepackage{luacode} % for "luacode" environment
\begin{luacode}
function makesc ( x )
return ( "\\textsc{" .. x:lower() .. "}" )
end
function uc2sc ( s )
return ( s:gsub ( "%u", makesc ) )
end
\end{luacode}
%% LaTeX wrapper macro:
\newcommand\famword[1]{\directlua{tex.sprint(uc2sc("#1"))}}
\usepackage{fontspec}
\setmainfont{Stix Two Text} % a font with italic-smallcap letters
\begin{document}
\famword{aKiLulat}
\itshape \famword{aKiLulat}
\end{document}