阐明 `\patchcmd` 和 `\@gobble`

阐明 `\patchcmd` 和 `\@gobble`

在下面的代码中,我期望\@gobble替换\@makechapterhead内部\@chapter,从而吞噬其参数(#2),以便禁用相关功能(创建章节标题)。但事实并非如此。为什么不呢?为了进行比较,显示了另一个符合要求的补丁。

\documentclass{report}
% <Commented out until this is fixed---------------------------------------------
% https://tex.stackexchange.com/questions/511782/does-titleps-conflict-with-babel
%\usepackage[T1]{fontenc} % due to warning from babel
%\usepackage[french]{babel}----------------------------------------------------->
\usepackage{lipsum}
\usepackage{titleps}

%==============================================================
% REQUIREMENT: \chapter{<title>} does not display anything
\usepackage{xpatch}
\tracingpatches
\makeatletter
% <PATCH No 1
% *.out: "search pattern found in replacement text"
\patchcmd{\@chapter}{\@makechapterhead}
{\@gobble}%>
%
%% <PATCH No 2
%\patchcmd{\@chapter}
%{\if@twocolumn
%  \@topnewpage[\@makechapterhead{#2}]%
%  \else
%  \@makechapterhead{#2}%
%  \@afterheading
%  \fi}%>
{}
{}
\makeatother%===================================================

\begin{document}
% REQUIREMENT translates here to: Contents\\1 Intro .......... 2
\tableofcontents

\chapter{Intro}

% REQUIREMENT translates here to: 'Chapter 1 \\ Intro' absent from top of the page.
% PATCH No 1: not met
% PATCH No 2: met
\lipsum[1]

% report.cls---------------------------------------------------------------------------
%\newcommand\chapter{\if@openright\cleardoublepage\else\clearpage\fi
%                    \thispagestyle{plain}%
%                    \global\@topnum\z@
%                    \@afterindentfalse
%                    \secdef\@chapter\@schapter}
%\def\@chapter[#1]#2{\ifnum \c@secnumdepth >\m@ne
%                         \refstepcounter{chapter}%
%                         \typeout{\@chapapp\space\thechapter.}%
%                         \addcontentsline{toc}{chapter}%
%                                   {\protect\numberline{\thechapter}#1}%
%                    \else
%                      \addcontentsline{toc}{chapter}{#1}%
%                    \fi
%                    \chaptermark{#1}%
%                    \addtocontents{lof}{\protect\addvspace{10\p@}}%
%                    \addtocontents{lot}{\protect\addvspace{10\p@}}%
%                    \if@twocolumn
%                      \@topnewpage[\@makechapterhead{#2}]%
%                    \else
%                      \@makechapterhead{#2}%
%                      \@afterheading
%                    \fi}
%\def\@makechapterhead#1{%
%  \vspace*{50\p@}%
%  {\parindent \z@ \raggedright \normalfont
%    \ifnum \c@secnumdepth >\m@ne
%        \huge\bfseries \@chapapp\space \thechapter
%        \par\nobreak
%        \vskip 20\p@
%    \fi
%    \interlinepenalty\@M
%    \Huge \bfseries #1\par\nobreak
%    \vskip 40\p@
%  }}
% -------------------------------------------------------------------------------------

\end{document}

镜头-1 镜头-2

答案1

正如@phelype-oleinik 所暗示的:

\documentclass{report}
\usepackage{lipsum}
\usepackage{titleps}

%==============================================================
% REQUIREMENT: \chapter{<title>} does not display anything
\usepackage{xpatch}
%\usepackage{etoolbox}
\tracingpatches
\makeatletter
\patchcmd{\@chapter}{\@makechapterhead}
{\@gobble}
{}
{}
\patchcmd{\@chapter}{\@makechapterhead}
{\@gobble}
{}
{}
\makeatother%===================================================

\begin{document}
% REQUIREMENT translates here to: toc show TOC\\1 Intro .......... 2
\tableofcontents

\chapter{Intro}

\lipsum[1]

\end{document}

相关内容