[Tex/LaTex] How to change the font of Japanese characters

cjkfontsluatexxetex

Im currently working on a file where I need to display some Kanji in the middle of some English text. For this I created a new environment with the CJKuft8 package, according to this post

\usepackage{CJKutf8}
\newcommand{\japanese}[1]{\begin{CJK}{UTF8}{ipxm}#1\end{CJK}}

This works still just fine, but I have a slight problem with it: I'd like to change the font in which the Kanji are displayed (only the Japanese characters, not the rest of the text), but I don't know how to achieve that.

I found this answer, but it suggests using XeLaTeX, with which I am not familiar. Since I wanted to use Source Han Code JP, which is a OpenType Source font, I found also this question here, but there LuaLaTex was suggested.

After all of this I'm somewhat confused what the best strategy is to achieve my goal. Should I switch to XeLaTeX or LuaLaTex? Or can I even achieve my goal without changing to much (currently running pdflatex)?


Further Information:
If possible I'd like to avoid having to switch to XeLaTeX or LuaLaTeX since the file is already quite big, has a lot of imported packages and I'm not familiar what is compatible with what.

Best Answer

If you stick to pdfLaTeX, you have to convert an arbitrary OpenType/TrueType font to a Type1 font and create a map file; that requires a lot of works and special knowledge about "how font is handled by TeX". Usually, the process cannot be completed automatically, and it's too difficult for beginners. IPAex font (= you are using that in the above MWE as "ipxm") is currently the only example which is contributed by a Japanese TeXnician, so I strongly recommend one of the followings:

  1. use "ipxm" with pdfLaTeX.
  2. switch to LuaLaTeX. (LuaLaTeX is upper-compatible with pdfLaTeX in most cases)

LuaLaTeX can handle OpenType/TrueType font natively. Here is a simple example of using Japanese fonts. (Here I used \font primitive directly but another LaTeX-like solution would be possible)

\documentclass{article}
\usepackage{fontspec}
\font\ipaexm=IPAexMincho % PSName of an arbitrary font
\font\ipaexg=IPAexGothic
\begin{document}
Type your content here.
{\ipaexm 日本語}
{\ipaexg 日本語}
\end{document}

lualatex example