This package makes it easy to have one or more customizable tables of contents in Org files. They can be updated manually, or automatically when the file is saved. Links to headings are created compatible with GitHub’s Org renderer.
If you installed from MELPA, you’re done.
Install these required packages:
dashsThen put this file in your load-path, and put this in your init file:
(require 'org-make-toc)A document may have any number of tables of contents (TOCs), each of which may list entries in a highly configurable way.
To make a basic TOC, follow these steps:
- Choose a heading to contain a TOC and move the point to it.
 - Run command 
org-make-toc-insert, which inserts a:CONTENTS:drawer and sets TOC properties. Set theincludeproperty toall. - Run the command 
org-make-tocto update all TOCs in the document. 
Use command org-make-toc-set to change TOC properties for the entry at point with completion.
Here’s a simple document containing a simple TOC:
* Heading
:PROPERTIES:
:TOC:      :include all
:END:
This text appears before the TOC.
:CONTENTS:
- [[#heading][Heading]]
  - [[#subheading][Subheading]]
:END:
This text appears after it.
** Subheading
The :TOC: property is a property list which may set these keys and values.
These keys accept one setting, like :include all:
:includeWhich headings to include in the TOC.allInclude all headings in the document.descendantsInclude the TOC’s descendant headings.siblingsInclude the TOC’s sibling headings.
:depthA number >= 0 indicating a depth relative to this heading. Descendant headings at or above this relative depth are included in TOCs that include this heading.
These keys accept either one setting or a list of settings, like :force depth or :force (depth ignore):
:forceHeading-local settings to override when generating the TOC at this heading.depthOverride:depthsettings.ignoreOverride:ignoresettings.
:ignoreWhich headings, relative to this heading, to exclude from TOCs.descendantsExclude descendants of this heading.siblingsExclude siblings of this heading.thisExclude this heading (not its siblings or descendants).
:localHeading-local settings to ignore when generating TOCs at higher levels.depthIgnore:depthsettings.
See example.org for a comprehensive example of the features described above.
To automatically update a file’s TOC when the file is saved, use the command add-file-local-variable to add org-make-toc to the Org file’s before-save-hook.
Or, you may activate it in all Org buffers like this:
(add-hook 'org-mode-hook #'org-make-toc-mode)Because of the way GitHub renders Org documents and links, it’s not possible to make links which work in both Org itself and the GitHub-rendered HTML unless headings have CUSTOM_ID properties.  If the option org-make-toc-insert-custom-ids is enabled, this package will automatically add them as needed.
Compatibility
- Org 9.3 or later is now required.
 
Additions
- Option 
org-make-toc-insert-custom-idsautomatically addsCUSTOM_IDproperties to headings so links can work on both GitHub-rendered Org files and in Emacs. (Thanks to Fox Kiester.) 
Fixes
- Tolerate whitespace before drawer opening/closing lines. (#15, #17. Thanks to Nicholas Vollmer.)
 - Link-type function called with position as argument. (Fixes occasional bugs with heading IDs.)
 - Mode 
org-make-toc-modenow adds to thebefore-save-hookin the local buffer rather than globally. (#24. Thanks to Akira Komamura.) 
This version is a major rewrite that requires reconfiguring existing TOCs. Please see the usage instructions anew. Users who don’t want to convert to 0.5-style TOCs may continue using version 0.4.
Changes
- TOCs are now contained in 
:CONTENTS:drawers, which allows them to co-exist with entry content and be placed flexibly. - The 
:TOC:property, which contains all TOC settings, is now formatted like a Lisp property list, and the settings have been redesigned to be clearer, more concise, more flexible, and more powerful. 
Additions
- Omit invisible characters from link titles (e.g. Org markup characters like 
=and~). - Option 
org-make-toc-link-type-fnallows choosing GitHub-compatible or regular Org-style links. - Command 
org-make-toc-at-point, which updates the TOC at the current entry. - Optionally place TOC in a 
:CONTENTS:drawer which co-exists with entry content. 
Changes
- Changed no-TOC-node-found error to a message, so e.g. when 
org-make-toc-modeis active in a buffer without a TOC, saving will not signal an error. 
Fixes
- Remove excess indentation from TOC while preserving list structure.
 - Don’t insert a blank line when TOC is empty.
 - Autoload minor mode. (Thanks to Akira Komamura.)
 - Filename prefix order in links. (Thanks to Daniel Kraus.)
 
Fixes
- Use 
cadrinstead ofsecond. 
Additions
- Option 
org-make-toc-filename-prefixto add the filename before the anchor in links. This allows a ToC to refer to entries in another file by manually copying a ToC from one file into another. See issue 2. Thanks to Daniel Kraus. 
Changes
- Minor refactoring.
 
Additions
- Multiple tables of contents are now supported in a single document.
 - Entries’ 
TOCproperty can now also be set to the valuesall,children, andsiblings, which allow tables of contents to be created for only parts of a document.allincludes all entries in a document, including other tables of contents, except ignored entries.childrenincludes only child entries, except ignored entries.siblingsincludes only sibling entries, except ignored entries.
 - The command 
org-make-toc-modetogglesorg-make-tocon thebefore-save-hookin the current buffer. This may be added to the globalorg-mode-hookto activate it in every Org buffer. - The 
examples.orgfile shows an example of all of the options used together in a complex, book-like document. 
Initial release.
This package was inspired by Sergei Nosov’s toc-org package.
Bug reports, feature requests, suggestions — oh my!
GPLv3