The simplest TeX file above cannot be compiled with xelatex, the errors are:


! LaTeX Error: Option clash for package xeCJK.

See the LaTeX manual or LaTeX Companion for explanation. Type  H
<return>  for immediate help.  ...                                    

l.44 \RequirePackage
                     { listings }

What's the root cause?

Weird Phenomena: Each of the following three versions is OK.

Good Version 1:

% \usepackage[adobefonts]{ctex}

Good Version 2:

% \usepackage[os=win]{menukeys}

Good Version 3:

% \usepackage{listings}    
  • It seems to be the line \usepackage[adobefonts]{ctex}. Unfortunately, I can't find English language documentation for ctex.sty, so I can't help. Mar 30, 2015 at 8:18
  • 3
    did you type h to the prompt as it suggests (if you did it suggests a change to the document to avoid the error) Mar 30, 2015 at 8:43
  • Actually your good version 2 shows the same error on my system. So I’d say menukeys has nothing to do with it. But since it does some changes on how options are handled it is recommended to load it as last (one of the later) package(s).
    – Tobi
    Mar 31, 2015 at 16:38

1 Answer 1


This combination of packages is attempting to load the xeCJK package twice: once on line 11 of ctex-xecjk-engine.def from the ctex package, and then again on line 43 of xeCJK-listings.sty from the listings package. The clash you are getting is that the options are different in each case (the first one specifies [BoldFont,normalindentfirst] while the second gives no options).

You can patch this by editing line 43 of xeCJK-listings.sty (which is in your texmf directory under tex/xelatex/xecjk) to read

\@ifpackageloaded{xeCJK}{}{\RequirePackage { xeCJK }}

which simply doesn't try to reload xeCJK if it's already loaded.

This allows your minimal example to compile, and a simple listing to be included. I should note, though, that I haven't checked whether anything in listings is specifically incompatible with the [BoldFont,normalindentfirst] options to xeCJK. I can't imagine there is, but still, caveat TeXor and all that.

(Edited to note: this patch is specific to listings being loaded second, after ctex. I don't know enough about these packages to advise whether this is the "right" order to load these in and therefore the right place to put the patch, but it does fix the document as specified.)


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .