Python에서 PowerPoint 프레젠테이션에 수학 방정식 추가

개요

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

PowerPoint에서 사용자는 일반적으로 Insert > Equation에서 방정식을 추가합니다:

PowerPoint 삽입 탭에 방정식 명령이 선택된 모습

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

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

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

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

아래 대부분의 예제는 MathematicalText와 MathElementBase의 유창한 메서드를 사용하여 코드를 간결하고 읽기 쉽게 유지합니다.

Python via .NET에서 프레젠테이션의 수학 방정식 내보내기Export Math Equations from Presentations in Python via .NET.

방정식 만들기

이 예제는 add_math_shape을 사용하여 수학 셰이프를 만들고 피타고라스 정리를 추가합니다:

c² = a² + b² 방정식

import aspose.slides as slides
import aspose.slides.mathtext as math

with slides.Presentation() as presentation:
    slide = presentation.slides[0]

    math_shape = slide.shapes.add_math_shape(20, 20, 700, 120)
    math_paragraph = math_shape.text_frame.paragraphs[0].portions[0].math_paragraph

    equation = (
        math.MathematicalText("c")
        .set_superscript("2")
        .join("=")
        .join(math.MathematicalText("a").set_superscript("2"))
        .join("+")
        .join(math.MathematicalText("b").set_superscript("2"))
    )

    math_paragraph.add(equation)

    presentation.save("pythagorean-theorem.pptx", slides.export.SaveFormat.PPTX)

분수 추가

divide를 사용하여 분수를 만들 수 있습니다. MathFractionTypes로 분수 스타일을 선택할 수 있습니다.

1을 x로 나눈 기울어진 수학 분수

import aspose.slides as slides
import aspose.slides.mathtext as math

with slides.Presentation() as presentation:
    slide = presentation.slides[0]

    math_shape = slide.shapes.add_math_shape(20, 20, 700, 100)
    math_paragraph = math_shape.text_frame.paragraphs[0].portions[0].math_paragraph

    fraction = math.MathematicalText("1").divide("x", math.MathFractionTypes.SKEWED)

    math_paragraph.add(math.MathBlock(fraction))

    presentation.save("fraction.pptx", slides.export.SaveFormat.PPTX)

스택형 분수의 경우, MathFractionTypes.BAR를 사용합니다:

import aspose.slides.mathtext as math

stacked_fraction = math.MathematicalText("x + 1").divide("y - 1", math.MathFractionTypes.BAR)

근호 추가

radical을 사용하여 제곱근, 세제곱근 또는 기타 근을 만들 수 있습니다. 현재 요소가 밑이 되고, 인수가 차수가 됩니다.

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

import aspose.slides as slides
import aspose.slides.mathtext as math

with slides.Presentation() as presentation:
    slide = presentation.slides[0]

    math_shape = slide.shapes.add_math_shape(20, 20, 700, 100)
    math_paragraph = math_shape.text_frame.paragraphs[0].portions[0].math_paragraph

    radical = math.MathematicalText("x").radical("n")

    math_paragraph.add(math.MathBlock(radical))

    presentation.save("radical.pptx", slides.export.SaveFormat.PPTX)

제곱근 차수 표시 또는 숨기기

제곱근은 명시적인 2를 표시하거나 일반적인 √x 표기법을 사용할 수 있습니다. MathRadical의 hide_degree 속성은 어떤 형태가 나타날지 제어합니다. 두 형태 모두 편집 가능한 방정식에서 차수 2와 근호 안의 x를 유지합니다.

좌측에 차수 2가 보이고 우측에 숨겨진 x의 제곱근

예제는 동일한 제곱근을 두 번 저장합니다. 차수 2는 visible-degree.pptx에서는 보이고 hidden-degree.pptx에서는 숨겨집니다.

import aspose.slides as slides
import aspose.slides.mathtext as math

with slides.Presentation() as presentation:
    slide = presentation.slides[0]
    
    radical = math.MathematicalText("x").radical("2")

    shape = slide.shapes.add_math_shape(20, 20, 200, 100)
    portion = shape.text_frame.paragraphs[0].portions[0]
    portion.math_paragraph.add(math.MathBlock(radical))

    radical.hide_degree = False
    presentation.save("visible-degree.pptx", slides.export.SaveFormat.PPTX)

    radical.hide_degree = True
    presentation.save("hidden-degree.pptx", slides.export.SaveFormat.PPTX)

함수 및 극한 추가

as_argument_of_function 또는 function을 사용하여 sin(x), log(x)와 같은 함수 또는 사용자 정의 함수 이름을 지정합니다. 극한의 경우, lim을 MathLimit에 넣거나 set_lower_limit를 사용합니다.

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

import aspose.slides as slides
import aspose.slides.mathtext as math

with slides.Presentation() as presentation:
    slide = presentation.slides[0]

    math_shape = slide.shapes.add_math_shape(20, 20, 700, 100)
    math_paragraph = math_shape.text_frame.paragraphs[0].portions[0].math_paragraph

    limit = (
        math.MathematicalText("lim")
        .set_lower_limit("x\u2192\u221E")
        .function("x")
    )

    math_paragraph.add(math.MathBlock(limit))

    presentation.save("functions-and-limits.pptx", slides.export.SaveFormat.PPTX)

사용자 정의 함수 이름의 경우, 함수 이름을 현재 요소로 만들고 그 인수와 함께 function을 호출합니다:

import aspose.slides.mathtext as math

custom_function = math.MathematicalText("f").function("x + 1")

N-ary 연산자 및 적분 추가

합계, 합집합, 교집합 및 기타 대형 연산자에는 nary를 사용합니다. 적분에는 integral를 사용합니다. 두 메서드 모두 하한 및 상한을 설정할 수 있습니다.

하한 및 상한이 있는 합계

import aspose.slides as slides
import aspose.slides.mathtext as math

with slides.Presentation() as presentation:
    slide = presentation.slides[0]

    math_shape = slide.shapes.add_math_shape(20, 20, 700, 120)
    math_paragraph = math_shape.text_frame.paragraphs[0].portions[0].math_paragraph

    summation_base = (
        math.MathematicalText("x")
        .set_superscript("k")
        .join(math.MathematicalText("a").set_superscript("n-k"))
    )

    summation = summation_base.nary(math.MathNaryOperatorTypes.SUMMATION, "k=0", "n")

    math_paragraph.add(math.MathBlock(summation))

    presentation.save("nary-operators.pptx", slides.export.SaveFormat.PPTX)

N-ary 연산자는 옵션 한계가 있는 대형 연산자를 위해 사용됩니다. +, -, =와 같은 간단한 연산자는 보통 MathematicalText로 추가하고 식에 결합합니다.

적분의 경우, integral를 사용합니다:

import aspose.slides.mathtext as math

integral_base = math.MathematicalText("x").join(math.MathematicalText("dx").to_box())
integral = integral_base.integral(math.MathIntegralTypes.SIMPLE, "0", "1")

행렬 추가

MathMatrix를 사용하여 행과 열을 정의합니다. 행렬은 기본적으로 괄호를 포함하지 않으므로, 괄호, 대괄호 또는 중괄호가 필요할 때는 행렬을 감싸야 합니다.

한 빈 셀을 가진 두 행 수학 행렬

import aspose.slides as slides
import aspose.slides.mathtext as math

with slides.Presentation() as presentation:
    slide = presentation.slides[0]

    math_shape = slide.shapes.add_math_shape(20, 20, 700, 120)
    math_paragraph = math_shape.text_frame.paragraphs[0].portions[0].math_paragraph

    matrix = math.MathMatrix(2, 3)

    matrix[0, 0] = math.MathematicalText("1")
    matrix[0, 1] = math.MathematicalText("x")
    matrix[1, 0] = math.MathematicalText("x")
    matrix[1, 1] = math.MathematicalText("2")
    matrix[1, 2] = math.MathematicalText("y")
    math_paragraph.add(math.MathBlock(matrix))

    presentation.save("matrix.pptx", slides.export.SaveFormat.PPTX)

기존 행렬 편집

matrix.pptx에 저장된 계수 행렬로 선형대수 수업이 시작된다고 가정해 보겠습니다(앞 예제에 의해 저장됨). 다음 연습에서는 첫 번째 방정식을 유지하고 두 번째를 두 개의 새로운 방정식으로 교체하며 변수 집합을 수정합니다. 적용 가능한 계수를 유지하려면 기존 행렬을 MathMatrix로 접근합니다.

첫 번째 행에 1, x 및 빈 셀, 두 번째 행에 x, 2, y가 포함된 원래 두 행 계수 행렬

행 및 열 인덱스는 0부터 시작하며, 각 호출 시점의 행렬을 참조합니다. 인덱스 1 앞에 행을 삽입하면 원래 두 번째 행이 인덱스 2로 이동합니다. 인덱스 2 뒤에 삽입하면 행이 추가됩니다. 행 2를 삭제하면 원래 두 번째 방정식이 제거되고 추가된 행이 한 위치 위로 이동합니다. 열도 같은 방식으로 이동합니다.

import aspose.slides as slides
import aspose.slides.mathtext as math

with slides.Presentation("matrix.pptx") as presentation:
    shape = presentation.slides[0].shapes[0]
    portion = shape.text_frame.paragraphs[0].portions[0]
    matrix = portion.math_paragraph[0][0]

    matrix.insert_row_before(1)
    matrix.insert_row_after(2)
    matrix.delete_row(2)

    matrix.insert_column_before(1)
    matrix.insert_column_after(3)
    matrix.delete_column(3)

    matrix[1, 0] = math.MathematicalText("12")
    matrix[1, 1] = math.MathematicalText("1")
    matrix[2, 2] = math.MathematicalText("10")
    matrix[2, 3] = math.MathematicalText("1")
    for row in range(matrix.row_count):
        for column in range(matrix.column_count):
            if matrix[row, column] is None:
                matrix[row, column] = math.MathematicalText("0")

    matrix.set_column_alignment(0, math.MathHorizontalAlignment.LEFT)
    matrix.set_columns_alignment(1, 3, math.MathHorizontalAlignment.RIGHT)

    presentation.save("updated-matrix.pptx", slides.export.SaveFormat.PPTX)

set_column_alignment은 첫 번째 열을 왼쪽으로 정렬합니다. set_columns_alignment은 인덱스 1부터 시작하는 연속된 세 열을 오른쪽으로 정렬합니다. updated-matrix.pptx에서는 행렬에 세 개의 방정식과 네 개의 변수가 있습니다. 원래 첫 번째 행의 계수 1과 x는 이제 첫 번째와 세 번째 열에 나타납니다.

행 1, 0, x, 0; 12, 1, 0, 0; 0, 0, 10, 1을 표시하는 업데이트된 세 행 행렬

방정식 배열 추가

정렬된 방정식이나 수직 스택 표현식이 필요할 때는 to_math_array를 사용합니다.

x 위에 y가 있는 수직 수학 배열

import aspose.slides as slides
import aspose.slides.mathtext as math

with slides.Presentation() as presentation:
    slide = presentation.slides[0]

    math_shape = slide.shapes.add_math_shape(20, 20, 700, 140)
    math_paragraph = math_shape.text_frame.paragraphs[0].portions[0].math_paragraph

    equation_array = (
        math.MathematicalText("x")
        .join("y")
        .to_math_array()
    )

    math_paragraph.add(math.MathBlock(equation_array))

    presentation.save("equation-array.pptx", slides.export.SaveFormat.PPTX)

주변 요소와 배열 정렬

MathArray.base_justification은 배열의 수직 정렬을 옆의 수학 요소와 상대적으로 제어합니다. 아래 예제는 첫 번째 행, 배열 중심, 마지막 행과의 정렬을 비교합니다.

다음 예제는 세 개의 동일한 배열을 만들며, 각 배열은 세 행과 이웃 요소 A= 및 =B를 포함합니다. 모든 수학 텍스트는 24포인트 Cambria Math를 사용합니다. 배열 정렬만 변경됩니다.

import aspose.slides as slides
import aspose.slides.mathtext as math


def create_text(value):
    text = math.MathematicalText(value)
    text.format.font_height = 24
    text.format.latin_font = slides.FontData("Cambria Math")
    return text


with slides.Presentation() as presentation:
    presentation.slide_size.set_size(780, 200, slides.SlideSizeScaleType.DO_NOT_SCALE)
    slide = presentation.slides[0]
    alignments = [math.MathVerticalAlignment.TOP, math.MathVerticalAlignment.CENTER, math.MathVerticalAlignment.BOTTOM]
    labels = ["Top", "Center", "Bottom"]

    for i, alignment in enumerate(alignments):
        label = slide.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 20 + i * 260, 10, 240, 30)
        label.fill_format.fill_type = slides.FillType.NO_FILL
        label.line_format.fill_format.fill_type = slides.FillType.NO_FILL
        label.text_frame.text = labels[i]
        label_format = label.text_frame.paragraphs[0].portions[0].portion_format
        label_format.font_height = 16
        label_format.fill_format.fill_type = slides.FillType.SOLID
        label_format.fill_format.solid_fill_color.color = slides.Color.black

        math_shape = slide.shapes.add_math_shape(20 + i * 260, 60, 240, 130)
        math_shape.text_frame.text_frame_format.anchoring_type = slides.TextAnchorType.TOP
        math_paragraph = math_shape.text_frame.paragraphs[0].portions[0].math_paragraph
        math_paragraph.justification = math.MathJustification.LEFT_JUSTIFIED

        rows = [create_text("x+y=3"), create_text("x-y=1"), create_text("x=2")]
        equation_array = math.MathArray(rows)
        equation_array.base_justification = alignment
        left_text = create_text("A=")
        right_text = create_text("=B")
        equation = math.MathBlock(left_text).join(equation_array).join(right_text)
        math_paragraph.add(equation)

    presentation.save("equation-array-alignment.pptx", slides.export.SaveFormat.PPTX)

다음 비교는 PowerPoint에서 저장된 프레젠테이션을 보여줍니다. 각 배열 옆에 있는 A=와 =B 위치를 확인하세요.

위, 중앙, 하단 정렬과 동일한 이웃 요소를 가진 PowerPoint의 방정식 배열

행 간격 구성

row_spacing_rule은 배열 내 행에 대한 간격 규칙을 선택합니다. row_spacing은 명시적 간격 규칙을 위한 숫자 값을 제공하며 사전 설정 규칙에서는 무시됩니다.

정확한 간격의 경우 값은 포인트로 측정됩니다. 비례 간격은 반 라인 단위로 측정됩니다: 예제의 값 3은 1.5 라인을 나타냅니다. 명시적 값을 지정할 때는 두 속성을 모두 설정하세요; 숫자 값만 바꾸면 간격 규칙이 선택되지 않습니다.

아래 예제는 동일한 방정식, 정렬 및 글꼴 설정으로 다섯 개의 프레젠테이션을 저장합니다. 처음 세 개는 사전 설정을 사용하고, 마지막 두 개는 명시적 값을 보여줍니다.

import aspose.slides as slides
import aspose.slides.mathtext as math


def create_text(value):
    text = math.MathematicalText(value)
    text.format.font_height = 24
    text.format.latin_font = slides.FontData("Cambria Math")
    return text


settings = [
    (math.MathRowSpacingRule.SINGLE_LINE_GAP, 0),
    (math.MathRowSpacingRule.ONE_AND_A_HALF_LINE_GAP, 0),
    (math.MathRowSpacingRule.TWO_LINE_GAP, 0),
    (math.MathRowSpacingRule.EXACTLY, 20),
    (math.MathRowSpacingRule.MULTIPLE, 3)
]

for rule, spacing in settings:
    file_name = f"equation-array-{rule.name}.pptx"
    with slides.Presentation() as presentation:
        math_shape = presentation.slides[0].shapes.add_math_shape(20, 20, 600, 300)
        paragraph = math_shape.text_frame.paragraphs[0]
        paragraph.paragraph_format.space_before = 0
        paragraph.paragraph_format.space_after = 0
        math_paragraph = paragraph.portions[0].math_paragraph
        math_paragraph.justification = math.MathJustification.LEFT_JUSTIFIED

        rows = [create_text("x+y=3"), create_text("x-y=1"), create_text("x=2")]
        equation_array = math.MathArray(rows)
        equation_array.base_justification = math.MathVerticalAlignment.CENTER
        equation_array.row_spacing_rule = rule
        equation_array.row_spacing = spacing
        left_text = create_text("A=")
        right_text = create_text("=B")
        equation = math.MathBlock(left_text).join(equation_array).join(right_text)
        math_paragraph.add(equation)

        presentation.save(file_name, slides.export.SaveFormat.PPTX)

배열 행 간격은 단락 간격과 별개입니다. space_before 및 space_after는 배열 행 사이가 아니라 포함하는 단락 주변에 공간을 추가합니다. 또한 MathParagraph.justification은 전체 수학 단락을 수평으로 배치하며, 배열의 수직 정렬 설정을 대체하지 않습니다.

삼각 함수 추가

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

2x에 적용된 삼각 함수 cos

import aspose.slides as slides
import aspose.slides.mathtext as math

with slides.Presentation() as presentation:
    slide = presentation.slides[0]

    math_shape = slide.shapes.add_math_shape(20, 20, 700, 100)
    math_paragraph = math_shape.text_frame.paragraphs[0].portions[0].math_paragraph

    cosine = math.MathematicalText("2x").as_argument_of_function(
        math.MathFunctionsOfOneArgument.COS
    )

    math_paragraph.add(math.MathBlock(cosine))

    presentation.save("trigonometric-function.pptx", slides.export.SaveFormat.PPTX)

첨자 및 위첨자 추가

인덱스와 거듭 제곱에 대해 첨자 및 위첨자 도우미를 사용합니다. 인덱스를 밑수의 왼쪽에 배치해야 할 경우, set_sub_superscript_on_the_left을 사용합니다.

좌측에 첨자 1과 위첨자 n이 있는 대문자 Y

import aspose.slides as slides
import aspose.slides.mathtext as math

with slides.Presentation() as presentation:
    slide = presentation.slides[0]

    math_shape = slide.shapes.add_math_shape(20, 20, 700, 100)
    math_paragraph = math_shape.text_frame.paragraphs[0].portions[0].math_paragraph

    scripts = math.MathematicalText("Y").set_sub_superscript_on_the_left("1", "n")

    math_paragraph.add(math.MathBlock(scripts))

    presentation.save("subscript-superscript.pptx", slides.export.SaveFormat.PPTX)

구분자 추가

enclose를 사용하여 표현식을 구분자 안에 넣습니다. 여러 요소가 포함된 구분자 표현식에 구분 문자도 설정할 수 있습니다.

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

import aspose.slides as slides
import aspose.slides.mathtext as math

with slides.Presentation() as presentation:
    slide = presentation.slides[0]

    math_shape = slide.shapes.add_math_shape(20, 20, 700, 100)
    math_paragraph = math_shape.text_frame.paragraphs[0].portions[0].math_paragraph

    delimiter = (
        math.MathematicalText("x")
        .join("y")
        .join("z")
        .enclose("<", ">")
    )
    delimiter.separator_character = "|"

    math_paragraph.add(math.MathBlock(delimiter))

    presentation.save("delimiters.pptx", slides.export.SaveFormat.PPTX)

구분자 크기 및 정렬

grow_to_match_operand_height를 True로 설정하면 큰 피연산자 주위에 괄호가 확대되고, False로 설정하면 정상 크기로 유지됩니다. delimiter_shape은 두 가지 MathDelimiterShape 값 중 하나를 취합니다. CENTERED는 등호 기호 중간을 통과하는 수학 축에 괄호를 중앙에 배치합니다. MATCH는 괄호를 포함된 내용에 맞춥니다. 두 설정은 구분자에만 영향을 미치며 내부 표현식은 동일하게 유지됩니다.

예제는 x의 지수에 분수를 배치하여 표현식이 기준선 위쪽으로 더 많이 확장되도록 합니다. 네 개의 방정식 모두 동일한 괄호와 글꼴 설정을 사용합니다.

import aspose.slides as slides
import aspose.slides.mathtext as math


def add_expression(slide, left, top, grow, shape):
    fraction = math.MathematicalText("a + b").divide("c + d")
    power = math.MathematicalText("x").set_superscript(fraction)
    delimiter = power.enclose("(", ")")
    delimiter.grow_to_match_operand_height = grow
    delimiter.delimiter_shape = shape

    math_shape = slide.shapes.add_math_shape(left, top, 300, 100)
    portion = math_shape.text_frame.paragraphs[0].portions[0]
    portion.portion_format.font_height = 32
    equation = math.MathematicalText("y = ").join(delimiter)
    portion.math_paragraph.add(equation)


with slides.Presentation() as presentation:
    slide = presentation.slides[0]
    add_expression(slide, 20, 20, True, math.MathDelimiterShape.CENTERED)
    add_expression(slide, 350, 20, True, math.MathDelimiterShape.MATCH)
    add_expression(slide, 20, 140, False, math.MathDelimiterShape.CENTERED)
    add_expression(slide, 350, 140, False, math.MathDelimiterShape.MATCH)

    presentation.save("delimiter-sizing.pptx", slides.export.SaveFormat.PPTX)

PowerPoint에서 행을 비교하여 확대 효과를 확인하세요. 상단 행에서는 괄호가 지수를 둘러싸도록 확대되어 두 형태가 동일하게 보입니다. 하단 행에서는 확대가 비활성화됩니다. 왼쪽의 작은 괄호(CENTERED)는 등호와 정렬되고, 오른쪽의 괄호(MATCH)는 표현식 위쪽에 높게 위치합니다.

PowerPoint에서 구분자 확대가 위쪽에 활성화되고 아래쪽에 비활성화된 네 개의 방정식, 왼쪽은 Centered, 오른쪽은 Match

테두리 박스 추가

분수에 to_border_box을 호출하면 전체 표현식을 프레임으로 묶습니다. 반환된 MathBorderBox는 기본적으로 네 면을 모두 표시합니다. 개별 면을 제거하려면 hide_top, hide_bottom, hide_left, hide_right를 사용합니다.

예제는 같은 분수를 한 슬라이드에 여섯 번 배치합니다. 취소 표시를 위해 네 면을 모두 숨기고 상승 대각선(↗)에는 strikethrough_bottom_left_to_top_right, 하강 대각선(↘)에는 strikethrough_top_left_to_bottom_right을 설정합니다. 또한 strikethrough_horizontal 또는 strikethrough_vertical을 사용하여 보이는 면을 조합할 수 있습니다.

import aspose.slides as slides
import aspose.slides.mathtext as math


def add_fraction(slide, x, y, hide_border=False):
    fraction = math.MathematicalText("x+1").divide("y+2")
    box = fraction.to_border_box()
    box.hide_top = box.hide_bottom = box.hide_left = box.hide_right = hide_border

    shape = slide.shapes.add_math_shape(x, y, 160, 90)
    portion = shape.text_frame.paragraphs[0].portions[0]
    portion.portion_format.font_height = 28
    portion.math_paragraph.add(math.MathBlock(box))
    return box


with slides.Presentation() as presentation:
    presentation.slide_size.set_size(540, 220, slides.SlideSizeScaleType.DO_NOT_SCALE)
    slide = presentation.slides[0]

    add_fraction(slide, 10, 10)

    partial = add_fraction(slide, 190, 10)
    partial.hide_top = True
    partial.hide_right = True

    add_fraction(slide, 370, 10, hide_border=True).strikethrough_bottom_left_to_top_right = True
    add_fraction(slide, 10, 120, hide_border=True).strikethrough_top_left_to_bottom_right = True
    add_fraction(slide, 190, 120, hide_border=True).strikethrough_horizontal = True
    add_fraction(slide, 370, 120).strikethrough_vertical = True

    presentation.save("border-box.pptx", slides.export.SaveFormat.PPTX)

PowerPoint에 편집 가능한 여섯 개의 분수. 상단 행: 전체 테두리, 하단 및 왼쪽 면, 상승 대각선. 하단 행: 하강 대각선, 수평 스트라이크, 전체 테두리와 함께 수직 스트라이크.

이 분수에서 수평 스트라이크는 분수 막대를 겹칩니다. 수직 스트라이크는 분자와 분모를 가로질러 주변 테두리는 보이게 유지됩니다. 이러한 선은 전체 표현식을 장식합니다. 일반 텍스트 취소선은 텍스트 실행의 문자에 적용됩니다. PowerPoint에서 프레젠테이션을 다시 열어도 분자와 분모를 독립적으로 편집할 수 있습니다.

Phantom 요소로 가시성 및 레이아웃 제어

표현식을 MathPhantom으로 감싸면 가시성과 방정식에 기여하는 공간을 독립적으로 제어할 수 있습니다. 그 속성은 다음을 제어합니다:

Property Effect
show False로 설정하면 표현식을 숨깁니다. 차원은 여전히 레이아웃에 기여합니다(아래 속성이 True가 아니면).
zero_width 표현식의 가로 너비를 zero로 처리하여 인접 요소가 더 가깝게 이동합니다.
zero_asc 상승 부분(기준선 위 높이)을 zero로 처리합니다. 이는 인접 요소 위의 공간을 줄일 수 있습니다.
zero_desc 하강 부분(기준선 아래 깊이)을 zero로 처리합니다. 이는 분수 막대와 같은 아래 내용이 인접 요소에 더 가깝게 배치될 수 있게 합니다.

기준선은 일반 수학 문자들이 놓이는 기준선입니다. 내용을 숨겨도 차원은 제거되지 않으며, 차원을 zero로 처리해도 표현식이 삭제되지 않습니다. 기본 표현식은 base을 통해 여전히 사용할 수 있습니다. show을 True로 다시 설정하면 다시 표시되며, 차원 설정은 그대로 유지됩니다.

import aspose.slides as slides
import aspose.slides.mathtext as math


def create_text(value):
    text = math.MathematicalText(value)
    text.format.font_height = 24
    text.format.latin_font = slides.FontData("Cambria Math")
    return text


with slides.Presentation() as presentation:
    presentation.slide_size.set_size(1000, 180, slides.SlideSizeScaleType.DO_NOT_SCALE)
    slide = presentation.slides[0]
    labels = ["Visible", "Hidden: reserves space", "Hidden: ZeroWidth", "Hidden: ZeroAsc", "Hidden: ZeroDesc"]

    guide = slide.shapes.add_auto_shape(slides.ShapeType.LINE, 10, 60, 980, 0)
    guide.line_format.fill_format.fill_type = slides.FillType.SOLID
    guide.line_format.fill_format.solid_fill_color.color = slides.Color.light_gray

    for i, label_text in enumerate(labels):
        left = 10 + i * 200
        label = slide.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, left, 10, 190, 30)
        label.fill_format.fill_type = slides.FillType.NO_FILL
        label.line_format.fill_format.fill_type = slides.FillType.NO_FILL
        label.text_frame.text = label_text
        label_format = label.text_frame.paragraphs[0].portions[0].portion_format
        label_format.font_height = 14
        label_format.fill_format.fill_type = slides.FillType.SOLID
        label_format.fill_format.solid_fill_color.color = slides.Color.black

        fraction_numerator = create_text("a+b")
        fraction_denominator = create_text("c+d")
        fraction = math.MathFraction(fraction_numerator, fraction_denominator)
        phantom = math.MathPhantom(fraction)
        phantom.show = i == 0
        phantom.zero_width = i == 2
        phantom.zero_asc = i == 3
        phantom.zero_desc = i == 4

        left_text = create_text("x+")
        right_text = create_text("+y")
        numerator = math.MathBlock(left_text).join(phantom).join(right_text)
        denominator = create_text("z")
        equation = math.MathFraction(numerator, denominator)

        shape = slide.shapes.add_math_shape(left, 60, 190, 100)
        shape.text_frame.text_frame_format.anchoring_type = slides.TextAnchorType.TOP
        math_paragraph = shape.text_frame.paragraphs[0].portions[0].math_paragraph
        math_paragraph.add(math.MathBlock(equation))

    presentation.save("math-phantom.pptx", slides.export.SaveFormat.PPTX)

PowerPoint에서 보이는 분수, 공간을 보존하는 숨긴 분수, ZeroWidth, ZeroAsc, ZeroDesc가 활성화된 숨긴 분수들을 비교한 다섯 개의 방정식

용어 그룹화

group을 사용하여 표현식 위나 아래에 그룹화 문자를 배치합니다. 그룹화된 용어에 레이블을 달려면 한계(limit)를 추가합니다.

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

import aspose.slides as slides
import aspose.slides.mathtext as math

with slides.Presentation() as presentation:
    slide = presentation.slides[0]

    math_shape = slide.shapes.add_math_shape(20, 20, 700, 120)
    math_paragraph = math_shape.text_frame.paragraphs[0].portions[0].math_paragraph

    grouped = (
        math.MathematicalText("x + y")
        .group(chr(0x23DF), math.MathTopBotPositions.BOTTOM, math.MathTopBotPositions.TOP)
        .set_lower_limit("any text")
    )

    math_paragraph.add(math.MathBlock(grouped))

    presentation.save("grouped-terms.pptx", slides.export.SaveFormat.PPTX)

수학 요소 서식 지정

포뮬러를 명확히 할 때만 서식 도우미를 사용합니다. 예를 들어, overbar는 수학 요소 위에 막대를 놓습니다.

overbar가 있는 수학 표현식 ABC

import aspose.slides as slides
import aspose.slides.mathtext as math

with slides.Presentation() as presentation:
    slide = presentation.slides[0]

    math_shape = slide.shapes.add_math_shape(20, 20, 700, 100)
    math_paragraph = math_shape.text_frame.paragraphs[0].portions[0].math_paragraph

    overbar = math.MathematicalText("ABC").overbar()

    math_paragraph.add(math.MathBlock(overbar))

    presentation.save("overbar.pptx", slides.export.SaveFormat.PPTX)

기존 방정식의 텍스트 서식 지정

기존 방정식 전체의 텍스트에 서식을 지정하려면 각 수학 블록의 요소 트리를 순회합니다. MathElementBase.get_children는 즉시 자식만 반환하므로, 재귀적으로 호출하여 분수, 스크립트, 근호 및 기타 중첩 구조 내부의 텍스트에 도달합니다. 현재 요소와 그 자식들을 확인하여 시작 요소가 MathematicalText일 때도 포함합니다.

이 예제는 input.pptx에 z = xᵢ / ∛y와 같은 방정식이 포함되어 있다고 가정합니다. 여기서 분수는 분자에 첨자, 분모에 근호가 있습니다. 블록의 최상위 요소만 처리하면 분수 내부 텍스트를 놓칠 수 있습니다. 예제는 슬라이드 텍스트 프레임에서 수학 부분을 찾고, MathPortion.math_paragraph를 통해 블록에 접근한 뒤, 각 텍스트 요소의 format 속성을 통해 font_height를 28포인트로 설정합니다.

import aspose.slides as slides
import aspose.slides.mathtext as math


def format_math_text(element):
    if isinstance(element, math.MathematicalText):
        element.format.font_height = 28

    for child in element.get_children():
        format_math_text(child)


with slides.Presentation("input.pptx") as presentation:
    for slide in presentation.slides:
        for shape in slide.shapes:
            if not isinstance(shape, slides.AutoShape) or shape.text_frame is None:
                continue

            for paragraph in shape.text_frame.paragraphs:
                for portion in paragraph.portions:
                    if isinstance(portion, math.MathPortion):
                        for block in portion.math_paragraph:
                            format_math_text(block)

    presentation.save("formatted-equations.pptx", slides.export.SaveFormat.PPTX)

저장된 프레젠테이션은 처리된 각 방정식의 모든 수준에서 텍스트 서식이 업데이트되었으며, 텍스트 내용과 수학 구조를 그대로 유지합니다.

빠른 참조

Task Main API
수학 텍스트 만들기 MathematicalText
요소 결합 MathElementBase.join
분수 만들기 MathElementBase.divide
위첨자 또는 첨자 추가 set_superscript, set_subscript
함수 추가 function, as_argument_of_function
근호 추가 radical
극한 추가 set_lower_limit, set_upper_limit
좌측 스크립트 추가 set_sub_superscript_on_the_left
합계와 적분 추가 nary, integral
행렬 추가 MathMatrix
방정식 배열 추가 to_math_array
구분자 추가 enclose
바와 테두리 추가 overbar, to_border_box
용어 그룹화 group

FAQ

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

예. 프레젠테이션을 열고, MathPortion을 포함하는 셰이프를 찾아 해당 math_paragraph을 가져온 다음 해당 단락의 수학 블록을 업데이트합니다.

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

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

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

예. 방정식의 MathParagraph을 해당 MathPortion에서 가져오고 MathParagraph.to_latex를 호출하면 직접 내보낼 수 있습니다. 전체 예제는 Python via .NET에서 프레젠테이션의 수학 방정식 내보내기를 참고하세요.