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,您會發現以下兩個實例:

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

這裡是#6切片指令的名稱,因此sectionsubsectionsubsubsectionparagraph或之一subparagraph。在特殊情況下,#6上面section的程式碼說:

如果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}

相關內容