Here is a code based on egreg
's answer, which automatically detects the current font before passing the value to the command.
EDIT:
I corrected the issue with WordSpace
by using \newfontfamily
instead of obsolete package option.
The apostrophe and comma not being rendered properly has been fixed thanks to user94293
's answer.
\documentclass{article}
\usepackage{fontspec}
\setmainfont{Times New Roman}
\newfontfamily\gill{gill Sans MT}
\newfontfamily\hadriano[UprightFont={* Light},BoldFont={* Bold}]{AT Hadriano Std}
\newfontfamily\minion{Minion Pro Capt}
\newfontfamily\stix{STIX Two Math}[AutoFakeBold=2]
\newfontfamily\djvs[BoldFont={* Bold}]{DejaVu Sans}
\newfontfamily\arial{Arial Unicode MS}
\newfontfamily\free{Free Serif}
\newfontfamily\symbola{Symbola}[FakeBold=0.5]
\ExplSyntaxOn
\NewDocumentCommand{\smartsc}{m}
{
\krebs_smartsc:n { #1 }
}
\seq_new:N \l__krebs_smartsc_words_in_seq
\seq_new:N \l__krebs_smartsc_words_out_seq
\cs_new_protected:Nn \krebs_smartsc:n
{
\group_begin:
\newfontfamily{\currentfont}{\csname f@family\endcsname}
\newfontfamily{\currentfontSC}{\csname f@family\endcsname}[Scale=0.72,WordSpace=1.75,FakeBold=1.1]
\currentfontSC
\seq_set_split:Nnn \l__krebs_smartsc_words_in_seq { ~ } { #1 }
\seq_set_map:NNn \l__krebs_smartsc_words_out_seq \l__krebs_smartsc_words_in_seq
{
\__krebs_smartsc:n { ##1 }
}
\seq_use:Nn \l__krebs_smartsc_words_out_seq { ~ }
\group_end:
}
\cs_new_protected:Nn \__krebs_smartsc:n
{
\text_map_inline:nn { #1 } { \__krebs_smartsc_letter:n { ##1 } }
}
\cs_new_protected:Nn \__krebs_smartsc_letter:n
{
\int_compare:nTF { \char_value_lccode:n { `#1 } = `#1 }
{
\char_uppercase:N #1
}
{
{\currentfont #1}
}
}
\ExplSyntaxOff
\begin{document}
\noindent
\smartsc{Small Caps are Nice, Aren't They?} (Times fake)
\textsc{Small Caps are Nice, Aren't They?} (Times real)
\gill\smartsc{Small Caps are Nice, Aren't They?} (Gill fake)
\textsc{Small Caps are Nice, Aren't They?} (Gill real - No support)
\hadriano\smartsc{Small Caps are Nice, Aren't They?} (Hadriano fake)
\textsc{Small Caps are Nice, Aren't They?} (Hadriano real - No support)
\minion\smartsc{Small Caps are Nice, Aren't They?} (Minion Pro Capt fake)
\textsc{Small Caps are Nice, Aren't They?} (Minion Pro Capt real)
\stix\smartsc{Small Caps are Nice, Aren't They?} (Stix Two Math fake)
\textsc{Small Caps are Nice, Aren't They?} (Stix Two Math real - No support)
\djvs\smartsc{Small Caps are Nice, Aren't They?} (DejaVu Sans fake)
\textsc{Small Caps are Nice, Aren't They?} (DejaVu Sans real - No support)
\arial\smartsc{Small Caps are Nice, Aren't They?} (Arial fake)
\textsc{Small Caps are Nice, Aren't They?} (Arial real - No support)
\free\smartsc{Small Caps are Nice, Aren't They?} (Free Serif fake)
\textsc{Small Caps are Nice, Aren't They?} (Free Serif real)
\symbola\smartsc{Small Caps are Nice, Aren't They?} (Symbola fake)
\textsc{Small Caps are Nice, Aren't They?} (Symbola real - No support)
\end{document}
