[Tex/LaTex] general method for obtaining small caps with custom fonts

font-encodingsfontssmall-caps

MWE:

\documentclass[a4paper,12pt,twoside]{memoir}
\usepackage{DejaVuSerifCondensed}
\usepackage[T1]{fontenc}
\begin{document}
\noindent\scshape{Hello World}\\
\textsc{Hello World}
\end{document}

Explanation and question:

As you can see, I am working with a memoir document class and I've load a font DejaVuSerifCondensed, I am trying to obtain small caps for my header (which I did not place in the MWE as unnecessary). However I can't obtain the desire effect with the \scshape command nor with the \textsc{}.

I've seen other questions like

But either they do not adapt to my problem (for what I can see) or they do not solve the problem (following the instructions there and "inserting" the piece of code in mine).

Question here is: is there a general method (piece of code or something) to obtain small caps from a custom font (even if that is one I upload with a ttf)?, if not, what would be the piece of code to select the standard small caps font?

Best Answer

In order to get small caps from a font through the standard commands such as \textsc, the font you have loaded needs to have small caps. The font you've chosen, DejaVu Serif Condensed, doesn't. When you compile your MWE, you will as a result get a font warning from LaTeX that no small caps exist for this font, and that it will use the normal font instead:

LaTeX Font Warning: Font shape `T1/DejaVuSerifCondensed-TLF/m/sc' undefined
(Font)              using `T1/DejaVuSerifCondensed-TLF/m/n' instead

There is therefore nothing you can do to get small caps from the font, other than faking them by tweaking the full caps glyphs. But unless you are tied to DejaVu Serif Condensed for some reason (and I don't see why you would be), what you should do if you want good-looking small caps is to switch to a font that has them. You can browse through the LaTeX font catalogue which will tell you if the font has small caps or not.

If you need to stick to DejaVu Serif, then you could switch to another font only when you need small caps. How to do that has been asked and answered before. I've just copied the code from there below.

\documentclass{memoir}
\usepackage{DejaVuSerifCondensed}
\usepackage[T1]{fontenc}
\usepackage{pdftexcmds}
\makeatletter
\let\scshape\relax % to avoid a warning
\DeclareRobustCommand\scshape{%
  \not@math@alphabet\scshape\relax
  \ifnum\pdf@strcmp{\f@family}{\familydefault}=\z@
    \fontfamily{lmr}%
  \fi
  \fontshape\scdefault\selectfont}
\makeatother
\begin{document}
This text should be in DejaVuSerif\par
\textsc{While this should be in Latin Modern}
\end{document}

enter image description here

See egreg's answer for more details, and Alan Munn's answer for how to find the font family names. You need to decide for yourself which small caps font goes well with DejaVu Serif (I don't recommend Latin Modern as in my example). Browse the font catalogue.