Is it possible to test, in the document body, whether small caps are available with the current font (both for pdf(la)tex and xe(la)tex)? What I'd like to do is something like:

\ifthenelse{<small caps are available with the current font>}{%
  \textsc{my text}%
  \uppercase{my text}%


OK as David pointed out in the comment, simply looking at \f@encoding/\f@family/\f@series/sc is not enough as this command is defined during a substitution. So one probably has to record if a substitution takes place:

      \try@load@fontshape % try always
       \csname\curr@fontshape\endcsname \relax
       \expandafter\gdef\csname \curr@fontshape/sub\endcsname{}% new      

 \ifcsname \f@encoding/\f@family/\f@series/sc/sub\endcsname
  \ifcsname \f@encoding/\f@family/\f@series/sc\endcsname  yes \else no \fi

\bfseries \testsc 

\scshape \testsc


Edit 2

Instead of patching \define@newfont one could also patch \wrong@fontshape:

\preto\wrong@fontshape{\expandafter\gdef\csname \curr@fontshape/sub\endcsname{}}

enter image description here

  • It's not always easy to interpret the result of that test, eg \bfseries \scshape \testsc typesets bold Aa but says yes. – David Carlisle Dec 18 '14 at 13:26
  • @DavidCarlisle: You are right, I hadn't realized that the substituation defines the macro. But your test has the same problem: If one adds \bfseries\scshape before the test one gets yes twice. – Ulrike Fischer Dec 18 '14 at 13:39
  • oops:-) I was originally going to do something like this answer then decided it's not really the right test, but as you say mine isn't much better, I think I may delete and come back to it later, the real test is to look in the nfss tables for a substitution rule I suppose but I was trying to avoid that:-) – David Carlisle Dec 18 '14 at 13:53
  • @DavidCarlisle: But I love such digging ... – Ulrike Fischer Dec 18 '14 at 15:15
  • don't we all:-) – David Carlisle Dec 18 '14 at 15:16

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.