3

I sometimes use a font without small caps, but want them. Hence I employ the following trick

% have \textsc use \fauxsc if \scshape not avalible
\let\textsc\relax
\DeclareRobustCommand{\textsc}[1]{%
  \sbox0{x\xdef\testA{\the\font}}%
  \sbox0{\scshape x\xdef\testB{\the\font}}%
  \ifx\testA\testB\fauxsc{#1}\else{\scshape #1}\fi
}

This words great! It just produces a warning every time it runs :(

I can't use silence because of the silense+hyperref package incompatability

MWE (fauxsc replaced by textbf)

\documentclass{article}

\usepackage{plex-serif}

% have \textsc use \fauxsc if \scshape not avalible
\let\textsc\relax
\DeclareRobustCommand{\textsc}[1]{%
  \sbox0{x\xdef\testA{\the\font}}%
  \sbox0{\scshape x\xdef\testB{\the\font}}%
  \ifx\testA\testB\textbf{#1}\else{\scshape #1}\fi
}

\begin{document}

Please \textsc{help} me

\end{document}
3
\documentclass{article}

\usepackage{plex-serif}

\makeatletter
\DeclareRobustCommand{\textsc}[1]{%
  \ifcsname \f@encoding/\f@family/\f@series/sc\endcsname
     {\scshape #1}%
  \else
    \textbf{#1}%
  \fi
}
\makeatother
\begin{document}
Please \textsc{help} me

\end{document}
  • Can you explain what the test is doing? – Raoul Kessels Oct 2 '19 at 10:36
  • 2
    @RaoulKessels When the .fd file is read, LaTeX defines control sequences for font selection; for instance, with the standard setup, the normal font set corresponds to \OT1/cmr/m/n and there are also control sequences for font sizes. – egreg Oct 2 '19 at 12:59
  • @egreg Ok. So the three macros are expanded and if the small caps have been defined in the current font, because the last item is forced to be /sc, it returns true – Raoul Kessels Oct 2 '19 at 13:11
  • @RaoulKessels Yes, that's it. – egreg Oct 2 '19 at 13:17
  • @egreg Thank you very much! – Raoul Kessels Oct 2 '19 at 13:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.