0

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

Kanji

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.

enter image description here

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?

James
  • 165
  • It appears correctly when I try your MWE. Does it help if you add \usepackage[utf8]{inputenc}? – erik Sep 19 '17 at 05: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 05:24
  • Can you try using ipxm family instead of min and see if the problem resolves? – yudai-nkt Sep 19 '17 at 05: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 05:30
  • @yudai-nkt The problem still persists when using ipxm instead of min.

    @erik As far as I know, the document is saved with utf8 encoding. Building the document with xelatex produces the same results.

    – James Sep 19 '17 at 05:42
  • As you guess, this seems to be a font problem of CJK unified ideographs in Unicode, but it's strange that IPAex Mincho doesn't show the correct glyph... The result of \listfiles might help especially if there might be residuals of old TeX systems. – yudai-nkt Sep 19 '17 at 05:56
  • And when you use XeLaTeX, you can use the fontspec package to specify which font to use. – yudai-nkt Sep 19 '17 at 05:57
  • @yudai-nkt Can you provide an example where this solves the problem? – James Sep 19 '17 at 06:09
  • What do you mean by "an example where this solves the problem"? Your MWE shows the correct "直" on my OS X and Ubuntu (both in Japanese though). – yudai-nkt Sep 19 '17 at 06:44
  • @yudai-nkt Please allow me to illustrate the problem. I've taken a screenshot of your reply, on two computers https://sta.sh/0mwcip2347l . As you can see, the kanji in your reply looks different, depending on which font the computer is using. Therefore, without knowing which font you're compiling the code with, you haven't answered my original question, you've simply told me that it's not a problem for you. – James Sep 19 '17 at 07:43
  • @yudai-nkt You have suggested using fontspec, but without providing an example where you've used it, showing how/which font you specified, with screenshots of the output. Simply saying "you can use fontspec " is meaningless. – James Sep 19 '17 at 07:44
  • 1
    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 https://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 08:07
  • @UlrikeFischer Thank you. I'm using MikTex, not texlive. Is it possible for me to specify a font that works when I compile the document? – James Sep 19 '17 at 08:24
  • How do you compile the document in miktex? With pdflatex? – Ulrike Fischer Sep 19 '17 at 08:32
  • @UlrikeFischer I'm using TexMaker as the editor which gives me several options. I've tried latex, pdflatex, xelatex and simply the "quick build" option. I understand there's a difference between the different options, but I'll confess I don't know what the differences are. I think I'm happy to use any of the options, if there's a way to solve the problem. – James Sep 19 '17 at 08:38
  • The cjk-support of miktex is incomplete. With pdflatex you should normally get errors, with other engines it could be that it falls back e.g. to cyberbit which could explain your output. When I copy the missing files from texlive to miktex it works with pdflatex as expected. – Ulrike Fischer Sep 19 '17 at 08:49

1 Answers1

1

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

xelatex

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

pdflatex

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?).

yudai-nkt
  • 921
  • 1
    The font for the ipxm-version is in miktex but currently doesn't work due to a packaging bug https://github.com/MiKTeX/miktex-packaging/issues/5. – Ulrike Fischer Sep 19 '17 at 09: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