%META:TOPICINFO{author="ProjectContributor" date="1655468868" format="1.1" version="1"}%
%META:TOPICPARENT{name="Macros"}%
---+ TOC -- table of contents
Shows a Table of Contents that is generated automatically based on headings of a topic. Headings in TopicMarkupLanguage (="---++ text"=) and HTML (="&lt;h2&gt;text&lt;/h2&gt;"=) are taken into account. Any heading text after ="!!"= is excluded from the TOC; for example, write ="---+!! text"= if you do not want to list a header in the TOC
---++ Parameters
    %TABLE{sort="off" columnwidths="30%,50%,20%"}%
    | *Parameter* | *Description* | *Default* |
    | ="TopicName"= | topic name | Current topic |
    | =web= | Name of web | Current web |
    | =depth= | Limit depth of headings shown in TOC | =6= |
    | =title= | Title to appear at top of TOC | |
    | =align=| Align at =left= or =right= side of the page | |
    | =id= | Optional ID in case multiple TOCs are on the page and each TOC needs to be addressable with an anchor link. Allowed characters: =a-zA-Z0-9-_=, no spaces. \
If you don't specify an id, the anchor =foswikiTOC= can be used in a link to the first TOC: =[<nop>[#foswikiTOC][Back to TOC]]= creates [[#foswikiTOC][Back to TOC]]. \
Multiple TOC macros will increment the generated ID. =#foswikiTOC=, =#foswikiTOC2= ... | ="foswikiTOC"= |
---++ Preference Settings
Default settings are defined in %SYSTEMWEB%.%WIKIPREFSTOPIC%, and can be overridden in %LOCALSITEPREFS%:
    <noautolink>
    %TABLE{sort="off" columnwidths="30%,50%,20%"}%
    | *Setting* | *Description* | *Value* |
    | =TOC_MIN_DEPTH= | The first header level to appear in the TOC | %TOC_MIN_DEPTH% |
    | =TOC_MAX_DEPTH= | The last header level to appear in the TOC | %TOC_MAX_DEPTH% |
    | =TOC_TITLE=     | The default TOC title | %TOC_TITLE% |
    | =TOC_HIDE_IF_INCLUDED= | Do not show a TOC if the topic it contains is included in another topic | %TOC_HIDE_IF_INCLUDED% |
    </noautolink>
---++ Examples
<pre class="tml">%<nop>TOC{depth="2"}%
%<nop>TOC{"CompleteDocumentation" web="%<nop>SYSTEMWEB%" title="Contents:"}%</pre>
   See also: Foswiki:Support/HowToCreateATableOfContents
   <div class="foswikiHelp">%T% If multiple headers have the exact same text, the anchors for the 2nd, 3rd etc will be suffixed by _AN1, _AN2 etc so the anchors become unique.

%X% If other topics are included using [[VarINCLUDE][INCLUDE]] then any =headingoffset= specified on the INCLUDE macro will not be seen by =TOC=.
</div>
