# Generate tags for all types of headlines automatically

Is it possible to create for each headline a tag with the same content (i.e. for all Title, Chapter, Subchapter, Section, Subsection, Subsunsection) automatically?

When using text processing tools like LibreOffice or Word, I always use a stylesheet and I also genreate a table of content (TOC) automatically very often, when a document exceeds a few pages. LibreOffice and Word automatically equip the TOC with hyperlinks from the TOC lines to the corresponding headlines. That is very nice to quickly navigate in the document. Fortunately, such hyperlinks within the document are also inherited to pdf files created from them and the hyperlinks also work in the derived pdf file.

I am looking foreward to generate such tags automatically and also I am looking for a tool to generate a TOC to be put at the beginning of a notebook. But unlike Generating a table of contents I would prefer hyperlinks in the TOC to the headlines instead of page numbers. The hyperlink mechanism in Mma seems to work without reference to a page numnber, so my idea should be feasible.

Has anybody already done something of this kind? (Of course, as in the model of the text processing programs, a TOC with page numbers and hyperlinks to all headlines would even be better).

N.B.: Is there a way to automatically format keywords with a hyperlink "behind " them such that they show up in blue and underliend such that they can easily be recognized in the text?

I wrote some code to do something very similar, though I only wanted to include Sections and Subsections in the table of contents.

The function finds all Sections/Subsections in the notebooks and then appends cell tags to those sections (note, if you have other cell tags this will overwrite them).

It then creates styled hyperlinks pointing to the tags. When clicked they will jump the notebook to the first tag appearance. There are two potential issues with this:

2. The hyperlinks point to a fixed file path, so if the notebook is downloaded and placed somewhere else, this won't work properly.

tableOfContents[notebook_]:=Module[{headerTypes,nb,header,headerCells,tagHeaders},
(* Cell types to include in ToC *)

(* Find cells of the desired type and tag with their names *)
nb=Import[notebook];

(* Export tagged cells *)

• Buttons can solve the fixed filed path problem - Button[sectionName, NotebookLocate[tag], BaseStyle -> {"Hyperlink"}, Appearance -> None]. This command just needs to be executed in the notebook that will hold the table of contents. – hbuchman Feb 14 '18 at 19:13