跳到主要内容

CreateMath

根据线性文本字符串创建数学公式。生成的对象可以像文本块一样插入到段落中(例如,通过 ApiParagraph#AddElement 或 ApiParagraph#Push)。

语法​

expression.CreateMath(text, format);

expression - 表示 Api 类的变量。

参数​

名称必需/可选数据类型默认值描述
text必需string以线性文本字符串形式编写的公式。
format可选"unicode" | "latex" | "mathml""unicode"指定线性表示的格式。

返回值​

ApiMath

示例​

在演示文稿中构建数学公式对象,并像文本块一样将其插入到形状的段落中。

// Insert a formula into a shape as if it were a run of text in a presentation.

// Produce a reusable equation object and place it into a shape's paragraph content in a presentation.

const presentation = Api.GetPresentation();
const slide = presentation.GetSlideByIndex(0);
slide.RemoveAllObjects();

const fill = Api.CreateSolidFill(Api.RGB(255, 111, 61));
const stroke = Api.CreateStroke(0, Api.CreateNoFill());
const shape = Api.CreateShape("rect", 300 * 36000, 100 * 36000, fill, stroke);
shape.SetPosition(608400, 1267200);
slide.AddObject(shape);

const paragraph = shape.GetDocContent().GetElement(0);
const math = Api.CreateMath("x^2 + y^2 = z^2", "unicode");
paragraph.AddElement(math);