1

I want to change the commands of the article/ book class and want to know how sections, especially in the article class but also in the book class, are defined.

I think it is something like this?:

\newcommand\subsection{\@startsection{subsection}{2}{\z@}%
                                     {-3.25ex\@plus -1ex \@minus -.2ex}%
                                     {1.5ex \@plus .2ex}%
                                     {\normalfont\large\bfseries}}

I want to alter them a little bit and add some commands using \renewcommand in a class (.cls) I'm currently writing. Where can I find the other section definitions? Can someone provide a link or the code in an answer?

Vebjorn
  • 1,778
  • 1
    That's the definition of \subsection. All of \(sub(sub))section and \(sub)paragraph have similar definitions (in the LaTeX standard classes, at least), which depend on \@startsection. \chapter and \part, in classes which have them, are different. Here's a description of how \@startsection works, if that's what you're looking for: https://tex.stackexchange.com/a/509474/134574. What exactly do you want to change in the sectioning commands? – Phelype Oleinik Nov 18 '19 at 17:44
  • @PhelypeOleinik I want to add a command I define, which I call \sectioncolor, \subsectioncolor etc. to the last line, so that I can use another command; \setsectioncolor{blue} before \begin{document}, and then all section headlines will appear blue. – Vebjorn Nov 18 '19 at 17:55
  • You can find the definition of @startsection in source2e.pdf (CTAN). The tricky bit is that it has 7 arguments. The first five are shown and the last two are stolen from \section etc. – John Kormylo Nov 18 '19 at 18:46
  • @JohnKormylo yes, but I want to know how \section{} is defined specifically in the article class so it will not appear different when I \renew it. – Vebjorn Nov 18 '19 at 18:58
  • 1
    It would be easier to do that with titlesec. – Bernard Nov 18 '19 at 18:59
  • @Bernard yes, I know. The other reason I want to know is to make other changes as well later, not only color. – Vebjorn Nov 18 '19 at 19:01
  • With titlesec you can change everything that can be done directly, in a simpler way. – Bernard Nov 18 '19 at 19:02
  • You can find that in article.cls (on my computer it is located in the C:\Program Files\MiKTeX 2.9\tex\latex\base folder). – John Kormylo Nov 18 '19 at 19:11

2 Answers2

2

Along these lines?

\newcommand{\subsectioncolor}{...}

\renewcommand\subsection{\@startsection{subsection}{2}{\z@}%
                                 {-3.25ex\@plus -1ex \@minus -.2ex}%
                                 {1.5ex \@plus .2ex}%
                                 {\subsectioncolor\normalfont\large\bfseries}}

but taking due account of how coloring works.

For the code for chapters look in the code for the appropriate class (book, report, memoir, etc)

Peter Wilson
  • 28,066
1

I found the whole article.cls file here (where the sections is defined): https://www.tug.org/svn/texlive/trunk/Master/texmf-dist/tex/latex/base/article.cls?view=co

I do not use a downloaded version of LaTeX, only online (Overleaf) so the command kpsewhere article.cls is no use because the file is not stored on my computer.

Vebjorn
  • 1,778