Change Kanji display with CJKutf8

I've been using CJKuftf8 to include Japanese in a book containing mostly Latin script. It works fine most of the time, but I'm having problems displaying a particular kanji, 直. When compiled, this kanji always appears different to the one intended.

Left is kanji as typed, right is the kanji as it appears in the compiled document

I believe the kanji being displayed is an equivalent in simplified Chinese, but of course, is not understood in Japan.

Furthermore, if I open the document in a pdf reader on a Japanese computer, and copy the kanji, it copies as the character I intended (the one on the left). If I open the document in a pdf reader on a computer which isn't in Japanese, it copies as the wrong kanji. It seems to be an issue with an overlap in utf8. Is it possible to edit the way that the kanji is displayed in the compiled document?

MWE:

\documentclass{article}

\usepackage{CJKutf8}
\begin{document}
\Huge
\begin{CJK}{UTF8}{min}直\end{CJK}
\end{document}


Since the kanji in the code may appear differently on other computers, to be sure, here's a picture of the code.

Update: It seems to be entirely a font issue. Writing the Kanji in Word/Libre office, the kanji is displayed differently depending on the font chosen. In particular, it is displayed as intended when using a Japanese font (e.g. TakaoExMincho), and incorrectly otherwise. As far as I know, the font can't be changed when using \usepackage{CJKutf8}. Is there a fix for this?

• It appears correctly when I try your MWE. Does it help if you add \usepackage[utf8]{inputenc}? – erik Sep 19 '17 at 5:15
• @erik I've tried \usepackage[utf8]{inputenc} and \usepackage[T1]{fontenc}, however the problem persists, the kanji is always displayed as the one on the right in the picture, not the left. Stranger still, when I open the TeX file on a different computer, the kanji in the TeX file is the wrong one. – James Sep 19 '17 at 5:24
• Can you try using ipxm family instead of min and see if the problem resolves? – yudai-nkt Sep 19 '17 at 5:27
• I wonder if your source file is saved with utf8 encoding or something else. Any chance you can change to xelatex? – erik Sep 19 '17 at 5:30
• When I compile your document with pdflatex in texlive2017 I get the kanji you want (left). The font used by pdflatex is fonts/type1/wadalab/dmj/dmjkh.pfb. The kanji copies correctly in sumatra, but not in adobe where I get an u. According to en.wikipedia.org/wiki/Han_unification both variants are on the same unicode position (U+76F4) , so the look (in the pdf, in your editor and also on webpages) will always depend on the font unless you use a graphic. – Ulrike Fischer Sep 19 '17 at 8:07

Let me post this as an answer rather than as a comment because this is too long for a comment.

As you say,

I think I'm happy to use any of the options, if there's a way to solve the problem.

I'll propose a XeLaTeX-based method. There is the fontspec, and it provides \newfontfamily, which defines a new font-switching command. Here is a simple examaple (I'm not sure that fonts in use are shipped with MiKTeX but both are available on CTAN).

% XeLaTeX document
\documentclass{article}
\usepackage{fontspec}
\newfontfamily{\jafamily}{ipam.ttf}  % Japanese typeface, which is what you want
\newfontfamily{\cnfamily}{FandolSong-Regular.otf}  % Simplified Chinese typeface
\begin{document}
{\jafamily 直} and {\cnfamily 直}
\end{document}


The output is

On the other hand, LaTeX with 8-bit engine should also be able to use Japanese glyphs if the font family (the second argument of CJK environment) is properly set.

% (pdf)LaTeX document
\documentclass{article}
\usepackage{CJKutf8}
\begin{document}
\begin{CJK}{UTF8}{ipxm}直\end{CJK} and \begin{CJK}{UTF8}{gbsn}直\end{CJK}
\end{document}


will produce

If this example results in a different look, Japanese fonts seems to be not installed in your MiKTeX (and maybe fall back to Chinese font?).

• The font for the ipxm-version is in miktex but currently doesn't work due to a packaging bug github.com/MiKTeX/miktex-packaging/issues/5. – Ulrike Fischer Sep 19 '17 at 9:42
• @UlrikeFischer I use TeX Live, so I didn't notice that some files are misplaced in MiKTeX. Thanks for your investigating and filing the issue. – yudai-nkt Sep 19 '17 at 10:01
• @UlrikeFischer Thank you. I also discovered there were problems when compiling because I had fontspec 2.5, which resulted in errors. I uninstalled and reinstalled the fontspec package (now 2.6d), which allows me to compile your example perfectly and solves the problem. – James Sep 19 '17 at 11:12