Git Product home page Git Product logo

Comments (9)

Sophanatprime avatar Sophanatprime commented on August 29, 2024 1

这几种方法都是因为改动太迟了。

现在采用了一种新方法。在需要延迟加载的库最开始加上 \CUSLibraryDelayedUntil{<package>}。这样就能方便配置了。而且在<package> 已经加载完毕的情况下也是有效的。

from cus.

Sophanatprime avatar Sophanatprime commented on August 29, 2024 1

这一功能已经在 v0.0.4f 更新了。

from cus.

Sophanatprime avatar Sophanatprime commented on August 29, 2024

由于 pgf 系列宏包不能在 latex3 环境下正确加载,所以 pgf 和 tcb 库采用延迟加载的方式,在使用 \CUSLoadLibrary 时,不会立刻加载它们,而是通过文件钩子,等到加载完 tikz 和 tcolorbox 宏包后才加载。这是由定义在 cus.sty 文件的 \c__cus_library_delayed_prop 控制,它的键为库名,值为宏包名。

from cus.

xkwxdyy avatar xkwxdyy commented on August 29, 2024

明白了,将 cus.sty 里的

\prop_set_from_keyval:Nn \c__cus_library_delayed_prop 
  { pgf=tikz , tcb=tcolorbox }

改成

\prop_set_from_keyval:Nn \c__cus_library_delayed_prop 
  {
    pgf     = tikz,
    tcb     = tcolorbox,
    pgf_cus = tikz,
    tcb_cus = tcolorbox
  }

就行。

请问除了改 cus.sty 文件源代码,能否通过别的接口来处理呢?我试了一下在 .tex 文件中加入

\ExplSyntaxOn
\prop_gput_from_keyval:Nn \c__cus_library_delayed_prop 
  {
    pgf_cus = tikz,
    tcb_cus = tcolorbox
  }
\ExplSyntaxOff

但好像不起作用,这段设置感觉需要在 cus.sty 里第一次使用 \CUSLoadLibrary 之前加?不知道有没有什么“用户接口”能处理这个需求呢?

from cus.

xkwxdyy avatar xkwxdyy commented on August 29, 2024

但好像不起作用,这段设置感觉需要在 cus.sty 里第一次使用 \CUSLoadLibrary 之前加?不知道有没有什么“用户接口”能处理这个需求呢?

如果加在 \usepackage{cus} 前肯定会报错,找不到 \c__cus_library_delayed_prop 这个变量。

from cus.

xkwxdyy avatar xkwxdyy commented on August 29, 2024

我试了一下用 AddToHook\CUSLoadLibrary 加钩子:

\documentclass{book}
\usepackage[library={pgf_cus}]{cus}
\ExplSyntaxOn
\AddToHook{cmd/CUSLoadLibrary/before}
  {
    \prop_set_from_keyval:Nn \c__cus_library_delayed_prop 
      { 
        pgf     = tikz , 
        tcb     = tcolorbox,
        pgf_cus = tikz,
        tcb_cus = tcolorbox
      }
  }
\ExplSyntaxOff


\begin{document}

test

\end{document}

但这样没有效果,我试了一下把 cus.sty\CUSLoadLibrary 的定义

cus/cus.sty

Lines 260 to 270 in 814e49c

\NewDocumentCommand \CUSLoadLibrary { m O{} O{0000/00/00} }
{
\prop_if_in:NnTF \c__cus_library_delayed_prop {#1}
{
\hook_gput_code:nnn
{ package/ \prop_item:Nn \c__cus_library_delayed_prop {#1} / after }
{ cus/load }
{ \__cus_load_library_real:nnn {#1} {#2} {#3} }
}
{ \__cus_load_library_real:nnn {#1} {#2} {#3} }
}

改成

\NewDocumentCommand \CUSLoadLibrary { m O{} O{0000/00/00} }
  {
    \prop_set_from_keyval:Nn \c__cus_library_delayed_prop 
      { 
        pgf     = tikz , 
        tcb     = tcolorbox,
        pgf_cus = tikz,
        tcb_cus = tcolorbox
      }
    \prop_if_in:NnTF \c__cus_library_delayed_prop {#1}
      {
        \hook_gput_code:nnn 
          { package/ \prop_item:Nn \c__cus_library_delayed_prop {#1} / after }
          { cus/load }
          { \__cus_load_library_real:nnn {#1} {#2} {#3} }
      }
      { \__cus_load_library_real:nnn {#1} {#2} {#3} }
  }

这样可行,但不知道为什么这样用钩子不行呢?有什么好一点的解决办法吗?

from cus.

xkwxdyy avatar xkwxdyy commented on August 29, 2024

还试了 RenewDocumentCommand

\documentclass{book}
\usepackage[library={pgf_cus}]{cus}
\ExplSyntaxOn
\RenewDocumentCommand \CUSLoadLibrary { m O{} O{0000/00/00} }
  {
    \prop_set_from_keyval:Nn \c__cus_library_delayed_prop 
      { 
        pgf     = tikz , 
        tcb     = tcolorbox,
        pgf_cus = tikz,
        tcb_cus = tcolorbox
      }
    \prop_if_in:NnTF \c__cus_library_delayed_prop {#1}
      {
        \hook_gput_code:nnn 
          { package/ \prop_item:Nn \c__cus_library_delayed_prop {#1} / after }
          { cus/load }
          { \__cus_load_library_real:nnn {#1} {#2} {#3} }
      }
      { \__cus_load_library_real:nnn {#1} {#2} {#3} }
  }
\ExplSyntaxOff


\begin{document}

test

\end{document}

也不行

from cus.

xkwxdyy avatar xkwxdyy commented on August 29, 2024

这几种方法都是因为改动太迟了。

现在采用了一种新方法。在需要延迟加载的库最开始加上 \CUSLibraryDelayedUntil{<package>}。这样就能方便配置了。而且在<package> 已经加载完毕的情况下也是有效的。

好的,期待您的更新

from cus.

xkwxdyy avatar xkwxdyy commented on August 29, 2024

这一功能已经在 v0.0.4f 更新了。

感谢,已经测试,本 issue 解决了

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.