5

This is a follow-up to Use \fauxsc if small caps not avaiaible

I need to use the Chivo font but, for unknown reasons, when package microtype is used, only the first invocation of \textsc works as expected.

Besides, is there a way to extend the \fauxsc macro so that it can accommodate math?

Here is a MWE:

\documentclass{article}

\usepackage{graphicx} \usepackage[familydefault]{Chivo} \usepackage{microtype}

\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 }

\makeatletter \newlength\fake@f \newlength\fake@c \def\fakesc#1{% \begingroup \xdef\fake@name{\csname\curr@fontshape/\f@size\endcsname}% \fontsize{\fontdimen8\fake@name}{\baselineskip}\selectfont \MakeUppercase{#1}% \endgroup } \makeatother \newcommand\fauxsc[1]{\fauxschelper#1 \relax\relax} \def\fauxschelper#1 #2\relax{% \fauxschelphelp#1\relax\relax \if\relax#2\relax\else\ \fauxschelper#2\relax\fi } \def\Hscale{.83}\def\Vscale{.72}\def\Cscale{1.00} \def\fauxschelphelp#1#2\relax{% \ifnum#1&gt;``\ifnum#1<`{\scalebox{\Hscale}[\Vscale]{\uppercase{#1}}\else \scalebox{\Cscale}[1]{#1}\fi\else\scalebox{\Cscale}[1]{#1}\fi \ifx\relax#2\relax\else\fauxschelphelp#2\relax\fi}

\begin{document}

With \verb+\testsc+

\textsc{Abc def}

\textsc{Ghi jkl} % Incorrect output when package microtype is used

\bigskip

\verb+\fauxsc+

\fauxsc{Abc def}

\fauxsc{Ghi jkl}

\bigskip

% \textsc{Case $x$ is odd} % Math (in this case, $x$) produces an error

\end{document}

enter image description here

user94293
  • 4,254

1 Answers1

2

First of all, I agree with @egreg's comment that the faux small caps are far from pretty and I wouldn't recommend using them at all. That said, here's what happens and how to fix it:

The problem is a side effect of pdflatex's font expansion, which makes fonts unequal (in terms of \ifx). I've reported this here a year ago, but it's unclear whether anything will be done about it, or whether it should even be considered a bug.

There is a simple solution, however, which Hans proposed in the above mentioned thread, and that is to compare \fontname\font instead of \the\font, so:

\DeclareRobustCommand{\textsc}[1]{%
  \sbox0{x\xdef\testA{\fontname\font}}%
  \sbox0{\scshape x\xdef\testB{\fontname\font}}%
  \ifx\testA\testB\fauxsc{#1}\else{\scshape #1}\fi
}

should yield the correct (albeit ugly) faux small caps.

Robert
  • 14,181
  • 1
  • 52
  • 77