titlesec はどのようにして sectionbreak を暗黙的に呼び出すのでしょうか?

titlesec はどのようにして sectionbreak を暗黙的に呼び出すのでしょうか?

パッケージはどのように機能しますか?コード内で明示的にtitlesec呼び出したことはありません。しかし、中間で呼び出されているようです。\sectionbreak\sectionbreak\section

\documentclass[fleqn]{report}
\usepackage{titlesec}
\newcommand{\sectionbreak}{\clearpage \setcounter{equation}{0}}

\begin{document}
\section{One}
\begin{equation} 2+2=3.99      \end{equation}
\begin{equation} \pi^2=9.86    \end{equation}

\section{Two}
\begin{equation} E=mc^2        \end{equation}
\begin{equation} v=\frac{e}{t} \end{equation}

\subsection{Two \& One}
\begin{equation} 2+2=22 \end{equation}
\end{document}

答え1

8ページによると、タイトル手動では、\sectionbreak各セクション コマンドの後に適用されます。 のパッケージ コードを調べるとtitlesec.sty、次の 2 つのインスタンスが見つかります。

\@ifundefined{#6break}%
  {\addpenalty{\@secpenalty}}%
  {\csname#6break\endcsname}%

ここで、 は#6セクション コマンドの名前なので、 、 、 のいずれかになりますsectionsubsectionsubsubsectionである特殊なケースでは、上記のコードは次のように解釈されますparagraphsubparagraph#6section

sectionbreak定義されていない場合は\@secpenaltyペナルティを追加し、定義されている場合は追加します\sectionbreak

ファイルをコンパイルするときにこれが起こっていることを確認したい場合は、たとえば、コマンド\typeout{Adding a section break!!!}の定義に追加し\sectionbreak(以下を参照)、ログ ファイルを確認します。ターミナルでファイルをコンパイルし、出力を確認します。

\documentclass[fleqn]{report}
\usepackage{titlesec}
\newcommand{\sectionbreak}{\clearpage \setcounter{equation}{0}\typeout{Adding a section break!!!}}

\begin{document}
\section{One}
\begin{equation} 2+2=3.99      \end{equation}
\begin{equation} \pi^2=9.86    \end{equation}

\section{Two}
\begin{equation} E=mc^2        \end{equation}
\begin{equation} v=\frac{e}{t} \end{equation}

\subsection{Two \& One}
\begin{equation} 2+2=22 \end{equation}
\end{document}

関連情報