Typesetting a single word with TeX Gyre Pagella at T5, using Palatino for everything else

babelfont-encodingsxetex

I need to typeset a single Vietnamese word in my otherwise English document. My document is in Palatino, which doesn't support T5, so after I switch to T5, it uses a different font. So far, this is the same problem as described in this question. However, there the solution was to change the main font to TeX Gyre Pagella. I'd like to apply that solution locally, i.e. use TeX Gyre Pagella just for this one word.

\documentclass{memoir}
\usepackage[T1,T5]{fontenc}
\usepackage{fontspec}
\usepackage[defaultsups]{newpxtext}
\usepackage[english,vietnamese]{babel}
\newfontfamily\vnfont{TeX Gyre Pagella}

\begin{document}
Nguyen

\noindent

{\fontencoding{T5}\vnfont\selectfont{}Nguy\~\ecircumflex{}n}
\end{document}

However, this fails with:

LaTeX Error: Command \ecircumflex unavailable in encoding TU.

If instead I write \vnfont\fontencoding{T5}, then the latter overrides the former and I get the non-Palatino-looking font.

Best Answer

Since you are loading fontspec, I presume you are using either xelatex or lualatex. In such a case, don’t load fontenc and declare the font for vietnamese in the following way:

\documentclass{memoir}

\usepackage[english]{babel}

\babelfont[vietnamese]{rm}{TeX Gyre Pagella}

\begin{document}

Nguyen in English text.

\foreignlanguage{vietnamese}{Nguy\~{\^{e}}n}

% Better:
\foreignlanguage{vietnamese}{Nguyễn}

\end{document}