# Specific font for a specific encoding or language

Is there a way to specify a specific font for a specific encoding or language?

Using the default font for everything has proper shapes, but using garamondx has no proper shapes for cyrillic, even when not using my hack. Is the problem that garamondx lacks cyrillic or that its package does not deal with that lack gracefully?

Note: the MWE requires garamondx and literaturnaya from the TUG getnonfreefonts script. (It might be the same with other fonts.)

\documentclass{article}
\usepackage[T2A,T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[russian,american]{babel}
\usepackage{garamondx}

%%% The hack
\DeclareFontSubstitution{T2A}{tli}{m}{n}

\begin{document}

This should be Garamond.

The following should be Literaturnaya:

\begin{otherlanguage}{russian}

\textbf{Русский язык} \ensuremath{\leftarrow} (should be bold)

\emph{восточнославянских} \ensuremath{\leftarrow} (should be italic)

\emph{\textbf{русского народа}} \ensuremath{\leftarrow} (should be bold italic).

\end{otherlanguage}

\end{document}


This is a job for substitutefont:

\documentclass{article}
\usepackage[T2A,T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[russian,american]{babel}
\usepackage{garamondx}
\usepackage{substitutefont}

\AtBeginDocument{%
\substitutefont{T2A}{\rmdefault}{tli}%
} % some packages could set \rmdefault at begin document

\begin{document}

This should be Garamond.

The following should be Literaturnaya:

\begin{otherlanguage}{russian}

\textbf{Русский язык} \ensuremath{\leftarrow} (should be bold)

\emph{восточнославянских} \ensuremath{\leftarrow} (should be italic)

\emph{\textbf{русского народа}} \ensuremath{\leftarrow} (should be bold italic).

\end{otherlanguage}

\end{document}


With some black magic that shows the current font, just for being completely sure we get the expected one.

\documentclass{article}
\usepackage[T2A,T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[russian,american]{babel}
\usepackage{garamondx}
\usepackage{substitutefont}

\AtBeginDocument{%
\substitutefont{T2A}{\rmdefault}{tli}%
} % some packages could set \rmdefault at begin document

\newcommand{\?}{%
\space
\begingroup\edef\x{\endgroup
{%
\noexpand\ttfamily\noexpand\upshape
\noexpand\string\the\font=\fontname\font
}%
}\x
}

\begin{document}

This should be Garamond.

The following should be Literaturnaya:

\begin{otherlanguage}{russian}

\textbf{Русский язык\?}

\emph{восточнославянских\?}

\emph{\textbf{русского народа\?}}

\end{otherlanguage}

\end{document}


• This works until I add the garamondx option osfI for old style figures. What could be causing this, and is that better suited to a new question? – svenper Nov 12 '17 at 10:47
• @svenper Fixed. The osfI option causes \rmdefault to be set at begin document rather than in the preamble. – egreg Nov 12 '17 at 10:54