C++에서 PowerPoint 프레젠테이션에 수학 방정식 추가
개요
PowerPoint는 방정식을 Office Math Markup Language(OMML)로 저장합니다. C++용 Aspose.Slides를 사용하면 프로그램matically 같은 종류의 수학 콘텐츠를 만들 수 있습니다: 분수, 근호, 함수, 극한, N‑ary 연산자, 행렬, 배열 및 형식이 지정된 수학 블록.
PowerPoint에서 사용자는 일반적으로 삽입 > 수식을 통해 방정식을 추가합니다:

그 결과 슬라이드에 편집 가능한 수학 텍스트가 나타납니다:

Aspose.Slides는 이 수학 텍스트를 세 가지 주요 객체를 통해 구성합니다:
- 수학 도형은 AddMathShape으로 생성되며, 방정식을 포함하는 도형입니다.
- MathPortion은 도형 텍스트 프레임 내부에 수학 콘텐츠를 저장합니다.
- MathParagraph는 하나 이상 MathBlock 객체를 포함합니다.
아래 대부분의 예제는 MathematicalText과 IMathElement의 유창한 메서드를 사용하여 코드를 짧고 읽기 쉽게 유지합니다.
MathML 내보내기 시나리오에 대해서는 Export Math Equations from Presentations in C++를 참조하십시오.
방정식 만들기
이 예제는 AddMathShape을 사용해 수학 도형을 만들고 피타고라스 정리를 추가합니다:

#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은 이미 수학 단락을 포함하는 도형을 생성합니다. 첫 번째 MathPortion에 접근하고, get_MathParagraph를 호출한 뒤, 수학 블록이나 수학 요소를 추가합니다.수학 블록 결합
방정식의 일부가 IMathBlock 객체로 독립적으로 구성된 경우, JoinBlock을 사용해 결합합니다. 예제에서는 왼쪽 블록에 c² =를, 오른쪽 블록에 a² + b²를 구성합니다. SetSuperscript은 세 개의 거듭 제곱에 대한 편집 가능한 위 첨자를 생성합니다.
#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/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 shape = slide->get_Shapes()->AddMathShape(20, 20, 600, 100);
auto mathPortion = System::ExplicitCast<MathPortion>(shape->get_TextFrame()->get_Paragraph(0)->get_Portion(0));
auto mathParagraph = mathPortion->get_MathParagraph();
auto leftBlock = System::MakeObject<MathBlock>();
auto cSquared = System::MakeObject<MathematicalText>(u"c")->SetSuperscript(u"2");
leftBlock->Add(cSquared);
auto equalsSign = System::MakeObject<MathematicalText>(u"=");
leftBlock->Add(equalsSign);
auto rightBlock = System::MakeObject<MathBlock>();
auto aSquared = System::MakeObject<MathematicalText>(u"a")->SetSuperscript(u"2");
rightBlock->Add(aSquared);
auto plusSign = System::MakeObject<MathematicalText>(u"+");
rightBlock->Add(plusSign);
auto bSquared = System::MakeObject<MathematicalText>(u"b")->SetSuperscript(u"2");
rightBlock->Add(bSquared);
auto combinedBlock = leftBlock->JoinBlock(rightBlock);
mathParagraph->Add(combinedBlock);
presentation->Save(u"equation.pptx", SaveFormat::Pptx);
presentation->Dispose();
JoinBlock은 leftBlock 자체를 반환하므로 두 부분이 순서대로 포함된 상태가 되고, rightBlock은 비게 됩니다. 결합된 블록은 IMathParagraph에 한 번만 추가합니다. equation.pptx를 다시 열면 단락에 c² = a² + b²를 나타내는 하나의 블록이 포함되며, 세 거듭 제곱이 수학 위 첨자로 보존됩니다.
leftBlock->Add(rightBlock)처럼 Add를 호출하면 블록을 다른 블록 안에 직접 중첩하려고 시도하게 되며 System::InvalidOperationException이 발생합니다.
분수 추가
Divide를 사용해 분수를 생성합니다. 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();
쌓인 분수의 경우 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);
근호 추가
Radical을 사용해 제곱근, 세제곱근 또는 기타 근호를 생성합니다. 현재 요소가 밑이 되고, 인수가 차수가 됩니다.

#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();
제곱근 차수 표시 또는 숨기기
제곱근은 명시적인 2를 표시하거나 전통적인 √x 표기법을 사용할 수 있습니다. IMathRadical::set_HideDegree를 사용해 두 형태 사이를 전환합니다. 두 경우 모두 차수 2와 근호 안의 x는 편집 가능한 방정식에 보존됩니다.

예제에서는 같은 제곱근을 두 번 저장합니다. visible-degree.pptx에서는 2가 보이고, hidden-degree.pptx에서는 숨겨집니다.
#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();
함수 및 극한 추가
함수(sin(x), log(x) 등) 또는 사용자 정의 함수 이름을 위해 AsArgumentOfFunction이나 Function을 사용합니다. 극한의 경우 MathLimit에 lim을 넣거나 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();
사용자 정의 함수 이름의 경우 현재 요소를 함수 이름으로 만든 뒤, 해당 인수와 함께 Function을 호출합니다:
#include <DOM/MathText/MathematicalText.h>
using namespace Aspose::Slides::MathText;
auto customFunction = System::MakeObject<MathematicalText>(u"f")->Function(u"x + 1");
N-ary 연산자 및 적분 추가
합계, 합집합, 교집합 및 기타 대형 연산자를 위해 Nary를 사용합니다. 적분은 Integral을 사용합니다. 두 메서드 모두 하한 및 상한을 설정할 수 있습니다.

#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();
N‑ary 연산자는 선택적 한계가 있는 대형 연산자를 위한 것입니다. +, -, =와 같은 단순 연산자는 보통 MathematicalText으로 추가하고 표현식에 결합합니다.
적분의 경우 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");
행렬 추가
행과 열을 위해 MathMatrix을 사용합니다. 행렬은 기본적으로 괄호를 포함하지 않으므로 필요한 경우 괄호, 대괄호 또는 중괄호로 둘러야 합니다.

#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();
기존 행렬 편집
선형 대수 수업이 matrix.pptx에 있는 계수 행렬로 시작한다고 가정합니다(이전 예제에서 저장). 다음 연습에서는 첫 번째 방정식을 유지하고 두 번째를 두 개의 새로운 방정식으로 교체하며 변수 집합을 수정합니다. 기존 행렬을 IMathMatrix를 통해 열어 적용 가능한 계수를 유지합니다.

행 및 열 인덱스는 0부터 시작하며 각 호출 시 현재 행렬 상태를 참조합니다. 인덱스 1 앞에 행을 삽입하면 원래 두 번째 행이 인덱스 2로 이동합니다. 인덱스 2 뒤에 삽입하면 행이 추가됩니다. 행 2를 삭제하면 원래 두 번째 방정식이 제거되고 추가된 행이 한 위치 위로 이동합니다. 열도 같은 방식으로 이동합니다.
#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);
// 새 셀은 처음에 null입니다. 0이 아닌 계수를 먼저 설정합니다.
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은 첫 번째 열을 왼쪽에 맞춥니다. SetColumnsAlignment은 인덱스 1부터 시작하는 세 연속 열을 오른쪽에 맞춥니다. updated-matrix.pptx에서 행렬은 세 방정식과 네 변수를 갖습니다. 원래 첫 행의 계수 1과 x가 이제 첫 번째와 세 번째 열에 나타납니다.

방정식 배열 추가
정렬된 방정식이나 수식의 세로 스택이 필요할 때 ToMathArray를 사용합니다.

#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();
주변 요소와 배열 정렬
IMathArray::set_BaseJustification은 배열이 옆의 수학 요소와 수직 정렬되는 방식을 제어합니다. 아래 예제는 첫 번째 행, 배열 중앙, 마지막 행과의 정렬을 비교합니다.
다음 예제는 각각 세 행과 주변 요소 A=와 =B가 있는 세 개의 동일한 배열을 만들고, 모든 수학 텍스트는 크기 24포인트 Cambria Math을 사용합니다. 오직 배열 정렬만 다릅니다.
#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();
다음 비교는 PowerPoint에서 저장된 프레젠테이션을 보여줍니다. 각 배열 옆에 있는 A=와 =B의 위치에 주목하십시오.

행 간격 구성
set_RowSpacingRule은 배열 내부 행의 간격 규칙을 선택합니다. set_RowSpacing은 명시적 간격 규칙에 대한 숫자 값을 제공하며, 사전 설정 규칙에서는 무시됩니다.
정확한 간격은 포인트 단위로 측정됩니다. 비례 간격은 반줄 단위로 측정됩니다: 예제의 값 3은 1.5줄을 의미합니다. 명시적 값을 지정할 때는 두 setter를 모두 호출해야 하며, 숫자 값만 변경해도 간격 규칙이 선택되지 않습니다.
아래 예제는 동일한 방정식, 정렬 및 글꼴 설정을 사용해 다섯 개의 프레젠테이션을 저장합니다. 처음 세 개는 사전 설정을 사용하고, 마지막 두 개는 명시적 값을 보여줍니다.
#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();
}
배열 행 간격은 단락 간격과 별개입니다. set_SpaceBefore와 set_SpaceAfter는 포함된 단락 주변에 공간을 추가하며, 배열 행 사이에는 영향을 주지 않습니다. 마찬가지로 IMathParagraph::set_Justification는 전체 수학 단락을 수평으로 위치시키며, 배열의 수직 정렬 설정을 대체하지 않습니다.
삼각 함수 추가
인수가 현재 요소이고 함수 이름이 알려진 경우 AsArgumentOfFunction을 사용합니다.

#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();
첨자 및 위 첨자 추가
인덱스와 거듭 제곱을 위해 첨자 및 위 첨자 도우미를 사용합니다. 인덱스가 기본 요소의 왼쪽에 표시되어야 할 경우 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();
오른쪽 첨자 및 위 첨자 정렬
같은 기본 요소에 두 스크립트가 속한 경우 MathRightSubSuperscriptElement을 사용합니다. 이 요소의 set_AlignScripts 메서드는 수평 위치를 제어합니다: 기본값인 false는 기본 요소의 윤곽을 따라 배치하고, true는 스크립트를 서로 수평으로 맞춥니다.
이 예제는 동일한 편집 가능한 식을 두 개 나란히 배치합니다. 두 경우 모두 수학 이탤릭 f(U+1D453), 아래 첨자 1, 위 첨자 2, 크기 72포인트 Cambria Math을 사용합니다. 기울어진 기본 요소가 PowerPoint에서 차이를 보이게 합니다. 예제를 실행하기 전에 Cambria Math을 설치하십시오.
#include <DOM/Fonts/FontData.h>
#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/IMathParagraph.h>
#include <DOM/MathText/MathBlock.h>
#include <DOM/MathText/MathPortion.h>
#include <DOM/MathText/MathRightSubSuperscriptElement.h>
#include <DOM/MathText/MathematicalText.h>
#include <DOM/PortionFormat.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(900, 250, SlideSizeScaleType::DoNotScale);
auto slide = presentation->get_Slide(0);
auto format = System::MakeObject<PortionFormat>();
format->set_FontHeight(72);
auto font = System::MakeObject<FontData>(u"Cambria Math");
format->set_LatinFont(font);
for (auto i = 0; i < 2; i++)
{
auto left = 40 + i * 440;
auto shape = slide->get_Shapes()->AddMathShape(left, 75, 380, 150);
auto baseText = System::MakeObject<MathematicalText>(u"\U0001D453", format);
auto subscript = System::MakeObject<MathematicalText>(u"1", format);
auto superscript = System::MakeObject<MathematicalText>(u"2", format);
auto scripts = System::MakeObject<MathRightSubSuperscriptElement>(baseText, subscript, superscript);
scripts->set_AlignScripts(i == 1);
auto portion = System::ExplicitCast<MathPortion>(shape->get_TextFrame()->get_Paragraph(0)->get_Portion(0));
portion->get_PortionFormat()->set_FontHeight(format->get_FontHeight());
portion->get_PortionFormat()->set_LatinFont(format->get_LatinFont());
auto mathBlock = System::MakeObject<MathBlock>(scripts);
portion->get_MathParagraph()->Add(mathBlock);
}
presentation->Save(u"aligned-scripts.pptx", SaveFormat::Pptx);
presentation->Dispose();

왼쪽에서는 아래 첨자가 위 첨자보다 더 왼쪽에서 시작해 기본 요소의 윤곽을 따릅니다. 오른쪽에서는 두 스크립트가 서로 수평으로 정렬됩니다.
구분 기호 추가
Enclose을 사용해 표현식을 구분 기호 안에 넣습니다. 여러 요소를 포함하는 구분 기호 표현식에는 구분 문자도 설정할 수 있습니다.

#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();
구분 기호 크기 및 정렬
set_GrowToMatchOperandHeight에 true를 전달하면 키가 큰 피연산자 주위에 괄호가 늘어나고, false이면 정상 크기를 유지합니다. set_DelimiterShape은 두 가지 MathDelimiterShape 값 중 하나를 받습니다. Centered는 괄호를 수식 축(등호 중앙을 지나는 선) 중심에 놓고, Match는 포함된 내용에 맞춥니다. 두 설정 모두 구분 기호에만 영향을 미치며, 내부 표현식은 변하지 않습니다.
예제는 x의 지수에 분수를 넣어 표현식이 기준선 위로 더 많이 확장되도록 합니다. 네 개의 방정식 모두 동일한 괄호와 글꼴 설정을 사용합니다.
#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();
PowerPoint에서 행을 비교하면 성장 효과를 확인할 수 있습니다. 상단 행에서는 괄호가 지수를 둘러싸도록 성장하고 두 모양이 비슷해 보입니다. 하단 행에서는 성장이 꺼져 있습니다. 왼쪽의 작은 괄호(Centered)는 등호에 맞추고, 오른쪽(Match)은 표현식 위쪽에 더 높게 위치합니다.

테두리 상자 추가
분수에 ToBorderBox를 호출해 전체 표현식을 프레임합니다. 반환된 IMathBorderBox는 기본적으로 네 면을 모두 표시합니다. set_HideTop, set_HideBottom, set_HideLeft, set_HideRight를 사용해 개별 면을 제거할 수 있습니다.
예제는 같은 분수를 슬라이드에 여섯 개 복제합니다. 취소 표시를 위해 네 면을 모두 숨기고, 상승 대각선(↗)을 위해 set_StrikethroughBottomLeftToTopRight를, 하강 대각선(↘)을 위해 set_StrikethroughTopLeftToBottomRight를 설정합니다. 또한 set_StrikethroughHorizontal이나 set_StrikethroughVertical을 사용해 표시되는 면과 조합할 수 있습니다.
#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();

이 분수에서 가로 스트라이크는 분수선 위에 겹칩니다. 세로 스트라이크는 분자와 분모를 모두 가로지르면서 주변 테두리는 그대로 보입니다. 이러한 선은 전체 표현식을 장식합니다. 일반 텍스트의 취소선은 텍스트 실행의 문자에만 적용됩니다. 프레젠테이션을 PowerPoint에서 다시 열어도 분자와 분모를 독립적으로 편집할 수 있습니다.
팬텀 요소로 가시성 및 레이아웃 제어
표현식을 MathPhantom으로 감싸면 가시성과 방정식 내에서 차지하는 공간을 개별적으로 제어할 수 있습니다. IMathPhantom의 setter 메서드는 다음을 제어합니다:
| 메서드 | 효과 |
|---|---|
| set_Show | false를 전달하면 표현식을 숨깁니다. 차원은 레이아웃에 계속 기여하지만, 아래 설정이 true이면 차원에 따라 보이지 않을 수 있습니다. |
| set_ZeroWidth | 표현식의 가로 너비를 0으로 처리하여 인접 요소가 더 가깝게 이동하도록 합니다. |
| set_ZeroAsc | 기준선 위의 높이(asc)를 0으로 처리하여 인접 요소 위의 공간을 줄입니다. |
| set_ZeroDesc | 기준선 아래의 깊이(desc)를 0으로 처리하여 분수선 등 아래 콘텐츠가 인접 요소에 더 가깝게 이동하도록 합니다. |
기준선은 일반 수학 문자들이 위치하는 기준선입니다. 내용을 숨겨도 차원은 남아 있으며, 차원을 0으로 처리해도 표현식 자체가 삭제되는 것은 아닙니다. 기본 표현식은 get_Base를 통해 계속 접근할 수 있습니다. set_Show에 true를 전달하면 다시 표시되며, 차원 설정은 변하지 않습니다.
아래 예제는 다섯 가지 변형을 나란히 만듭니다: 보이는 분수, 공간을 예약하는 숨긴 분수, 그리고 각각 ZeroWidth, ZeroAsc, ZeroDesc가 활성화된 숨긴 분수. 각 변형은 동일한 주변 표현식과 24포인트 Cambria Math을 사용합니다. 모든 방정식 도형은 동일한 상단 위치를 가지며 회색 가이드로 표시됩니다. 팬텀을 외부 분수의 분자에 넣으면 수직 레이아웃 변화를 쉽게 확인할 수 있습니다.
#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();

항목 그룹화
Group을 사용해 표현식 위 또는 아래에 그룹화 문자를 배치합니다. 그룹화된 항목에 라벨을 추가하려면 한계를 지정합니다.

#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();
수학 요소 서식 지정
수식을 명확히 할 때만 서식 도우미를 사용합니다. 예를 들어, Overbar는 수학 요소 위에 선을 그립니다.

#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();
기존 방정식의 텍스트 서식 지정
기존 방정식 전체 텍스트의 서식을 지정하려면 각 수학 블록의 요소 트리를 순회합니다. IMathElement::GetChildren는 즉시 자식만 반환하므로, 분수, 첨자, 근호 및 기타 중첩 구조 내부의 텍스트에 도달하려면 재귀적으로 호출해야 합니다. 현재 요소와 자식을 모두 확인하여 시작 요소가 MathematicalText인 경우도 포함합니다.
예제는 프레젠테이션에 z = xᵢ / ∛y와 같이 분수에 분자에 아래첨자가 있고, 분모에 근호가 있는 방정식이 포함되어 있다고 가정합니다. 블록 수준 요소만 처리하면 분수 내부 텍스트를 놓치게 됩니다. 예제는 슬라이드 텍스트 프레임에서 수학 부분을 찾아 IMathPortion::get_MathParagraph을 통해 블록에 접근하고, 각 텍스트 요소의 get_Format 메서드로 set_FontHeight를 사용해 글꼴 높이를 28포인트로 설정합니다.
#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();
저장된 프레젠테이션에는 각 처리된 방정식의 모든 수준에서 텍스트 서식이 업데이트되며, 텍스트 내용과 수학 구조는 그대로 유지됩니다.
빠른 참조
| 작업 | 주요 API |
|---|---|
| 수학 텍스트 만들기 | MathematicalText |
| 요소 결합 | IMathElement.Join |
| 분수 만들기 | IMathElement.Divide |
| 위 첨자 또는 아래 첨자 추가 | SetSuperscript, SetSubscript |
| 함수 추가 | Function, AsArgumentOfFunction |
| 근호 추가 | IMathElement.Radical |
| 극한 추가 | SetLowerLimit, SetUpperLimit |
| 왼쪽 첨자 추가 | SetSubSuperscriptOnTheLeft |
| 합계와 적분 추가 | Nary, Integral |
| 행렬 추가 | MathMatrix |
| 방정식 배열 추가 | ToMathArray |
| 구분 기호 추가 | Enclose |
| 바 및 테두리 추가 | Overbar, ToBorderBox |
| 항목 그룹화 | Group |
FAQ
기존 PowerPoint 방정식을 편집할 수 있나요?
예. 프레젠테이션을 연 뒤, MathPortion을 포함하는 도형을 찾아 get_MathParagraph을 호출하고 해당 단락의 수학 블록을 업데이트하면 됩니다.
방정식이 편집 가능한 PowerPoint 수학으로 저장되나요?
예. PPTX로 저장하면 Aspose.Slides는 방정식을 편집 가능한 Office 수학 콘텐츠로 기록합니다.
방정식을 LaTeX로 내보낼 수 있나요?
예. 방정식의 IMathParagraph를 해당 IMathPortion에서 가져와 IMathParagraph::ToLatex를 호출하면 직접 내보낼 수 있습니다. 전체 예제는 Export Math Equations from Presentations in C++ 를 참조하십시오.