15

I'm writing a document in English. However, I need to use a few words of both Japanese and Russian. In principle, it seems to work, but as soon as I used Japanese characters, I cannot use Russian characters afterwards. Please note that it is crucial for me that the document compiles using pdflatex.

Here are two minimal examples to illustrate my problem.

This one works:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T2A,T1]{fontenc}
\usepackage{CJK}

\begin{document}
{\fontencoding{T2A}\selectfont ф}
\begin{CJK}{UTF8}{min}
ル
\end{CJK}
\end{document}

But this doesn't:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T2A,T1]{fontenc}
\usepackage{CJK}

\begin{document}
  {\fontencoding{T2A}\selectfont ф}
  \begin{CJK}{UTF8}{min}
  ル
  \end{CJK}
  {\fontencoding{T2A}\selectfont ф}
\end{document}

I cannot figure out why. In the second case, I get this error message:

! Undefined control sequence.
\CJK@XX ...r `#1\endcsname {`#2}\CJK@ignorespaces 
                                                  \fi 
l.12   {\fontencoding{T2A}\selectfont ф
                                        }

I cannot find any explanation and I would really appreciate any help.

Pete
  • 151

2 Answers2

8

Hmm seems like CJK package is making some definitions global when perhaps it shouldn't. You can reset the inputenc settings like so:

enter image description here

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T2A,T1]{fontenc}
\usepackage{CJK}

\begin{document}
  {\fontencoding{T2A}\selectfont ф}
  \begin{CJK}{UTF8}{min}
  ル
  \end{CJK}%
\sbox0{\input{utf8.def}}%
  {\fontencoding{T2A}\selectfont ф}
\end{document}
David Carlisle
  • 757,742
  • 1
    @Pete Welcome to tex.sx! If David’s answer solved your problem, you can accept it by clicking on the check below the vote count. – doncherry Jun 11 '13 at 22:38
8

David Carlisle's solution works, but it is not as good as it could be.

In fact, there's a CJKutf8 package which solves the problem that inputenc and CJK packages may conflict.

Here's an example:

enter image description here

\documentclass{article}
\usepackage[T2A]{fontenc}
\usepackage{CJKutf8}
\begin{document}
\begin{CJK}{UTF8}{min}

ру́сский: абвгдеАБВГДЕ

English: abcdefABCDEF

日本語:ぁぃぅぇぉか

\clearpage\end{CJK}
\end{document}

NOTES:

  1. Please always use CJK environment globally, unless you know what you are doing.
    The extra \clearpage is used to solve an old sutle bug of CJK described in the package document.

  2. T2A font encoding is sufficient if you only use basic Latin letters used by English. However, if you need more accented letters, you can mix T1 and T2A font encodings manually.

  3. For multilingual documents, I think it is always preferrable to use XeLaTeX or LuaLaTeX. For XeLaTeX, use our xeCJK package to support automatical font selection and other features. For LuaLaTeX, use luatexja bundle to support similar features.

Leo Liu
  • 77,365