Number only certain sections in bookdown

Hello,

I'm working on a bookdown::gitbook, and the pages have lots of 4th, 5th, and 6th level headers. The output from these levels looks rough (e.g. 4.2.4.5.1 Fifth Level Header Example). I'm aware that it's possible to manually suppress the numbering such as in the example below using {-}:

##### Fifth Level Header Example {-}

However, I would like to suppress the numbering at just the 4th, 5th, and 6th level for the entire book. Is there a way to accomplish this? Thanks!

1 Like

First word of advice - using unnumbered header with Bookdown can mess up the TOC or cross reference in those chapters.

But anyway, to do it I think you would need to use Lua filter with Pandoc for that.

Some info about Lua filter and how to use it with Rmd in our R Markdown Cookbook - you'll find also an example in there.

It is not easy at first but it is really powerful to do such thing you are seeking. Your Lua filter would need to do

  • Process Headers
  • Check the number of the Header
  • if 4 5 or 6, then add the unnumberedattributes on the Header
  • return back the header.

This will do programmatically as if you added the class to each header.

We've got some more resource about Lua for Pandoc in the new tool Quarto. That could help.

You'll need to do some try and error to create this filter.

Hope it helps

1 Like

Thanks for the recommendation @cderv! I wasn't aware of Lua--I'll see if I can put together a solution, and add it to my post later on.

1 Like