이것을 어떻게 진단해야 합니까? 타사 패키지 동작을 변경하기 위해 후크에 코드를 삽입할 시기 파악

이것을 어떻게 진단해야 합니까? 타사 패키지 동작을 변경하기 위해 후크에 코드를 삽입할 시기 파악

이 질문은 제게는 매우 혼란스러워 보입니다. 그래서 여러분이 이 질문을 이해하실 수 있을지 확신할 수 없습니다.

나는 (지금) 이 문제를 해결하는 방법을 알고 있습니다. 제가 알고 싶은 것은 어떻게 진단하고 해결했어야 했는지 입니다. 이 문제를 해결하는 데 대략 24시간이 걸렸습니다. (물론 이 문제가 저의 유일한 직업은 아니었습니다.) 문제를 상대적으로 쉽게 분리했고 솔루션이 상대적으로 잘 문서화되어 있다는 점을 고려하면 너무 오랜 시간이 걸린 것 같습니다. 알아내는 데 시간이 걸렸습니다어디---또는 아마도 더 정확하게는,언제그것을 넣어.

내 실제 코드는 다소 복잡하지만 복잡성이 커진다고 해서 문제를 찾는 것이 더 어려워지는 것은 아닙니다.

기본적인 문제는 하나 이상의 용어집을 생성해야 하지만 glossaries최상위 수준에서 제목, 목차 항목 및 페이지 나누기를 생성하지 못하는 것입니다. 하지만 glossaries두 개 이상의 용어집 항목 세트가 하나의 기본 제목 아래 그룹화되는 하위 용어집의 제목을 만들고 싶습니다 .

나는 빨리 찾았습니다:제목 없이 용어집 인쇄그리고제목 없이 용어집 인쇄. [SE의 검색을 사용한 것을 고려하면 매우 빠릅니다.]

그래서 저는 다음 23시간 동안 어디에/언제 개입해야 할지 알아내려고 노력했습니다.

돌이켜보면 문서 자체가 아닌 클래스에서 개입하려던 게 얼마나 복잡한 일이었는지. \begin{document}문서에서 직접 변경하면 전후에 변경이 가능하지만 어떤 후크를 사용할지는 미묘한 문제인 것 같습니다 .

변경된 사항이 begindocument작동하는 것 같습니다. 하나는 begindocument/after그렇지 않습니다. \printglossary수업 직전에 변경한 내용은 작동하지만 로컬에서만 가능합니다. 클래스에서 섹션 명령을 변경하려는 시도는 begindocument매우 가까운 것을 제외하고 는 실패하는 것 같습니다 \printglossary. 그러나 cmd/printglossary/before작동하지 않습니다.

따라서 개입 측면에서 작동하는 곳은 거의 없습니다. 이 특정 장소를 어떻게 찾았어야 했습니까? 특히, 변경이 필요하다는 것을 어떻게 확인할 수 있었습니까?더 일찍아니면 단지훨씬 나중에오히려 내 예상대로조금 나중에?

\begin{filecontents}[overwrite]{\jobname-g1.tex}
\ProvidesFile{\jobname-g1.tex}
\newglossaryentry{a}{name=a,description=A,type=ga}
\newglossaryentry{b}{name=b,description=B,type=gb}
\newglossaryentry{c}{name=c,description=C,type=gc}
\newglossaryentry{m}{name=m,description=M}
\end{filecontents}
\documentclass{book}
\ExplSyntaxOn
% the next line doesn't work
\hook_gput_code:nnn { begindocument / after } { . / my glossaries }
% the next line does work (begindocument/before works, too)
% \hook_gput_code:nnn { begindocument } { . / glossaries }
% the following line also works
% \hook_gput_code:nnn { package/glossaries/after } { . }
{
  \setglossarysection {subsection}
  \renewcommand* \glsclearpage {}
}
\ExplSyntaxOff
\NewDocumentCommand \mything {+m}
{%
  \cleardoublepage
  {\parindent=0pt
    \hrule\par
    {\Huge #1\par}%
    \hrule\par   
  }%
}
\NewDocumentCommand \mywords {ommo}
{% intervening up here somewhere doesn't work
  \mything{#3}%
  \addcontentsline{toc}{section}{#3}%
    \IfValueTF{#4}{%
      % intervening here works, but { cmd/printglossary/before } doesn't
      \printglossary[title={#2},type=#2]%
      \printglossary[title={#4},type=#4]%
    }{%
      \printglossary[title={},type=#2]%
    }
}
\usepackage[nonumberlist,subentrycounter,toc,xindy]{glossaries}
\newglossary[ga-glg]{ga}{ga-gls}{ga-glo}{As} 
\newglossary[gb-glg]{gb}{gb-gls}{gb-glo}{Bs} 
\newglossary[gc-glg]{gc}{gc-gls}{gc-glo}{Cs} 
\setglossarystyle{altlist}
\loadglsentries{\jobname-g1}
\makeglossaries
% Uncommenting the following line works
% \setglossarysection{subsection}
\begin{document}
% uncommenting this line works
% \setglossarysection{subsection}
\tableofcontents

\mything{T}
\gls{a} \gls{b}  \gls{c} \gls{m}

\mywords[b]{ga}{A-B-Words}[gb]

\mywords{gc}{C-Words}

\mywords{main}{M-Words}

\end{document}

예를 들어 후크의 내용을 볼 수 있습니다 begindocument.

-> The hook 'begindocument/after':
> The hook is not declared.
> Code chunks:
>     top-level/myglossaries -> \setglossarysection {subsection}\renewcommand *
\glsclearpage {}
> Document-level (top-level) code:
>     ---
> Extra code for next invocation:
>     ---
> Rules:
>     ---
> Execution order:
>     Not set because the hook is undeclared.
<recently read> }

l.895 \hook_show:n { begindocument/after }

?

-> The hook 'begindocument':
> Code chunks:
>     amsmath -> \reset@strutbox@ \MakeRobust \dddot \MakeRobust \ddddot \mathc
hardef \std@minus \mathcode `\-\relax \mathchardef \std@equal \mathcode `\=\rel
ax \expandafter \let \csname overleftarrow \endcsname \@undefined \expandafter
\let \csname overrightarrow \endcsname \@undefined \MakeRobust \overrightarrow
\MakeRobust \overleftarrow \MakeRobust \overleftrightarrow \MakeRobust \underri
ghtarrow \MakeRobust \underleftarrow \MakeRobust \underleftrightarrow
>     datatool-base -> \@ifundefined {texteuro}{}{\DTLnewcurrencysymbol {\texte
uro }}\@ifundefined {textdollar}{}{\DTLnewcurrencysymbol {\textdollar }}\@ifund
efined {textstirling}{}{\DTLnewcurrencysymbol {\textstirling }}\@ifundefined {t
extyen}{}{\DTLnewcurrencysymbol {\textyen }}\@ifundefined {textwon}{}{\DTLnewcu
rrencysymbol {\textwon }}\@ifundefined {textcurrency}{}{\DTLnewcurrencysymbol {
\textcurrency }}\@ifundefined {euro}{}{\DTLnewcurrencysymbol {\euro }}\@ifundef
ined {yen}{}{\DTLnewcurrencysymbol {\yen }}
>     glossaries -> \ifglsacronym \providecommand *{\printacronyms }[1][]{\prin
tglossary [type=\acronymtype ,##1]}\fi \ifx \gls@codepage \@empty \@ifpackagelo
aded {fontspec}{\def \gls@codepage {utf8}}{}\fi \gls@begindocdefs \@ifpackagelo
aded {amsmath}{\let \gls@if@measuring \@gls@if@measuring }{}\let \gls@org@refst
epcounter \refstepcounter \let \gls@org@label \label \renewcommand *{\@gls@adju
stmode }{\ifvmode \mbox {}\fi }
> Document-level (top-level) code (executed last):
>     ---
> Extra code for next invocation:
>     ---
> Rules:
>     ---
> Execution order:
>     amsmath, datatool-base, glossaries.
<recently read> }

l.896 \hook_show:n { begindocument }
?

-> The hook 'begindocument/before':
> The hook is empty.
<recently read> }

l.897 \hook_show:n { begindocument/before }

?

begindocument/after그러나 이는 기본 설정이 완료된 후 내 코드가 실행되고 있음을 확인하는 것 같습니다 . 이는 이후 문서의 코드를 사용하는 것과 동일해야 한다는 것을 의미 \begin{document}하지만, 후자는 작동하지만 전자는 실패합니다.

그렇다면 후크에 방해할 수 있는 다른 코드가 포함되어 있지 않은 경우 begindocument/after후크에서 실행되는 코드와 이후에 실행되는 코드 는 어떻게 다릅니까 ? \begin{document}코드가 왜더 일찍후크, 문서 자체에 삽입하면 타이밍이 중요하지 않더라도?

관련 정보