4

I'm trying to produce a report using memoir and CJK and seem to keep running into a wall. I was hoping someone on here uses CJK and can point me in the right direction.

First, if I want the entire document to be in Japanese, I can use the \begin{CJK} and \end{CJK} tags immediately after and before the \begin{document} and \end{document} tags respectively, right? The problem is that while I can get Japanese text into the body this way, pdfLaTeX throws an error if I put it in the chapter or title fields. Any ideas why?

Secondly, according to CJK.txt there are three parameters, [<fontencoding>], {<encoding>}, and {<family>}. I'm on Mac OS X and just want to type the Japanese characters directly into my .tex document using the built-in Japanese support (I believe it's called Kotoeri). What encoding and fontencoding settings should I use? The only one I'm having any luck with is UTF-8. Also, "fontencoding" is wrapped in square brackets in the CJK.txt document, but shouldn't they be curly braces? Or do the square brackets indicate it's an optional parameter?

Thirdly, what's a good font family to use, and where should I put the files once I've downloaded them? This example uses the "min" family, but the characters look really sloppy – I'd prefer something that looks more like MS Mincho or Hiragino Mincho Pro. If I have these fonts on my computer (i.e., in Font Book), is that enough for LaTeX to use them, or do I need to download separate font packages for use with LaTeX? If those fonts are accessible, is it enough to enter "Hiragino", for instance, in the "family" parameter of the \begin{CJK} tag, or do I need to do something special?

Finally, have you heard of any incompatibility between the memoir package and CJK?

I had no idea using Japanese in LaTeX was so much work. I guess I'm used to the luxury of a word processor.

Thank you very much for taking the time to look.

1 Answers1

8

While each of your issues can be addressed in detail, I think the easiest solution for you now is to use XeLaTeX. You can then access any Japanese fonts installed on your operating system.

A minimal example:

\documentclass{memoir}

\usepackage{xeCJK}
\setCJKmainfont{Hiragino Mincho Pro}
\setmainfont{Baskerville}

\usepackage[japanese]{babel}
\renewcommand\chaptername{第}
\addtodef{\afterchapternum}{章}{} % Rather an ugly hack

\begin{document}
\tableofcontents
\chapter{手引}
おはようございます!

\begin{figure}[hbt!]
\centering\Large よろしくお願いします。
\caption{はーい}
\end{figure}

\begin{table}[hbt!]
\centering
\begin{tabular}{c c}
\hline
one & 一\\
two & 二\\
\hline
\end{tabular}
\caption{あれ。}
\end{table}

\section{文章}
何これ?

\end{document}

Remember to process the above code with xelatex , not pdflatex.

I was pleasantly surprised to find that there's a japanese localisation file for babel, and it works with XeLaTeX! So you'll get "目次" instead of "Contents" for the ToC heading, etc. You will have to install the japanese package. (Available on TeXLive and hence MacTeX, but not bundled with MikTeX.) However the chapter labels ("Chapter 1") aren't localised, so we'll have to change that ourselves. It takes two commands to do it, since we need the ordinal prefix before the chapter number, and the chapter name after it.

If you prefer to set the localisation strings manually (or if you have problems with \usepackage[japanese]{babel}:

\renewcommand\contentsname{目次}
\renewcommand\figurename{図}
\renewcommand\tablename{表}
...

See section 18.20 (Words and Phrases) in the memoir manual, where there is a list of strings that you can localise by \renewcommanding them.

Alternatively, there is the ptex platform, which is optimised for Japanese typesetting, but I've never tried it out.

Moriambar
  • 11,466
imnothere
  • 14,215
  • Thank you so much! This is so much simpler than what I was trying to do. Also, the sectional headings and ToC labels rendered fine – perhaps the package has been updated? – jefflovejapan Nov 11 '11 at 03:03
  • Ahhh, no, you're right. My mistake. You mentioned that it would be more work – where would I start looking? – jefflovejapan Nov 11 '11 at 03:53
  • 1
    I was pleasantly surprised to discover just now that there's a japanese language file for babel, and it works in XeLaTeX just fine! I've updated my answer accordingly. – imnothere Nov 11 '11 at 07:12
  • たびたびすみませんが、I can't seem to find a link for the japanese.ldf anywhere. I get this error on compile: ! Package babel Error: Language definition file japanese.ldf not found. According to the TeX Live Utility though, I have everything updated. Would you mind telling me where I can get the file, and how I can install it? – jefflovejapan Nov 12 '11 at 00:19
  • 1
    You have to install a package named japanese, it's listed in the TeX Live Utility. If all fails, you can still set the localisation strings manually: see my updated answer. – imnothere Nov 12 '11 at 07:16
  • It worked like a charm. I can't thank you enough! – jefflovejapan Nov 12 '11 at 09:03
  • 1
    Using xeCJK, you can also use \xeCJKcaption{ja} to load ja.cpx which is included in CJK bundle. – Leo Liu Dec 03 '11 at 15:05
  • @LeoLiu Thanks, I didn't know about ja.cpx. However I get a \partformat undefined error, when used with memoir and book classes. Is there any cleaner workaround, instead of issuing a \newcommand\partname{} before loading ja.cpx? – imnothere Dec 03 '11 at 15:21
  • Sorry, I forgot that. \partformat is defined in KOMA-script. \CJKcaption is defined for KOMA-script classes only (e.g. scrartcl). See CJK.txt for more information. – Leo Liu Dec 03 '11 at 15:27
  • +1 tyvm - works great! I wonder how to get Chinese working now: I can't seem to find a babel package for chinese. – kfmfe04 Jan 29 '12 at 06:50
  • 1
    @kfmfe04 Try \documentclass{ctexart} or \documentclass{ctexbook}. :) – imnothere Jan 29 '12 at 07:43