Main Content

mlreportgen.dom.TOC class

Package: mlreportgen.dom

Create placeholder for generating table of contents

Description

Create a placeholder for a document table of contents. When a generated Word document opens, Word replaces the placeholder with a TOC that it generates. Similarly, when a generated HTML document opens in an HTML browser, the browser replaces the placeholder with a TOC that it generates. For PDF, the DOM API replaces the placeholder with a TOC that it generates when outputting the document.

In all cases, the TOC entries consist of the content of paragraphs using the number of heading levels that you specify. For PDF and Word, the TOC placeholder also specifies a leader that fills the space between the content and the page number in the TOC entry.

The mlreportgen.dom.TOC class is a handle class.

Creation

Description

toc = TOC() generates a three-level TOC that uses a dot leader.

toc = TOC(levels) uses the specified number of heading levels.

example

toc = TOC(levels,leader) uses the specified leader.

Input Arguments

expand all

Number of heading levels to use in TOC, specified as a positive integer.

Type of leader to use between title and page number, specified as '.' (i.e., period or dot) or ' ' (a space).

Properties

expand all

Children of this document element, specified as an array of DOM objects. This property is read-only.

Custom attributes of this element, specified as an array of mlreportgen.dom.CustomAttribute objects. Use custom attributes supported by the output format.

ID for this document element, specified as a character vector or string scalar. The DOM generates a session-unique ID when it creates the document element. You can specify your own ID.

Attributes:

GetAccess
public
SetAccess
public
NonCopyable
true

Data Types: char | string

Type of leader to use between title and page number, specified as '.' (i.e., period or dot) or .' ' (a space).

Number of heading levels to use in the TOC, specified as a positive integer.

Parent of this document element, specified as a DOM object. This property is read-only.

Attributes:

GetAccess
public
SetAccess
private
NonCopyable
true

Format objects that specify the format of a document element.

Name of the style to apply from the style sheet, specified as a character vector.

Tag for this document element, specified as a character vector or string scalar.

The DOM generates a session-unique tag as part of the creation of this object. The generated tag has the form CLASS:ID, where CLASS is the object class and ID is the value of the Id property of the object. Specifying your own tag value can help you to identify where an issue occurred during document generation.

Attributes:

GetAccess
public
SetAccess
public
NonCopyable
true

Data Types: char | string

Examples

collapse all

This example adds a table of contents to a document using a TOC object. This document contains three levels of heads—|Heading1|, Heading2, and Heading3. Because the TOC object specifies only two heading levels, Heading3 is not included in the TOC. The leader is a space.

import mlreportgen.dom.*;
d = Document('mydoc','pdf');
open(d);

title = append(d, Paragraph('My TOC Document'));
title.Bold = true;
title.FontSize = '28pt';

toc = append(d,TOC(2,' '));
toc.Style = {PageBreakBefore(true)};

h1 = append(d,Heading1('Chapter 1'));
h1.Style = {PageBreakBefore(true)};
p1 = append(d,Paragraph('Hello World'));

h2 = append(d,Heading2('Section 1.1'));
h2.Style = {PageBreakBefore(true)};
p2 = append(d,Paragraph('Another page'));

h3 = append(d,Heading3('My Subsection 1.1.a'));
p3 = append(d, Paragraph('My Level 3 Heading Text'));

close(d);
rptview(d.OutputPath);

Version History

Introduced in R2016a