CTeX-org / ctex-kit

Macro Packages and Scripts for Chinese TeX users
976 stars 124 forks source link

与 ruby 冲突 #510

Open MilkFather opened 4 years ago

MilkFather commented 4 years ago

ctex包与cjk当中的ruby产生了冲突。使用的ctex包的版本为2.5.2 (4819efe),使用了 TeXLive 2020 (具体而言是XeLaTeX),操作系统为macOS 10.15。

如果同时引入ctex和ruby,XeLaTeX在编译文档时将会报错(LaTeX Error: Command \CJKglue already defined.)。如果文档中只含有英文,则报错后仍然可以生成可读的PDF文档;如果文档中含有中文字符,则无法生成文档。

以下是产生错误的一个例子:

%!TEX TS-program=xelatex
\documentclass{article}
\usepackage[UTF8]{ctex}
\usepackage{ruby}
\begin{document}
\ruby{四种脱氧核糖核苷酸}{AGCT}
\end{document}

这是对应的终端输出:

This is XeTeX, Version 3.14159265-2.6-0.999992 (TeX Live 2020) (preloaded format=xelatex)
 restricted \write18 enabled.
entering extended mode
(/Users/kevin/Desktop/folder/ctex-with-ruby.tex
LaTeX2e <2020-02-02> patch level 5
L3 programming layer <2020-05-15> (/usr/local/texlive/2020/texmf-dist/tex/latex/base/article.cls
Document Class: article 2019/12/20 v1.4l Standard LaTeX document class
(/usr/local/texlive/2020/texmf-dist/tex/latex/base/size10.clo)) (/usr/local/texlive/2020/texmf-dist/tex/latex/ctex/ctex.sty (/usr/local/texlive/2020/texmf-dist/tex/latex/l3kernel/expl3.sty (/usr/local/texlive/2020/texmf-dist/tex/latex/l3backend/l3backend-xdvipdfmx.def)) (/usr/local/texlive/2020/texmf-dist/tex/latex/l3packages/xparse/xparse.sty (/usr/local/texlive/2020/texmf-dist/tex/latex/l3packages/xparse/xparse-generic.tex)) (/usr/local/texlive/2020/texmf-dist/tex/latex/l3packages/l3keys2e/l3keys2e.sty) (/usr/local/texlive/2020/texmf-dist/tex/latex/ctex/ctexhook.sty) (/usr/local/texlive/2020/texmf-dist/tex/latex/ctex/ctexpatch.sty) (/usr/local/texlive/2020/texmf-dist/tex/latex/base/fix-cm.sty (/usr/local/texlive/2020/texmf-dist/tex/latex/base/ts1enc.def)) (/usr/local/texlive/2020/texmf-dist/tex/latex/ms/everysel.sty) (/usr/local/texlive/2020/texmf-dist/tex/latex/ctex/config/ctexopts.cfg) (/usr/local/texlive/2020/texmf-dist/tex/latex/ctex/engine/ctex-engine-xetex.def (/usr/local/texlive/2020/texmf-dist/tex/xelatex/xecjk/xeCJK.sty (/usr/local/texlive/2020/texmf-dist/tex/latex/l3packages/xtemplate/xtemplate.sty) (/usr/local/texlive/2020/texmf-dist/tex/latex/fontspec/fontspec.sty (/usr/local/texlive/2020/texmf-dist/tex/latex/fontspec/fontspec-xetex.sty (/usr/local/texlive/2020/texmf-dist/tex/latex/base/fontenc.sty) (/usr/local/texlive/2020/texmf-dist/tex/latex/fontspec/fontspec.cfg))) (/usr/local/texlive/2020/texmf-dist/tex/xelatex/xecjk/xeCJK.cfg))) (/usr/local/texlive/2020/texmf-dist/tex/latex/zhnumber/zhnumber.sty (/usr/local/texlive/2020/texmf-dist/tex/latex/zhnumber/zhnumber-utf8.cfg)) (/usr/local/texlive/2020/texmf-dist/tex/latex/ctex/scheme/ctex-scheme-chinese.def (/usr/local/texlive/2020/texmf-dist/tex/latex/ctex/config/ctex-name-utf8.cfg)) (/usr/local/texlive/2020/texmf-dist/tex/latex/tools/indentfirst.sty) (/usr/local/texlive/2020/texmf-dist/tex/latex/ctex/ctex-c5size.clo) (/usr/local/texlive/2020/texmf-dist/tex/latex/ctex/fontset/ctex-fontset-mac.def (/usr/local/texlive/2020/texmf-dist/tex/latex/ctex/fontset/ctex-fontset-macnew.def

Package fontspec Warning: Font "Songti SC Light" does not contain requested
(fontspec)                Script "CJK".

))) (/usr/local/texlive/2020/texmf-dist/tex/latex/ctex/config/ctex.cfg) (/usr/local/texlive/2020/texmf-dist/tex/latex/cjk/texinput/ruby.sty (/usr/local/texlive/2020/texmf-dist/tex/latex/cjk/texinput/CJK.sty (/usr/local/texlive/2020/texmf-dist/tex/latex/cjk/texinput/mule/MULEenc.sty) (/usr/local/texlive/2020/texmf-dist/tex/latex/cjk/texinput/CJK.enc)

/usr/local/texlive/2020/texmf-dist/tex/latex/cjk/texinput/CJK.sty:809: LaTeX Error: Command \CJKglue already defined.
               Or name \end... illegal, see p.192 of the manual.

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

l.809 ...glue}{\hskip \z@ \@plus .08\baselineskip}

))
No file ctex-with-ruby.aux.
ABD: EverySelectfont initializing macros

LaTeX Warning: Command \selectfont   has changed.
               Check if current package is valid.

/Users/kevin/Desktop/folder/ctex-with-ruby.tex:6: Missing number, treated as zero.
<to be read again> 
                   四
l.6 \ruby{四种脱氧核糖核苷酸}{AGCT}

/Users/kevin/Desktop/folder/ctex-with-ruby.tex:6: Missing number, treated as zero.
<to be read again> 
                   四
l.6 \ruby{四种脱氧核糖核苷酸}{AGCT}

/Users/kevin/Desktop/folder/ctex-with-ruby.tex:6: Missing number, treated as zero.
<to be read again> 
                   脱
l.6 \ruby{四种脱氧核糖核苷酸}{AGCT}

/Users/kevin/Desktop/folder/ctex-with-ruby.tex:6: Missing number, treated as zero.
<to be read again> 
                   脱
l.6 \ruby{四种脱氧核糖核苷酸}{AGCT}

/Users/kevin/Desktop/folder/ctex-with-ruby.tex:6: Missing number, treated as zero.
<to be read again> 
                   核
l.6 \ruby{四种脱氧核糖核苷酸}{AGCT}

/Users/kevin/Desktop/folder/ctex-with-ruby.tex:6: Missing number, treated as zero.
<to be read again> 
                   核
l.6 \ruby{四种脱氧核糖核苷酸}{AGCT}

/Users/kevin/Desktop/folder/ctex-with-ruby.tex:6: Missing number, treated as zero.
<to be read again> 
                   核
l.6 \ruby{四种脱氧核糖核苷酸}{AGCT}

/Users/kevin/Desktop/folder/ctex-with-ruby.tex:6: Missing number, treated as zero.
<to be read again> 
                   核
l.6 \ruby{四种脱氧核糖核苷酸}{AGCT}

/Users/kevin/Desktop/folder/ctex-with-ruby.tex:6: Missing number, treated as zero.
<to be read again> 
                   酸
l.6 \ruby{四种脱氧核糖核苷酸}{AGCT}

/Users/kevin/Desktop/folder/ctex-with-ruby.tex:6: Missing number, treated as zero.
<to be read again> 
                   酸
l.6 \ruby{四种脱氧核糖核苷酸}{AGCT}

(./ctex-with-ruby.aux) )
(\end occurred inside a group at level 1)

### simple group (level 1) entered at line 6 ({)
### bottom level
(see the transcript file for additional information)
No pages of output.
Transcript written on ctex-with-ruby.log.
qinglee commented 4 years ago

ruby 包会引入 CJK 包,CJK 包与 xeCJK 冲突。暂时的解决方法是

%!TEX TS-program=xelatex
\documentclass{article}
\usepackage[UTF8]{ctex}

\ExplSyntaxOn
\ctex_at_begin_package:nn { ruby }
  { \tl_set:cn { ver@CJK.sty } { 9999/99/99 } }
\ctex_at_end_package:nn { ruby }
  { \cs_undefine:c { ver@CJK.sty } }
\ExplSyntaxOff

\usepackage{ruby}

\begin{document}
\ruby{四种脱氧核糖核苷酸}{AGCT}
\end{document}

这样能保证编译不出错。但是由于 CJK 包和 xeCJK 的实现不同,效果并不完全一致,长期目标是完全兼容 ruby。

MilkFather commented 4 years ago

感谢。这个workaround确实有用。

tanukihee commented 4 years ago

xe 下似乎可用 pxrubica……希望将来能在 xpinyin 下扩展 ruby 功能

\documentclass{ctexart}
\usepackage{pxrubrica}

\begin{document}
\ruby{{四种脱氧核糖核苷酸}}{ACGT}
\end{document}

image