mdBook icon indicating copy to clipboard operation
mdBook copied to clipboard

Numbering in section headings

Open thejpster opened this issue 6 years ago • 3 comments

Is it possible to enable numbering of section headings in the output? Without it, the print preview can be a little confusing as you have to rely entirely on the heading styles to work out which are sub-headings and which are top-level headings.

thejpster avatar Jul 16 '18 11:07 thejpster

I agree that this would be a nice feature.

martinjaeger avatar Jun 12 '19 21:06 martinjaeger

Any updates?

your-diary avatar Aug 26 '22 12:08 your-diary

OK, I could customize general.css.

  1. mdbook init --theme to create a new book.

  2. Move theme/ to your existing book directory.

  3. Append the lines below to theme/css/general.css.

body {
    counter-reset: section -1;
}
h1 {
    counter-reset: subsection 0;
}
h1::before {
    counter-increment: section;
    content: counter(section) ": ";
}
h2::before {
    counter-increment: subsection;
    content: counter(section) "." counter(subsection) ": ";
}
  1. Build

your-diary avatar Nov 14 '22 03:11 your-diary