CTeX-org / ctex-kit

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

Undefined control sequence error in loading xeCJK with xelatex-dev #707

Closed akiyks closed 6 months ago

akiyks commented 6 months ago

MWE (test.tex):

\documentclass{article}
\usepackage{xeCJK}
\setCJKmainfont{Noto Serif CJK SC}
\begin{document}
中文 \LaTeX 示例。
\end{document}

Running xelatex test.tex works fine, provided "Noto Serif CJK" font is available. Running xelatex-dev test.tex stops with:

This is XeTeX, Version 3.141592653-2.6-0.999996 (TeX Live 2024) (preloaded format=xelatex-dev)
 restricted \write18 enabled.
entering extended mode
(./main.tex
LaTeX2e <2024-06-01> pre-release-1 (develop 2024-3-15 branch)
L3 programming layer <2024-03-14>
(/usr/local/texlive/2024/texmf-dist/tex/latex-dev/base/article.cls
Document Class: article 2024/02/08 v1.4n Standard LaTeX document class
(/usr/local/texlive/2024/texmf-dist/tex/latex-dev/base/size10.clo))
(/usr/local/texlive/2024/texmf-dist/tex/xelatex/xecjk/xeCJK.sty
(/usr/local/texlive/2024/texmf-dist/tex/latex/l3kernel/expl3.sty
(/usr/local/texlive/2024/texmf-dist/tex/latex/l3backend/l3backend-xetex.def))
(/usr/local/texlive/2024/texmf-dist/tex/latex/ctex/ctexhook.sty)
(/usr/local/texlive/2024/texmf-dist/tex/latex/l3packages/xtemplate/xtemplate.st
y)
! Undefined control sequence.
\xeCJKDeclarePunctStyle code ...IfInstanceExistTF 
                                                  {xeCJK/punctuation}{#1}{\_...
l.2976 \xeCJKDeclarePunctStyle { quanjiao } { }

? 

It might well be an intermittent regression in -dev packages, but can someone have a look into this?

muzimuzhi commented 6 months ago

Cause by an upstream problem, see

Closing issue here.

muzimuzhi commented 6 months ago

Ah, \IfInstanceExist(TF) were reintroduced to the kernel in commit latex3/latex2e@41f33bc4 (Re-introduce \IfInstanceExist(TF), 2024-02-15). It's just not included in any public nor dev releases.

https://github.com/latex3/latex3/issues/1514#issuecomment-2014349473

So the problem is already fixed in latest code base (of the LaTeX2e kernel), and what you encountered with xelatex-dev is a temp situation.

akiyks commented 6 months ago

latex3/latex3#1514 (comment)

So the problem is already fixed in latest code base (of the LaTeX2e kernel), and what you encountered with xelatex-dev is a temp situation.

Thank @muzimuzhi for taking the time!

muzimuzhi commented 6 months ago

As a workaround with LaTeX2e 2024-06-01 pre-release 1, you can add definitions of \IfInstanceExist(TF) manually, before loading xeCJK, or even before \documentclass.

\ExplSyntaxOn
\cs_if_exist:NF \IfInstanceExistTF
  {
    \cs_new:Npn \IfInstanceExistTF #1#2
      { \__template_if_instance_exist:nnTF {#1} {#2} }
    \cs_new:Npn \IfInstanceExistT #1#2
      { \__template_if_instance_exist:nnT {#1} {#2} }
    \cs_new:Npn \IfInstanceExistF #1#2
      { \__template_if_instance_exist:nnF {#1} {#2} }
  }
\ExplSyntaxOff

\documentclass{article}
\usepackage{xeCJK}
\setCJKmainfont{Noto Serif CJK SC}
\begin{document}
中文 \LaTeX 示例。
\end{document}
muzimuzhi commented 6 months ago

A more robust workaround which works for both 2023-11-01 and 2024-06-01 pre-release 1 LaTeX2e releases would be

\ExplSyntaxOn
\makeatletter
\bool_lazy_all:nT
  {
    { ! \cs_if_exist_p:N \IfInstanceExistTF } % just in case
    { \str_if_eq_p:ee { \fmtversion } { 2024-06-01 } }
    { \str_if_eq_p:ee { \patch@level } { -1 } }
  }
  {
    \cs_new:Npn \IfInstanceExistTF #1#2
      { \__template_if_instance_exist:nnTF {#1} {#2} }
    \cs_new:Npn \IfInstanceExistT #1#2
      { \__template_if_instance_exist:nnT {#1} {#2} }
    \cs_new:Npn \IfInstanceExistF #1#2
      { \__template_if_instance_exist:nnF {#1} {#2} }
  }
\makeatother
\ExplSyntaxOff

\documentclass{article}
\usepackage{xeCJK}
\setCJKmainfont{Noto Serif CJK SC}
\begin{document}
中文 \LaTeX 示例。
\end{document}

But unfortunately it makes use of LaTeX2e internals.

muzimuzhi commented 6 months ago

FYI, a new pre-release, LaTeX2e 2024-06-02 pre-release 2 is now available from CTAN mirrors, which resolves the problem reported here.