TransWikia.com

How to write Japanese with LaTeX?

TeX - LaTeX Asked by Alenanno on February 3, 2021

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?

5 Answers

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.

Answered by Davislor on February 3, 2021

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

Answered by Colin Woodbury on February 3, 2021

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.

Answered by Bob Beckett on February 3, 2021

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 scatterldots \
cherry blossoms

end{document}

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

Answered by Gambhiro on February 3, 2021

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} こんにちわ}

clearpageend{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.

Answered by Leo Liu on February 3, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP