افزودن معادلات ریاضی به ارائههای پاورپوینت در جاوااسکریپت
مرور کلی
PowerPoint معادلات را به صورت Office Math Markup Language (OMML) ذخیره میکند. با Aspose.Slides برای Node.js از طریق Java میتوانید همان نوع محتواهای ریاضی را بهصورت برنامهنویسی ایجاد کنید: کسرها، رادیکالها، توابع، حدود، عملگرهای N-ary، ماتریسها، آرایهها و بلوکهای ریاضی قالببندیشده.
در PowerPoint، کاربران معمولاً معادلات را از Insert > Equation اضافه میکنند:

نتیجه یک متن ریاضی قابل ویرایش بر روی اسلاید است:

Aspose.Slides متن ریاضی را از طریق سه شیء اصلی میسازد:
- یک شکل ریاضی که با addMathShape ایجاد میشود، همان شکلی است که معادله را دربردارد.
- MathPortion محتوای ریاضی را داخل فریم متن شکل ذخیره میکند.
- MathParagraph شامل یک یا چند شیء MathBlock است.
بیشتر مثالهای زیر از MathematicalText و متدهای زنجیرهای MathElementBase برای کوتاه و خوانا نگه داشتن کد استفاده میکنند.
برای سناریوهای خروجی MathML، به Export Math Equations from Presentations in Node.js via Java مراجعه کنید.
ایجاد یک معادله
این مثال یک شکل ریاضی ایجاد کرده و تئوری فیثاغورث را اضافه میکند:

let presentation = new aspose.slides.Presentation();
try {
let slide = presentation.getSlides().get_Item(0);
let mathShape = slide.getShapes().addMathShape(20, 20, 700, 120);
let mathParagraph = mathShape.getTextFrame().getParagraphs()
.get_Item(0).getPortions().get_Item(0).getMathParagraph();
let equation = new aspose.slides.MathematicalText("c")
.setSuperscript("2")
.join("=")
.join(new aspose.slides.MathematicalText("a").setSuperscript("2"))
.join("+")
.join(new aspose.slides.MathematicalText("b").setSuperscript("2"));
mathParagraph.add(equation);
presentation.save("pythagorean-theorem.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
presentation.dispose();
}
addMathShape یک شکل ایجاد میکند که از پیش شامل یک پاراگراف ریاضی است. به اولین MathPortion دسترسی پیدا کنید، MathParagraph آن را دریافت کنید و بلوکها یا عناصر ریاضی را به آن اضافه کنید.
اضافهکردن کسرها
از divide برای ایجاد یک کسر استفاده کنید. میتوانید سبک کسر را با MathFractionTypes انتخاب کنید.

let presentation = new aspose.slides.Presentation();
try {
let slide = presentation.getSlides().get_Item(0);
let mathShape = slide.getShapes().addMathShape(20, 20, 700, 100);
let mathParagraph = mathShape.getTextFrame().getParagraphs()
.get_Item(0).getPortions().get_Item(0).getMathParagraph();
let fraction = new aspose.slides.MathematicalText("1")
.divide("x", aspose.slides.MathFractionTypes.Skewed);
mathParagraph.add(new aspose.slides.MathBlock(fraction));
presentation.save("fraction.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
presentation.dispose();
}
برای یک کسر طبقهبندیشده، از MathFractionTypes.Bar استفاده کنید:
let stackedFraction = new aspose.slides.MathematicalText("x + 1").divide("y - 1", aspose.slides.MathFractionTypes.Bar);
اضافهکردن رادیکالها
از radical برای ایجاد رادیکال درجه دوم، سوم یا سایر رادیکالها استفاده کنید. عنصر فعلی به عنوان پایه در میآید و آرگومان به عنوان درجه رادیکال.

let presentation = new aspose.slides.Presentation();
try {
let slide = presentation.getSlides().get_Item(0);
let mathShape = slide.getShapes().addMathShape(20, 20, 700, 100);
let mathParagraph = mathShape.getTextFrame().getParagraphs()
.get_Item(0).getPortions().get_Item(0).getMathParagraph();
let radical = new aspose.slides.MathematicalText("x")
.radical("n");
mathParagraph.add(new aspose.slides.MathBlock(radical));
presentation.save("radical.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
presentation.dispose();
}
اضافهکردن توابع و حدود
از asArgumentOfFunction یا function برای توابعی مانند sin(x), log(x) یا نامهای توابع دلخواه استفاده کنید. برای حدود، lim را در یک MathLimit قرار دهید یا از setLowerLimit استفاده کنید.

let presentation = new aspose.slides.Presentation();
try {
let slide = presentation.getSlides().get_Item(0);
let mathShape = slide.getShapes().addMathShape(20, 20, 700, 100);
let mathParagraph = mathShape.getTextFrame().getParagraphs()
.get_Item(0).getPortions().get_Item(0).getMathParagraph();
let limit = new aspose.slides.MathematicalText("lim")
.setLowerLimit("x\u2192\u221E")
.function("x");
mathParagraph.add(new aspose.slides.MathBlock(limit));
presentation.save("functions-and-limits.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
presentation.dispose();
}
برای نام توابع سفارشی، نام تابع را بهعنوان عنصر فعلی تنظیم کنید:
let customFunction = new aspose.slides.MathematicalText("f").function("x + 1");
اضافهکردن عملگرهای N-ary و انتگرالها
از nary برای جمعها، اتحادیهها، تقاطعها و سایر عملگرهای بزرگ استفاده کنید. برای انتگرالها از integral استفاده کنید. هر دو متد امکان تنظیم حدود پایین و بالا را میدهند.

let presentation = new aspose.slides.Presentation();
try {
let slide = presentation.getSlides().get_Item(0);
let mathShape = slide.getShapes().addMathShape(20, 20, 700, 120);
let mathParagraph = mathShape.getTextFrame().getParagraphs()
.get_Item(0).getPortions().get_Item(0).getMathParagraph();
let summationBase = new aspose.slides.MathematicalText("x")
.setSuperscript("k")
.join(new aspose.slides.MathematicalText("a").setSuperscript("n-k"));
let summation = summationBase.nary(aspose.slides.MathNaryOperatorTypes.Summation, "k=0", "n");
mathParagraph.add(new aspose.slides.MathBlock(summation));
presentation.save("nary-operators.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
presentation.dispose();
}
عملگرهای N-ary برای عملگرهای بزرگ با حدود اختیاری استفاده میشوند. عملگرهای ساده مانند +، - و = معمولاً بهصورت MathematicalText اضافه شده و در عبارت ترکیب میشوند.
برای یک انتگرال، از integral استفاده کنید:
let integralBase = new aspose.slides.MathematicalText("x").join(new aspose.slides.MathematicalText("dx").toBox());
let integral = integralBase.integral(aspose.slides.MathIntegralTypes.Simple, "0", "1");
اضافهکردن ماتریسها
از MathMatrix برای ردیفها و ستونها استفاده کنید. بهطور پیشفرض ماتریسها براکت ندارند؛ بنابراین هنگامی که نیاز به پرانتز، براکت یا کروشه دارید، ماتریس را درون آنها بگذارید.

let presentation = new aspose.slides.Presentation();
try {
let slide = presentation.getSlides().get_Item(0);
let mathShape = slide.getShapes().addMathShape(20, 20, 700, 120);
let mathParagraph = mathShape.getTextFrame().getParagraphs()
.get_Item(0).getPortions().get_Item(0).getMathParagraph();
let matrix = new aspose.slides.MathMatrix(2, 3);
matrix.set_Item(0, 0, new aspose.slides.MathematicalText("1"));
matrix.set_Item(0, 1, new aspose.slides.MathematicalText("x"));
matrix.set_Item(1, 0, new aspose.slides.MathematicalText("x"));
matrix.set_Item(1, 1, new aspose.slides.MathematicalText("2"));
matrix.set_Item(1, 2, new aspose.slides.MathematicalText("y"));
mathParagraph.add(new aspose.slides.MathBlock(matrix));
presentation.save("matrix.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
presentation.dispose();
}
اضافهکردن آرایههای معادلهای
هنگامی که به معادلات همتراز یا پشتهای عمودی از عبارات نیاز دارید، از toMathArray استفاده کنید.

let presentation = new aspose.slides.Presentation();
try {
let slide = presentation.getSlides().get_Item(0);
let mathShape = slide.getShapes().addMathShape(20, 20, 700, 140);
let mathParagraph = mathShape.getTextFrame().getParagraphs()
.get_Item(0).getPortions().get_Item(0).getMathParagraph();
let equationArray = new aspose.slides.MathematicalText("x")
.join("y")
.toMathArray();
mathParagraph.add(new aspose.slides.MathBlock(equationArray));
presentation.save("equation-array.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
presentation.dispose();
}
اضافهکردن توابع مثلثاتی
وقتی آرگومان عنصر فعلی است و نام تابع شناخته شده، از asArgumentOfFunction استفاده کنید.

let presentation = new aspose.slides.Presentation();
try {
let slide = presentation.getSlides().get_Item(0);
let mathShape = slide.getShapes().addMathShape(20, 20, 700, 100);
let mathParagraph = mathShape.getTextFrame().getParagraphs()
.get_Item(0).getPortions().get_Item(0).getMathParagraph();
let cosine = new aspose.slides.MathematicalText("2x")
.asArgumentOfFunction(aspose.slides.MathFunctionsOfOneArgument.Cos);
mathParagraph.add(new aspose.slides.MathBlock(cosine));
presentation.save("trigonometric-function.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
presentation.dispose();
}
اضافهکردن زیرنویسها و بالانویسها
از کمکیهای زیرنویس و بالانویس برای اندیسها و توانها استفاده کنید. وقتی اندیسها باید در سمت چپ پایه ظاهر شوند، از setSubSuperscriptOnTheLeft استفاده کنید.

let presentation = new aspose.slides.Presentation();
try {
let slide = presentation.getSlides().get_Item(0);
let mathShape = slide.getShapes().addMathShape(20, 20, 700, 100);
let mathParagraph = mathShape.getTextFrame().getParagraphs()
.get_Item(0).getPortions().get_Item(0).getMathParagraph();
let scripts = new aspose.slides.MathematicalText("Y")
.setSubSuperscriptOnTheLeft("1", "n");
mathParagraph.add(new aspose.slides.MathBlock(scripts));
presentation.save("subscript-superscript.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
presentation.dispose();
}
اضافهکردن جداکنندهها
از enclose برای قرار دادن یک عبارت داخل جداکنندهها استفاده کنید. میتوانید یک کاراکتر جداکننده برای عبارات شامل چند عنصر نیز تنظیم کنید.

let presentation = new aspose.slides.Presentation();
try {
let slide = presentation.getSlides().get_Item(0);
let mathShape = slide.getShapes().addMathShape(20, 20, 700, 100);
let mathParagraph = mathShape.getTextFrame().getParagraphs()
.get_Item(0).getPortions().get_Item(0).getMathParagraph();
let delimiter = new aspose.slides.MathematicalText("x")
.join("y")
.join("z")
.enclose(java.newChar('<'), java.newChar('>'));
delimiter.setSeparatorCharacter(java.newChar('|'));
mathParagraph.add(new aspose.slides.MathBlock(delimiter));
presentation.save("delimiters.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
presentation.dispose();
}
اضافهکردن جعبهٔ حاشیهای
وقتی معادله خود باید داخل یک قاب باشد، از toBorderBox استفاده کنید.

let presentation = new aspose.slides.Presentation();
try {
let slide = presentation.getSlides().get_Item(0);
let mathShape = slide.getShapes().addMathShape(20, 20, 700, 100);
let mathParagraph = mathShape.getTextFrame().getParagraphs()
.get_Item(0).getPortions().get_Item(0).getMathParagraph();
let boxedEquation = new aspose.slides.MathematicalText("a")
.setSuperscript("2")
.join("=")
.join(new aspose.slides.MathematicalText("b").setSuperscript("2"))
.join("+")
.join(new aspose.slides.MathematicalText("c").setSuperscript("2"))
.toBorderBox();
mathParagraph.add(new aspose.slides.MathBlock(boxedEquation));
presentation.save("border-box.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
presentation.dispose();
}
گروهبندی عبارات
از group برای قرار دادن یک کاراکتر گروهبندی بالا یا پایین یک عبارت استفاده کنید. برای برچسبگذاری عبارات گروهبندیشده میتوانید یک حد اضافه کنید.

let presentation = new aspose.slides.Presentation();
try {
let slide = presentation.getSlides().get_Item(0);
let mathShape = slide.getShapes().addMathShape(20, 20, 700, 120);
let mathParagraph = mathShape.getTextFrame().getParagraphs()
.get_Item(0).getPortions().get_Item(0).getMathParagraph();
let grouped = new aspose.slides.MathematicalText("x + y")
.group(java.newChar('\u23DF'), aspose.slides.MathTopBotPositions.Bottom, aspose.slides.MathTopBotPositions.Top)
.setLowerLimit("any text");
mathParagraph.add(new aspose.slides.MathBlock(grouped));
presentation.save("grouped-terms.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
presentation.dispose();
}
قالببندی عناصر ریاضی
از کمکیهای قالببندی فقط در جایی استفاده کنید که فرمول را واضحتر میکند. برای مثال، overbar یک نوار بالای عنصر ریاضی میگذارد.

let presentation = new aspose.slides.Presentation();
try {
let slide = presentation.getSlides().get_Item(0);
let mathShape = slide.getShapes().addMathShape(20, 20, 700, 100);
let mathParagraph = mathShape.getTextFrame().getParagraphs()
.get_Item(0).getPortions().get_Item(0).getMathParagraph();
let overbar = new aspose.slides.MathematicalText("ABC").overbar();
mathParagraph.add(new aspose.slides.MathBlock(overbar));
presentation.save("overbar.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
presentation.dispose();
}
مرجع سریع
| کار | API اصلی |
|---|---|
| ایجاد متن ریاضی | MathematicalText |
| ترکیب عناصر | join |
| ایجاد کسرها | divide |
| افزودن بالانویس یا زیرنویس | setSuperscript, setSubscript |
| افزودن توابع | function, asArgumentOfFunction |
| افزودن رادیکالها | radical |
| افزودن حدود | setLowerLimit, setUpperLimit |
| افزودن اسکریپتهای سمت چپ | setSubSuperscriptOnTheLeft |
| افزودن جمعها و انتگرالها | nary, integral |
| افزودن ماتریسها | MathMatrix |
| افزودن آرایههای معادلهای | toMathArray |
| افزودن جداکنندهها | enclose |
| افزودن نوارها و قابها | overbar, toBorderBox |
| گروهبندی عبارات | group |
سوالات متداول
آیا میتوانم یک معادله موجود در PowerPoint را ویرایش کنم؟
بله. ارائه را باز کنید، شکل حاوی MathPortion را پیدا کنید، MathParagraph آن را دریافت کنید و بلوکهای ریاضی در آن پاراگراف را بهروزرسانی کنید.
آیا معادلات بهصورت ریاضی قابل ویرایش در PowerPoint ذخیره میشوند؟
بله. هنگام ذخیره به فرمت PPTX، Aspose.Slides معادله را به عنوان محتوای ریاضی Office قابل ویرایش مینویسد.
آیا میتوانم معادلات را به LaTeX صادر کنم؟
Aspose.Slides معادلات ریاضی را به MathML صادر میکند. اگر به LaTeX نیاز دارید، ابتدا به MathML صادر کنید و سپس با ابزارهایی که از دیالکت LaTeX هدف پشتیبانی میکنند، MathML را به LaTeX تبدیل کنید.