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.
Creation
Description
creates an empty equation reporter object. Use the object properties to specify the
equation and its formatting.equation
= mlreportgen.report.Equation
formats the equation that is specified by the LaTeX markup for the equation. See the
Content
property.equation
= mlreportgen.report.Equation(markup
)
sets properties using name-value pairs. You can specify multiple name-value pair arguments
in any order.equation
= mlreportgen.report.Equation(Name=Value
)
Properties
Content
— LaTeX markup
[]
(default) | character vector | string scalar
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
FontSize
— Font size
[]
(default) | positive integer
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
Color
— Font color
[]
(default) | character vector | string scalar
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 Value | Name | RGB Triplet | Hexadecimal Code |
---|---|---|---|
true | "red" | "rgb(255,0,0)" | "#FF0000" |
false | "red" or "r" | "[1,0,0]" | "#FF0000" |
Data Types: char
| string
BackgroundColor
— Name of background color
[]
(default) | character vector | string scalar
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
DisplayInline
— Display equation in line with text
false
(default) | true
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
SnapshotFormat
— Snapshot image format
"svg"
(default) | "png"
| "emf"
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 istrue
, only the PNG image format is supported. If your application requires another format, set theUseDirectRenderer
property tofalse
.
Data Types: char
| string
UseDirectRenderer
— Whether to use direct equation rendering
false
(default) | true
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
TemplateSrc
— Source of template for reporter
[]
(default) | character vector | string scalar | reporter or report | DOM document or document part
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.
TemplateName
— Name of template for this reporter
character vector | string scalar
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
LinkTarget
— Hyperlink target for this reporter
[]
(default) | character vector | string scalar | mlreportgen.dom.LinkTarget
object
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
Public Methods
mlreportgen.report.Equation.createTemplate | Create equation template |
mlreportgen.report.Equation.customizeReporter | Create custom equation reporter class |
mlreportgen.report.Equation.getClassFolder | Equation class definition file location |
copy | Create copy of reporter object and make deep copies of property values that
reference a reporter, ReporterLayout , or DOM object |
getContentReporter | Get equation content hole reporter |
getSnapshotImage | Create equation image and return file path or data URL |
getImpl | Get implementation of reporter. If the DisplayInline property is set to |
Examples
Add an Equation to a Chapter
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);
Set Equation Font Size and Color
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);
Display Equation in Line with the Text of a Paragraph
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 R2017bR2019b: Word reports with SVG images
Starting in R2019b, Scalable Vector Graphics (SVG) images are supported for Microsoft Word reports. For all report types (HTML, PDF, and Word), the default format for
equation images is SVG. Word reports that contain SVG images require Word 2016 or a later
version. In MATLAB R2019b or a later release, to generate a report with equation images that are
compatible with earlier versions of Word, set the SnapshotFormat
property to a value other than "svg"
. To specify the equation image
format used by default for Word reports in earlier releases of MATLAB, set SnapshotFormat
to:
"emf"
for a Windows platform"png"
for a UNIX® or Mac platform
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)