How can I partially re-implement an existing command in Latex?

I have a \documentclass with:

\ProvidesClass{myclass}[My sample class]

When someone uses \subsection{}, I really want to treat it as if they wrote \subsection*{} (no section numbers). In my *.cls I've tried:


But this just causes an infinite loop in Latex and I need to kill the process. I've also tried:


But this simply lets \subsection equal itself and then prints a *

  • 3
    what about just \setcounter{secnumdepth}{0} \setcounter{tocdepth}{0}? – touhami Feb 24 at 11:08
  • sorry, for subsection it's 1. – touhami Feb 24 at 11:15
  • There is no need to redefined macros here, as touhami mentions, just globally disable the section numbering for subsections and below. Setting secnumdepth to 1 tells LaTeX to number down to and including section, but not subsection and below – daleif Feb 24 at 11:15
  • In case you're interested, this explains why your macro doesn't work and Steven's does: Redefine marginpar with \renewcommand (it's basically the same question). – TivV Feb 24 at 11:16

LaTeX has a built-in mechanism for this. Each sectioning command is assigned a level

part −1
chapter 0
section 1
subsection 2
subsubsection 3
paragraph 4
subparagraph 5

A class might not have chapters, but for uniformity the levels are always the same.

You can decide up to what level sectional titles are numbered by setting the counter secnumdepth:


will only number parts, chapters (if provided by the class) and sections.

There is a companion counter, tocdepth, that controls what sectioning levels are listed in the table of contents.

Of course, users can override your setting, if they know about secnumdepth. You can't do much about that.

Even if you decide to go the “redefine” way with


a user can still do


and override your decision.

|improve this answer|||||
\section{Section Name}
\subsection{Subsection Name}

enter image description here

|improve this answer|||||
  • I just had to re-implement \includegraphics to include a default [max width=\textwidth] and this worked perfectly! – Stewart Feb 24 at 12:40

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.