Git Product home page Git Product logo

Comments (12)

Sophanatprime avatar Sophanatprime commented on August 29, 2024 2

问题找到了,原来是 struct 模块 patch thmtools 出现了错误,马上修复。不必麻烦 muzi 了。

from cus.

Sophanatprime avatar Sophanatprime commented on August 29, 2024

\CUSLibraryDelayedUntil 不在 LaTeX3 环境,参数不能有多余的空格。

from cus.

xkwxdyy avatar xkwxdyy commented on August 29, 2024

感谢,不过在更新之后:

\documentclass{ctexbook}
\makeatletter
\@ifundefined{input@path}{\let\input@path\@empty}{}
\g@addto@macro\input@path{{./module}{./library}{./lt3ekeys}{./cus-doc}{./cus-doc-aux}}
\makeatother
\usepackage[
  library={
    math.theorem
  }
]{cus}
\usepackage{amsmath}

\begin{document}
\begin{theorem}
  测试
\end{theorem}
\end{document}

↑上面是主文件,↓是 math.theorem 库更新:

% https://tex.stackexchange.com/a/130655/246645
% amsthm 要在 amsmath 后面载入,否则 \qedhere 会在 align* 中失效
\CUSLibraryDelayedUntil*{amsmath}
\CUSDependency { package = { thmtools } }
\CUSProvideExplLibrary{math.theorem}{\cus@d@te}{\cus@versi@n}{define math theorem environment}


\declaretheorem{theorem}

使用 xelatex 编译后出现报错:

! Extra \else.
\reserved@a ...fter}\UseHook {package/after}\else 
                                                  \ifx \@currext \@clsextens...
l.12 
     
? 

这个 package 的 hook 感觉是 cus 的行为?

from cus.

Sophanatprime avatar Sophanatprime commented on August 29, 2024

3bb230a 已经修复了该问题。

from cus.

xkwxdyy avatar xkwxdyy commented on August 29, 2024

我测试了这个问题没有被修复,仍然是上面的代码,同样的报错

from cus.

xkwxdyy avatar xkwxdyy commented on August 29, 2024

已经 pull 了最新的代码。

\documentclass{ctexbook}
\makeatletter
\@ifundefined{input@path}{\let\input@path\@empty}{}
\g@addto@macro\input@path{{./module}{./library}{./lt3ekeys}{./cus-doc}{./cus-doc-aux}}
\makeatother
\usepackage[
  library={
    math.theorem
  }
]{cus}
\usepackage{amsmath}

\begin{document}
\begin{theorem}
  测试
\end{theorem}
\end{document}
% https://tex.stackexchange.com/a/130655/246645
% amsthm 要在 amsmath 后面载入,否则 \qedhere 会在 align* 中失效
\CUSLibraryDelayedUntil*{amsmath}
\CUSDependency { package = { thmtools } }
\CUSProvideExplLibrary{math.theorem}{\cus@d@te}{\cus@versi@n}{define math theorem environment}


\declaretheorem{theorem}

报错:

! Extra \else.
\reserved@a ...fter}\UseHook {package/after}\else 
                                                  \ifx \@currext \@clsextens...
l.12 
     
? 

from cus.

Sophanatprime avatar Sophanatprime commented on August 29, 2024

cus 无关,或者说问题的根源不在 cus

旧的 \ifx.. \else ..\fi 写法有严重问题,直接把内容放在 \ifx \else \fi 中间可能有不易发现的重大错误,上面这个问题就是该写法导致。

  1. 把 LaTeX 内核 \load@onefile@withoptions 里的上述写法全部替换为 LaTeX3 的 ..TF 写法则不会有此错误。
  2. \declaretheorem 的实现也必然有类似的问题,只有 \load@onefile@withoptions 不会出现错误。

因此 cus 没法解决这个问题。
可以先把定义定理的代码保存起来,然后在 begindocument 等钩子中执行。

from cus.

xkwxdyy avatar xkwxdyy commented on August 29, 2024

可以先把定义定理的代码保存起来

您的意思是把 \declaretheorem 的定义 copy 过来重新 new 一个 cs,并把里面出现的 \ifx \else \fi 换成 LaTeX3 的 ..TF 写法?

然后在 begindocument 等钩子中执行

为什么要在钩子中执行呢?上面定义完之后我把 math.theorem 库里的 \declaretheorem 换成改过的新的 cs,然后就正常定义新定理命题。之后还需要做其它操作?

from cus.

xkwxdyy avatar xkwxdyy commented on August 29, 2024

把 LaTeX 内核 \load@onefile@withoptions 里的上述写法全部替换为 LaTeX3 的 ..TF 写法则不会有此错误。

请问是换成 \cs_if_eq:NNTF 吗?

from cus.

xkwxdyy avatar xkwxdyy commented on August 29, 2024

我改成了

% https://tex.stackexchange.com/a/130655/246645
% amsthm 要在 amsmath 后面载入,否则 \qedhere 会在 align* 中失效
\CUSLibraryDelayedUntil*{amsmath}
\CUSDependency { package = { thmtools } }
\CUSProvideExplLibrary{math.theorem}{\cus@d@te}{\cus@versi@n}{define math theorem environment}

% \AtBeginDocument
% \AddToHook{begindocument/end}
\AddToHook{env/document/begin}
  {
    \def\load@onefile@withoptions#1
      {
        \let\CurrentOption\@empty
        \@reset@ptions
        \def\reserved@a
          {
            \@pass@ptions\@currext{#1}{\@currname}
            \expandafter\let
              \csname opt@\@currpkg@reqd\expandafter\endcsname
              \csname opt@\@currname.\@currext\endcsname
            \expandafter\let
              \csname @raw@opt@\@currpkg@reqd\expandafter\endcsname
              \csname @raw@opt@\@currname.\@currext\endcsname
            \global\expandafter
            \let\csname ver@\@currname.\@currext\endcsname\@empty
            \expandafter\let\csname\@currname.\@currext-h@@k\endcsname\@empty
            \cs_if_eq:NNTF \@currext \@pkgextension
              {
                \UseHook{package/before}
                \UseOneTimeHook{package/\@currname/before}
              }
              {
                \cs_if_eq:NNT \@currext \@clsextension
                  {
                    \UseHook{class/before}
                    \UseOneTimeHook{class/\@currname/before}
                  }
              }
            \InputIfFileExists{\@currpath\@currpkg@reqd}{}
              {\@latex@error
                {The \@cls@pkg\space\@currpkg@reqd\space failed to load}\@ehd}
            \expandafter\let\csname unprocessedoptions-\@currname.\@currext\endcsname
                            \@@unprocessedoptions
            \csname\@currname.\@currext-h@@k\endcsname
            \expandafter\let\csname\@currname.\@currext-h@@k\endcsname
                      \@undefined
            \cs_if_eq:NNTF \@unprocessedoptions \relax
              { \let\@unprocessedoptions\@undefined }
              { \csname unprocessedoptions-\@currname.\@currext\endcsname }
            \expandafter\let
                \csname unprocessedoptions-\@currname.\@currext\endcsname
              \@undefined
            \cs_if_eq:NNTF \@currext\@pkgextension
              {
                \UseOneTimeHook{package/\@currname/after}
                \UseHook{package/after}
              }
              {
                \cs_if_eq:NNT \@currext\@clsextension
                  {
                    \UseOneTimeHook{class/\@currname/after}
                    \UseHook{class/after}
                  }
              }
          }
        \@ifl@aded\@currext\@currname{}{\reserved@a}
      }
  }
\declaretheorem{theorem}

但是还是一样的报错,不知道该 hook 到哪里才行

from cus.

xkwxdyy avatar xkwxdyy commented on August 29, 2024

我整理不出 MWE,因为平时不用 cus 我都是那样定义定理的,不过 cls 都很简单,也没遇到过问题。
我感觉从根源上解决比较好,重定义感觉只是临时之举而且我看了 thmtools 关于 declaretheorem 的源码,有很多个 \ifx,感觉修改起来也很麻烦。我看了一下 thmtools 目前的维护者是 @muzimuzhi,可能麻烦 muzi 看一下这个问题了

from cus.

Sophanatprime avatar Sophanatprime commented on August 29, 2024

重定义 \load@onefile@withoptions 要在放在 cus.sty 最开始,而且任然会存在问题。

经过我的测试,目前问题是由于 \thmt@newtheoremiv 在执行前后的 \currentiflevel 不一致,但是在正常的情况下是一致的,还没有定位到准确原因(应该是发生在 \thmt@newtheorem@predefinition 之中)。

from cus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.