Python में PowerPoint प्रस्तुतियों में गणितीय समीकरण जोड़ें

अवलोकन

PowerPoint समीकरणों को Office Math Markup Language (OMML) के रूप में संग्रहीत करता है। Aspose.Slides for Python via Java के साथ, आप प्रोग्रामेटिक रूप से समान प्रकार की गणितीय सामग्री बना सकते हैं: भिन्न, मूल, फ़ंक्शन, सीमा, N-ary ऑपरेटर, मैट्रिक्स, एरे और स्वरूपित गणित ब्लॉक्स।

PowerPoint में, उपयोगकर्ता सामान्यतः Insert > Equation से समीकरण जोड़ते हैं:

PowerPoint Insert tab with the Equation command selected

परिणाम स्लाइड पर संपादन योग्य गणितीय पाठ होता है:

A PowerPoint slide containing an editable math equation

Aspose.Slides उस गणितीय पाठ को तीन मुख्य वस्तुओं के माध्यम से बनाता है:

  • गणितीय आकार, जिसे addMathShape से बनाया जाता है, वह आकार है जो समीकरण को रखता है।
  • MathPortion आकार के टेक्स्ट फ्रेम के भीतर गणितीय सामग्री संग्रहीत करता है।
  • MathParagraph एक या अधिक MathBlock वस्तुओं को सम्मिलित करता है।

नीचे के अधिकांश उदाहरण MathematicalText और MathElementBase की प्रवाहशील विधियों का उपयोग करते हैं ताकि कोड छोटा और पढ़ने योग्य रहे।

MathML निर्यात परिदृश्यों के लिए, देखें Export Math Equations from Presentations in Python।

समीकरण बनाएं

यह उदाहरण addMathShape का उपयोग करके एक गणितीय आकार बनाता है और पायथागोरस प्रमेय जोड़ता है:

The equation c squared equals a squared plus b squared

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 के साथ भिन्न शैली चुन सकते हैं।

A skewed math fraction showing one divided by 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 का उपयोग करके वर्गमूल, घनमूल या अन्य मूल बनाएँ। वर्तमान तत्व आधार बन जाता है, और तर्क डिग्री बन जाता है।

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

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 का उपयोग करें।

The limit of x as x approaches infinity

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 का उपयोग करें। दोनों विधियों से आप निचली और ऊपरी सीमाएँ सेट कर सकते हैं।

A summation with lower and upper limits

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 का उपयोग पंक्तियों और स्तंभों के लिए करें। डिफ़ॉल्ट रूप से मैट्रिक्स में कोष्ठक नहीं होते, इसलिए जब आपको कोष्ठक, वर्ग कोष्ठक या कर्ली ब्रैकेट की आवश्यकता हो तो मैट्रिक्स को इनके भीतर रखें।

A two-row math matrix with one empty cell

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 का उपयोग करें।

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

परिधीय तत्वों के साथ एरे को संरेखित करें

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 की स्थिति पर ध्यान दें।

Equation arrays in PowerPoint with Top, Center, and Bottom alignment and identical neighboring elements

पंक्ति अंतराल कॉन्फ़िगर करें

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 का उपयोग करें।

The trigonometric function cos applied to 2x

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 का उपयोग करें।

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

    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 का उपयोग करके अभिव्यक्ति को डिलिमिटर के भीतर रखें। आप कई तत्वों वाली डिलिमिटर अभिव्यक्तियों के लिए विभाजक अक्षर भी सेट कर सकते हैं।

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

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) अभिव्यक्ति के चारों ओर ऊँची बैठी हैं।

Four equations in PowerPoint with delimiter growth enabled above and disabled below, and Centered on the left and Match on the right

एक बॉर्डर बॉक्स जोड़ें

भिन्न पर toBorderBox को कॉल करके पूरी अभिव्यक्ति को फ्रेम करें। लौटाया गया MathBorderBox डिफ़ॉल्ट रूप से सभी चार पक्ष दिखाता है। व्यक्तिगत पक्ष हटाने के लिए setHideTop, setHideBottom, setHideLeft, और setHideRight का उपयोग करें।

उदाहरण एक स्लाइड पर समान भिन्न के छह प्रतिलिपि रखता है। रद्द करने के लिये, सभी चार पक्ष छिपाएँ और setStrikethroughBottomLeftToTopRight को True पास करें ताकि एक ऊपर की तरफ तिरछी रेखा (↗) बन सके या 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()

Six editable fractions in PowerPoint. Top row: full border, bottom and left sides, rising diagonal. Bottom row: falling diagonal, horizontal strike, vertical strike with a full border.

इस भिन्न पर, क्षैतिज स्ट्राइक फ्रैक्शन बार को कवर करता है। लंबवत स्ट्राइक न्यूमेरेटर और डिनॉमिनेटर दोनों को काटता है जबकि चारों ओर का बॉर्डर दृश्यमान रहता है। ये रेखाएँ पूरी अभिव्यक्ति को सजाती हैं। सामान्य टेक्स्ट स्ट्राइकथ्रू केवल टेक्स्ट रन के अक्षर पर लागू होता है। PowerPoint में प्रस्तुति को पुनः खोलने के बाद, आप अभी भी न्यूमेरेटर और डिनॉमिनेटर को स्वतंत्र रूप से संपादित कर सकते हैं।

फ़ैंटम तत्वों के साथ दृश्यता और लेआउट नियंत्रित करें

MathPhantom में अभिव्यक्ति को लपेटें ताकि उसकी दृश्यता और समीकरण में योगदानित स्थान को स्वतंत्र रूप से नियंत्रित किया जा सके। MathPhantom विधियाँ निम्नलिखित को नियंत्रित करती हैं:

विधि प्रभाव
setShow अभिव्यक्ति को छिपाने के लिये False पास करें। इसके आयाम लेआउट में अभी भी योगदान देते हैं जब तक नीचे की संबंधित विधियाँ True न प्राप्त करें।
setZeroWidth अभिव्यक्ति की क्षैतिज चौड़ाई को शून्य मानें, जिससे पड़ोसी तत्व करीब आ सकें।
setZeroAsc इसके आरोहण (बेसलाइन के ऊपर की ऊँचाई) को शून्य मानें। इससे पड़ोसी तत्वों के ऊपर आरक्षित स्थान कम हो सकता है।
setZeroDesc इसके अवरोहण (बेसलाइन के नीचे की गहराई) को शून्य मानें। इससे अभिव्यक्ति के नीचे का फ्रैक्शन बार या अन्य सामग्री पड़ोसियों के निकट आ सकती है।

बेसलाइन वह संदर्भ रेखा है जिस पर सामान्य गणितीय अक्षर स्थित होते हैं। सामग्री को छिपाना उसके आयामों को नहीं हटाता, और आयाम को शून्य मानना अभिव्यक्ति को नहीं हटाता। अंतर्निहित अभिव्यत्ति getBase के माध्यम से उपलब्ध रहती है। उसे फिर से दिखाने के लिये setShow में True पास करें; आयाम सेटिंग्स अपरिवर्तित रहती हैं।

निम्न उदाहरण पाँच समानांतर विविधताएँ बनाता है: एक दृश्यमान भिन्न, एक छिपा भिन्न जो स्थान आरक्षित करता है, और तीन छिपे भिन्न जहाँ एक आयाम शून्य माना गया है। प्रत्येक विविधता समान परिधीय अभिव्यक्ति और Cambria Math 24 पॉइंट का उपयोग करती है। सभी समीकरण आकार समान शीर्ष स्थिति रखते हैं, जो ग्रे गाइड द्वारा चिह्नित है। बाहरी भिन्न के न्यूमेरेटर में फ़ैंटम रखने से ऊर्ध्विक लेआउट परिवर्तन देखना आसान हो जाता है।

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

Five equations in PowerPoint comparing a visible fraction, a hidden fraction that reserves space, and hidden fractions with ZeroWidth, ZeroAsc, or ZeroDesc enabled

शब्दों को समूहित करें

एक अभिव्यक्ति के ऊपर या नीचे समूहिंग अक्षर रखने के लिये group का उपयोग करें। समूहित शब्दों को लेबल करने के लिये एक सीमा जोड़ें।

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

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 एक गणितीय तत्व के ऊपर बार रखता है।

A math expression ABC with an 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 को कॉल करें। पूर्ण उदाहरण के लिये, देखें Export Math Equations from Presentations in Python।