Tambahkan Persamaan Matematika ke Presentasi PowerPoint dalam C++
Ikhtisar
PowerPoint menyimpan persamaan sebagai Office Math Markup Language (OMML). Dengan Aspose.Slides untuk C++, Anda dapat membuat jenis konten matematika yang sama secara programatis: pecahan, radikal, fungsi, batas, operator N-ary, matriks, array, dan blok matematika berformat.
Di PowerPoint, pengguna biasanya menambahkan persamaan dari Insert > Equation:

Hasilnya adalah teks matematika yang dapat diedit pada slide:

Aspose.Slides membangun teks matematika tersebut melalui tiga objek utama:
- Sebuah bentuk matematika, dibuat dengan AddMathShape, adalah bentuk yang berisi persamaan.
- MathPortion menyimpan konten matematika di dalam bingkai teks bentuk.
- MathParagraph berisi satu atau lebih objek MathBlock.
Sebagian besar contoh di bawah ini menggunakan MathematicalText dan metode fluent dari IMathElement untuk menjaga kode tetap singkat dan mudah dibaca.
Untuk skenario ekspor MathML, lihat Ekspor Persamaan Matematika dari Presentasi di C++.
Buat Persamaan
Contoh ini menggunakan AddMathShape untuk membuat bentuk matematika dan menambahkan teorema Pythagoras:

#include <DOM/IAutoShape.h>
#include <DOM/IParagraph.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ITextFrame.h>
#include <DOM/MathText/IMathBlock.h>
#include <DOM/MathText/IMathParagraph.h>
#include <DOM/MathText/IMathSuperscriptElement.h>
#include <DOM/MathText/MathPortion.h>
#include <DOM/MathText/MathematicalText.h>
#include <DOM/Presentation.h>
#include <Export/SaveFormat.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace Aspose::Slides::MathText;
auto presentation = System::MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);
auto mathShape = slide->get_Shapes()->AddMathShape(20.0f, 20.0f, 700.0f, 120.0f);
auto mathPortion = System::ExplicitCast<MathPortion>(mathShape->get_TextFrame()->get_Paragraph(0)->get_Portion(0));
auto mathParagraph = mathPortion->get_MathParagraph();
auto equation = System::MakeObject<MathematicalText>(u"c")
- >SetSuperscript(u"2")
- >Join(u"=")
- >Join(System::MakeObject<MathematicalText>(u"a")->SetSuperscript(u"2"))
- >Join(u"+")
- >Join(System::MakeObject<MathematicalText>(u"b")->SetSuperscript(u"2"));
mathParagraph->Add(equation);
presentation->Save(u"pythagorean-theorem.pptx", SaveFormat::Pptx);
presentation->Dispose();
Note
AddMathShape membuat sebuah bentuk yang sudah berisi paragraf matematika. Akses MathPortion pertama, panggil get_MathParagraph, dan tambahkan blok matematika atau elemen matematika ke dalamnya.Tambahkan Pecahan
Gunakan Divide untuk membuat sebuah pecahan. Anda dapat memilih gaya pecahan dengan MathFractionTypes.

#include <DOM/IAutoShape.h>
#include <DOM/IParagraph.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ITextFrame.h>
#include <DOM/MathText/IMathParagraph.h>
#include <DOM/MathText/MathBlock.h>
#include <DOM/MathText/MathFractionTypes.h>
#include <DOM/MathText/MathPortion.h>
#include <DOM/MathText/MathematicalText.h>
#include <DOM/Presentation.h>
#include <Export/SaveFormat.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace Aspose::Slides::MathText;
auto presentation = System::MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);
auto mathShape = slide->get_Shapes()->AddMathShape(20.0f, 20.0f, 700.0f, 100.0f);
auto mathPortion = System::ExplicitCast<MathPortion>(mathShape->get_TextFrame()->get_Paragraph(0)->get_Portion(0));
auto mathParagraph = mathPortion->get_MathParagraph();
auto fraction = System::MakeObject<MathematicalText>(u"1")
- >Divide(u"x", MathFractionTypes::Skewed);
mathParagraph->Add(System::MakeObject<MathBlock>(fraction));
presentation->Save(u"fraction.pptx", SaveFormat::Pptx);
presentation->Dispose();
Untuk pecahan bertumpuk, gunakan MathFractionTypes::Bar:
#include <DOM/MathText/MathFractionTypes.h>
#include <DOM/MathText/MathematicalText.h>
using namespace Aspose::Slides::MathText;
auto stackedFraction = System::MakeObject<MathematicalText>(u"x + 1")->Divide(u"y - 1", MathFractionTypes::Bar);
Tambahkan Radikal
Gunakan Radical untuk membuat akar kuadrat, akar kubik, atau akar lainnya. Elemen saat ini menjadi basis, dan argumen menjadi derajat.

#include <DOM/IAutoShape.h>
#include <DOM/IParagraph.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ITextFrame.h>
#include <DOM/MathText/IMathParagraph.h>
#include <DOM/MathText/MathBlock.h>
#include <DOM/MathText/MathPortion.h>
#include <DOM/MathText/MathematicalText.h>
#include <DOM/Presentation.h>
#include <Export/SaveFormat.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace Aspose::Slides::MathText;
auto presentation = System::MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);
auto mathShape = slide->get_Shapes()->AddMathShape(20.0f, 20.0f, 700.0f, 100.0f);
auto mathPortion = System::ExplicitCast<MathPortion>(mathShape->get_TextFrame()->get_Paragraph(0)->get_Portion(0));
auto mathParagraph = mathPortion->get_MathParagraph();
auto radical = System::MakeObject<MathematicalText>(u"x")
- >Radical(u"n");
mathParagraph->Add(System::MakeObject<MathBlock>(radical));
presentation->Save(u"radical.pptx", SaveFormat::Pptx);
presentation->Dispose();
Tampilkan atau Sembunyikan Derajat Akar Kuadrat
Akar kuadrat dapat menampilkan angka 2 secara eksplisit atau menggunakan notasi √x konvensional. Gunakan IMathRadical::set_HideDegree untuk beralih antara kedua bentuk. Kedua cara mempertahankan derajat 2 dan radikand x dalam persamaan yang dapat diedit.

Contoh ini menyimpan akar kuadrat yang sama dua kali. Pada visible-degree.pptx angka 2 terlihat. Pada hidden-degree.pptx angka 2 tersembunyi.
#include <DOM/IAutoShape.h>
#include <DOM/IParagraph.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ITextFrame.h>
#include <DOM/MathText/IMathRadical.h>
#include <DOM/MathText/IMathParagraph.h>
#include <DOM/MathText/MathBlock.h>
#include <DOM/MathText/MathPortion.h>
#include <DOM/MathText/MathematicalText.h>
#include <DOM/Presentation.h>
#include <Export/SaveFormat.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace Aspose::Slides::MathText;
auto presentation = System::MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);
auto radicand = System::MakeObject<MathematicalText>(u"x");
auto radical = radicand->Radical(u"2");
auto block = System::MakeObject<MathBlock>(radical);
auto mathShape = slide->get_Shapes()->AddMathShape(20.0f, 20.0f, 200.0f, 100.0f);
auto mathPortion = System::ExplicitCast<MathPortion>(mathShape->get_TextFrame()->get_Paragraph(0)->get_Portion(0));
auto mathParagraph = mathPortion->get_MathParagraph();
mathParagraph->Add(block);
radical->set_HideDegree(false);
presentation->Save(u"visible-degree.pptx", SaveFormat::Pptx);
radical->set_HideDegree(true);
presentation->Save(u"hidden-degree.pptx", SaveFormat::Pptx);
presentation->Dispose();
Tambahkan Fungsi dan Batas
Gunakan AsArgumentOfFunction atau Function untuk fungsi seperti sin(x), log(x), atau nama fungsi khusus. Untuk batas, letakkan lim dalam sebuah MathLimit atau gunakan SetLowerLimit.

#include <DOM/IAutoShape.h>
#include <DOM/IParagraph.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ITextFrame.h>
#include <DOM/MathText/IMathLimit.h>
#include <DOM/MathText/IMathParagraph.h>
#include <DOM/MathText/MathBlock.h>
#include <DOM/MathText/MathPortion.h>
#include <DOM/MathText/MathematicalText.h>
#include <DOM/Presentation.h>
#include <Export/SaveFormat.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace Aspose::Slides::MathText;
auto presentation = System::MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);
auto mathShape = slide->get_Shapes()->AddMathShape(20.0f, 20.0f, 700.0f, 100.0f);
auto mathPortion = System::ExplicitCast<MathPortion>(mathShape->get_TextFrame()->get_Paragraph(0)->get_Portion(0));
auto mathParagraph = mathPortion->get_MathParagraph();
auto limit = System::MakeObject<MathematicalText>(u"lim")
- >SetLowerLimit(u"x→∞")
- >Function(u"x");
mathParagraph->Add(System::MakeObject<MathBlock>(limit));
presentation->Save(u"functions-and-limits.pptx", SaveFormat::Pptx);
presentation->Dispose();
Untuk nama fungsi khusus, jadikan nama fungsi sebagai elemen saat ini dan panggil Function dengan argumennya:
#include <DOM/MathText/MathematicalText.h>
using namespace Aspose::Slides::MathText;
auto customFunction = System::MakeObject<MathematicalText>(u"f")->Function(u"x + 1");
Tambahkan Operator N-ary dan Integral
Gunakan Nary untuk penjumlahan, union, irisan, dan operator besar lainnya. Gunakan Integral untuk integral. Kedua metode memungkinkan Anda mengatur batas bawah dan atas.

#include <DOM/IAutoShape.h>
#include <DOM/IParagraph.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ITextFrame.h>
#include <DOM/MathText/IMathParagraph.h>
#include <DOM/MathText/IMathSuperscriptElement.h>
#include <DOM/MathText/MathBlock.h>
#include <DOM/MathText/MathNaryOperatorTypes.h>
#include <DOM/MathText/MathPortion.h>
#include <DOM/MathText/MathematicalText.h>
#include <DOM/Presentation.h>
#include <Export/SaveFormat.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace Aspose::Slides::MathText;
auto presentation = System::MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);
auto mathShape = slide->get_Shapes()->AddMathShape(20.0f, 20.0f, 700.0f, 120.0f);
auto mathPortion = System::ExplicitCast<MathPortion>(mathShape->get_TextFrame()->get_Paragraph(0)->get_Portion(0));
auto mathParagraph = mathPortion->get_MathParagraph();
auto summationBase = System::MakeObject<MathematicalText>(u"x")
- >SetSuperscript(u"k")
- >Join(System::MakeObject<MathematicalText>(u"a")->SetSuperscript(u"n-k"));
auto summation = summationBase->Nary(MathNaryOperatorTypes::Summation, u"k=0", u"n");
mathParagraph->Add(System::MakeObject<MathBlock>(summation));
presentation->Save(u"nary-operators.pptx", SaveFormat::Pptx);
presentation->Dispose();
Operator N-ary digunakan untuk operator besar dengan batas opsional. Operator sederhana seperti +, -, dan = biasanya ditambahkan sebagai MathematicalText dan digabungkan ke dalam ekspresi.
Untuk integral, gunakan Integral:
#include <DOM/MathText/IMathBlock.h>
#include <DOM/MathText/IMathBox.h>
#include <DOM/MathText/IMathElement.h>
#include <DOM/MathText/MathIntegralTypes.h>
#include <DOM/MathText/MathematicalText.h>
using namespace Aspose::Slides::MathText;
auto integralBase = System::MakeObject<MathematicalText>(u"x")->Join(System::MakeObject<MathematicalText>(u"dx")->ToBox());
auto integral = integralBase->Integral(MathIntegralTypes::Simple, u"0", u"1");
Tambahkan Matriks
Gunakan MathMatrix untuk baris dan kolom. Matriks tidak menyertakan kurung secara default, jadi balut matriks ketika Anda memerlukan tanda kurung, kurung siku, atau kurung kurawal.

#include <DOM/IAutoShape.h>
#include <DOM/IParagraph.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ITextFrame.h>
#include <DOM/MathText/IMathBlock.h>
#include <DOM/MathText/IMathElement.h>
#include <DOM/MathText/IMathParagraph.h>
#include <DOM/MathText/MathBlock.h>
#include <DOM/MathText/MathMatrix.h>
#include <DOM/MathText/MathPortion.h>
#include <DOM/MathText/MathematicalText.h>
#include <DOM/Presentation.h>
#include <Export/SaveFormat.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace Aspose::Slides::MathText;
auto presentation = System::MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);
auto mathShape = slide->get_Shapes()->AddMathShape(20.0f, 20.0f, 700.0f, 120.0f);
auto mathPortion = System::ExplicitCast<MathPortion>(mathShape->get_TextFrame()->get_Paragraph(0)->get_Portion(0));
auto mathParagraph = mathPortion->get_MathParagraph();
auto matrix = System::MakeObject<MathMatrix>(2, 3);
matrix->idx_set(0, 0, System::MakeObject<MathematicalText>(u"1"));
matrix->idx_set(0, 1, System::MakeObject<MathematicalText>(u"x"));
matrix->idx_set(1, 0, System::MakeObject<MathematicalText>(u"x"));
matrix->idx_set(1, 1, System::MakeObject<MathematicalText>(u"2"));
matrix->idx_set(1, 2, System::MakeObject<MathematicalText>(u"y"));
mathParagraph->Add(System::MakeObject<MathBlock>(matrix));
presentation->Save(u"matrix.pptx", SaveFormat::Pptx);
presentation->Dispose();
Sunting Matriks yang Ada
Misalkan pelajaran aljabar linier dimulai dengan matriks koefisien dalam matrix.pptx, yang disimpan oleh contoh sebelumnya. Untuk latihan berikutnya, pertahankan persamaan pertama, ganti yang kedua dengan dua persamaan baru, dan revisi kumpulan variabel. Buka matriks yang ada melalui IMathMatrix untuk mempertahankan koefisien yang masih berlaku.

Indeks baris dan kolom dimulai dari nol dan mengacu pada matriks pada setiap pemanggilan. Menyisipkan baris sebelum indeks 1 memindahkan baris kedua asli ke indeks 2. Menyisipkan setelah indeks 2 kemudian menambahkan sebuah baris. Menghapus baris 2 menghilangkan persamaan kedua asli dan memindahkan baris yang ditambahkan naik satu posisi. Kolom bergeser dengan cara yang sama.
#include <DOM/IAutoShape.h>
#include <DOM/IParagraph.h>
#include <DOM/IPortion.h>
#include <DOM/ISlide.h>
#include <DOM/ITextFrame.h>
#include <DOM/MathText/IMathBlock.h>
#include <DOM/MathText/IMathElement.h>
#include <DOM/MathText/IMathMatrix.h>
#include <DOM/MathText/IMathParagraph.h>
#include <DOM/MathText/IMathPortion.h>
#include <DOM/MathText/MathHorizontalAlignment.h>
#include <DOM/MathText/MathematicalText.h>
#include <DOM/Presentation.h>
#include <Export/SaveFormat.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace Aspose::Slides::MathText;
auto presentation = System::MakeObject<Presentation>(u"matrix.pptx");
auto shape = System::ExplicitCast<IAutoShape>(presentation->get_Slide(0)->get_Shape(0));
auto portion = System::ExplicitCast<IMathPortion>(shape->get_TextFrame()->get_Paragraph(0)->get_Portion(0));
auto block = portion->get_MathParagraph()->idx_get(0);
auto matrix = System::ExplicitCast<IMathMatrix>(block->idx_get(0));
matrix->InsertRowBefore(1);
matrix->InsertRowAfter(2);
matrix->DeleteRow(2);
matrix->InsertColumnBefore(1);
matrix->InsertColumnAfter(3);
matrix->DeleteColumn(3);
// Sel baru awalnya null. Atur koefisien tidak nol terlebih dahulu.
matrix->idx_set(1, 0, System::MakeObject<MathematicalText>(u"12"));
matrix->idx_set(1, 1, System::MakeObject<MathematicalText>(u"1"));
matrix->idx_set(2, 2, System::MakeObject<MathematicalText>(u"10"));
matrix->idx_set(2, 3, System::MakeObject<MathematicalText>(u"1"));
for (auto row = 0; row < matrix->get_RowCount(); ++row)
{
for (auto column = 0; column < matrix->get_ColumnCount(); ++column)
{
if (matrix->idx_get(row, column) == nullptr)
matrix->idx_set(row, column, System::MakeObject<MathematicalText>(u"0"));
}
}
matrix->SetColumnAlignment(0, MathHorizontalAlignment::Left);
matrix->SetColumnsAlignment(1, 3, MathHorizontalAlignment::Right);
presentation->Save(u"updated-matrix.pptx", SaveFormat::Pptx);
presentation->Dispose();
SetColumnAlignment menyelaraskan kolom pertama ke kiri. SetColumnsAlignment menyelaraskan tiga kolom berturut-turut ke kanan, dimulai dari indeks 1. Pada updated-matrix.pptx, matriks memiliki tiga persamaan dan empat variabel. Koefisien baris pertama asli 1 dan x kini muncul di kolom pertama dan ketiga.

Tambahkan Array Persamaan
Gunakan ToMathArray ketika Anda membutuhkan persamaan yang diratakan atau tumpukan vertikal ekspresi.

#include <DOM/IAutoShape.h>
#include <DOM/IParagraph.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ITextFrame.h>
#include <DOM/MathText/IMathParagraph.h>
#include <DOM/MathText/MathBlock.h>
#include <DOM/MathText/MathPortion.h>
#include <DOM/MathText/MathematicalText.h>
#include <DOM/Presentation.h>
#include <Export/SaveFormat.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace Aspose::Slides::MathText;
auto presentation = System::MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);
auto mathShape = slide->get_Shapes()->AddMathShape(20.0f, 20.0f, 700.0f, 140.0f);
auto mathPortion = System::ExplicitCast<MathPortion>(mathShape->get_TextFrame()->get_Paragraph(0)->get_Portion(0));
auto mathParagraph = mathPortion->get_MathParagraph();
auto equationArray = System::MakeObject<MathematicalText>(u"x")
- >Join(u"y")
- >ToMathArray();
mathParagraph->Add(System::MakeObject<MathBlock>(equationArray));
presentation->Save(u"equation-array.pptx", SaveFormat::Pptx);
presentation->Dispose();
Ratakan Array dengan Elemen Sekitar
IMathArray::set_BaseJustification mengendalikan perataan vertikal sebuah array relatif terhadap elemen matematika di sampingnya. Contoh di bawah membandingkan perataan dengan baris pertama, tengah array, dan baris terakhir.
Contoh berikut membuat tiga array identik, masing-masing dengan tiga baris dan elemen tetangga A= dan =B. Semua teks matematika menggunakan Cambria Math ukuran 24 poin. Hanya perataan array yang berubah.
#include <system/array.h>
#include <system/console.h>
#include <drawing/color.h>
#include <DOM/IAutoShape.h>
#include <DOM/IParagraph.h>
#include <DOM/IParagraphFormat.h>
#include <DOM/IPortion.h>
#include <DOM/IPortionFormat.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ITextFrame.h>
#include <DOM/Fonts/FontData.h>
#include <DOM/MathText/IMathParagraph.h>
#include <DOM/MathText/MathArray.h>
#include <DOM/MathText/MathBlock.h>
#include <DOM/MathText/MathJustification.h>
#include <DOM/MathText/MathPortion.h>
#include <DOM/MathText/MathVerticalAlignment.h>
#include <DOM/MathText/MathRowSpacingRule.h>
#include <DOM/MathText/MathematicalText.h>
#include <DOM/Presentation.h>
#include <Export/SaveFormat.h>
#include <DOM/FillType.h>
#include <DOM/IColorFormat.h>
#include <DOM/IFillFormat.h>
#include <DOM/ILineFormat.h>
#include <DOM/ISlideSize.h>
#include <DOM/ITextFrameFormat.h>
#include <DOM/ShapeType.h>
#include <DOM/SlideSizeScaleType.h>
#include <DOM/TextAnchorType.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace Aspose::Slides::MathText;
auto createText = [](System::String value)
{
auto text = System::MakeObject<MathematicalText>(value);
text->get_Format()->set_FontHeight(24);
auto font = System::MakeObject<FontData>(u"Cambria Math");
text->get_Format()->set_LatinFont(font);
return text;
};
auto presentation = System::MakeObject<Presentation>();
presentation->get_SlideSize()->SetSize(780, 200, SlideSizeScaleType::DoNotScale);
auto slide = presentation->get_Slide(0);
MathVerticalAlignment alignments[] = {MathVerticalAlignment::Top, MathVerticalAlignment::Center, MathVerticalAlignment::Bottom};
System::String labels[] = {u"Top", u"Center", u"Bottom"};
for (auto i = 0; i < 3; i++)
{
auto label = slide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, 20 + i * 260, 10, 240, 30);
label->get_FillFormat()->set_FillType(FillType::NoFill);
label->get_LineFormat()->get_FillFormat()->set_FillType(FillType::NoFill);
label->get_TextFrame()->set_Text(labels[i]);
auto labelFormat = label->get_TextFrame()->get_Paragraph(0)->get_Portion(0)->get_PortionFormat();
labelFormat->set_FontHeight(16);
labelFormat->get_FillFormat()->set_FillType(FillType::Solid);
labelFormat->get_FillFormat()->get_SolidFillColor()->set_Color(System::Drawing::Color::get_Black());
auto mathShape = slide->get_Shapes()->AddMathShape(20 + i * 260, 60, 240, 130);
mathShape->get_TextFrame()->get_TextFrameFormat()->set_AnchoringType(TextAnchorType::Top);
auto mathPortion = System::ExplicitCast<MathPortion>(mathShape->get_TextFrame()->get_Paragraph(0)->get_Portion(0));
auto mathParagraph = mathPortion->get_MathParagraph();
mathParagraph->set_Justification(MathJustification::LeftJustified);
auto rows = System::MakeArray<System::SharedPtr<IMathElement>>({createText(u"x+y=3"), createText(u"x-y=1"), createText(u"x=2")});
auto equationArray = System::MakeObject<MathArray>(rows);
equationArray->set_BaseJustification(alignments[i]);
auto leftText = createText(u"A=");
auto rightText = createText(u"=B");
auto equation = System::MakeObject<MathBlock>(leftText)->Join(equationArray)->Join(rightText);
mathParagraph->Add(equation);
}
presentation->Save(u"equation-array-alignment.pptx", SaveFormat::Pptx);
presentation->Dispose();
Perbandingan berikut menampilkan presentasi yang disimpan di PowerPoint. Perhatikan posisi A= dan =B di samping setiap array.

Konfigurasi Jarak Baris
set_RowSpacingRule memilih aturan jarak untuk baris dalam array. set_RowSpacing memberikan nilai numerik untuk aturan jarak eksplisit dan diabaikan oleh aturan preset.
Untuk jarak tepat, nilai diukur dalam poin. Untuk jarak proporsional, diukur dalam setengah baris: nilai 3 dalam contoh menunjukkan 1,5 baris. Panggil kedua setter saat menentukan nilai eksplisit; mengubah nilai numerik saja tidak memilih aturan jarak.
Contoh di bawah menyimpan lima presentasi dengan persamaan, perataan, dan pengaturan font yang sama. Tiga pertama menggunakan preset; dua terakhir menunjukkan nilai eksplisit.
#include <system/array.h>
#include <system/console.h>
#include <drawing/color.h>
#include <DOM/IAutoShape.h>
#include <DOM/IParagraph.h>
#include <DOM/IParagraphFormat.h>
#include <DOM/IPortion.h>
#include <DOM/IPortionFormat.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ITextFrame.h>
#include <DOM/Fonts/FontData.h>
#include <DOM/MathText/IMathParagraph.h>
#include <DOM/MathText/MathArray.h>
#include <DOM/MathText/MathBlock.h>
#include <DOM/MathText/MathJustification.h>
#include <DOM/MathText/MathPortion.h>
#include <DOM/MathText/MathVerticalAlignment.h>
#include <DOM/MathText/MathRowSpacingRule.h>
#include <DOM/MathText/MathematicalText.h>
#include <DOM/Presentation.h>
#include <Export/SaveFormat.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace Aspose::Slides::MathText;
auto createText = [](System::String value)
{
auto text = System::MakeObject<MathematicalText>(value);
text->get_Format()->set_FontHeight(24);
auto font = System::MakeObject<FontData>(u"Cambria Math");
text->get_Format()->set_LatinFont(font);
return text;
};
struct ArraySettings
{
MathRowSpacingRule rule;
uint32_t spacing;
System::String name;
};
ArraySettings settings[] =
{
{MathRowSpacingRule::SingleLineGap, 0, u"SingleLineGap"},
{MathRowSpacingRule::OneAndAHalfLineGap, 0, u"OneAndAHalfLineGap"},
{MathRowSpacingRule::TwoLineGap, 0, u"TwoLineGap"},
{MathRowSpacingRule::Exactly, 20, u"Exactly"},
{MathRowSpacingRule::Multiple, 3, u"Multiple"}
};
for (const auto& setting : settings)
{
auto fileName = u"equation-array-" + setting.name + u".pptx";
auto presentation = System::MakeObject<Presentation>();
auto mathShape = presentation->get_Slide(0)->get_Shapes()->AddMathShape(20, 20, 600, 300);
auto paragraph = mathShape->get_TextFrame()->get_Paragraph(0);
paragraph->get_ParagraphFormat()->set_SpaceBefore(0);
paragraph->get_ParagraphFormat()->set_SpaceAfter(0);
auto mathPortion = System::ExplicitCast<MathPortion>(paragraph->get_Portion(0));
auto mathParagraph = mathPortion->get_MathParagraph();
mathParagraph->set_Justification(MathJustification::LeftJustified);
auto rows = System::MakeArray<System::SharedPtr<IMathElement>>({createText(u"x+y=3"), createText(u"x-y=1"), createText(u"x=2")});
auto equationArray = System::MakeObject<MathArray>(rows);
equationArray->set_BaseJustification(MathVerticalAlignment::Center);
equationArray->set_RowSpacingRule(setting.rule);
equationArray->set_RowSpacing(setting.spacing);
auto leftText = createText(u"A=");
auto rightText = createText(u"=B");
auto equation = System::MakeObject<MathBlock>(leftText)->Join(equationArray)->Join(rightText);
mathParagraph->Add(equation);
presentation->Save(fileName, SaveFormat::Pptx);
presentation->Dispose();
}
Jarak baris array terpisah dari jarak paragraf. set_SpaceBefore dan set_SpaceAfter menambahkan ruang di sekitar paragraf yang berisi, bukan di antara baris array. Demikian juga, IMathParagraph::set_Justification memposisikan seluruh paragraf matematika secara horizontal; tidak menggantikan pengaturan perataan vertikal array.
Tambahkan Fungsi Trigonometri
Gunakan AsArgumentOfFunction ketika argumen adalah elemen saat ini dan nama fungsi diketahui.

#include <DOM/IAutoShape.h>
#include <DOM/IParagraph.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ITextFrame.h>
#include <DOM/MathText/IMathParagraph.h>
#include <DOM/MathText/MathBlock.h>
#include <DOM/MathText/MathFunctionsOfOneArgument.h>
#include <DOM/MathText/MathPortion.h>
#include <DOM/MathText/MathematicalText.h>
#include <DOM/Presentation.h>
#include <Export/SaveFormat.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace Aspose::Slides::MathText;
auto presentation = System::MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);
auto mathShape = slide->get_Shapes()->AddMathShape(20.0f, 20.0f, 700.0f, 100.0f);
auto mathPortion = System::ExplicitCast<MathPortion>(mathShape->get_TextFrame()->get_Paragraph(0)->get_Portion(0));
auto mathParagraph = mathPortion->get_MathParagraph();
auto cosine = System::MakeObject<MathematicalText>(u"2x")
- >AsArgumentOfFunction(MathFunctionsOfOneArgument::Cos);
mathParagraph->Add(System::MakeObject<MathBlock>(cosine));
presentation->Save(u"trigonometric-function.pptx", SaveFormat::Pptx);
presentation->Dispose();
Tambahkan Subskrip dan Superskrip
Gunakan pembantu subskrip dan superskrip untuk indeks dan pangkat. Ketika indeks harus muncul di sisi kiri basis, gunakan SetSubSuperscriptOnTheLeft.

#include <DOM/IAutoShape.h>
#include <DOM/IParagraph.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ITextFrame.h>
#include <DOM/MathText/IMathParagraph.h>
#include <DOM/MathText/MathBlock.h>
#include <DOM/MathText/MathPortion.h>
#include <DOM/MathText/MathematicalText.h>
#include <DOM/Presentation.h>
#include <Export/SaveFormat.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace Aspose::Slides::MathText;
auto presentation = System::MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);
auto mathShape = slide->get_Shapes()->AddMathShape(20.0f, 20.0f, 700.0f, 100.0f);
auto mathPortion = System::ExplicitCast<MathPortion>(mathShape->get_TextFrame()->get_Paragraph(0)->get_Portion(0));
auto mathParagraph = mathPortion->get_MathParagraph();
auto scripts = System::MakeObject<MathematicalText>(u"Y")
- >SetSubSuperscriptOnTheLeft(u"1", u"n");
mathParagraph->Add(System::MakeObject<MathBlock>(scripts));
presentation->Save(u"subscript-superscript.pptx", SaveFormat::Pptx);
presentation->Dispose();
Tambahkan Pembatas
Gunakan Enclose untuk menempatkan sebuah ekspresi di dalam pembatas. Anda juga dapat mengatur karakter pemisah untuk ekspresi pembatas yang berisi beberapa elemen.

#include <DOM/IAutoShape.h>
#include <DOM/IParagraph.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ITextFrame.h>
#include <DOM/MathText/IMathParagraph.h>
#include <DOM/MathText/MathBlock.h>
#include <DOM/MathText/MathPortion.h>
#include <DOM/MathText/MathematicalText.h>
#include <DOM/Presentation.h>
#include <Export/SaveFormat.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace Aspose::Slides::MathText;
auto presentation = System::MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);
auto mathShape = slide->get_Shapes()->AddMathShape(20.0f, 20.0f, 700.0f, 100.0f);
auto mathPortion = System::ExplicitCast<MathPortion>(mathShape->get_TextFrame()->get_Paragraph(0)->get_Portion(0));
auto mathParagraph = mathPortion->get_MathParagraph();
auto delimiter = System::MakeObject<MathematicalText>(u"x")
- >Join(u"y")
- >Join(u"z")
- >Enclose(u'<', u'>', u'|');
mathParagraph->Add(System::MakeObject<MathBlock>(delimiter));
presentation->Save(u"delimiters.pptx", SaveFormat::Pptx);
presentation->Dispose();
Ukuran dan Perataan Pembatas
Berikan true ke set_GrowToMatchOperandHeight agar tanda kurung tumbuh mengelilingi operand tinggi, atau false agar tetap pada ukuran normal. set_DelimiterShape menerima salah satu dari dua nilai MathDelimiterShape. Centered menempatkan tanda kurung di tengah sumbu matematika, yang melintasi tengah tanda sama dengan. Match menyelaraskan mereka dengan konten yang dibungkus. Kedua pengaturan hanya memengaruhi pembatas. Ekspresi di dalamnya tetap sama.
Contoh menempatkan pecahan di eksponen x sehingga ekspresi meluas lebih tinggi di atas garis dasar daripada di bawahnya. Semua empat persamaan menggunakan tanda kurung dan pengaturan font yang sama.
#include <DOM/IAutoShape.h>
#include <DOM/IParagraph.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ITextFrame.h>
#include <DOM/MathText/IMathParagraph.h>
#include <DOM/IPortionFormat.h>
#include <DOM/MathText/IMathBlock.h>
#include <DOM/MathText/IMathDelimiter.h>
#include <DOM/MathText/IMathFraction.h>
#include <DOM/MathText/IMathSuperscriptElement.h>
#include <DOM/MathText/MathDelimiterShape.h>
#include <DOM/MathText/MathPortion.h>
#include <DOM/MathText/MathematicalText.h>
#include <DOM/Presentation.h>
#include <Export/SaveFormat.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace Aspose::Slides::MathText;
auto presentation = System::MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);
auto addExpression = [slide](float left, float top, bool grow, MathDelimiterShape shape)
{
auto fraction = System::MakeObject<MathematicalText>(u"a + b")->Divide(u"c + d");
auto power = System::MakeObject<MathematicalText>(u"x")->SetSuperscript(fraction);
auto delimiter = power->Enclose(u'(', u')');
delimiter->set_GrowToMatchOperandHeight(grow);
delimiter->set_DelimiterShape(shape);
auto mathShape = slide->get_Shapes()->AddMathShape(left, top, 300, 100);
auto portion = System::ExplicitCast<MathPortion>(mathShape->get_TextFrame()->get_Paragraph(0)->get_Portion(0));
portion->get_PortionFormat()->set_FontHeight(32);
auto equation = System::MakeObject<MathematicalText>(u"y = ")->Join(delimiter);
portion->get_MathParagraph()->Add(equation);
};
addExpression(20, 20, true, MathDelimiterShape::Centered);
addExpression(350, 20, true, MathDelimiterShape::Match);
addExpression(20, 140, false, MathDelimiterShape::Centered);
addExpression(350, 140, false, MathDelimiterShape::Match);
presentation->Save(u"delimiter-sizing.pptx", SaveFormat::Pptx);
presentation->Dispose();
Di PowerPoint, bandingkan baris untuk melihat efek pertumbuhan. Pada baris atas, tanda kurung tumbuh untuk membungkus eksponen dan terlihat serupa untuk kedua bentuk. Pada baris bawah, pertumbuhan dimatikan. Tanda kurung yang lebih kecil di kiri (Centered) selaras dengan tanda sama dengan, sementara yang di kanan (Match) berada lebih tinggi di sekitar ekspresi.

Tambahkan Kotak Batas
Gunakan ToBorderBox pada sebuah pecahan untuk membingkai seluruh ekspresi. IMathBorderBox yang dikembalikan menampilkan keempat sisi secara default. Gunakan set_HideTop, set_HideBottom, set_HideLeft, dan set_HideRight untuk menghapus sisi tertentu.
Contoh menempatkan enam salinan pecahan yang sama pada satu slide. Untuk menunjukkan pembatalan, sembunyikan semua empat sisi dan atur set_StrikethroughBottomLeftToTopRight untuk diagonal naik (↗) atau set_StrikethroughTopLeftToBottomRight untuk diagonal turun (↘). Anda juga dapat menggunakan set_StrikethroughHorizontal atau set_StrikethroughVertical dengan kombinasi sisi yang terlihat apa saja.
#include <DOM/IAutoShape.h>
#include <DOM/IParagraph.h>
#include <DOM/IPortionFormat.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ISlideSize.h>
#include <DOM/ITextFrame.h>
#include <DOM/MathText/IMathBorderBox.h>
#include <DOM/MathText/IMathFraction.h>
#include <DOM/MathText/IMathParagraph.h>
#include <DOM/MathText/MathBlock.h>
#include <DOM/MathText/MathPortion.h>
#include <DOM/MathText/MathematicalText.h>
#include <DOM/Presentation.h>
#include <DOM/SlideSizeScaleType.h>
#include <Export/SaveFormat.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace Aspose::Slides::MathText;
auto presentation = System::MakeObject<Presentation>();
presentation->get_SlideSize()->SetSize(540, 220, SlideSizeScaleType::DoNotScale);
auto slide = presentation->get_Slide(0);
auto addFraction = [slide](float x, float y, bool hideBorder = false)
{
auto fraction = System::MakeObject<MathematicalText>(u"x+1")->Divide(u"y+2");
auto box = fraction->ToBorderBox();
box->set_HideTop(hideBorder);
box->set_HideBottom(hideBorder);
box->set_HideLeft(hideBorder);
box->set_HideRight(hideBorder);
auto shape = slide->get_Shapes()->AddMathShape(x, y, 160, 90);
auto portion = System::ExplicitCast<MathPortion>(shape->get_TextFrame()->get_Paragraph(0)->get_Portion(0));
portion->get_PortionFormat()->set_FontHeight(28);
auto mathBlock = System::MakeObject<MathBlock>(box);
portion->get_MathParagraph()->Add(mathBlock);
return box;
};
addFraction(10, 10);
auto partial = addFraction(190, 10);
partial->set_HideTop(true);
partial->set_HideRight(true);
addFraction(370, 10, true)->set_StrikethroughBottomLeftToTopRight(true);
addFraction(10, 120, true)->set_StrikethroughTopLeftToBottomRight(true);
addFraction(190, 120, true)->set_StrikethroughHorizontal(true);
addFraction(370, 120)->set_StrikethroughVertical(true);
presentation->Save(u"border-box.pptx", SaveFormat::Pptx);
presentation->Dispose();

Pada pecahan ini, garis horizontal menutupi batang pecahan. Garis vertikal melintasi baik penyebut maupun pembilang sementara batas di sekitarnya tetap terlihat. Garis-garis ini menghias seluruh ekspresi. Coretan teks biasa berlaku pada karakter dalam satu rangkaian teks. Setelah membuka kembali presentasi di PowerPoint, Anda masih dapat menyunting penyebut dan pembilang secara terpisah.
Kontrol Visibilitas dan Tata Letak dengan Elemen Phantom
Balut sebuah ekspresi dengan MathPhantom untuk mengontrol visibilitasnya dan ruang yang disumbangkannya ke sebuah persamaan secara independen. Metode setter IMathPhantom mengontrol hal berikut:
| Method | Effect |
|---|---|
| set_Show | Berikan false untuk menyembunyikan ekspresi. Dimensinya masih berkontribusi pada tata letak kecuali pengaturan terkait di bawah ini true. |
| set_ZeroWidth | Anggap lebar horizontal ekspresi sebagai nol, memungkinkan elemen tetangga bergerak lebih dekat. |
| set_ZeroAsc | Anggap asennya, tinggi di atas garis dasar, sebagai nol. Hal ini dapat mengurangi ruang yang disediakan di atas elemen tetangga. |
| set_ZeroDesc | Anggap turunannya, kedalaman di bawah garis dasar, sebagai nol. Hal ini dapat memindahkan batang pecahan atau konten lain di bawah ekspresi lebih dekat ke tetangganya. |
Garis dasar adalah garis referensi tempat huruf matematika biasa berada. Menyembunyikan konten tidak menghapus dimensinya, dan memperlakukan dimensi sebagai nol tidak menghapus ekspresi. Ekspresi yang mendasarinya tetap tersedia melalui get_Base. Berikan true ke set_Show untuk menampilkannya kembali; pengaturan dimensi tetap tidak berubah.
Contoh di bawah membuat lima varian berdampingan: sebuah pecahan terlihat, pecahan tersembunyi yang tetap menyimpan ruang, dan tiga pecahan tersembunyi dengan satu dimensi diperlakukan sebagai nol. Setiap varian menggunakan ekspresi sekitarnya yang sama dan Cambria Math ukuran 24 poin. Semua bentuk persamaan memiliki posisi atas yang sama, ditandai oleh panduan abu-abu. Menempatkan phantom di pembilang sebuah pecahan luar membuat perubahan tata letak vertikal lebih mudah dilihat.
#include <array>
#include <drawing/color.h>
#include <DOM/FillType.h>
#include <DOM/Fonts/FontData.h>
#include <DOM/IAutoShape.h>
#include <DOM/IColorFormat.h>
#include <DOM/IFillFormat.h>
#include <DOM/ILineFormat.h>
#include <DOM/IParagraph.h>
#include <DOM/IPortion.h>
#include <DOM/IPortionFormat.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ISlideSize.h>
#include <DOM/ITextFrame.h>
#include <DOM/ITextFrameFormat.h>
#include <DOM/MathText/IMathParagraph.h>
#include <DOM/MathText/MathBlock.h>
#include <DOM/MathText/MathFraction.h>
#include <DOM/MathText/MathPhantom.h>
#include <DOM/MathText/MathPortion.h>
#include <DOM/MathText/MathematicalText.h>
#include <DOM/Presentation.h>
#include <DOM/ShapeType.h>
#include <DOM/SlideSizeScaleType.h>
#include <DOM/TextAnchorType.h>
#include <Export/SaveFormat.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace Aspose::Slides::MathText;
auto createText = [](System::String value)
{
auto text = System::MakeObject<MathematicalText>(value);
text->get_Format()->set_FontHeight(24);
auto font = System::MakeObject<FontData>(u"Cambria Math");
text->get_Format()->set_LatinFont(font);
return text;
};
auto presentation = System::MakeObject<Presentation>();
presentation->get_SlideSize()->SetSize(1000, 180, SlideSizeScaleType::DoNotScale);
auto slide = presentation->get_Slide(0);
std::array<System::String, 5> labels = {u"Visible", u"Hidden: reserves space", u"Hidden: ZeroWidth", u"Hidden: ZeroAsc", u"Hidden: ZeroDesc"};
auto guide = slide->get_Shapes()->AddAutoShape(ShapeType::Line, 10, 60, 980, 0);
guide->get_LineFormat()->get_FillFormat()->set_FillType(FillType::Solid);
guide->get_LineFormat()->get_FillFormat()->get_SolidFillColor()->set_Color(System::Drawing::Color::get_LightGray());
for (auto i = 0; i < labels.size(); i++)
{
auto left = 10 + i * 200;
auto label = slide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, left, 10, 190, 30);
label->get_FillFormat()->set_FillType(FillType::NoFill);
label->get_LineFormat()->get_FillFormat()->set_FillType(FillType::NoFill);
label->get_TextFrame()->set_Text(labels[i]);
auto labelFormat = label->get_TextFrame()->get_Paragraph(0)->get_Portion(0)->get_PortionFormat();
labelFormat->set_FontHeight(14);
labelFormat->get_FillFormat()->set_FillType(FillType::Solid);
labelFormat->get_FillFormat()->get_SolidFillColor()->set_Color(System::Drawing::Color::get_Black());
auto fractionNumerator = createText(u"a+b");
auto fractionDenominator = createText(u"c+d");
auto fraction = System::MakeObject<MathFraction>(fractionNumerator, fractionDenominator);
auto phantom = System::MakeObject<MathPhantom>(fraction);
phantom->set_Show(i == 0);
phantom->set_ZeroWidth(i == 2);
phantom->set_ZeroAsc(i == 3);
phantom->set_ZeroDesc(i == 4);
auto leadingText = createText(u"x+");
auto trailingText = createText(u"+y");
auto numeratorBlock = System::MakeObject<MathBlock>(leadingText);
auto numerator = numeratorBlock->Join(phantom)->Join(trailingText);
auto denominator = createText(u"z");
auto equation = System::MakeObject<MathFraction>(numerator, denominator);
auto shape = slide->get_Shapes()->AddMathShape(left, 60, 190, 100);
shape->get_TextFrame()->get_TextFrameFormat()->set_AnchoringType(TextAnchorType::Top);
auto mathPortion = System::ExplicitCast<MathPortion>(shape->get_TextFrame()->get_Paragraph(0)->get_Portion(0));
auto mathParagraph = mathPortion->get_MathParagraph();
auto mathBlock = System::MakeObject<MathBlock>(equation);
mathParagraph->Add(mathBlock);
}
presentation->Save(u"math-phantom.pptx", SaveFormat::Pptx);
presentation->Dispose();

Kelompokkan Istilah
Gunakan Group untuk menempatkan karakter pengelompokan di atas atau di bawah sebuah ekspresi. Tambahkan batas untuk memberi label pada istilah yang dikelompokkan.

#include <DOM/IAutoShape.h>
#include <DOM/IParagraph.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ITextFrame.h>
#include <DOM/MathText/IMathGroupingCharacter.h>
#include <DOM/MathText/IMathParagraph.h>
#include <DOM/MathText/MathBlock.h>
#include <DOM/MathText/MathPortion.h>
#include <DOM/MathText/MathTopBotPositions.h>
#include <DOM/MathText/MathematicalText.h>
#include <DOM/Presentation.h>
#include <Export/SaveFormat.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace Aspose::Slides::MathText;
auto presentation = System::MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);
auto mathShape = slide->get_Shapes()->AddMathShape(20.0f, 20.0f, 700.0f, 120.0f);
auto mathPortion = System::ExplicitCast<MathPortion>(mathShape->get_TextFrame()->get_Paragraph(0)->get_Portion(0));
auto mathParagraph = mathPortion->get_MathParagraph();
auto grouped = System::MakeObject<MathematicalText>(u"x + y")
- >Group(u'\u23DF', MathTopBotPositions::Bottom, MathTopBotPositions::Top)
- >SetLowerLimit(u"any text");
mathParagraph->Add(System::MakeObject<MathBlock>(grouped));
presentation->Save(u"grouped-terms.pptx", SaveFormat::Pptx);
presentation->Dispose();
Format Elemen Matematika
Gunakan pembantu pemformatan hanya di mana mereka memperjelas formula. Misalnya, Overbar menempatkan sebuah bar di atas elemen matematika.

#include <DOM/IAutoShape.h>
#include <DOM/IParagraph.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ITextFrame.h>
#include <DOM/MathText/IMathParagraph.h>
#include <DOM/MathText/MathBlock.h>
#include <DOM/MathText/MathPortion.h>
#include <DOM/MathText/MathematicalText.h>
#include <DOM/Presentation.h>
#include <Export/SaveFormat.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace Aspose::Slides::MathText;
auto presentation = System::MakeObject<Presentation>();
auto slide = presentation->get_Slide(0);
auto mathShape = slide->get_Shapes()->AddMathShape(20.0f, 20.0f, 700.0f, 100.0f);
auto mathPortion = System::ExplicitCast<MathPortion>(mathShape->get_TextFrame()->get_Paragraph(0)->get_Portion(0));
auto mathParagraph = mathPortion->get_MathParagraph();
auto overbar = System::MakeObject<MathematicalText>(u"ABC")->Overbar();
mathParagraph->Add(System::MakeObject<MathBlock>(overbar));
presentation->Save(u"overbar.pptx", SaveFormat::Pptx);
presentation->Dispose();
Format Teks dalam Persamaan yang Ada
Untuk memformat teks dalam seluruh persamaan yang ada, telusuri pohon elemen setiap blok matematika. IMathElement::GetChildren mengembalikan hanya anak langsung, jadi panggil secara rekursif untuk mencapai teks di dalam pecahan, skrip, radikal, dan struktur bersarang lainnya. Periksa elemen saat ini serta anak-anaknya untuk menyertakan elemen awal ketika itu adalah MathematicalText.
Contoh ini mengasumsikan bahwa sebuah presentasi berisi persamaan seperti z = xᵢ / ∛y, dengan sebuah pecahan yang memiliki subskrip di pembilangnya dan radikal di penyebutnya. Memproses hanya elemen tingkat atas pada blok akan melewatkan teks di dalam pecahan. Contoh menemukan bagian matematika dalam bingkai teks slide, mengakses bloknya melalui IMathPortion::get_MathParagraph, dan mengatur tinggi font menjadi 28 poin dengan set_FontHeight, mengakses pemformatan melalui metode get_Format setiap elemen teks.
#include <functional>
#include <system/array.h>
#include <DOM/IAutoShape.h>
#include <DOM/IParagraph.h>
#include <DOM/IParagraphCollection.h>
#include <DOM/IPortion.h>
#include <DOM/IPortionCollection.h>
#include <DOM/IPortionFormat.h>
#include <DOM/IShapeCollection.h>
#include <DOM/ISlide.h>
#include <DOM/ISlideCollection.h>
#include <DOM/ITextFrame.h>
#include <DOM/MathText/IMathBlock.h>
#include <DOM/MathText/IMathElement.h>
#include <DOM/MathText/IMathParagraph.h>
#include <DOM/MathText/IMathPortion.h>
#include <DOM/MathText/MathematicalText.h>
#include <DOM/Presentation.h>
#include <Export/SaveFormat.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace Aspose::Slides::MathText;
std::function<void(System::SharedPtr<IMathElement>)> formatMathText;
formatMathText = [&formatMathText](System::SharedPtr<IMathElement> element)
{
auto text = System::DynamicCast<MathematicalText>(element);
if (text != nullptr)
text->get_Format()->set_FontHeight(28.0f);
for (auto child : element->GetChildren())
formatMathText(child);
};
auto presentation = System::MakeObject<Presentation>(u"input.pptx");
for (auto slide : presentation->get_Slides())
{
for (auto shape : slide->get_Shapes())
{
auto autoShape = System::DynamicCast<IAutoShape>(shape);
if (autoShape == nullptr || autoShape->get_TextFrame() == nullptr)
continue;
for (auto paragraph : autoShape->get_TextFrame()->get_Paragraphs())
{
for (auto portion : paragraph->get_Portions())
{
auto mathPortion = System::DynamicCast<IMathPortion>(portion);
if (mathPortion != nullptr)
{
for (auto block : mathPortion->get_MathParagraph())
formatMathText(block);
}
}
}
}
}
presentation->Save(u"formatted-equations.pptx", SaveFormat::Pptx);
presentation->Dispose();
Presentasi yang disimpan berisi pemformatan teks yang diperbarui pada setiap tingkat masing-masing persamaan yang diproses, sambil mempertahankan konten teks dan struktur matematika.
Referensi Cepat
| Tugas | API Utama |
|---|---|
| Buat teks matematika | MathematicalText |
| Gabungkan elemen | IMathElement.Join |
| Buat pecahan | IMathElement.Divide |
| Tambahkan superskrip atau subskrip | SetSuperscript, SetSubscript |
| Tambahkan fungsi | Function, AsArgumentOfFunction |
| Tambahkan radikal | IMathElement.Radical |
| Tambahkan batas | SetLowerLimit, SetUpperLimit |
| Tambahkan skrip sisi kiri | SetSubSuperscriptOnTheLeft |
| Tambahkan penjumlahan dan integral | Nary, Integral |
| Tambahkan matriks | MathMatrix |
| Tambahkan array persamaan | ToMathArray |
| Tambahkan pembatas | Enclose |
| Tambahkan bar dan batas | Overbar, ToBorderBox |
| Kelompokkan istilah | Group |
FAQ
Apakah saya dapat menyunting persamaan PowerPoint yang ada?
Ya. Buka presentasi, temukan bentuk yang berisi MathPortion, panggil get_MathParagraph, dan perbarui blok matematika dalam paragraf tersebut.
Apakah persamaan disimpan sebagai matematika PowerPoint yang dapat diedit?
Ya. Saat Anda menyimpan ke PPTX, Aspose.Slides menulis persamaan sebagai konten Office math yang dapat diedit.
Apakah saya dapat mengekspor persamaan ke LaTeX?
Ya. Dapatkan IMathParagraph persamaan dari IMathPortion, dan panggil IMathParagraph::ToLatex untuk mengekspornya secara langsung. Untuk contoh lengkap, lihat Ekspor Persamaan Matematika dari Presentasi di C++.