如何读写日语
本指南将会告诉你如何在非日语系统上读写日语。你可以根据自己的经验来对下述步骤进行修改。
需求
为了能支持日语和日语符号,我们需要安装或启用一些工具、库和功能。
日语字体
大多数非日语系统上都没有安装日语字体。在这时如果试图输入日语,你将只能在屏幕上看到一个个小方块。
输入法
首先我们要实现能通过键盘输入日语文字和符号。我们使用一种被叫做“输入法”的程序来实现这个目标。我们有两种常见的日语输入法:anthy 和 mozc。
使用输入法可以在我们在键盘上敲下 ta 时输入日语假名 た。同时通过一些简单的操作可以从平假名 た 切换到片假名 タ。
同时我们敲下 “nihou” 时将会输入 にほん,我们也可以很容易得切换到日语汉字版的词语,日本。
It is not the purpose of this guide to describe in detail how the "anthy" or "mozc" input methods work. Please refer to the documentation of these software components.
IME
On top of this users also need a way to switch from the input method normally used for the primary language to the one needed for the Japanese language. This functionality is provided by another piece of software called an IME (Input Method Editor) such as app-i18n/ibus, app-i18n/scim or app-i18n/fcitx.
Once installed, this allows users to switch from one language's input method to the Japanese input method using a key combination or using the mouse to select a relevant icon in the icon tray.
Installation
Japanese fonts
As a minimum, install the media-fonts/kochi-substitute package.
root #
emerge --ask kochi-substitute
Additionally, the following packages are also available:
- media-fonts/ja-ipafonts
- media-fonts/vlgothic
- media-fonts/mplus-outline-fonts
- media-fonts/monafont
- media-fonts/ipamonafont
- media-fonts/sazanami
Input tools
It is recommended to use ibus instead of scim.
To install ibus, install app-i18n/ibus-anthy:
root #
emerge --ask ibus-anthy
mozc
mozc is provided through the app-i18n/mozc package.
mozc has a better reputation than anthy though anthy has been proving working fine for years now. Among pros for mozc, there are the fact that it shows the candidates instantly during typing and has a better learning system in order to present the user the best candidates depending on the user's habit and context. It also provides the ATOK mechanism for quickly change an hiragana input to katakana (e.g. F7 as default before hitting space) or to other modes.
When trying to use mozc some problems might occur. After selecting mozc as an input method in the ibus-preferences graphical utility, the mozc icon in the keyboard icon tray might not be visible. Open the gnome settings --> Countries & Languages, remove all Japanese input methods (in this case "anthy") and add "Japanese(Mozc)".
Launching the ibus daemon at login time
Add these lines to the ~/.xprofile file and log out/log in again.
~/.xprofile
export GTK_IM_MODULE=ibus
export QT_IM_MODULE=ibus
export XMODIFIERS=@im=ibus
ibus-daemon -drx
This will allow the ibus daemon to start at login time.
Configuring
To configure the Input Method Editor, use the following command as a standard user
user $
ibus-setup
Alternatively, when using GNOME, type "ibus" in the search bar and launch "ibus-preferences".
In the dialog box that appears, click on the Input method tab and add the "japanese-anthy" method. Then return to the General tab and define a key combination as a keyboard short cut for switching the input method.
Latex
Here are some additional requirements to write Latex files in Japanese.
ibus-qt
When using editor aiming at writing Latex files such as TexMaker or TexStudio, ibus crashes each time a Latex command is entered (specially after entering the { char). To solve this kind of malfunctioning install app-i18n/ibus-qt:
root #
emerge --ask app-i18n/ibus-qt
CJK and xetex support
In order to write Japanese chunks in Latex files, add support for CJK languages and for [xetex] in Texlive.
This can be accomplished by adding or modifying the following lines in /etc/portage/package.use:
/etc/portage/package.use/latex
Enabling cjk and xetex supportapp-text/texlive cjk xetex
app-text/texlive-core cjk xetex
Then reinstall the packages:
root #
emerge --ask --newuse app-text/texlive app-text/texlive-core
Here is a working short LaTeX sample:
japanese.tex
\documentclass{article}
\usepackage{CJKutf8}
\usepackage{color}
\begin{document}
\begin{CJK}{UTF8}{min}
\section{One simple example}
\textcolor{red}{これは赤いです。}
\\
私は日本語で書けます。
\\
But I can also write with latin characters
\end{CJK}
\end{document}
In the
\begin{CJK}{UTF8}{min}
command in the example above, the third argument defines the font. Here {min}
is used for Mincho, but other supported fonts are Gothic ({goth}
) and Maru Gothic ({maru}
).Editor configuration
To compile and visualize the output of the sample above Texmaker or Texstudio editor needs to be configured properly.
Open Texmaker, and go to Options -> Configure Texmaker. Under the Commands tab change the following:
- At the LaTeX line, change "latex" with "platex".
- At the Dvipdfm line, change "divipdfm" with "dvipdfmx".
Through the Fast compile tab, choose "Latex + Dvipdfm + View PDF".
Finally go to the Editor tab, choose UTF8 encoding and deselect On the fly on the dictionary line.