[Tex/LaTex] TeX capacity exceeded with multiple font encodings

font-encodingslanguages

I work in humanities, so please forgive my lack of competence and the weirdness of my computing needs. Is there a way to make this work? I need to use three (for starters) languages in the same document. Lithuanian (L7x), polish (LaTeX seems to render it fine without stating \usepackage{polski}) and russian (T2A). I get the error message below as soon as I introduce any third language-specific symbol into the document.

! TeX capacity exceeded, sorry [input stack size=5000].\L ->\L7x-cmd \L 
                 \L7x\L 
l.9 ĄąĆćĘęŁ
                  łŃńÓóŻż
!  ==> Fatal error occurred, no output PDF file produced!

Russian+lithuanian works fine, but a single "ł" triggers an error. The same with russian+polish and a "ė". A cyrillic character only causes non-fatal error (msg. below) for each symbol and cyrillic text is simply ignored in the output file.

! Package inputenc Error: Unicode char \u8:ц not set up for use with LaTeX.

Here is a MWE

\documentclass{article}
\usepackage[L7x,T2A]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[lithuanian,russian]{babel}
\begin{document}
%lithuanian    
ĄąČčĘęĖėĮįŠšŲųŪūŽž
%russian
БбЖжЬьЯяЭэЩщШшПпЦц
%polish
ĄąĆćĘꣳŃńÓóŻż
\end{document}

Best Answer

There is a bug in l7xenc.def that, as far as I can see, can be fixed. You should also confine the languages in the proper tags. For Polish either use the T1 encoding or, if you want to stay with L7x, add its selection when switching to Polish:

\documentclass{article}
\usepackage[L7x,T2A]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[lithuanian,polish,russian]{babel}

%%% Fix for L7x encoding
\makeatletter
\expandafter\let\csname L7x-cmd\endcsname\@changed@cmd
\makeatother

%%% Use L7x for Polish
\addto\extraspolish{\fontencoding{L7x}\selectfont}
\addto\noextraspolish{\fontencoding{\encodingdefault}\selectfont}

\begin{document}

%lithuanian
\begin{otherlanguage*}{lithuanian}
ĄąČčĘęĖėĮįŠšŲųŪūŽž
\end{otherlanguage*}

%russian
БбЖжЬьЯяЭэЩщШшПпЦц

%polish
\begin{otherlanguage*}{polish}
ĄąĆćĘꣳŃńÓóŻż
\end{otherlanguage*}

\end{document}
Related Question