Python'da PowerPoint Sunumlarına Matematik Denklemleri Ekleme

Genel Bakış

PowerPoint, denklemleri Office Math Markup Language (OMML) formatında saklar. Aspose.Slides for Python via .NET ile aynı türde matematik içeriğini programlı olarak oluşturabilirsiniz: kesirler, kökler, fonksiyonlar, limitler, N-ary operatörler, matrisler, diziler ve biçimlendirilmiş matematik blokları.

PowerPoint’te kullanıcılar genellikle denklemleri Ekle > Denklem üzerinden ekler:

PowerPoint Insert tab with the Equation command selected

Sonuç, slaytta düzenlenebilir matematik metnidir:

A PowerPoint slide containing an editable math equation

Aspose.Slides, bu matematik metnini üç ana nesne aracılığıyla oluşturur:

Aşağıdaki çoğu örnek, kodu kısa ve okunabilir tutmak için MathematicalText ve IMathElement üzerindeki akıcı metodları kullanır.

MathML dışa aktarma senaryoları için, Python ile .NET üzerinden Sunumlarda Matematik Denklemlerini Dışa Aktarma bölümüne bakın.

Denklem Oluşturma

Bu örnek bir matematik şekli oluşturur ve Pisagor teoremini ekler:

The equation c squared equals a squared plus b squared

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)

Kesir Ekleme

divide kullanarak bir kesir oluşturabilirsiniz. Bir kesir stilini MathFractionTypes ile seçebilirsiniz.

A skewed math fraction showing one divided by 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)

Yığılmış bir kesir için MathFractionTypes.BAR kullanın:

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

Kök Ekleme

radical kullanarak karekök, küpkök veya diğer kökleri oluşturabilirsiniz. Mevcut öğe taban olur, argüman ise derecesi olur.

An n-th root radical expression with x under the radical sign

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)

Fonksiyon ve Limit Ekleme

as_argument_of_function ya da function metodlarını sin(x), log(x) gibi fonksiyonlar veya özel fonksiyon adları için kullanın. Limitler için lim ifadesini bir MathLimit içine koyun veya set_lower_limit metodunu kullanın.

The limit of x as x approaches infinity

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)

Özel bir fonksiyon adı için, fonksiyon adını mevcut öğe yapın:

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

N-ary Operatör ve İntegral Ekleme

Toplamalar, birleşimler, kesişimler ve diğer büyük operatörler için nary kullanın. İntegraller için integral kullanın. Her iki yöntem de alt ve üst limitleri ayarlamanıza izin verir.

A summation with lower and upper limits

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 operatörler, isteğe bağlı limitleri olan büyük operatörler içindir. +, -, = gibi basit operatörler genellikle MathematicalText olarak eklenir ve ifadeye birleştirilir.

Bir integral için integral kullanın:

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

Matris Ekleme

Satır ve sütunlar için MathMatrix kullanın. Matrisler varsayılan olarak köşeli parantez içermez, bu nedenle parantez, köşeli parantez veya süslü parantez gerektiğinde matrisi bu işaretlerle çevreleyin.

A two-row math matrix with one empty cell

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)

Denklem Dizileri Ekleme

Hizalanmış denklemler veya dikey bir ifade yığını gerektiğinde to_math_array kullanın.

A vertical math array with x above 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)

Trigonometrik Fonksiyon Ekleme

Argüman mevcut öğe ve fonksiyon adı biliniyorsa as_argument_of_function kullanın.

The trigonometric function cos applied to 2x

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)

Alt ve Üst Simge Ekleme

İndeks ve üsler için alt ve üst simge yardımcılarını kullanın. İndekslerin tabanın sol tarafında görünmesi gerektiğinde set_sub_superscript_on_the_left kullanın.

A capital Y with left-side subscript 1 and superscript 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

    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)

Ayırıcılar Ekleme

Bir ifadeyi ayırıcıların içine yerleştirmek için enclose kullanın. Birden fazla öğe içeren ayırıcı ifadeler için ayırıcı karakter de ayarlayabilirsiniz.

A delimiter expression containing x, y, and z separated by vertical bars

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)

Kenar Kutusu Ekleme

Denklemin kendisinin çerçevelenmesi gerektiğinde to_border_box kullanın.

A boxed equation showing a squared equals b squared plus c squared

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

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

    math_paragraph.add(math.MathBlock(boxed_equation))

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

Terimleri Gruplama

Bir ifadeye grup karakteri üstüne veya altına yerleştirmek için group kullanın. Gruplanmış terimleri etiketlemek için bir limit ekleyin.

The expression x plus y grouped with the label any text below it

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)

Matematik Öğelerini Biçimlendirme

Biçimlendirme yardımcılarını yalnızca formülü netleştirdiği durumlarda kullanın. Örneğin, overbar bir matematik öğesinin üzerine bir çubuk yerleştirir.

A math expression ABC with an overbar

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)

Hızlı Başvuru

Görev Ana API
Matematik metni oluşturma MathematicalText
Öğeleri birleştirme IMathElement.join
Kesir oluşturma IMathElement.divide
Üst simge veya alt simge ekleme set_superscript, set_subscript
Fonksiyon ekleme function, as_argument_of_function
Kök ekleme radical
Limit ekleme set_lower_limit, set_upper_limit
Sol taraflı indeks ekleme set_sub_superscript_on_the_left
Toplamlar ve integraller ekleme nary, integral
Matris ekleme MathMatrix
Denklem dizileri ekleme to_math_array
Ayırıcı ekleme enclose
Çubuk ve kenar ekleme overbar, to_border_box
Terimleri gruplama group

SSS

Mevcut bir PowerPoint denklemine düzenleme yapabilir miyim?

Evet. Sunumu açın, bir MathPortion içeren şekli bulun, onun MathParagraph‘ını alın ve o paragraftaki matematik bloklarını güncelleyin.

Denklikler düzenlenebilir PowerPoint matematiği olarak kaydediliyor mu?

Evet. PPTX olarak kaydettiğinizde, Aspose.Slides denklemi düzenlenebilir Office math içeriği olarak yazar.

Denklikleri LaTeX’e dışa aktarabilir miyim?

Aspose.Slides, matematik denklemlerini MathML olarak dışa aktarır. LaTeX’e ihtiyacınız varsa, önce MathML’e aktarın ve ardından hedef LaTeX diline destek veren bir araçla MathML’i dönüştürün.