10

I'm trying to change \textsc to produce small caps from a different font. The font pajp is used for the main text, but it doesn't have small caps. The font paj contains small caps, but I don't want to use anything else from that font.

The current and edited MWE:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{pdftexcmds}

\renewcommand{\sfdefault}{paj}

\makeatletter
\let\scshape\relax % to avoid a warning
\DeclareRobustCommand\scshape{%
  \not@math@alphabet\scshape\relax
  \ifnum\pdf@strcmp{\f@family}{\familydefault}=\z@
    \fontfamily{paj}%
  \fi
  \fontshape\scdefault\selectfont}
\makeatother

\begin{document}

% This font contains small caps that I want to use
% Shows T1/paj/m/sc is defined
\usefont{T1}{paj}{m}{sc}
\fontsize{14pt}{1em}\selectfont
Lorem ipsum dolor (small caps)

% This font is used for everything else and doesn't contain small caps
% Shows T1/pajp/m/n is defined
% When using this \scshape and \textsc don't work
\usefont{T1}{pajp}{m}{n}
\fontsize{14pt}{1em}\selectfont
Lorem ipsum dolor (regular)\\

% Set the default family
\renewcommand{\familydefault}{pjap}
\fontfamily{\familydefault}\selectfont

% This doesn't work
%\fontfamily{pajp}\selectfont

%This is the standard small caps font:
%{\fontshape\scdefault\selectfont Small Caps}

This is the new one: {\scshape Small Caps}

This is the new one: \textsc{Small Caps}

\sffamily

Let's try \textsc{Small Caps}
\end{document}

The first image is from the MWE as above. It works. The second image is produced if I use commented out \usefont{T1}{pajp}{m}{n} or \fontfamily{pajp}\selectfont to select the regular font. It doesn't have the correct font as the small caps one.

Working Non working

In the latter case the error messages are:

LaTeX Font Warning: Font shape `T1/pajp/m/sc' undefined
(Font)              using `T1/pajp/m/n' instead on input line 41.

LaTeX Font Warning: Font shape `T1/pajp/m/sc' undefined
(Font)              using `T1/pajp/m/n' instead on input line 43.

1 Answer 1

10

The replacement text of \scdefault should be a string good for the fourth argument to \usefont; its default value is sc. Your paj is a family name.

Redefine \scshape:

\makeatletter
\let\scshape\relax % to avoid a warning
\DeclareRobustCommand\scshape{%
  \not@math@alphabet\scshape\relax
  \ifnum\pdf@strcmp{\f@family}{\familydefault}=\z@
    \fontfamily{qbk}%
  \fi
  \fontshape\scdefault\selectfont}
\makeatother

This requires the package pdftexcmds.

With the redefinition \scshape, in a serif font context will be the same as

\usefont{<current encoding>}{paj}{<current weight>}{sc}

Complete code, where some visually clashing fonts are used just by way of example; use your favorite fonts.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{pdftexcmds}

\renewcommand{\sfdefault}{qag} % TeX Gyre Adventor has small caps

\makeatletter
\let\scshape\relax % to avoid a warning
\DeclareRobustCommand\scshape{%
  \not@math@alphabet\scshape\relax
  \ifnum\pdf@strcmp{\f@family}{\familydefault}=\z@
    \fontfamily{qbk}%
  \fi
  \fontshape\scdefault\selectfont}
\makeatother

\begin{document}

This is the standard small caps font: 
{\fontshape\scdefault\selectfont Small Caps}

This is the new one: {\scshape Small Caps}

This is the new one: \textsc{Small Caps}

\sffamily

Let's try \textsc{Small Caps}

\end{document}

enter image description here

For assigning the font used by \section, use sectsty or titlesec (there are several questions on the site dealing with the problem).

8
  • This works if both the regular font (The parts starting with word This) and the other font with new small caps contain small caps. If I change the regular one to a font that doesn't have them then the other font that contains small caps doesn't work.
    – karu
    Jul 26, 2014 at 21:23
  • @karu Of course, if a font family doesn't have small caps, the substitution rules prevail.
    – egreg
    Jul 26, 2014 at 21:26
  • I have two fonts. One without small caps for the bulk of the document and the other that has the small caps I want. How do I make either the substitution rules work or solve the matter otherwise?
    – karu
    Jul 26, 2014 at 21:36
  • 1
    @karu Isn't mine the solution based on the information you gave? Set \familydefault to pajp and in the redefinition of \scshape use paj where I used qbk.
    – egreg
    Jul 26, 2014 at 21:42
  • 1
    @GeorgeG. You have to wrap \DeclareRobustCommand{\scshape}{...} in \AtBeginDocument{...}
    – egreg
    Aug 16, 2021 at 14:53

You must log in to answer this question.

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