77

I've recently started to use LaTeX but I've just encountered a problem, I tried searching it, although apparently no-one asked it before.

I'd like to write using Japanese input, but when I typeset, there can happen 3 things:

  1. I get some error when compiling;
  2. I get question marks where Japanese stuff should appear;
  3. Nothing appears.

For example I had an example .tex file, compiled it and it worked, so I added some japanese in order to see "The author is [Japanese here]", but what I could see was "The author is [blank space]".

I've tried checking some guides, but I haven't found anything that could solve my problem (they are too old, or they don't talk about this at all).

Some minutes ago I tried compiling this:

\documentclass[12pt]{article}  
\usepackage[T1]{fontenc}  
\usepackage{CJKutf8}  
\usepackage[romanian]{babel}  
\usepackage[overlap, CJK]{ruby}  
\usepackage{CJKulem}  
\renewcommand{\rubysep}{-0.2ex}  
\newenvironment{Japanese}{%  
\CJKfamily{min}%  
\CJKtilde  
\CJKnospace}{}  
\begin{document}  
\parskip 3ex  
\parindent 0pt  
\begin{CJK}{UTF8}{}  
\begin{Japanese}  
ねこ   
\end{Japanese}  
\end{CJK}  
\end{document}

It compiles fine but, still same problem, nothing appears when typeset, even if I should see "ねこ". There are many Linux guides, but I have a Mac and apparently, there aren't a lot around...

EDIT: A small add, if I get this to work, is the solution related to other asian languages such as Korean or Chinese?

CampanIgnis
  • 4,624
Alenanno
  • 37,338
  • @Leo Liu, @Nyiti, @Bob BeckettGuys, I found out that probably it's a matter of encoding. If I write 丸 (example) I'll get nothing like I said but if I write ¥›, it will appear properly on pdf! :| – Alenanno Apr 13 '11 at 10:02
  • It's testament to the quality of this site that when Googling 'japanese in latex', this is the first search result. (As opposed to some of the more questionable results which appear further down the list) – Bill Cheatham Jun 09 '15 at 14:12

6 Answers6

78

1. XeLaTeX

For XeLaTeX, the document should be saved in UTF-8 encoding.

1.1. xeCJK package

I advice you to use XeLaTeX with package xeCJK. An example:

\documentclass{article}
\usepackage{xeCJK}
\setCJKmainfont{MS Mincho} % for \rmfamily
\setCJKsansfont{MS Gothic} % for \sffamily
\begin{document}

\section{日本語}
お早う

\textsf{こんにちわ}

\end{document}

See manual of xeCJK and fontspec for more information.

Chinese and Korean work the same. In fact, xeCJK is originally designed for Chinese by Prof. 孙文昌.

xeCJK: http://mirrors.ctan.org/macros/xetex/latex/xecjk/xeCJK.pdf
fontspec: http://mirrors.ctan.org/macros/latex/contrib/fontspec/fontspec.pdf

1.2. zxjatype package

zxjatype internally calls xeCJK, with some configurations for Japanese. You can also use zxjafont package to use some predefined fonts. It is easier to use compared to raw xeCJK. An example:

\documentclass{article}
\usepackage{zxjatype}
\usepackage[ipa]{zxjafont}
\begin{document}

\section{日本語}
お早う

\textsf{こんにちわ}

\end{document}

zxjatype: http://zrbabbler.sp.land.to/zxjatype.html

1.3. bxjsclasses with zxjatype

bxjsclasses bundle provides some Japanese local classes. It can be used with different TeX engines.

\documentclass{bxjsarticle}
\usepackage{zxjatype}
\usepackage[ipa]{zxjafont}

\begin{document}

\section{日本語}
お早う

\textsf{こんにちわ}

\end{document}

2. LuaLaTeX

For LuaLaTeX, the document should be saved in UTF-8 encoding.

2.1. luatexja-fontspec package in luatexja bundle

luatexja bundle provides Japanese support for LuaTeX. A simple LaTeX example:

\documentclass{article}
\usepackage{luatexja-fontspec}
\setmainjfont{MS Mincho} % \mcfamily
\setsansjfont{MS Gothic} % \gtfamily

\begin{document}
\section{日本語}

お早う

\textgt{こんにちわ}

\end{document}

2.2. ltjsclasses classes in luatexja bundle

ltjsclasses provides some Japanese document classes for convenience. An example:

\documentclass{ltjsarticle}
\usepackage{luatexja-fontspec}
\setmainjfont{MS Mincho} % \mcfamily
\setsansjfont{MS Gothic} % \gtfamily

\begin{document}

\section{日本語}

お早う

\textgt{こんにちわ}

\end{document}

3. upLaTeX + ujclasses

upLaTeX is a Japanese TeX format. It needs UTF-8 encoding.

An example:

\documentclass{ujarticle}

\begin{document}

\section{日本語}

お早う

\textgt{こんにちわ}

\end{document}

Compile with

uplatex foo.tex
dvipdfmx foo.dvi

4. pLaTeX + jsclasses (Relatively Old)

pLaTeX is a Japanese TeX format. Documents should be saved in SJIS encoding. Documentation in English is available here.

An example:

% SJIS encoding
\documentclass{jsarticle}

\begin{document}

\section{日本語}

お早う

\textgt{こんにちわ}

\end{document}

Compile with

pdfplatex foo.tex

or

platex foo.tex
dvipdfmx foo.dvi

5. CJK package (Obsolete)

Older CJK package is still useful. It works well with PDFLaTeX and LaTeX (Dvips, dvipdfmx). If the document has only a few wide characters, CJK package may be a reasonable choice with better compatibility.

Be sure you have installed the proper CJK fonts for CJK package. Typically, this is not done. TeX Live and MiKTeX have a wadalab package, install it when necessary. (Also ipaex and ipaex-type1) Then you can use:

% UTF-8 encoding
\documentclass{article}
\usepackage{CJKutf8}
\begin{document}
\begin{CJK*}{UTF8}{min}

\section{日本語}
お早う

{\CJKfamily{goth} こんにちわ}

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

See $TEXMF/tex/latex/cjk/texinput/UTF8/c70*.fd, $TEXMF/tex/latex/cjk/contrib/wadalab/c70*.fd, etc. for pre-installed CJK font families. Frankly speaking, these free Type1 CJK fonts are not very good. It is better to install the fonts yourself.

Leo Liu
  • 77,365
  • Thanks a lot! I'll give this all a try... It might take some time though, due to my noobness :) I'll let you know. – Alenanno Apr 11 '11 at 10:58
  • If we use XeLaTeX instead of PDFLaTeX, do we lose features provided by microtype? – kiss my armpit Mar 06 '12 at 01:10
  • @Damien: Develop version of microtype partly support XeTeX. – Leo Liu Mar 06 '12 at 04:51
  • I can't understand how to install the wadalab package. I spent the two hours trying to install at least one of those packages, but when I came to convert .afm files to .tfm files using a not-to-be-found encoding file I came to the conclusion that I would have never been able to do such thing...

    I'd use Xelatex, but my nearly-finished document uses a big quantity of packages (inputenc, babel, tocbibind, makeidx, mathptmx, geometry, lipsum, fancyhdr, chngcntr, url, footmisc, etoolbox) which, I'd have to install again. How is this possible that I can't just download a package and write kanji?

    – il mietitore Feb 22 '14 at 01:09
  • @user46007: No, you don't need to install these packages yourself. You can install a full version of TeX Live or MiKTeX and start working. No .afm to .tfm conversion is needed at all. You may ask a local expert nearby to deal with your thesis. – Leo Liu Feb 22 '14 at 09:08
  • I installed TeXlive. I switched the LaTex and PdfLaTeX directory in the TeXstudio configuration panel. Yet if I use the example code I find in the CJK documentation it won't work. If i try to use the wadalab package latex doesn't find it. I get the most various errors when I try to compile the given code :( – il mietitore Feb 22 '14 at 14:47
  • 1
    @user46007: I've no idea. I use TeX Live 2013 (updated with TeX Live Manager), and all these code was tested. – Leo Liu Feb 22 '14 at 16:34
  • @user46007: Run TeX Live Manager to update all the pacakges and DON'T put any files you download yourself. I don't recommend CJK package at all. Anyway, a CJK solution will be easy if you only use one or two CJK font family like min, mj. – Leo Liu Feb 24 '14 at 02:42
  • @user46007: And don't use those example code from CJK document. They are quite outdated. Use my code. – Leo Liu Feb 24 '14 at 02:49
  • In the end I found a way to not use them in my document, and brutally solved the problem that way. I don't think it's a matter of upgrade anyway: I downloaded TeX Live two days ago. – il mietitore Feb 24 '14 at 18:15
  • with xeCJK and XeLaTeX, \textbf or \bfseries doesn't work. why? – hello all Feb 25 '16 at 01:41
  • @GreekFellows: You need to use a font family which does have a Bold variant, e.g. Microsoft YaHei. Otherwise you must set the actual font of bold series, or you mey use the AutoFakeBold option. – Leo Liu Feb 25 '16 at 06:36
  • 10
    Not related to LaTeX, but it should really be こんにちは instead of こんいちわ – A.Ellett Sep 22 '18 at 01:55
  • I had to use \setCJKmainfont{PingFang SC} on Mac OSX as a japanese character 勧(U+52E7) was rendering as letter F in a box. A good tip I read on another post is to use a WYSIWYG editor to verify the target font, make sure all the characters work and then update the CJK main font in the LaTeX header. – Gaurav May 06 '20 at 00:33
  • Method 1 works for me - on linux ubuntu I need to apt install fonts-takao-mincho and set the font to \setCJKmainfont{TakaoPMincho} otherwise some characters are missing. – squarespiral Oct 09 '20 at 11:59
45

This blog post outlines Chinese-Japanese-Korean support in LaTeX: link

This is a minimal working example:

\documentclass{memoir}

\usepackage{CJKutf8}

\begin{document}

\begin{CJK}{UTF8}{min}未練なく散も桜はさくら哉\end{CJK} \\
without regret \\
they fall and scatter\ldots \\
cherry blossoms

\end{document}

You can compile it with the latex, dvips, ps2pdf combo or with pdflatex as well.

David Carlisle
  • 757,742
Gambhiro
  • 3,384
  • Thanks for the link, the site is loading so slow though :D I'll wait until it's done... Hopefully. :) – Alenanno Apr 11 '11 at 18:07
  • Sorry, it took quite some time, honestly I left it lol... I chose you because your example worked. :) – Alenanno May 08 '11 at 18:00
  • I hope it works out, good luck with your project! – Gambhiro May 09 '11 at 06:45
  • Characters are working, I have some new problems sometimes (things like size, font choice, etc) but there is plenty of material... I might be able to solve it by myself :D – Alenanno May 09 '11 at 08:02
  • Note that this example only works on Ubuntu Quetzal if you install the package latex-cjk-japanese-wadalab (via http://blog.mindfall.net/?p=221). – Reid Mar 18 '13 at 23:12
  • 3
    Please don't use the default min, goth CJK fonts for Japanese. They are not professional. Instead use fonts provided by ipaex-type1 package. In Ubuntu it is provided by texlive-fonts-extra package. – eiennohito Jun 27 '19 at 00:58
6

You might also try XeteX with the genzi.sty package, which is specifically for Japanese.

If you read Japanese well, Google "luajalayout" and "LuaTeX-ja." A pdf sample of the output looks very good. It appears to require a separate installation from the standard LuaTeX, but I'm not sure.

chl
  • 8,890
6

2020 Update

Thanks to a comment above from eiennohito, I've gotten a professional looking Japanese font working on Arch Linux with pdflatex (although it should work for other distros).

Necessary Packages

  • texlive-bin (provides pdflatex)
  • texlive-fontsextra

The latter should install (among others) the following file:

/usr/share/texmf-dist/tex/latex/ipaex-type1/c70ipxm.fdx

This is the font we want. Now, in our .tex file, using this font is as simple as:

\usepackage{CJKutf8}
\begin{document}
\begin{CJK}{UTF8}{ipxm}

\section{私の人生} % Works in section titles too. 田舎に派遣されました。

\end{CJK} \end{document}

A normal run of pdflatex on this file should succeed, and the resulting .pdf should have nice, professionally looking Japanese text within.

Note: If you want other text effects like \textbf, use ipmxa instead.

References

1

Another option is to use babel. As of 2020, this translates strings such as “Table of Contents” and allows you to select many different styles of counters (such as Hirigana, Katakana, Iroha and more).

Mixing Japanese with other scripts, such as Arabic or Devanagari, and automatically selecting the correct language and font without language and tagging, is possible in babel, and not other packages. In theory, the translator and translations packages support Japanese dictionaries and would automatically select them, but as of 2020, you would need to write them yourself.

It also has the advantage of allowing you to mix Japanese and Chinese in the same document, although if you do this, you unfortunately will need to turn off the feature that automatically changes the language when it sees characters from a CJK script. The Original Sin of the Unicode Consortium was thinking that 16 bits would be enough forever if they just forced Japan to share the same codepoints as China and Korea.

Davislor
  • 44,045
1
\documentclass{article}
\usepackage{xeCJK}
\setCJKmainfont{Noto Serif CJK TC}
\setCJKsansfont{Noto Sans CJK TC}
\setCJKmonofont{Noto Sans Mono CJK TC}
\begin{document}

\section{これは最初のセクションである}
日本語で \LaTeX の組版を実証するための導入部分。

フォントはまた、数学的な形態および他の環境で使用することができる

\bigskip

And you can also use Latin characters within your Japanese document.

\bigskip

\begin{verbatim}
このテキストは、別のフォントを持つことになります

This is a verbatim environment using a monospaced font.
\end{verbatim}
\end{document}

enter image description here

go poke
  • 59