Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

As it is stated in answer to Can XeTeX | LuaTeX use MetaFont fonts?, LuaLaTeX can use MetaFont fonts. If so, how can one instruct LuaLaTeX to use T2A encoded fonts (e.g. cm-super) to typeset cyrillic text? I used to think that LuaLaTeX can use only those fonts which are internally encoded accoding to Unicode. Am I right?

UPDATE: The following code (slightly modifed from @Leo Liu's answer) prints "Б-Б-Б" if it is compiled by pdflatex but "Б--Б" in case of lualatex:

\documentclass{minimal}
\usepackage[T2A]{fontenc} % cyrillic font encoding
\usepackage[utf8]{inputenc} % source file encoding
\begin{document}
\symbol{"C1}-Б-\CYRB
\end{document}

I wonder why \usepackage[utf8]{inputenc} does not work for lualatex. I tried also luainputenc with same result. Note that \CYRB command is defined by fontenc which loads t2aenc.def. As to inputenc it should match unicode chars in source file to corresponding \cyr... macros. And it did so for pdflatex but not lualatex.

share|improve this question
3  
Note that inputenc does not support luatex (nor xetex) as the author(s) refuse to added support for new engines. But there is luainputenc if you really need that stuff. –  Khaled Hosny Oct 16 '11 at 13:59
    
@KhaledHosny, I substituted inputenc with luainputenc but did not reach desired result. –  Igor Kotelnikov Oct 16 '11 at 14:18
    
It does here, I get Б-Б-Б, but to be honest, I never used that stuff, but luainputenc documentation is a good start to get an overall idea of the issue. –  Khaled Hosny Oct 16 '11 at 17:03
add comment

1 Answer

up vote 8 down vote accepted

You can use it directly. fontenc works well with XeTeX/LuaTeX. For example,

\documentclass{article}
\usepackage[T2A]{fontenc}

\begin{document}

\symbol{"C1} % produce Б

\end{document}

However, you can't use it with fontspec. A error will be produced:

! Corrupted NFSS tables.

Moreover, it is a problem to input Cyrillic text. inputenc cannot be used in XeTeX and LuaTeX directly.

Anyway, if you want to use Cyrillic text in XeLaTeX and LuaTeX, just use CM Unicode fonts. For example,

\documentclass{article}
\usepackage{fontspec}
\setmainfont{CMU Serif}
\setsansfont{CMU Sans Serif}
\setmonofont{CMU Typewriter Text}

\begin{document}

Русский язык

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

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

\end{document}

Additional notes:

inputenc is used for text of 8 bits encodings. Knuth's tradational TeX can use ASCII (0x00--0x7F) only. Later TeX implementations can process 8 bits extended ASCII (0x00--0xFF).

Most western encodings are some types of extended ASCII, e.g. Latin 1 (ISO 8859-1), KOI8-R, CP866. The ASCII part are identical, but higher codes (0x80--0xFF) are different.

Fonts has there own encodings. Basically, a font encoding corresponds with a input encoding. For example, T1 encoding is very similar to Latin 1 encoding, and T2A is very similar to Code Page 1251 in Windows. That is to say, if you TeX a source file of CP1251, and use \usepackage[T2A]{fontenc}, you will get proper Russian text without any other packages.

inputenc makes us to input text with different encodings, but use fonts of only one font encoding. When you choose utf8x option, and use T2A font encoding, then the characters are mapped to T2A (CP1251) from UTF-8 inputs. That's what inputenc do.

How inputenc works? It makes the characters active (catcode 13), and do the mapping. For multibyte characters, things may be more complex.

Why inputenc cannot be used in XeTeX and LuaTeX? XeTeX and LuaTeX use UTF-8 encoding for input. A multibyte Unicode character in XeTeX/LuaTeX is only one character, but in pdfTeX it's two or three. Thus the different TeX engines sees the input stream differently. inputenc fails in XeTeX and LuaTeX.

I'm not very familar with LuaTeX. In XeTeX, there is a special mode for compatibility. You can use \XeTeXinputencoding to change the input encoding temporarily, and the "bytes" encoding makes XeTeX works like a 8 bit TeX engine. Thus, this works for XeTeX:

\XeTeXinputencoding "bytes"
\documentclass{article}

\usepackage[T2A]{fontenc}
\usepackage[utf8x]{inputenc}

\begin{document}

Русский язык

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

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

\end{document}

(This technique is used by obsolete xCJK package.)

However, inputenc may cause real Unicode fonts with fontspec works unusually. It is still not a good idea to use it.


By Khaled Hosny

luainputenc can be used here. I didn't know that.

\documentclass{article}

\usepackage[T2A]{fontenc}
\usepackage[lutf8x]{luainputenc}


\begin{document}

Русский язык

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

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

\end{document}
share|improve this answer
    
Sorry, this is not what I asked. If you type "Б" from keybord, you will get no output: \documentclass{article} \usepackage[T2A]{fontenc} \begin{document} "Б" produce nothing \end{document} –  Igor Kotelnikov Oct 16 '11 at 12:12
3  
@Igor: LuaTeX is a UTF-8 only engine, and Leo has said that you can't use inputenc with it. Can you explain what is wrong with the standard approach of loading a proper Unicode font? –  Joseph Wright Oct 16 '11 at 12:33
2  
@Igor: You are still confusing what the engine can do with what is convenient for the user. LuaTeX can certainly load MetaFont fonts, which you can happily do with the \font primitive. However, they simply don't map correctly to UTF-8 input, and so there is a lot of 'behind the scenes' work in the inputenc package to convert from a UTF-8 sequence into something that 8-bit pdfTeX can display. So if you want to use an 8-bit encoded font with LuaTeX, you will have to use macro-based input to access the glyphs outside of the 8-bit range. –  Joseph Wright Oct 16 '11 at 13:04
3  
@Igor: The key point is that LuaTeX is fundamentally a UTF-8 engine, so for direct use of UTF-8 characters in the input you need a font that includes the appropriately-placed glyph. If you want to use an 8-bit font, then you have to accept other input forms. That is fine, for example, if you want the 'dangerous end' character that Knuth used in The TeXbook, as it's a one-off, but for general UTF-8 input use a modern font. –  Joseph Wright Oct 16 '11 at 13:06
1  
@Igor: See my comments in the chat system –  Joseph Wright Oct 16 '11 at 13:20
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.