3

I appear to be having a conflict with font encodings. I am currently using LyX 2.1.1 (under Linux Mint 17). I have Chinese text scattered throughout most chapters, but I receive the following error when exporting to PDF:

Use of \@chapter doesn't match its definition

   ...ing{latin9}Pottery Production at Huizui I}

To be specific, as you can see, only the chapter title seems to generate this error. When I change the encoding to UTF8 (Document > Settings > Language), I then get an error with the Chinese text:

...in Ancient China'' {[}\begin{CJK}{GB}{}
                                 Ŵչо\end{CJK... The control sequence at the end of the top line of your error message was never \def'ed.

This was not an issue under LyX 2.0.6, though at the time I used a cumbersome ERT inset; under 2.1.1 I just change the Language to "Chinese" and change the input on my computer to Chinese as well.

Clearly, the issue seems to stem from something with \@chapter, but I don't know why this is suddenly a problem.

Unfortunately, I don't know if I can provide a MWE: this is a multi-chapter dissertation with master and child docs. Still I'm hoping some folks have some ideas that I can try out.

If there are any enterprising folks that want me to send the document to look at, I am happy to do so!

Edit1:

Looking at the source, here is the bit causing trouble:

\usepackage{CJKutf8}

\begin{document} \begin{CJK}{UTF8}{}%

\chapter{\end{CJK}\inputencoding{latin9}Pottery Production at Huizui I}

\inputencoding{latin9}\label{chap:Chapter-4}In this chapter I analyze and discuss the primary data collected from the Huizui site and the

And later, when Chinese is used:

...by Li Wenjie ``A Study of
the Pottery-Making Technology in Ancient China'' \begin{CJK}{GB}{}中国古代制陶工艺研究\end{CJK}\inputencoding{latin9}
 using pottery in the National History Museum collection.

As you can see, the encodings seem to switch back and forth correctly, though the bit of code above

\begin{CJK}{UTF8}{}%

    \chapter{\end{CJK}

Seems strange to me because \chapter ends up "as" CJK.

Edit2:

Actually, that last comment (below) is not entirely true; that unusual coding is not present when I change the encoding (Document>Settings>Language) to "Unicode (utf8)" rather than "Unicode (CJK)(utf8)". However, then the CJK text throws errors as "not found", which is still odd because in the preamble it has this code:

\usepackage[utf8]{inputenc}
\usepackage{CJKutf8}

which I would think covers the CJK text. I think LyX adds this line because it detects that I've used "Chinese" in the document.

Edit 3:

I have now tried a work-around based on egreg's answer below, and changed the beginning code to:

\makeatother

\begin{document}
\begin{CJK}{UTF8}{}%
\end{CJK}\inputencoding{latin9}\chapter{Pottery Production at Huizui I}

\label{chap:Chapter-4}In this chapter I analyze and discuss the primary
data collected from the Huizui site and the archaeometric analysis...

Here, \begin{CJK} is not incorporated into \chapter, but now I get an error for the Chinese text even though I have the encoding set to "Unicode (CJK)(utf8)"!! Makes me think it is actually a problem with the CJK font family as egreg points out. Not sure why mine is set to {GB} rather than {gbsm} which worked previously.

  • \@chapter complains because something is putting the [ at the start of its first argument in braces. You can see such a [ in your second snippet. But it is not possible to see under which circumstances lyx does it and if it is related to the chinese. – Ulrike Fischer Jul 25 '14 at 7:40
  • Thanks Ulrike, that's a start. I include the Chinese text in braces [Zhongguo] to set it apart from conventional asides in parentheses. Could this be causing the problem? Will check it out. – charles Jul 25 '14 at 16:51
  • ***Okay, removing braces and changing encoding to UTF-CJK gives same error as my first example. – charles Jul 25 '14 at 16:55
  • You shouldn't start \begin{CJK} before \chapter and end it in the argument of \chapter: this will leave unbalanced groups. – egreg Jul 25 '14 at 17:45
  • 1
    @scottkosty Was thinking I needed to do just that. Thanks for the link. – charles Jul 26 '14 at 13:35
2

My impression is that LyX is overzealous in doing encoding switching. But

\begin{CJK}{}
\chapter{\end{CJK}\inputencoding{latin9}Something}

is simply wrong code that can't work with any trick whatsoever.

If you plan to use CJKutf8, the document encoding should be UTF-8, of course, and not Latin-9. How to set this up for LyX is beyond my knowledge. The following code works.

\documentclass{book}
\usepackage[utf8]{inputenc}
\usepackage{CJKutf8}

\begin{document}

\chapter{Pottery Production at Huizui I}\label{chap:Chapter-4}

In this chapter I analyze and discuss the primary data collected
from the Huizui site and the \dots

\dots\ by Li Wenjie ``A Study of
the Pottery-Making Technology in Ancient China''
\begin{CJK}{UTF8}{gbsn}中国古代制陶工艺研究\end{CJK}
using pottery in the National History Museum collection.

\end{document}

Note the font family in the argument to \begin{CJK}.

enter image description here

  • The zealous encoding by LyX does seem to be the problem. I cannot understand why it keeps invoking {latin9}, as you'll notice in Edit 1 that after the CJK text, it "switches" back to {latin9}. Must be one of the settings – charles Jul 25 '14 at 20:38
  • @charles I once tried LyX. After no more than half an hour, there was no longer any trace of it on my machine. – egreg Jul 25 '14 at 20:47
  • Yes, I am becoming increasingly frustrated by it, too. I have had to use a fair amount of ERT to format things the way I want. Also, still no support for biblatex, so I cannot use Chinese in my references list... – charles Jul 25 '14 at 21:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.