إضافة معادلات رياضية إلى عروض PowerPoint التقديمية في Python
نظرة عامة
PowerPoint يخزن المعادلات كـ Office Math Markup Language (OMML). باستخدام Aspose.Slides للغة Python عبر Java، يمكنك إنشاء نفس نوع محتوى الرياضيات برمجياً: الكسور، الجذور، الدوال، الحدود، عوامل N-ary، المصفوفات، المصفوفات المتعددة، وكتل الرياضيات المنسقة.
في PowerPoint، يضيف المستخدمون عادة المعادلات من إدراج > معادلة:

النتيجة هي نص رياضي قابل للتحرير على الشريحة:

يُنشئ Aspose.Slides ذلك النص الرياضي من خلال ثلاثة كائنات رئيسية:
- A شكل رياضي، يُنشأ باستخدام 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()
إضافة الدوال والحدود
استخدم 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():
jpase.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. جميع النصوص الرياضية تستخدم Cambria Math بحجم 24 نقطة. فقط محاذاة المصفوفة تتغير.
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()
حجم ومحاذاة الفواصل
مرّر True إلى setGrowToMatchOperandHeight لجعل الأقواس تتسع حول عنصر طويل، أو مرّر False للحفاظ على حجمها الطبيعي. استخدم setDelimiterShape مع أحد قيمتي MathDelimiterShape. 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 لإزالة جوانب معينة.
يضع المثال ست نسخ من نفس الكسر على شريحة واحدة. لإظهار الإلغاء، أخفِ جميع الجوانب الأربعة ومرّر True إلى setStrikethroughBottomLeftToTopRight لخط قطري صاعد (↗) أو إلى setStrikethroughTopLeftToBottomRight لخط قطري هابط (↘). يمكنك أيضًا استخدام 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، يمكنك ما زال تحرير البسط والمقام بشكل مستقل.
تجميع المصطلحات
استخدم 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، ويستخدم setFontHeight لضبط حجم الخط إلى 28 نقطة لكل عنصر نصي عبر طريقة getFormat.
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()
العرض التقديمي المحفوظ يحتوي على تنسيق النص المحدّث في كل مستوى من كل معادلة تم معالجتها، مع الحفاظ على محتوى النص والبنية الرياضية.
مرجع سريع
| المهمة | واجهة برمجة التطبيقات الرئيسية |
|---|---|
| إنشاء نص رياضي | 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 Math قابل للتحرير.
هل يمكنني تصدير المعادلات إلى LaTeX؟
نعم. احصل على MathParagraph للمعادلة من MathPortion، واستدعِ MathParagraph.toLatex لتصديره مباشرة. للحصول على مثال كامل، راجع تصدير المعادلات الرياضية من العروض التقديمية في Python.