6
\documentclass{article}
\usepackage[adobefonts]{ctex}
\usepackage[os=win]{menukeys}
\usepackage{listings}    
\begin{document}
\end{document}

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

(/opt/local/texlive/2014/texmf-dist/tex/latex/adjustbox/adjustbox.sty
(/opt/local/texlive/2014/texmf-dist/tex/latex/xkeyval/xkeyval.sty
(/opt/local/texlive/2014/texmf-dist/tex/generic/xkeyval/xkeyval.tex))
(/opt/local/texlive/2014/texmf-dist/tex/latex/adjustbox/adjcalc.sty)
(/opt/local/texlive/2014/texmf-dist/tex/latex/adjustbox/trimclip.sty
(/opt/local/texlive/2014/texmf-dist/tex/latex/collectbox/collectbox.sty)
(/opt/local/texlive/2014/texmf-dist/tex/latex/adjustbox/tc-xetex.def))
(/opt/local/texlive/2014/texmf-dist/tex/latex/ifoddpage/ifoddpage.sty)
(/opt/local/texlive/2014/texmf-dist/tex/latex/varwidth/varwidth.sty))
(/opt/local/texlive/2014/texmf-dist/tex/latex/relsize/relsize.sty)
(/opt/local/texlive/2014/texmf-dist/tex/latex/catoptions/catoptions.sty)
(/opt/local/texlive/2014/texmf-dist/tex/latex/oberdiek/kvoptions.sty
(/opt/local/texlive/2014/texmf-dist/tex/generic/oberdiek/ltxcmds.sty)
(/opt/local/texlive/2014/texmf-dist/tex/generic/oberdiek/kvsetkeys.sty
(/opt/local/texlive/2014/texmf-dist/tex/generic/oberdiek/infwarerr.sty)
(/opt/local/texlive/2014/texmf-dist/tex/generic/oberdiek/etexcmds.sty
(/opt/local/texlive/2014/texmf-dist/tex/generic/oberdiek/ifluatex.sty)))))
(/opt/local/texlive/2014/texmf-dist/tex/latex/listings/listings.sty
(/opt/local/texlive/2014/texmf-dist/tex/latex/listings/lstmisc.sty)
(/opt/local/texlive/2014/texmf-dist/tex/latex/listings/listings.cfg))
(/opt/local/texlive/2014/texmf-dist/tex/xelatex/xecjk/xeCJK-listings.sty

! 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:

\documentclass{article}
% \usepackage[adobefonts]{ctex}
\usepackage[os=win]{menukeys}
\usepackage{listings}    
\begin{document}
\end{document}

Good Version 2:

\documentclass{article}
\usepackage[adobefonts]{ctex}
% \usepackage[os=win]{menukeys}
\usepackage{listings}    
\begin{document}
\end{document}

Good Version 3:

\documentclass{article}
\usepackage[adobefonts]{ctex}
\usepackage[os=win]{menukeys}
% \usepackage{listings}    
\begin{document}
\end{document}
3
  • 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

10

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

0

You must log in to answer this question.

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