1

In the code below I expected \@gobble to replace \@makechapterhead inside \@chapter, and thus gobble its argument (#2), so that the associated feature, make a chapter head, is disabled. But it doesn't. Why not? For comparison, another patch is shown, that meets the requirement.

\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}

Shot-1 Shot-2

  • 1
    Use the \patchcmd twice – Phelype Oleinik Oct 11 '19 at 9:56
  • Not recursive, duh. – Erwann Oct 11 '19 at 10:02
  • Not recursion, but \patchcmd will replace only one instance of the search text, and you have two there. If I'm not mistaken, xpatch or regexpatch (or both) has a command to replace all occurrences. – Phelype Oleinik Oct 11 '19 at 10:04
  • Using it twice does not solve the problem. Tracing says first/second patching is/isn't possible, which tells me the replacement is exhaustive (said differently, recursive). – Erwann Oct 11 '19 at 10:15
  • 2
    @PhelypeOleinik Only regexpatch can do “replace all”. – egreg Oct 18 '19 at 14:07
0

As hinted by @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}
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.