[Tex/LaTex] Uppercase Smallcaps with LaTeX (not XeLaTeX)

fontspdftexsmall-caps

In XeLaTeX there is an UppercaseSmallCaps font option (as mentioned in this question for example) that will cause upper-case letters to be rendered in small-caps and lower-case letters to remain.

Question: How can UppercaseSmallCaps be implemented in plain LaTeX (or pdfLaTeX) so that text like \upsc{ABCdef} will be rendered as \textsc{abc}def?

Best Answer

\documentclass[convert,border=1]{standalone}

\makeatletter
\newif\ifsc@active
\newif\ifnf@active
\def\upsc#1{{\sc@activefalse\nf@activetrue\@upsc#1\@nil}}
\def\@upsc#1{\ifx#1\@nil\else\@@upsc{#1}\expandafter\@upsc\fi}
\def\@@upsc#1{%
  \ifnum\uccode`#1=`#1\relax
     \ifsc@active\else\sc@activetrue\nf@activefalse\scshape\fi
     \expandafter\@firstoftwo
   \else
     \ifsc@active\sc@activefalse\fi
     \ifnf@active\else\nf@activetrue\normalfont\fi
     \expandafter\@secondoftwo
   \fi
     {\lowercase{#1}}%
     {#1}}
\makeatother

\begin{document}
\upsc{xABCdovff}
\end{document}

Doesn't work with accented letters, of course.

enter image description here

Related Question