これをどう診断すべきだったのでしょうか? サードパーティのパッケージの動作を変更するためにフックにコードを挿入するタイミングを把握する

これをどう診断すべきだったのでしょうか? サードパーティのパッケージの動作を変更するためにフックにコードを挿入するタイミングを把握する

この質問は私には非常に混乱しているように思えるので、あなたがそれを理解できるかどうかわかりません。

この問題の解決方法はわかっています(今)。知りたいのは、どのように診断して解決すべきだったかということです。解決には約24時間かかりました(確かに、この問題は私の唯一の仕事ではありませんでした)。問題の切り分けは比較的簡単で、解決策も比較的よく文書化されていたことを考えると、これは長すぎるように思えます。時間がかかったのは、どこ--- あるいは、もっと正確に言えば、いつ置く。

私の実際のコードはもっと複雑ですが、複雑さが増しても問題を見つけるのが難しくなることはありませんでした。

基本的な問題は、1 つ以上の用語集を生成する必要があるものの、glossaries最上位レベルでタイトル、目次エントリ、および改ページを作成しないようにすることです。ただし、glossaries2 つ以上の用語集エントリ セットが 1 つのメイン見出しの下にグループ化されているサブ用語集のタイトルは作成したいと考えています。

すぐに見つかりました:タイトルなしで用語集を印刷するそしてタイトルなしで用語集を印刷する[SE の検索を使用したことを考えると、驚くほど早いです。]

そこで私は次の 23 時間を、いつどこで介入すべきかを考えることに費やしました。

振り返ってみると、複雑だったのは、ドキュメント自体ではなくクラスから介入しようとしていたことでした。ドキュメント\begin{document}内で直接変更を加えると、前後に変更を加えることができますが、どのフックを使用するかは微妙な問題のようです。

までの変更はbegindocument機能しているようですが、 での変更は機能していません。 クラスのbegindocument/after直前での変更は機能しますが、ローカルのみです。の非常に近いところを除いて の後で、 クラスから section コマンドを変更しようとすると失敗するようです。 しかし、も機能しません。\printglossarybegindocument\printglossarycmd/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}?なぜコードをフックに入れる必要があるのでしょうか?以前ドキュメント自体に挿入された場合、タイミングは重要ではないにもかかわらず、フックはありますか?

関連情報