6

How can I have known current font encoding? I know that a list of font encodings is saved in \cdp@list macro. Last element of \cdp@list is usually the effective encoding but this is not always true; for example, \setlanguage might switch current encoding.

Actually, I want to distinguish the case where either EU1 or EU2 font encoding is in effect from a non-unicode encoding.

lockstep
  • 250,273

1 Answers1

8

The macro \f@encoding always expands to the current encoding:

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

\makeatletter
\newcommand{\printenc}{the current encoding is~\texttt{\f@encoding}}
\makeatother

\begin{document}
Text in English: \printenc

\foreignlanguage{russian}{Какой-то осмысленный текст: \printenc}

English again: \printenc

\begin{otherlanguage}{russian}
Какой-то осмысленный текст: \printenc
\end{otherlanguage}
\end{document}

enter image description here

As far as XeLaTeX and LuaLaTeX are concerned, the encoding should always be EU1 or EU2, respectively, unless you're mixing fonts, which is not recommended.

egreg
  • 1,121,712
  • 1
    Nowadays, the default encoding used with XeLaTeX or LuaLaTeX and fontspec is TU. – egreg Nov 03 '20 at 09:21
  • Indeed, since 2017, as announced in the LaTeX News: https://www.latex-project.org/news/latex2e-news/ltnews26.pdf. – 0 _ Apr 19 '21 at 06:07