# \cf@encoding vs. \UTFencname: which of them has priority?

There are two macros that bear the name of current font encoding. First is \cf@encoding which seems to be set by core of LaTeX 2e and NFSS and changed by the fontenc package. Second macro is \UTFencname. It is set, in particluar, by fontspec package and, perhaps, by some other packages that deal with OTF/TTF fonts and unicode. What is the relation between these two macros? I noted \cf@encoding also changes when LuaLaTeX runs.

-

\cf@encoding (current font encoding) is the core command. There is also f@encoding which is used by \fontencoding to store its argument. In general both have the same value except between the \fontencoding and the next \selectfont:

\documentclass[a4paper]{article}
\usepackage[T1]{fontenc}
\begin{document}
\makeatletter
\f@encoding, \cf@encoding;
\fontencoding{OT1}
\f@encoding, \cf@encoding;
\selectfont
\f@encoding, \cf@encoding;
\end{document}


\UTFencname is a command used by xunicode in its various declarations. (xunicode can setup definitions for various encoding names). fontspec sets UTFencname to the correct "unicode encoding" name before loading xunicode (EU1 for xetex, EU2 for luatex, the reason for the different names is that the two engines needs different fd-files/font declarations to load fonts as they use a different syntax).

UTFencname is normally fix in a document. It doesn't change if you switch to another font encoding:

\documentclass[a4paper]{article}
\usepackage{fontspec}
\begin{document}
\makeatletter
\f@encoding, \cf@encoding,\UTFencname;
\fontencoding{OT1}
\selectfont
\f@encoding, \cf@encoding,\UTFencname;
\end{document}

-