Python을 사용하여 PowerPoint 프레젠테이션에 수학 방정식 추가

개요

PowerPoint는 방정식을 Office Math Markup Language(OMML)로 저장합니다. Aspose.Slides for Python via Java를 사용하면 프로그래밍 방식으로 동일한 유형의 수학 콘텐츠(분수, 근호, 함수, 극한, N-ary 연산자, 행렬, 배열 및 서식이 지정된 수학 블록)를 만들 수 있습니다.

PowerPoint에서 사용자는 일반적으로 삽입 > 방정식을 통해 수식을 추가합니다:

PowerPoint 삽입 탭에서 방정식 명령이 선택된 화면

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

편집 가능한 수학 방정식을 포함한 PowerPoint 슬라이드

Aspose.Slides는 세 가지 주요 개체를 통해 해당 수학 텍스트를 생성합니다:

  • 수학 모양은 addMathShape으로 생성되며, 방정식을 포함하는 도형입니다.
  • MathPortion은 도형 텍스트 프레임 내부에 수학 콘텐츠를 저장합니다.
  • MathParagraph은 하나 이상의 MathBlock 개체를 포함합니다.

아래 대부분의 예제는 코드를 짧고 읽기 쉽도록 MathematicalTextMathElementBase의 유창한 메서드를 사용합니다.

MathML 내보내기 시나리오에 대해서는 Python 프레젠테이션에서 수학 방정식 내보내기를 참조하십시오.

방정식 만들기

이 예제는 수학 모양을 생성하고 피타고라스 정리를 추가합니다:

c 제곱이 a 제곱 더하기 b 제곱과 같은 방정식

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()

분수 추가

분수를 만들려면 divide를 사용합니다. MathFractionTypes를 사용해 분수 스타일을 선택할 수 있습니다.

하나가 x 로 나누어진 기울어진 수학 분수

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를 사용하면 제곱근, 세제곱근 또는 기타 루트를 만들 수 있습니다. 현재 요소가 밑이 되고, 인수가 차수가 됩니다.

x 가 근호 기호 아래에 있는 n 제곱근 표현식

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()

함수 및 극한 추가

함수(예: sin(x), log(x)) 혹은 사용자 정의 함수 이름을 위해서는 asArgumentOfFunction 또는 function을 사용합니다. 극한을 위해서는 MathLimitlim을 넣거나 setLowerLimit를 사용합니다.

x 가 무한대로 접근할 때의 극한

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()

사용자 정의 함수 이름의 경우, 현재 요소를 함수 이름으로 만듭니다:

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를 사용합니다.

x 위에 y 가 있는 세로 수학 배열

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()

삼각 함수 추가

인수가 현재 요소이고 함수 이름이 알려진 경우, asArgumentOfFunction을 사용합니다.

2x에 적용된 삼각 함수 cos

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를 사용합니다.

왼쪽에 첨자 1과 위첨자 n이 있는 대문자 Y

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를 사용해 표현식을 구분 기호 안에 넣습니다. 여러 요소가 포함된 구분 기호 표현식의 경우 구분 문자도 설정할 수 있습니다.

x, y, z 가 수직 막대로 구분된 구분 기호 표현식

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()

테두리 상자 추가

방정식 자체를 테두리로 감싸야 할 경우 toBorderBox를 사용합니다.

a² = b² + c² 를 보여주는 박스가 있는 방정식

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()

    b_squared = MathematicalText("b").setSuperscript("2")
    c_squared = MathematicalText("c").setSuperscript("2")
    boxed_equation = MathematicalText("a").setSuperscript("2").join("=").join(b_squared).join("+").join(c_squared).toBorderBox()

    math_block = MathBlock(boxed_equation)
    math_paragraph.add(math_block)

    presentation.save("border-box.pptx", SaveFormat.Pptx)
finally:
    presentation.dispose()

항 그룹화

group를 사용해 표현식 위나 아래에 그룹화 문자를 배치합니다. 라벨을 달아 그룹화된 항에 한계를 추가합니다.

x + y 가 아래에 임의의 텍스트 라벨과 함께 그룹화된 표현식

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는 수학 요소 위에 선을 그립니다.

ABC에 위선이 있는 수학 표현식

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()

빠른 참고

작업 주 API
수학 텍스트 만들기 MathematicalText
요소 결합 MathElementBase.join
분수 만들기 MathElementBase.divide
위첨자 또는 아래첨자 추가 setSuperscript, setSubscript
함수 추가 function, asArgumentOfFunction
근호 추가 MathElementBase.radical
극한 추가 setLowerLimit, setUpperLimit
왼쪽 첨자/위첨자 추가 setSubSuperscriptOnTheLeft
합계와 적분 추가 nary, integral
행렬 추가 MathMatrix
방정식 배열 추가 toMathArray
구분 기호 추가 enclose
선과 테두리 추가 overbar, toBorderBox
항 그룹화 group

FAQ

기존 PowerPoint 방정식을 편집할 수 있나요?

예. 프레젠테이션을 열고, MathPortion을 포함하는 도형을 찾은 뒤, 해당 MathParagraph을 가져와 해당 단락의 수학 블록을 업데이트합니다.

방정식이 편집 가능한 PowerPoint 수학으로 저장되나요?

예. PPTX로 저장하면 Aspose.Slides는 방정식을 편집 가능한 Office 수학 콘텐츠로 씁니다.

방정식을 LaTeX로 내보낼 수 있나요?

예. 방정식의 MathParagraph를 해당 MathPortion에서 가져온 뒤, MathParagraph.toLatex를 호출하면 직접 내보낼 수 있습니다. 전체 예제는 Python 프레젠테이션에서 수학 방정식 내보내기를 참조하십시오.