Python으로 PowerPoint 프레젠테이션에 수학 방정식 추가
개요
PowerPoint는 방정식을 Office Math Markup Language(OMML)로 저장합니다. Aspose.Slides for Python via Java를 사용하면 프로그래밍 방식으로 동일한 종류의 수학 콘텐츠를 만들 수 있습니다: 분수, 근, 함수, 제한, N-ary 연산자, 행렬, 배열 및 서식이 지정된 수학 블록.
PowerPoint에서 사용자는 일반적으로 삽입 > 수식에서 방정식을 추가합니다:

그 결과 슬라이드에 편집 가능한 수학 텍스트가 표시됩니다:

Aspose.Slides는 세 가지 주요 객체를 통해 해당 수학 텍스트를 구성합니다:
- 수식 모양은 addMathShape으로 생성되며, 방정식을 포함하는 도형입니다.
- MathPortion은 도형 텍스트 프레임 내부에 수학 내용을 저장합니다.
- MathParagraph은 하나 이상의 MathBlock 객체를 포함합니다.
아래 대부분의 예제는 코드를 간결하고 가독성 있게 유지하기 위해 MathematicalText과 MathElementBase의 유창한 메서드를 사용합니다.
MathML 내보내기 시나리오에 대해서는 Python에서 프레젠테이션의 수학 방정식 내보내기를 참조하세요.
방정식 만들기
이 예제는 addMathShape을 사용하여 수식 모양을 만들고 피타고라스 정리를 추가합니다:

import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import MathematicalText, Presentation, SaveFormat
presentation = Presentation()
try:
slide = presentation.getSlides().get_Item(0)
math_shape = slide.getShapes().addMathShape(20, 20, 700, 120)
math_paragraph = math_shape.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0).getMathParagraph()
a_squared = MathematicalText("a").setSuperscript("2")
b_squared = MathematicalText("b").setSuperscript("2")
equation = MathematicalText("c").setSuperscript("2").join("=").join(a_squared).join("+").join(b_squared)
math_paragraph.add(equation)
presentation.save("pythagorean-theorem.pptx", SaveFormat.Pptx)
finally:
presentation.dispose()
Note
addMathShape은 이미 수식 단락을 포함하는 도형을 생성합니다. 첫 번째 MathPortion에 접근하고, getMathParagraph을 호출한 뒤, 수식 블록이나 수식 요소를 추가합니다.분수 추가
divide를 사용하여 분수를 생성합니다. MathFractionTypes로 분수 스타일을 선택할 수 있습니다.

import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import MathBlock, MathFractionTypes, MathematicalText, Presentation, SaveFormat
presentation = Presentation()
try:
slide = presentation.getSlides().get_Item(0)
math_shape = slide.getShapes().addMathShape(20, 20, 700, 100)
math_paragraph = math_shape.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0).getMathParagraph()
fraction = MathematicalText("1").divide("x", MathFractionTypes.Skewed)
math_block = MathBlock(fraction)
math_paragraph.add(math_block)
presentation.save("fraction.pptx", SaveFormat.Pptx)
finally:
presentation.dispose()
스택형 분수를 사용하려면 MathFractionTypes.Bar을 사용하십시오:
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import MathFractionTypes, MathematicalText
stacked_fraction = MathematicalText("x + 1").divide("y - 1", MathFractionTypes.Bar)
근 추가
radical을 사용하여 제곱근, 세제곱근 또는 기타 루트를 생성합니다. 현재 요소가 베이스가 되고, 인수가 차수가 됩니다.

import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import MathBlock, MathematicalText, Presentation, SaveFormat
presentation = Presentation()
try:
slide = presentation.getSlides().get_Item(0)
math_shape = slide.getShapes().addMathShape(20, 20, 700, 100)
math_paragraph = math_shape.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0).getMathParagraph()
radical = MathematicalText("x").radical("n")
math_block = MathBlock(radical)
math_paragraph.add(math_block)
presentation.save("radical.pptx", SaveFormat.Pptx)
finally:
presentation.dispose()
제곱근 차수 표시 또는 숨기기
제곱근은 명시적인 2를 표시하거나 기존의 √x 표기법을 사용할 수 있습니다. MathRadical의 setHideDegree 메서드는 어떤 형태가 표시될지를 제어합니다. 두 형태 모두 편집 가능한 방정식에서 차수 2와 근인 x를 유지합니다.

예제는 동일한 제곱근을 두 번 저장합니다. visible-degree.pptx에서는 2가 보이며, hidden-degree.pptx에서는 숨겨져 있습니다.
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import MathBlock, MathematicalText, Presentation, SaveFormat
presentation = Presentation()
try:
slide = presentation.getSlides().get_Item(0)
radical = MathematicalText("x").radical("2")
math_block = MathBlock(radical)
math_shape = slide.getShapes().addMathShape(20, 20, 200, 100)
math_paragraph = math_shape.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0).getMathParagraph()
math_paragraph.add(math_block)
radical.setHideDegree(False)
presentation.save("visible-degree.pptx", SaveFormat.Pptx)
radical.setHideDegree(True)
presentation.save("hidden-degree.pptx", SaveFormat.Pptx)
finally:
presentation.dispose()
함수 및 제한 추가
asArgumentOfFunction 또는 function를 사용하여 sin(x), log(x)와 같은 함수 또는 사용자 정의 함수 이름을 지정합니다. 제한을 위해서는 lim을 MathLimit에 넣거나 setLowerLimit를 사용합니다.

import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import MathBlock, MathematicalText, Presentation, SaveFormat
presentation = Presentation()
try:
slide = presentation.getSlides().get_Item(0)
math_shape = slide.getShapes().addMathShape(20, 20, 700, 100)
math_paragraph = math_shape.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0).getMathParagraph()
limit = MathematicalText("lim").setLowerLimit("x\u2192\u221E").function("x")
math_block = MathBlock(limit)
math_paragraph.add(math_block)
presentation.save("functions-and-limits.pptx", SaveFormat.Pptx)
finally:
presentation.dispose()
사용자 정의 함수 이름의 경우, 함수 이름을 현재 요소로 만든 뒤, function에 인수를 전달합니다:
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import MathematicalText
custom_function = MathematicalText("f").function("x + 1")
N-ary 연산자 및 적분 추가
합계, 합집합, 교집합 및 기타 대형 연산자를 위해서는 nary를 사용합니다. 적분을 위해서는 integral를 사용합니다. 두 메서드 모두 하한 및 상한을 설정할 수 있습니다.

import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import MathBlock, MathNaryOperatorTypes, MathematicalText, Presentation, SaveFormat
presentation = Presentation()
try:
slide = presentation.getSlides().get_Item(0)
math_shape = slide.getShapes().addMathShape(20, 20, 700, 120)
math_paragraph = math_shape.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0).getMathParagraph()
a_power = MathematicalText("a").setSuperscript("n-k")
summation_base = MathematicalText("x").setSuperscript("k").join(a_power)
summation = summation_base.nary(MathNaryOperatorTypes.Summation, "k=0", "n")
math_block = MathBlock(summation)
math_paragraph.add(math_block)
presentation.save("nary-operators.pptx", SaveFormat.Pptx)
finally:
presentation.dispose()
N-ary 연산자는 선택적 제한이 있는 대형 연산자를 위한 것입니다. +, -, =와 같은 간단한 연산자는 보통 MathematicalText로 추가하고 식에 결합합니다.
적분의 경우, integral을 사용합니다:
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import MathIntegralTypes, MathematicalText
differential = MathematicalText("dx").toBox()
integral_base = MathematicalText("x").join(differential)
integral = integral_base.integral(MathIntegralTypes.Simple, "0", "1")
행렬 추가
행과 열을 위해서는 MathMatrix를 사용합니다. 행렬은 기본적으로 괄호를 포함하지 않으므로, 괄호, 대괄호 또는 중괄호가 필요할 경우 행렬을 둘러싸야 합니다.

import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import MathBlock, MathMatrix, MathematicalText, Presentation, SaveFormat
presentation = Presentation()
try:
slide = presentation.getSlides().get_Item(0)
math_shape = slide.getShapes().addMathShape(20, 20, 700, 120)
math_paragraph = math_shape.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0).getMathParagraph()
matrix = MathMatrix(2, 3)
cell_0_0 = MathematicalText("1")
matrix.set_Item(0, 0, cell_0_0)
cell_0_1 = MathematicalText("x")
matrix.set_Item(0, 1, cell_0_1)
cell_1_0 = MathematicalText("x")
matrix.set_Item(1, 0, cell_1_0)
cell_1_1 = MathematicalText("2")
matrix.set_Item(1, 1, cell_1_1)
cell_1_2 = MathematicalText("y")
matrix.set_Item(1, 2, cell_1_2)
math_block = MathBlock(matrix)
math_paragraph.add(math_block)
presentation.save("matrix.pptx", SaveFormat.Pptx)
finally:
presentation.dispose()
방정식 배열 추가
정렬된 방정식이나 표현식의 수직 스택이 필요할 때는 toMathArray를 사용합니다.

import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import MathBlock, MathematicalText, Presentation, SaveFormat
presentation = Presentation()
try:
slide = presentation.getSlides().get_Item(0)
math_shape = slide.getShapes().addMathShape(20, 20, 700, 140)
math_paragraph = math_shape.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0).getMathParagraph()
equation_array = MathematicalText("x").join("y").toMathArray()
math_block = MathBlock(equation_array)
math_paragraph.add(math_block)
presentation.save("equation-array.pptx", SaveFormat.Pptx)
finally:
presentation.dispose()
주변 요소와 배열 정렬
setBaseJustification은 배열이 옆의 수학 요소에 대해 수직 정렬을 제어합니다. 아래 예제는 첫 번째 행, 배열 중앙, 마지막 행과의 정렬을 비교합니다.
다음 예제는 세 개의 동일한 배열을 생성합니다. 각각은 세 행과 주변 요소 A= 및 =B를 갖습니다. 모든 수학 텍스트는 24포인트 Cambria Math를 사용합니다. 배열 정렬만 변경됩니다.
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import FillType, FontData, MathArray, MathBlock, MathJustification, MathematicalText, MathVerticalAlignment, Presentation, SaveFormat, ShapeType, SlideSizeScaleType, TextAnchorType
from java.awt import Color
def create_text(value):
text = MathematicalText(value)
text.getFormat().setFontHeight(24)
text.getFormat().setLatinFont(FontData("Cambria Math"))
return text
presentation = Presentation()
try:
presentation.getSlideSize().setSize(780, 200, SlideSizeScaleType.DoNotScale)
slide = presentation.getSlides().get_Item(0)
alignments = (("Top", MathVerticalAlignment.Top), ("Center", MathVerticalAlignment.Center), ("Bottom", MathVerticalAlignment.Bottom))
for index, (name, alignment) in enumerate(alignments):
x = 20 + index * 260
label = slide.getShapes().addAutoShape(ShapeType.Rectangle, x, 10, 240, 30)
label.getFillFormat().setFillType(FillType.NoFill)
label.getLineFormat().getFillFormat().setFillType(FillType.NoFill)
label.getTextFrame().setText(name)
label_format = label.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0).getPortionFormat()
label_format.setFontHeight(16)
label_format.getFillFormat().setFillType(FillType.Solid)
label_format.getFillFormat().getSolidFillColor().setColor(Color.BLACK)
math_shape = slide.getShapes().addMathShape(x, 60, 240, 130)
math_shape.getTextFrame().getTextFrameFormat().setAnchoringType(TextAnchorType.Top)
paragraph = math_shape.getTextFrame().getParagraphs().get_Item(0)
math_paragraph = paragraph.getPortions().get_Item(0).getMathParagraph()
math_paragraph.setJustification(MathJustification.LeftJustified)
equation_array = MathArray(create_text("x+y=3"))
equation_array.getArguments().add(create_text("x-y=1"))
equation_array.getArguments().add(create_text("x=2"))
equation_array.setBaseJustification(alignment)
equation = MathBlock(create_text("A=")).join(equation_array).join(create_text("=B"))
math_paragraph.add(equation)
presentation.save("equation-array-alignment.pptx", SaveFormat.Pptx)
finally:
presentation.dispose()
다음 비교는 PowerPoint에서 저장된 프레젠테이션을 보여줍니다. 각 배열 옆에 있는 A=와 =B의 위치를 확인하십시오.

행 간격 구성
setRowSpacingRule은 배열 내 행에 대한 간격 규칙을 선택합니다. setRowSpacing은 명시적 간격 규칙을 위한 숫자 값을 제공하며, 사전 설정 규칙에는 무시됩니다.
정확한 간격의 경우 값은 포인트 단위로 측정됩니다. 비례 간격의 경우 반줄 단위로 측정됩니다: 예제의 값 3은 1.5줄을 의미합니다. 명시적 값을 지정할 때는 두 속성을 모두 설정하십시오; 숫자 값만 변경해도 간격 규칙이 선택되지 않습니다.
아래 예제는 동일한 방정식, 정렬 및 글꼴 설정을 가진 다섯 개의 프레젠테이션을 저장합니다. 처음 세 개는 사전 설정을 사용하고, 마지막 두 개는 명시적 값을 보여줍니다.
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import FontData, MathArray, MathBlock, MathJustification, MathematicalText, MathRowSpacingRule, MathVerticalAlignment, Presentation, SaveFormat
def create_text(value):
text = MathematicalText(value)
text.getFormat().setFontHeight(24)
text.getFormat().setLatinFont(FontData("Cambria Math"))
return text
settings = (("SingleLineGap", MathRowSpacingRule.SingleLineGap, 0), ("OneAndAHalfLineGap", MathRowSpacingRule.OneAndAHalfLineGap, 0), ("TwoLineGap", MathRowSpacingRule.TwoLineGap, 0), ("Exactly", MathRowSpacingRule.Exactly, 20), ("Multiple", MathRowSpacingRule.Multiple, 3))
for name, rule, spacing in settings:
presentation = Presentation()
try:
slide = presentation.getSlides().get_Item(0)
math_shape = slide.getShapes().addMathShape(20, 20, 600, 300)
paragraph = math_shape.getTextFrame().getParagraphs().get_Item(0)
paragraph.getParagraphFormat().setSpaceBefore(0)
paragraph.getParagraphFormat().setSpaceAfter(0)
math_paragraph = paragraph.getPortions().get_Item(0).getMathParagraph()
math_paragraph.setJustification(MathJustification.LeftJustified)
equation_array = MathArray(create_text("x+y=3"))
equation_array.getArguments().add(create_text("x-y=1"))
equation_array.getArguments().add(create_text("x=2"))
equation_array.setBaseJustification(MathVerticalAlignment.Center)
equation_array.setRowSpacingRule(rule)
equation_array.setRowSpacing(spacing)
equation = MathBlock(create_text("A=")).join(equation_array).join(create_text("=B"))
math_paragraph.add(equation)
presentation.save(f"equation-array-{name}.pptx", SaveFormat.Pptx)
finally:
presentation.dispose()
배열 행 간격은 단락 간격과 별개입니다. setSpaceBefore와 setSpaceAfter은 배열 행 사이가 아니라 포함된 단락 주위에 공간을 추가합니다. 마찬가지로, MathParagraph.setJustification은 전체 수식 단락을 수평으로 배치하며, 배열의 수직 정렬 설정을 대체하지 않습니다.
삼각 함수 추가
인수가 현재 요소이고 함수 이름이 알려진 경우 asArgumentOfFunction을 사용합니다.

import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import MathBlock, MathFunctionsOfOneArgument, MathematicalText, Presentation, SaveFormat
presentation = Presentation()
try:
slide = presentation.getSlides().get_Item(0)
math_shape = slide.getShapes().addMathShape(20, 20, 700, 100)
math_paragraph = math_shape.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0).getMathParagraph()
cosine = MathematicalText("2x").asArgumentOfFunction(MathFunctionsOfOneArgument.Cos)
math_block = MathBlock(cosine)
math_paragraph.add(math_block)
presentation.save("trigonometric-function.pptx", SaveFormat.Pptx)
finally:
presentation.dispose()
아래첨자 및 위첨자 추가
인덱스와 거듭 제곱을 위해 아래첨자와 위첨자 도우미를 사용합니다. 인덱스를 베이스의 왼쪽에 표시해야 할 경우 setSubSuperscriptOnTheLeft을 사용하십시오.

import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import MathBlock, MathematicalText, Presentation, SaveFormat
presentation = Presentation()
try:
slide = presentation.getSlides().get_Item(0)
math_shape = slide.getShapes().addMathShape(20, 20, 700, 100)
math_paragraph = math_shape.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0).getMathParagraph()
scripts = MathematicalText("Y").setSubSuperscriptOnTheLeft("1", "n")
math_block = MathBlock(scripts)
math_paragraph.add(math_block)
presentation.save("subscript-superscript.pptx", SaveFormat.Pptx)
finally:
presentation.dispose()
구분자 추가
enclose를 사용하여 표현식을 구분자 안에 넣습니다. 여러 요소를 포함하는 구분자 표현식의 경우 구분 문자도 설정할 수 있습니다.

import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import MathBlock, MathematicalText, Presentation, SaveFormat
presentation = Presentation()
try:
slide = presentation.getSlides().get_Item(0)
math_shape = slide.getShapes().addMathShape(20, 20, 700, 100)
math_paragraph = math_shape.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0).getMathParagraph()
delimiter = MathematicalText("x").join("y").join("z").enclose('<', '>')
delimiter.setSeparatorCharacter('|')
math_block = MathBlock(delimiter)
math_paragraph.add(math_block)
presentation.save("delimiters.pptx", SaveFormat.Pptx)
finally:
presentation.dispose()
구분자 크기 및 정렬
setGrowToMatchOperandHeight에 True를 전달하면 큰 피연산자 주위에 괄호가 확장됩니다. False를 전달하면 정상 크기를 유지합니다. 두 가지 MathDelimiterShape 값 중 하나와 함께 setDelimiterShape을 사용하십시오. Centered는 괄호를 등호 기호 중간을 지나는 수학 축에 가운데 맞춥니다. Match는 포함된 내용에 맞추어 정렬합니다. 두 설정은 구분자에만 영향을 미치며, 내부 표현식은 동일하게 유지됩니다.
예제는 x의 지수에 분수를 배치하여 표현식이 기준선 위쪽으로 더 많이 확장되도록 합니다. 네 개의 방정식 모두 동일한 괄호와 글꼴 설정을 사용합니다.
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import MathDelimiterShape, MathematicalText, Presentation, SaveFormat
presentation = Presentation()
try:
slide = presentation.getSlides().get_Item(0)
for row, grow in enumerate((True, False)):
for column, shape in enumerate((MathDelimiterShape.Centered, MathDelimiterShape.Match)):
fraction = MathematicalText("a + b").divide("c + d")
power = MathematicalText("x").setSuperscript(fraction)
delimiter = power.enclose("(", ")")
delimiter.setGrowToMatchOperandHeight(grow)
delimiter.setDelimiterShape(shape)
math_shape = slide.getShapes().addMathShape(20 + 330 * column, 20 + 120 * row, 300, 100)
portion = math_shape.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0)
portion.getPortionFormat().setFontHeight(32)
equation = MathematicalText("y = ").join(delimiter)
portion.getMathParagraph().add(equation)
presentation.save("delimiter-sizing.pptx", SaveFormat.Pptx)
finally:
presentation.dispose()
PowerPoint에서 행을 비교하여 성장 효과를 확인하십시오. 상단 행에서는 괄호가 지수를 둘러싸도록 확장되어 두 형태가 동일하게 보입니다. 하단 행에서는 확대가 비활성화됩니다. 왼쪽의 작은 괄호(Centered)는 등호 기호에 맞추어지고, 오른쪽의 괄호(Match)는 표현식 위쪽에 더 높게 위치합니다.

테두리 상자 추가
분수에 toBorderBox를 호출하면 전체 표현식을 테두리로 감쌀 수 있습니다. 반환된 MathBorderBox는 기본적으로 모든 네 면을 표시합니다. 개별 면을 제거하려면 setHideTop, setHideBottom, setHideLeft, setHideRight를 사용하십시오.
예제는 하나의 슬라이드에 동일한 분수를 여섯 개 배치합니다. 취소 표시를 위해 네 면을 모두 숨기고 setStrikethroughBottomLeftToTopRight에 True를 전달하여 상승 대각선(↗)을, 또는 setStrikethroughTopLeftToBottomRight에 True를 전달하여 하강 대각선(↘)을 표시합니다. 또한 setStrikethroughHorizontal 또는 setStrikethroughVertical를 사용하여 보이는 면의 조합을 지정할 수 있습니다.
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import MathBlock, MathematicalText, Presentation, SaveFormat, SlideSizeScaleType
presentation = Presentation()
try:
presentation.getSlideSize().setSize(540, 220, SlideSizeScaleType.DoNotScale)
slide = presentation.getSlides().get_Item(0)
def add_fraction(x, y, hide_border):
fraction = MathematicalText("x+1").divide("y+2")
box = fraction.toBorderBox()
box.setHideTop(hide_border)
box.setHideBottom(hide_border)
box.setHideLeft(hide_border)
box.setHideRight(hide_border)
shape = slide.getShapes().addMathShape(x, y, 160, 90)
portion = shape.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0)
portion.getPortionFormat().setFontHeight(28)
math_block = MathBlock(box)
portion.getMathParagraph().add(math_block)
return box
add_fraction(10, 10, False)
partial = add_fraction(190, 10, False)
partial.setHideTop(True)
partial.setHideRight(True)
add_fraction(370, 10, True).setStrikethroughBottomLeftToTopRight(True)
add_fraction(10, 120, True).setStrikethroughTopLeftToBottomRight(True)
add_fraction(190, 120, True).setStrikethroughHorizontal(True)
add_fraction(370, 120, False).setStrikethroughVertical(True)
presentation.save("border-box.pptx", SaveFormat.Pptx)
finally:
presentation.dispose()

이 분수에서 가로 취소선은 분수선을 겹칩니다. 세로 취소선은 분자와 분모를 모두 가로지르면서 주변 테두리는 보이게 유지됩니다. 이러한 선은 전체 표현식을 장식합니다. 일반 텍스트 취소선은 텍스트 실행의 문자에 적용됩니다. PowerPoint에서 프레젠테이션을 다시 열어도 분자와 분모를 독립적으로 편집할 수 있습니다.
팬텀 요소로 가시성 및 레이아웃 제어
표현식을 MathPhantom으로 감싸면 가시성과 방정식에 기여하는 공간을 독립적으로 제어할 수 있습니다. MathPhantom 메서드는 다음을 제어합니다:
| 메서드 | 효과 |
|---|---|
| setShow | False를 전달하면 표현식이 숨겨집니다. 해당 차원은 아래 메서드가 True를 받지 않는 한 레이아웃에 여전히 기여합니다. |
| setZeroWidth | 표현식의 가로 폭을 0으로 간주하여 인접 요소가 더 가깝게 이동하도록 합니다. |
| setZeroAsc | 베이스라인 위의 높이인 상승을 0으로 간주합니다. 이는 인접 요소 위에 예약된 공간을 줄일 수 있습니다. |
| setZeroDesc | 베이스라인 아래의 깊이인 하강을 0으로 간주합니다. 이는 분수선이나 표현식 아래의 다른 콘텐츠를 인접 요소에 더 가깝게 이동시킬 수 있습니다. |
베이스라인은 일반 수학 문자들이 놓이는 기준선입니다. 콘텐츠를 숨겨도 차원이 제거되지 않으며, 차원을 0으로 처리해도 표현식이 삭제되지 않습니다. 기본 표현식은 getBase을 통해 계속 접근할 수 있습니다. setShow에 True를 전달하면 다시 표시되며, 차원 설정은 그대로 유지됩니다.
아래 예제는 다섯 개의 나란히 배치된 변형을 생성합니다: 보이는 분수, 공간을 유지하는 숨긴 분수, 그리고 하나의 차원만 0으로 처리된 세 개의 숨긴 분수. 각 변형은 동일한 주변 표현식과 24포인트 Cambria Math를 사용합니다. 모든 방정식 도형은 회색 가이드가 표시한 동일한 상단 위치를 가집니다. 외부 분수의 분자에 팬텀을 배치하면 수직 레이아웃 변화를 더 쉽게 볼 수 있습니다.
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import FillType, FontData, MathBlock, MathFraction, MathematicalText, MathPhantom, Presentation, SaveFormat, ShapeType, SlideSizeScaleType, TextAnchorType
from java.awt import Color
def create_text(value):
text = MathematicalText(value)
text.getFormat().setFontHeight(24)
text.getFormat().setLatinFont(FontData("Cambria Math"))
return text
presentation = Presentation()
try:
presentation.getSlideSize().setSize(1000, 180, SlideSizeScaleType.DoNotScale)
slide = presentation.getSlides().get_Item(0)
labels = ("Visible", "Hidden: reserves space", "Hidden: ZeroWidth", "Hidden: ZeroAsc", "Hidden: ZeroDesc")
guide = slide.getShapes().addAutoShape(ShapeType.Line, 10, 60, 980, 0)
guide.getLineFormat().getFillFormat().setFillType(FillType.Solid)
guide.getLineFormat().getFillFormat().getSolidFillColor().setColor(Color.LIGHT_GRAY)
for index, name in enumerate(labels):
left = 10 + index * 200
label = slide.getShapes().addAutoShape(ShapeType.Rectangle, left, 10, 190, 30)
label.getFillFormat().setFillType(FillType.NoFill)
label.getLineFormat().getFillFormat().setFillType(FillType.NoFill)
label.getTextFrame().setText(name)
label_format = label.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0).getPortionFormat()
label_format.setFontHeight(14)
label_format.getFillFormat().setFillType(FillType.Solid)
label_format.getFillFormat().getSolidFillColor().setColor(Color.BLACK)
fraction_numerator = create_text("a+b")
fraction_denominator = create_text("c+d")
fraction = MathFraction(fraction_numerator, fraction_denominator)
phantom = MathPhantom(fraction)
phantom.setShow(index == 0)
phantom.setZeroWidth(index == 2)
phantom.setZeroAsc(index == 3)
phantom.setZeroDesc(index == 4)
left_text = create_text("x+")
right_text = create_text("+y")
numerator = MathBlock(left_text).join(phantom).join(right_text)
denominator = create_text("z")
equation = MathFraction(numerator, denominator)
shape = slide.getShapes().addMathShape(left, 60, 190, 100)
shape.getTextFrame().getTextFrameFormat().setAnchoringType(TextAnchorType.Top)
math_portion = shape.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0)
math_paragraph = math_portion.getMathParagraph()
math_block = MathBlock(equation)
math_paragraph.add(math_block)
presentation.save("math-phantom.pptx", SaveFormat.Pptx)
finally:
presentation.dispose()

항목 그룹화
group을 사용하면 표현식 위나 아래에 그룹화 문자를 배치할 수 있습니다. 그룹화된 항목에 라벨을 추가하려면 제한을 지정하십시오.

import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import MathBlock, MathTopBotPositions, MathematicalText, Presentation, SaveFormat
presentation = Presentation()
try:
slide = presentation.getSlides().get_Item(0)
math_shape = slide.getShapes().addMathShape(20, 20, 700, 120)
math_paragraph = math_shape.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0).getMathParagraph()
grouped = MathematicalText("x + y").group('\u23DF', MathTopBotPositions.Bottom, MathTopBotPositions.Top).setLowerLimit("any text")
math_block = MathBlock(grouped)
math_paragraph.add(math_block)
presentation.save("grouped-terms.pptx", SaveFormat.Pptx)
finally:
presentation.dispose()
수학 요소 서식 지정
서식 도우미는 공식이 명확해지는 경우에만 사용하십시오. 예를 들어, overbar은 수학 요소 위에 바를 놓습니다.

import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import MathBlock, MathematicalText, Presentation, SaveFormat
presentation = Presentation()
try:
slide = presentation.getSlides().get_Item(0)
math_shape = slide.getShapes().addMathShape(20, 20, 700, 100)
math_paragraph = math_shape.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0).getMathParagraph()
overbar = MathematicalText("ABC").overbar()
math_block = MathBlock(overbar)
math_paragraph.add(math_block)
presentation.save("overbar.pptx", SaveFormat.Pptx)
finally:
presentation.dispose()
기존 방정식의 텍스트 서식 지정
기존 방정식 전체의 텍스트를 서식 지정하려면 각 수식 블록의 요소 트리를 순회합니다. MathElementBase.getChildren은 즉시 자식만 반환하므로, 재귀적으로 호출하여 분수, 스크립트, 근 및 기타 중첩 구조 내부의 텍스트에 도달합니다. 시작 요소가 MathematicalText인 경우 현재 요소와 자식 요소를 모두 확인하십시오.
이 예제는 input.pptx에 z = xᵢ / ∛y와 같은 방정식이 포함되어 있다고 가정합니다. 여기서 분수는 분자에 아래첨자를, 분모에 근을 포함합니다. 블록의 최상위 요소만 처리하면 분수 내부 텍스트가 누락됩니다. 예제는 슬라이드 텍스트 프레임에서 수학 부분을 찾아 MathPortion.getMathParagraph를 통해 블록에 접근하고, 각 텍스트 요소의 getFormat 메서드를 사용하여 setFontHeight으로 글꼴 크기를 28포인트로 설정합니다.
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import AutoShape, MathematicalText, MathPortion, Presentation, SaveFormat
def format_math_text(element):
if isinstance(element, MathematicalText):
element.getFormat().setFontHeight(28)
for child in element.getChildren():
format_math_text(child)
presentation = Presentation("input.pptx")
try:
for slide in presentation.getSlides():
for shape in slide.getShapes():
if not isinstance(shape, AutoShape):
continue
if shape.getTextFrame() is None:
continue
for paragraph in shape.getTextFrame().getParagraphs():
for portion in paragraph.getPortions():
if isinstance(portion, MathPortion):
for block in portion.getMathParagraph():
format_math_text(block)
presentation.save("formatted-equations.pptx", SaveFormat.Pptx)
finally:
presentation.dispose()
저장된 프레젠테이션은 처리된 각 방정식의 모든 수준에서 업데이트된 텍스트 서식을 포함하며, 텍스트 내용과 수학 구조는 그대로 유지됩니다.
빠른 참조
| 작업 | 주요 API |
|---|---|
| 수학 텍스트 만들기 | MathematicalText |
| 요소 결합 | MathElementBase.join |
| 분수 만들기 | MathElementBase.divide |
| 위첨자 또는 아래첨자 추가 | setSuperscript, setSubscript |
| 함수 추가 | function, asArgumentOfFunction |
| 근 추가 | MathElementBase.radical |
| 제한 추가 | setLowerLimit, setUpperLimit |
| 왼쪽 스크립트 추가 | setSubSuperscriptOnTheLeft |
| 합계 및 적분 추가 | nary, integral |
| 행렬 추가 | MathMatrix |
| 방정식 배열 추가 | toMathArray |
| 구분자 추가 | enclose |
| 바와 테두리 추가 | overbar, toBorderBox |
| 항목 그룹화 | group |
자주 묻는 질문
기존 PowerPoint 방정식을 편집할 수 있나요?
예. 프레젠테이션을 열고, MathPortion을 포함하는 도형을 찾은 다음, getMathParagraph을 호출하고 해당 단락의 수식 블록을 업데이트합니다.
방정식이 편집 가능한 PowerPoint 수학으로 저장되나요?
예. PPTX로 저장하면 Aspose.Slides가 방정식을 편집 가능한 Office 수학 콘텐츠로 기록합니다.
방정식을 LaTeX로 내보낼 수 있나요?
예. 방정식의 MathParagraph을 MathPortion에서 가져와 MathParagraph.toLatex을 호출하면 직접 내보낼 수 있습니다. 전체 예제는 Python에서 프레젠테이션의 수학 방정식 내보내기를 참조하십시오.