# XeLaTeX: Using japanese.ldf for babel causes invalid characters errors

I'm trying to typeset a Japanese book with LaTeX.

I want to use Japanese for chapter titles, so instead of "Chapter 1 ジャン・バルジン", I get "第1章 ジャン・バルジャン".

I got the Japanese option for babel with the TeX Live Manager which contains a few files, including japanese.ldf, japanese.dtx and japanese.ins. I think I'm supposed to put one of these files in the babel folder of my TeX directories, where there are a bunch of .sty files, each with the name of a language option for babel.

I tried putting the japanese.ldf in the folder. Then I tried this simple example:

\documentclass[a4paper, 10pt, twoside, draft]{memoir}

\usepackage[japanese]{babel}

\begin{document}

\title{題}
\author{作者}
\date{日付}

\maketitle
\clearpage

\tableofcontents
\clearpage

\chapter{章1}
ウェルギリウスの作品。
\clearpage
\section{節1.1}
事実両者を区別した。
\clearpage
\section{節1.2}
キケロは上流の家柄の出。
\clearpage

\chapter{章2}2}
事実両者を区別した。
\clearpage
\section{節2.1}
キケロは上流の家柄の出。
\clearpage
\section{節2.2}
ウェルギリウスの作品。
\clearpage

\chapter{章3}
キケロは上流の家柄の出。
\section{節3.1}
ウェルギリウスの作品。
\clearpage
\section{節3.2}
事実両者を区別した。
\clearpage

\end{document}


Then I got this error:

\l@japanese = a dialect from \language0
! Text line contains an invalid character.
l.35   \def\prepartname{^^[
\$BBh^^[(B}%
? x


I believe something is wrong with the encoding of japanese.ldf. When I opened it with Sublime Text, there were weird characters exactly where the errors occured:

Is there a working version of japanese.ldf distributed somewhere? Or am I doing anything wrong here?

• Those files are for use with platex; I don't think they're compatible with XeLaTeX. – egreg Jul 19 '16 at 7:21
• @egreg Should I use polyglossia instead? I can't find Japanese support for polyglossia though. – hello all Jul 19 '16 at 7:55
• You should try xeCJK instead – egreg Jul 19 '16 at 12:02

There is currently no support for Japanese in Polyglossia (there's work on it, however).

The japanese.ldf file you found is for platex (the Japanese version of TeX) and is incompatible with other engines.

Here's a minimal working example, to be compiled with

ptex2pdf -u -l <filename>


Code, note that memoir is not supported.

\documentclass[a4paper, 10pt, twoside, draft]{ujbook}
\usepackage[japanese]{babel}

\begin{document}

\tableofcontents

\chapter{ジャン・バルジン}
ウェルギリウスの作品。

\end{document}


• Hmm, we (japanese) should make some effort on japanese.ldf for japanese support with xelatex etc. Thanks for report – Hironobu YAMASHITA Oct 2 '16 at 5:15
• @HironobuYAMASHITA That would be great. My feeling is that pTeX is still needed for properly typesetting Japanese texts, but for multilingual documents having better support for XeLaTeX and LuaLaTeX would be very welcome. – egreg Oct 2 '16 at 9:09
• Yes, it's true that we cannot do without pTeX. At the same time, we know many users prefer to create multilingual documents (including japanese) on xelatex. The error from current japanese.ldf on xetex is reasonable and inevitable, since the file is encoded in iso-2022-jp, which is necessary for pTeX (for historical reasons) but not available with xetex. The easiest way to get japanese document from xelatex is \documentclass[xelatex,ja=standard]{bxjsbook} (\usepackage[japanese]{babel} is not needed at all). – Hironobu YAMASHITA Oct 2 '16 at 13:17
• @HironobuYAMASHITA That's very important information and you should add an answer with a few examples; possibly, also luatexja should be mentioned. – egreg Oct 2 '16 at 13:41

[Update 2016-12-18] The file japanese.ldf was only for use with Japanese pLaTeX/upLaTeX until yesterday (thus encoded in ISO-2022-JP), which is the reason why "invalid characters" error occured.

Yesterday I (a member of Japanese TeX Development Community) submitted a new version of japanese.ldf, which supports LuaLaTeX/XeLaTeX as well as pLaTeX/upLaTeX. Development place is

and CTAN catalogue has also changed from japanese to babel-japanese. The new version is intalled in TeX Live r42738, so it will be soon available.

However, the package is not perfect: as I stated in README.md, Japanese language has different word order compared to most western languages. The standard classes (article, book etc) has \chap­ter­name in front of the num­ber­ing but no se­quence be­hind the num­bering, so there is no way for replacing "Chapter 1" and "Part 1" with Japanese counterpart "第 1 章" and "第 1 部". The alternative way is to use bxjs... document class which has been developed for Japanese language.

If you like to get japanese document using xelatex, the easiest way is to use bxjs... document class. In this case, \usepackage[japanese]{babel} is not needed at all.

The bxjs document class family (bxjsarticle, bxjsreport, bxjsbook, bxjsslide) is designed by japanese developer, and almost compatible with js documentclass family (jsarticle & jsbook; only supports pTeX/upTeX). The bxjs classes can be used with almost all common TeX engines, such as pdflatex, lualatex and of course xelatex. You have to specify the engine as class option. With xelatex, \documentclass[xelatex,ja=standard]{bxjsbook} is the best.

\documentclass[a4paper,10pt,twoside,draft,xelatex,ja=standard]{bxjsbook}

\begin{document}

\title{題}
\author{作者}
\date{日付}

\maketitle
\clearpage

\tableofcontents
\clearpage

\chapter{章1}
ウェルギリウスの作品。
\clearpage
\section{節1.1}

\clearpage
\section{節1.2}
キケロは上流の家柄の出。
\clearpage

\chapter{章2.2}

\clearpage
\section{節2.1}
キケロは上流の家柄の出。
\clearpage
\section{節2.2}
ウェルギリウスの作品。
\clearpage

\chapter{章3}
キケロは上流の家柄の出。
\section{節3.1}
ウェルギリウスの作品。
\clearpage
\section{節3.2}

\clearpage

\end{document}


• Some more info: bxjs class on xelatex uses xeCJK internally, and some adjustment for japanese document is also done. When bxjs class is used with lualatex, then it depends on luatexja package to produce better output. – Hironobu YAMASHITA Oct 2 '16 at 14:51