Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Japanese characters in a latex \section{} cause an error

Tags:

unicode

latex

cjk

I am working on getting Japanese documents created with latex. I have installed the latest version of texlive-2008 which includes CJK.

In my document I have the following:

\documentclass{class}
\usepackage{CJK}
\begin{document}
\begin{CJK*}{UTF8}{min}
\title{[Japanese Characters here 1]}
\maketitle
\section{[Japanese Characters here 2]}
[Japanese Characters here 3]
\end{CJK*}
\end{document}

In the above code there are 3 locations Japanese characters are used.

1 + 3 work fine whereas 2, which contains Japanese characters in a \section{} fails with the following error.

! Argument of \@sect has an extra }.

After some research it turns out this error manifests when you’ve put a fragile command inside a moving argument. A moving argument because section can be moved to a contents page for example.

Does anyone know how to get this to work and why latex thinks Japanese characters are "fragile".

like image 217
Tom Avatar asked Dec 18 '22 06:12

Tom


2 Answers

Sorry to post this as an answer rather than a comment to your answer; I don't have enough rep yet to comment. (EDIT: Now I have enough rep to comment, but I'm not sorry anymore. Thanks Will.)

Your solution of replacing

\section{[Japanese Text]}

with

\section{\texorpdfstring{[Japanese Text]}{}}

suggests that you're using the hyperref package. When you use the hyperref package, any sort of not-totally-boring text (e.g. math) within \section causes a problem because \section is having trouble generating pdf bookmarks. \texorpdfstring allows you to specify how you want the section title to appear in the pdf bookmark. For example, I might write

\section{Calculation of \texorpdfstring{$H_2(\mathcal{X})$}{H\_2(X)}}

if I want the section title to be "Calculation of $H_2(\mathcal{X})$" but I want the pdf bookmark to be "Calculation of H_2(X)".

like image 138
Anton Geraschenko Avatar answered Feb 21 '23 12:02

Anton Geraschenko


You should probably use xetex/xelatex, as it has been created to support unicode. The change is sometimes not easy for already existing documents, though. (xelatex should be included in texlive, it is just different executable to call -- this is how it is done in Debian).

like image 33
liori Avatar answered Feb 21 '23 13:02

liori