Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

mlreportgen.dom.WhiteSpace class

Package: mlreportgen.dom
Superclasses:

White space type

Description

Specifies behavior for white space and line breaks in text.

Construction

ws = WhiteSpace(option) applies the specified white space option to white space in a Text or Paragraph object. For PDF, you can specify WhiteSpace only for a Paragraph object.

Input Arguments

expand all

White space behavior, specified as one of these values.

Note

Only 'preserve' and 'normal' affect Word output.

ValueDescription

'preserve'

Preserves spaces and line breaks.

'normal' (default)

For HTML and PDF, removes leading and trailing spaces and collapses multiple spaces within text to a single space, ignoring line breaks.

For Word, removes leading and trailing spaces, ignoring line breaks.

'nowrap'

Sequences of white spaces collapse into a single white space. Text does not wrap to the next line. The text continues on the same line until a <br /> tag is encountered.

'pre'

Preserves white space. Text wraps only on line breaks. Acts like the <pre> tag in HTML.

'pre-line'

Sequences of white spaces collapses into a single white space. Text wraps when necessary and on line breaks.

'pre-wrap'

Preserves white space. Text wraps when necessary and on line breaks.

Output Arguments

expand all

White space type, returned as an mlreportgen.dom.WhiteSpace object.

Properties

expand all

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

Tag for document element, specified as a character vector.

A session-unique ID is generated as part of document element creation. The generated tag has the form CLASS:ID, where CLASS is the class of the element and ID is the value of the Id property of the object. You can specify a tag to replace the generated tag.

For example, to make it easier to identify where an issue occurred during document generation, you can specify your own tag value.

To specify how to handle white space, use one of these values.

ValueDescriptionSupported Output Types

'normal' (default)

For HTML and PDF, removes spaces at beginning and end of text. Multiple spaces within the text collapse to single space.

For Word, removes spaces at beginning and end of text.

All output types

'nowrap'

Sequences of white space collapse into a single white space. Text never wraps to the next line.

HTML

'preserve'

Preserves spaces and line feeds. Acts like the <pre> tag in HTML.

All output types

'pre'

Preserves white space. Text wraps only on line breaks. Acts like the <pre> tag in HTML.

HTML and PDF

'pre-line'

Sequences of white space collapse into a single white space. Text wraps.

HTML and PDF

'pre-wrap'

Preserves white space. Text wraps when necessary and on line breaks

HTML and PDF

Setting the WhiteSpace property adds a corresponding WhiteSpace format object to Style property. Removing the WhiteSpace property setting removes the WhiteSpace object.

Examples

expand all

This example shows the effect of using the 'preserve' option for each of the output formats. In HTML, multiple spaces collapse, but the trailing space is preserved. Preserving the trailing space is useful, for example, when you are creating a chapter title. Typically, you append an autonumber after the text 'Chapter: '. Using 'preserve' keeps the trailing space.

import mlreportgen.dom.*;
doctype = 'html';
d = Document('test',doctype);
open(d);
     
p = Paragraph('This paragraph has extra spaces    and one after the colon: ');
p.Style = {WhiteSpace('preserve')};

append(p,'XX');
append(d,p);
     
close(d);
rptview(d.OutputPath);

This example uses Word output. The multiple spaces do not collapse, and the trailing space is preserved. Try commenting out the WhiteSpace property. The multiple spaces are preserved, but the trailing space is removed.

import mlreportgen.dom.*;
doctype = 'docx';
d = Document('test',doctype);
open(d);
     
p = Paragraph('This paragraph has extra spaces    and one after the colon: ');
p.Style = {WhiteSpace('preserve')};

append(p,'XX');
append(d,p);
     
close(d);
rptview(d.OutputPath);

This example uses PDF output.

import mlreportgen.dom.*;
doctype = 'pdf';
d = Document('test',doctype);
open(d);
     
p = Paragraph('This paragraph has extra spaces    and one after the colon: ');

% p.Style = {WhiteSpace('preserve')};

append(p,'XX');
append(d,p);
     
close(d);
rptview(d.OutputPath);

Was this topic helpful?