Main Content

mlreportgen.report.Equation Class

Namespace: mlreportgen.report
Superclasses: mlreportgen.report.Reporter

Equation reporter

Description

Create an equation reporter that adds an equation to a report.

An equation is added to a report as an image of the formatted equation. By default, the image is embedded in an empty, centered paragraph. Optionally, it can be appended in line with other text in a paragraph. The image, and therefore, the equation can be scaled to any size.

The snapshot image of the equation is stored in the temporary folder of the report. When the report is closed, the equation image is copied into the report and, then, the image is deleted from the temporary folder. To prevent the equation image files from being deleted, use the Debug property of the report. See mlreportgen.report.Report.

The mlreportgen.report.Equation class is a handle class.

Class Attributes

HandleCompatible
true

For information on class attributes, see Class Attributes.

Creation

Description

equation = mlreportgen.report.Equation creates an empty equation reporter object. Use the object properties to specify the equation and its formatting.

equation = mlreportgen.report.Equation(markup) formats the equation that is specified by the LaTeX markup for the equation. See the Content property.

example

equation = mlreportgen.report.Equation(Name=Value) sets properties using name-value pairs. You can specify multiple name-value pair arguments in any order.

Properties

expand all

LaTeX markup for the equation, specified as a character vector or string scalar. You can use any LaTeX markup that is supported by the Interpreter property of a MATLAB® text object. See Text Properties.

Data Types: char | string

Font size for the formatted equation, specified as empty, or as a positive integer. If the FontSize property is empty, the font size defaults to 10.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Font color, specified as a character vector or string scalar that contains the color name or equivalent hexadecimal or RGB triplet specification.

The color specification depends on the value of the UseDirectRenderer property. If the property value is true, specify a valid CSS color name, RGB triplet, or hexadecimal value. See https://www.w3.org/TR/2018/REC-css-color-3-20180619/. If the property value is false, specify the color by using a name, short name, RGB triplet, or hexadecimal value as described in the Color property of Text Properties. This table shows how to specify the color red for different values of the UseDirectRenderer property.

UseDirectRenderer ValueNameRGB TripletHexadecimal Code
true"red""rgb(255,0,0)""#FF0000"
false"red" or "r""[1,0,0]""#FF0000"

Data Types: char | string

Name of background color for the formatted equation, specified as empty, or as a character vector or string scalar. If Color is empty, the background color defaults to white. You can use long or short color names. For a list of valid color names, see the Color property in Text Properties.

If the UseDirectRenderer property is true, the BackgroundColor property is ignored.

Data Types: char | string

Display equation in line with text, specified as true or false.

If the DisplayInline property is set to false, the reporter takes an image of the equation, wraps the image in a paragraph, and adds the paragraph to the report. In the report, the equation is on a line by itself. See Add an Equation to a Chapter. Use this option to fill block holes in a template.

If the DisplayInline property is set to true, the equation image is not wrapped in a paragraph. To add the equation to the report, get the equation image by using the getImpl method and then add the image to a paragraph. In the generated report, the equation is in line with the text of a paragraph. See Display Equation in Line with the Text of a Paragraph. Use this option to fill inline holes in a template.

Note

By default, the bottom of an inline image is aligned with the base line of the surrounding text. If an inline equation image is taller than the surrounding text, you can use the mlreportgen.dom.VerticalAlign format to align the image relative to the text base line so that the equation base line matches the text base line. You must experiment to determine the required amount of vertical adjustment.

Data Types: logical

Snapshot image format, specified as a character vector or string scalar. Supported formats are:

  • "png" — PNG image.

  • "emf" — Enhanced metafile. This format is supported only in DOCX output on Windows® platforms.

  • "svg" — Scalable Vector Graphics (SVG).

    Note

    If the UseDirectRenderer property is true, only the PNG image format is supported. If your application requires another format, set the UseDirectRenderer property to false.

Data Types: char | string

Whether to use the direct equation rendering, specified as true or false. If the value is true, the reporter renders an equation directly by using the rendering used by the Live Editor and Simulink® Editor. If the value is false, the reporter uses a figure window to render an equation.

Direct rendering provides better support for equation markup than the support provided by a figure window. With direct rendering, rendered equations have the same appearance as equations in the Live Editor and Simulink annotations.

Direct equation rendering is not available in MATLAB Online.

Direct rendering does not support:

  • Image formats other than PNG.

  • Background colors for equations.

  • The short name for a color, such as "r". You must use a valid CSS color name, such as "red", or the equivalent RGB triplet or hexadecimal color code. See https://www.w3.org/wiki/CSS/Properties/color/keywords.

If your application requires formats other than PNG or a different background color, set the UseDirectRenderer property to false.

Data Types: logical

Source of the template for this reporter, specified in one of these ways:

  • Character vector or string scalar that specifies the path of the file that contains the template for this reporter

  • Reporter or report whose template is used for this reporter or whose template library contains the template for this reporter

  • DOM document or document part whose template is used for this reporter or whose template library contains the template for this reporter

The specified template must be the same type as the report to which you append this report. For example, for a Microsoft® Word report, TemplateSrc must be a Word reporter template. If the TemplateSrc property is empty, this reporter uses the default reporter template for the output type of the report.

Name of the template for this reporter, specified as a character vector or string scalar. The template for this reporter must be in the template library of the template specified by the TemplateSrc property of this reporter.

Data Types: char | string

Hyperlink target for this reporter, specified as a character vector or string scalar that specifies the link target ID, or an mlreportgen.dom.LinkTarget object. A character vector or string scalar value converts to a LinkTarget object. The link target immediately precedes the content of this reporter in the output report.

Methods

expand all

Examples

collapse all

Create a report that includes an equation in a chapter. By default, the reporter adds an image of the equation on a separate line of the report.

% Import the API namespaces
import mlreportgen.report.*

% Create the report and chapter 
% Add an equation as a separate line in the chapter
rpt = Report('equation','docx');
ch = Chapter(Title='Equation');
add(ch,Equation('\int_{0}^{2} x^2\sin(x) dx'));
add(rpt,ch);

% Close and view the report.
close(rpt);
rptview(rpt);

Create a report that includes an equation on a yellow background in 14-pt font.

% Import the API namespaces
import mlreportgen.report.*

% Create the report and chapter 
% Create an Equation reporter and set the FontSize and Color properties
rpt = Report('equation','docx');
ch = Chapter(Title='Equation');
eq = Equation;
eq.Content = '\int_{0}^{2} x^2\sin(x) dx';
eq.FontSize = 14; 
eq.Color = 'blue';
eq.BackgroundColor = 'y';
add(ch,eq);
add(rpt,ch);

% Close and view the report
close(rpt);
rptview(rpt);

Create an equation that is in line with the text of a paragraph by setting the DisplayInline property to true. Then, call the getImpl method to get the image snapshot of the equation. Add the snapshot of the image to the paragraph.

% Import the API namespaces
import mlreportgen.report.*
import mlreportgen.dom.*

% Create report
% Add equation in line with text in a paragraph of the report
rpt = Report("equation","docx");
eq = Equation("\int_{0}^{2} x^2\sin(x) dx");
eq.DisplayInline = true;
img = getImpl(eq,rpt);
img.Style = {VerticalAlign("-5pt")};
p = Paragraph("Here is an inline equation: ");
p.WhiteSpace = 'preserve';
append(p,img);
append(p," More text ");

add(rpt,p);

% Close and view the report
close(rpt);
rptview(rpt);

Version History

Introduced in R2017b

expand all