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:

\usepackage{xifthen}
...
\ifthenelse{<small caps are available with the current font>}{%
  \textsc{my text}%
}{%
  \uppercase{my text}%
}
up vote 8 down vote accepted

Edit

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:

\documentclass[11pt,a4paper]{scrartcl}
\makeatletter
\def\define@newfont{%
  \begingroup
    \let\typeout\@font@info
    \escapechar\m@ne
    \expandafter\expandafter\expandafter
       \split@name\expandafter\string\font@name\@nil
      \try@load@fontshape % try always
    \expandafter\ifx
       \csname\curr@fontshape\endcsname \relax
       \expandafter\gdef\csname \curr@fontshape/sub\endcsname{}% new      
      \wrong@fontshape\else
      \extract@font\fi
  \endgroup}

\newcommand\testsc{%
 \ifcsname \f@encoding/\f@family/\f@series/sc/sub\endcsname
  no
 \else 
  \ifcsname \f@encoding/\f@family/\f@series/sc\endcsname  yes \else no \fi
 \fi   
 \textsc{Aa}}
\makeatother
\begin{document}
\testsc

\bfseries \testsc 

\scshape \testsc

\end{document}

Edit 2

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

\usepackage{etoolbox}
\makeatletter
\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 acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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