Main Content

mlreportgen.dom.LOC class

Package: mlreportgen.dom

List of captions

Description

Use an object of the mlreportgen.dom.LOC class to generate a list of captioned report elements. To generate a list of figures with captions or tables with titles, use objects of the mlreportgen.dom.LOF and mlreportgen.dom.LOT classes, respectively. To generate a list for other types of report elements, such as equations, use an LOC object.

Each list item contains the caption of a report element and links to the caption in the report. In a PDF or Microsoft® Word report, a list item also includes the page number and a leader that fills the space between the caption and page number.

In PDF and Word reports, the list of captions is placed at the location that you specified in the report generation program. In HTML reports, the list of captions is placed in a side panel and has a title that consists of List of followed by the value of the AutoNumberStreamName property with the first letter capitalized.

To include report elements in the list:

  1. Choose a numbering stream name, for example, equation. Set the AutoNumberStreamName property of the LOC object to the numbering stream name.

  2. Create captions or titles for the report elements using mlreportgen.dom.Paragraph objects.

  3. Associate the Paragraph objects with the numbering stream name by using an mlreportgen.dom.AutoNumber object.

The way a list is generated depends on the report type.

  • PDF — The DOM API generates the list during report generation.

  • Word — The DOM API generates a placeholder for the list. To generate the list items, you must update the Word document in your report generation program or in Word. See Update a Table of Contents or Generated List in a Word Document.

  • HTML — The DOM API generates a placeholder for the list. When the report opens in an HTML browser, the browser generates the list.

Note

You can use an LOC object for captions that follow a report element or titles that precede a report element.

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

Class Attributes

ConstructOnLoad
true
HandleCompatible
true

For information on class attributes, see Class Attributes.

Creation

Description

example

LOCObj = mlreportgen.dom.LOC() creates an mlreportgen.dom.LOC object and sets the LeaderPattern property to '.'.

LOCObj = mlreportgen.dom.LOC(leaderPattern) creates an mlreportgen.dom.LOC object and sets the LeaderPattern property to the specified leader pattern.

Properties

expand all

Name of numbering stream, specified as a character vector or string scalar.

Type of leader to use between the caption and the page number, specified as one of these character vectors or string scalars:

  • '.' or 'dots'

  • ' ' or 'space'

This property applies only to PDF reports. Word reports always have a dots leader. HTML reports do not have a leader.

Name of the stylesheet-defined style for formatting the list of captions, specified as a character vector or string scalar.

The style specified by the StyleName property must be defined in the stylesheet of the document or document part to which this list of captions is appended. The specified style defines the appearance of the list of captions in the output document, except for formats that are specified by the Style property of this LOC object. The format objects specified by the Style property override formats defined by the stylesheet.

Formats that define the style of the list of captions, specified as a cell array of DOM format objects. The formats override the corresponding formats defined by the stylesheet style specified by the StyleName property. Formats that do not apply to a list of captions are ignored.

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

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

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

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.

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.

Methods

expand all

Examples

collapse all

This example generates a list of the captions for example code in a report. You can use the same procedure to generate a list of captions for other report elements. This example identifies the captions to include in the list by associating the captions with the automatic numbering stream that has the name example. You can use any name for the numbering stream as long as the name matches the value of the AutoNumberStream property of the mlreportgen.dom.LOC object that represents the list of captions.

Import the DOM API package so that you do not have to use long, fully qualified class names.

import mlreportgen.dom.*

Create a report.

d = Document("DOM Report with List of Captions","pdf");

Create a list of captions placeholder and append it to the report.

locObj = LOC();
locObj.AutoNumberStreamName = "example";
append(d,locObj);
append(d,PageBreak);

Create a paragraph that includes example code.

pr1 = Preformatted("  a = 1;" + newline + "  b = 2;" + newline + "  c = a + b;");
append(d,pr1);

Create a paragraph for the example code caption.

p1 = Paragraph("Example ");

Create an automatic numbering stream with the name example and associate it with the paragraph.

append(p1,AutoNumber("example"));

Increment the counter for the numbering stream.

p1.Style = {CounterInc("example"),WhiteSpace("preserve")};

Append the rest of the caption text to the paragraph and append the paragraph to the report.

append(p1,".");
append(p1," Addition");
append(d,p1);

Create another paragraph that contains example code and a caption for the example code. Associate the example numbering stream with the caption and increment the numbering counter.

pr2 = Preformatted("  a = 1;" + newline + "  b = 2;" + newline + "  c = a * b;");
append(d,pr2);
p2 = Paragraph("Example ");
append(p2,AutoNumber("example"));
p2.Style = {CounterInc("example"),WhiteSpace("preserve")};

Append the rest of the caption text to the paragraph and append the paragraph to the report.

append(p2,".");
append(p2," Multiplication");
append(d,p2);

Close and view the report.

close(d);
rptview(d);

Here is the list of captions in the generated report:

Introduced in R2020b