9

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}%
}
0

1 Answer 1

9

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

9
  • It's not always easy to interpret the result of that test, eg \bfseries \scshape \testsc typesets bold Aa but says yes. Commented Dec 18, 2014 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. Commented Dec 18, 2014 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:-) Commented Dec 18, 2014 at 13:53
  • @DavidCarlisle: But I love such digging ... Commented Dec 18, 2014 at 15:15
  • don't we all:-) Commented Dec 18, 2014 at 15:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .