51

I can't find official documentation for the \@startsection command. I already looked in:

  1. LaTeX Wikibook
  2. LaTeX: Structured document for TEX, 2008
  3. beginLatex — a book that comes with ProTeX
  4. in the files that comes with MikTeX in the folder doc

and Google. I found a lot of sites that show examples and discussions about it but I'd like to find the official help or document.

Caramdir
  • 89,023
  • 26
  • 255
  • 291
mjsr
  • 3,425

6 Answers6

65

The actual command, including its formal definition posted by @JoshLee is contained in the LaTeX 2e source, section 61.2 Sectioning (p 283). It forms part of ltsect.dtx, the bundle containing all sectioning commands for LaTeX. It even includes a pseudo-code interpretation of the actual macro. Here is an extract:

The \@startsection{<name>}{<level>}{<indent>}{<beforeskip>}{<afterskip>}{<style>}*[<altheading>]{<heading>} command is the mother of all the user level sectioning commands. The part after the *, including the * is optional.

  • name: e.g., subsection
  • level: a number, denoting depth of section - e.g., chapter = 0, section = 1, etc.
  • indent: Indentation of heading from left margin
  • beforeskip: Absolute value = skip to leave above the heading. If negative, then paragraph indent of text following heading is suppressed.
  • afterskip: If positive, then skip to leave below heading, else negative of skip to leave to right of run-in heading.
  • style: Commands to set style. Since June 1996 release the last command in this argument may be a command such as \MakeUppercase or \fbox that takes an argument. The section heading will be supplied as the argument to this command. So setting #6 to, say, \bfseries\MakeUppercase would produce bold, uppercase headings.

If * is missing, then increment the counter. If it is present, then there should be no [<altheading>] argument. The command uses the counter secnumdepth. It contains a pointer to the highest section level that is to be numbered.

Werner
  • 603,163
  • Excellent that is exactly what I want. Let's read! – mjsr Oct 17 '11 at 22:06
  • 3
    Can anyone help explain to me the use \@plus and \@minus in this context \@startsection{subexperiment}{2}{\z@} {1ex \@plus 2ex \@minus 0.5ex}{1.3ex \@plus.2ex}{\raggedsection\normalfont\sectfont\nobreak\normalsize\nobreak} {#1} – George Feb 26 '16 at 04:17
  • 2
    @George: \@plus and \@minus are similar to \plus and \minus and refer to glue. See What is glue stretching? – Werner Feb 26 '16 at 04:47
  • It seems @startsection messes up \leftmark and \rightmark. What is the easiest way to prevent this) – Alberto Feb 08 '17 at 19:37
  • @Alberto: In what way? Can you provide a minimal working example (MWE) that replicates your issues? – Werner Feb 09 '17 at 00:08
  • I think this should be some kind of interference from some packages I am using, like bidi... – Alberto Feb 09 '17 at 16:28
  • @Werner, there is no mention to \addcontentsline{toc} as in \@chapter for example. So, how the section goes to contents? – Sigur Feb 21 '19 at 01:53
  • @Sigur: There is \addcontentsline{toc} in \@chapter in book.cls (if you're using \chapters). Also, there is \addcontentsline{toc} in \@sect in latex.ltx (if you're using \sections and below). \@sect is the macro called by \@startsection if you're setting a numbered section. If you're setting an unnumbered section, it calls \@ssect and no ToC entry is set. – Werner Feb 21 '19 at 06:44
  • @Werner, so \@sect is what I have to look for. Thanks. – Sigur Feb 21 '19 at 12:28
19

It’s not a LaTeX command per se (which is why it’s not well documented), but a TeX macro that’s defined in the implementation of LaTeX’s kernel. @Concerned has a good answer, but you can also explore macros in LaTeX’s interactive mode:

~$ latex
**\makeatletter
*\show\@startsection
> \@startsection=macro:
#1#2#3#4#5#6->\if@noskipsec \leavevmode \fi \par \@tempskipa #4\relax
\@afterindenttrue \ifdim \@tempskipa <\z@ \@tempskipa -\@tempskipa \@afterindentfalse \fi
\if@nobreak \everypar {}\else \addpenalty \@secpenalty \addvspace \@tempskipa \fi
\@ifstar {\@ssect {#3}{#4}{#5}{#6}}{\@dblarg {\@sect {#1}{#2}{#3}{#4}{#5}{#6}}}.
Josh Lee
  • 576
  • 1
    Great comment. I didn't know about that. Does it also work after including packages to get more information about in-package defined macros? – Mathias Soeken Feb 19 '10 at 15:07
  • Yep. \section, for example, doesn't exist until you include the document class. – Josh Lee Feb 19 '10 at 15:13
  • 5
    Actually, using texdoc packagename (or texdoc source2e for the kernel) will often give better results, as it also contains clarification for the commands. – Paŭlo Ebermann Oct 13 '11 at 15:02
9

I'd consider the LaTeX companion (second edition) as a very good ressource for this kind of command. It may be not up to date in every aspect, but IMO very much is still valid.

topskip
  • 37,020
  • 1
    It's the second book every LaTeX user should have. The first one should be Lamport's. – Martin Schröder Nov 01 '11 at 22:54
  • And en passant, you will NOT find it in Formatting Information (beginlatex, see http://latex.silmaril.ie/) as that's aimed more at complete beginners, and @startsection is a bit more advanced than that. – Peter Flynn Feb 05 '17 at 14:19
5

look into the main LaTeX file latex.ltx. You'll find it in the tex/latex/base directory, or let kpsewhich find the place:

kpsewhich latex.ltx

For my system:

voss@shania:~> kpsewhich latex.ltx
/usr/local/texlive/2011/texmf-dist/tex/latex/base/latex.ltx

in this file you'll find all definitions.

3

A lot of LaTex's internals can be mastered only by using the source, but have a look at LaTeX 2e for Class and Package Writers.

2

See This discussion on the texhax mailing list for where to find the definition in the LaTeX distribution This link (PDF) has some documentation about it.