Voeg wiskundige vergelijkingen toe aan PowerPoint‑presentaties op Android

Overzicht

PowerPoint slaat vergelijkingen op als Office Math Markup Language (OMML). Met Aspose.Slides for Android via Java kun je dezelfde soort wiskundige inhoud programmatically maken: breuken, wortels, functies, limieten, N-ary‑operatoren, matrices, arrays en opgemaakte wiskundige blokken.

In PowerPoint voegen gebruikers normaal gesproken vergelijkingen toe via Invoegen > Vergelijking:

PowerPoint tabblad Invoegen met de opdracht Vergelijking geselecteerd

Het resultaat is bewerkbare wiskundige tekst op de dia:

Een PowerPoint‑dia met een bewerkbare wiskundige vergelijking

Aspose.Slides bouwt die wiskundige tekst via drie hoofdobjecten:

De meeste voorbeelden hieronder gebruiken MathematicalText en de fluente methoden van IMathElement om de code kort en leesbaar te houden.

Voor MathML‑exportscenario’s, zie Export Math Equations from Presentations on Android.

Een vergelijking maken

Dit voorbeeld maakt een wiskundige vorm en voegt de stelling van Pythagoras toe:

De vergelijking c² = a² + b²

Presentation presentation = new Presentation();
try {
    ISlide slide = presentation.getSlides().get_Item(0);

    IAutoShape mathShape = slide.getShapes().addMathShape(20, 20, 700, 120);
    IMathParagraph mathParagraph = ((MathPortion) mathShape.getTextFrame().getParagraphs()
            .get_Item(0).getPortions().get_Item(0)).getMathParagraph();

    IMathBlock equation = new MathematicalText("c")
            .setSuperscript("2")
            .join("=")
            .join(new MathematicalText("a").setSuperscript("2"))
            .join("+")
            .join(new MathematicalText("b").setSuperscript("2"));

    mathParagraph.add(equation);

    presentation.save("pythagorean-theorem.pptx", SaveFormat.Pptx);
} finally {
    presentation.dispose();
}

Breuken toevoegen

Gebruik divide om een breuk te maken. Je kunt een breukstijl kiezen met MathFractionTypes.

Een scheve wiskundige breuk die één gedeeld door x toont

Presentation presentation = new Presentation();
try {
    ISlide slide = presentation.getSlides().get_Item(0);

    IAutoShape mathShape = slide.getShapes().addMathShape(20, 20, 700, 100);
    IMathParagraph mathParagraph = ((MathPortion) mathShape.getTextFrame().getParagraphs()
            .get_Item(0).getPortions().get_Item(0)).getMathParagraph();

    IMathFraction fraction = new MathematicalText("1")
            .divide("x", MathFractionTypes.Skewed);

    mathParagraph.add(new MathBlock(fraction));

    presentation.save("fraction.pptx", SaveFormat.Pptx);
} finally {
    presentation.dispose();
}

Voor een gestapelde breuk, gebruik MathFractionTypes.Bar:

IMathFraction stackedFraction = new MathematicalText("x + 1").divide("y - 1", MathFractionTypes.Bar);

Wortels toevoegen

Gebruik radical om een vierkantswortel, kubuswortel of andere wortel te maken. Het huidige element wordt de basis, en het argument wordt de graad.

Een n‑de wortel met x onder het wortelteken

Presentation presentation = new Presentation();
try {
    ISlide slide = presentation.getSlides().get_Item(0);

    IAutoShape mathShape = slide.getShapes().addMathShape(20, 20, 700, 100);
    IMathParagraph mathParagraph = ((MathPortion) mathShape.getTextFrame().getParagraphs()
            .get_Item(0).getPortions().get_Item(0)).getMathParagraph();

    IMathRadical radical = new MathematicalText("x")
            .radical("n");

    mathParagraph.add(new MathBlock(radical));

    presentation.save("radical.pptx", SaveFormat.Pptx);
} finally {
    presentation.dispose();
}

Functies en limieten toevoegen

Gebruik asArgumentOfFunction of function voor functies zoals sin(x), log(x) of aangepaste functienamen. Voor limieten, plaats lim in een MathLimit of gebruik setLowerLimit.

De limiet van x wanneer x naar oneindig gaat

Presentation presentation = new Presentation();
try {
    ISlide slide = presentation.getSlides().get_Item(0);

    IAutoShape mathShape = slide.getShapes().addMathShape(20, 20, 700, 100);
    IMathParagraph mathParagraph = ((MathPortion) mathShape.getTextFrame().getParagraphs()
            .get_Item(0).getPortions().get_Item(0)).getMathParagraph();

    IMathFunction limit = new MathematicalText("lim")
            .setLowerLimit("x→∞")
            .function("x");

    mathParagraph.add(new MathBlock(limit));

    presentation.save("functions-and-limits.pptx", SaveFormat.Pptx);
} finally {
    presentation.dispose();
}

Voor een aangepaste functienaam, maak de functienaam het huidige element:

IMathFunction customFunction = new MathematicalText("f").function("x + 1");

N-ary‑operatoren en integralen toevoegen

Gebruik nary voor sommatie‑, unie‑, intersectie‑ en andere grote operatoren. Gebruik integral voor integralen. Beide methoden laten je onder‑ en bovengrenzen instellen.

Een sommatie met onder‑ en bovengrenzen

Presentation presentation = new Presentation();
try {
    ISlide slide = presentation.getSlides().get_Item(0);

    IAutoShape mathShape = slide.getShapes().addMathShape(20, 20, 700, 120);
    IMathParagraph mathParagraph = ((MathPortion) mathShape.getTextFrame().getParagraphs()
            .get_Item(0).getPortions().get_Item(0)).getMathParagraph();

    IMathBlock summationBase = new MathematicalText("x")
            .setSuperscript("k")
            .join(new MathematicalText("a").setSuperscript("n-k"));

    IMathNaryOperator summation = summationBase.nary(MathNaryOperatorTypes.Summation, "k=0", "n");

    mathParagraph.add(new MathBlock(summation));

    presentation.save("nary-operators.pptx", SaveFormat.Pptx);
} finally {
    presentation.dispose();
}

N-ary‑operatoren zijn voor grote operatoren met optionele grenzen. Simpele operatoren zoals +, - en = worden gewoonlijk toegevoegd als MathematicalText en samengevoegd in de expressie.

Voor een integraal, gebruik integral:

IMathBlock integralBase = new MathematicalText("x").join(new MathematicalText("dx").toBox());
IMathNaryOperator integral = integralBase.integral(MathIntegralTypes.Simple, "0", "1");

Matrices toevoegen

Gebruik MathMatrix voor rijen en kolommen. Matrices bevatten standaard geen haakjes, dus omsluit de matrix wanneer je ronde haakjes, vierkante haakjes of accolades nodig hebt.

Een matrix met twee rijen en één lege cel

Presentation presentation = new Presentation();
try {
    ISlide slide = presentation.getSlides().get_Item(0);

    IAutoShape mathShape = slide.getShapes().addMathShape(20, 20, 700, 120);
    IMathParagraph mathParagraph = ((MathPortion) mathShape.getTextFrame().getParagraphs()
            .get_Item(0).getPortions().get_Item(0)).getMathParagraph();

    MathMatrix matrix = new MathMatrix(2, 3);
    matrix.set_Item(0, 0, new MathematicalText("1"));
    matrix.set_Item(0, 1, new MathematicalText("x"));
    matrix.set_Item(1, 0, new MathematicalText("x"));
    matrix.set_Item(1, 1, new MathematicalText("2"));
    matrix.set_Item(1, 2, new MathematicalText("y"));

    mathParagraph.add(new MathBlock(matrix));

    presentation.save("matrix.pptx", SaveFormat.Pptx);
} finally {
    presentation.dispose();
}

Vergelijkings‑arrays toevoegen

Gebruik toMathArray wanneer je uitgelijnde vergelijkingen of een verticale stapeling van expressies nodig hebt.

Een verticale wiskundige array met x boven y

Presentation presentation = new Presentation();
try {
    ISlide slide = presentation.getSlides().get_Item(0);

    IAutoShape mathShape = slide.getShapes().addMathShape(20, 20, 700, 140);
    IMathParagraph mathParagraph = ((MathPortion) mathShape.getTextFrame().getParagraphs()
            .get_Item(0).getPortions().get_Item(0)).getMathParagraph();

    IMathArray equationArray = new MathematicalText("x")
            .join("y")
            .toMathArray();

    mathParagraph.add(new MathBlock(equationArray));

    presentation.save("equation-array.pptx", SaveFormat.Pptx);
} finally {
    presentation.dispose();
}

Trigonometrische functies toevoegen

Gebruik asArgumentOfFunction wanneer het argument het huidige element is en de functienaam bekend is.

De trigonometrische functie cos toegepast op 2x

Presentation presentation = new Presentation();
try {
    ISlide slide = presentation.getSlides().get_Item(0);

    IAutoShape mathShape = slide.getShapes().addMathShape(20, 20, 700, 100);
    IMathParagraph mathParagraph = ((MathPortion) mathShape.getTextFrame().getParagraphs()
            .get_Item(0).getPortions().get_Item(0)).getMathParagraph();

    IMathFunction cosine = new MathematicalText("2x")
            .asArgumentOfFunction(MathFunctionsOfOneArgument.Cos);

    mathParagraph.add(new MathBlock(cosine));

    presentation.save("trigonometric-function.pptx", SaveFormat.Pptx);
} finally {
    presentation.dispose();
}

Subscript‑ en superscript‑tekens toevoegen

Gebruik de subscript‑ en superscript‑helpers voor indexen en machten. Wanneer de indexen links van de basis moeten verschijnen, gebruik setSubSuperscriptOnTheLeft.

Een hoofdletter Y met links‑bij subscript 1 en superscript n

Presentation presentation = new Presentation();
try {
    ISlide slide = presentation.getSlides().get_Item(0);

    IAutoShape mathShape = slide.getShapes().addMathShape(20, 20, 700, 100);
    IMathParagraph mathParagraph = ((MathPortion) mathShape.getTextFrame().getParagraphs()
            .get_Item(0).getPortions().get_Item(0)).getMathParagraph();

    IMathLeftSubSuperscriptElement scripts = new MathematicalText("Y")
            .setSubSuperscriptOnTheLeft("1", "n");

    mathParagraph.add(new MathBlock(scripts));

    presentation.save("subscript-superscript.pptx", SaveFormat.Pptx);
} finally {
    presentation.dispose();
}

Scheidingstekens toevoegen

Gebruik enclose om een expressie tussen scheidingstekens te plaatsen. Je kunt ook een scheidingsteken‑karakter instellen voor uitdrukkingen die meerdere elementen bevatten.

Een scheidingsteken‑expressie met x, y en z gescheiden door verticale strepen

Presentation presentation = new Presentation();
try {
    ISlide slide = presentation.getSlides().get_Item(0);

    IAutoShape mathShape = slide.getShapes().addMathShape(20, 20, 700, 100);
    IMathParagraph mathParagraph = ((MathPortion) mathShape.getTextFrame().getParagraphs()
            .get_Item(0).getPortions().get_Item(0)).getMathParagraph();

    IMathDelimiter delimiter = new MathematicalText("x")
            .join("y")
            .join("z")
            .enclose('<', '>');
    delimiter.setSeparatorCharacter('|');

    mathParagraph.add(new MathBlock(delimiter));

    presentation.save("delimiters.pptx", SaveFormat.Pptx);
} finally {
    presentation.dispose();
}

Een kader‑vak toevoegen

Gebruik toBorderBox wanneer de vergelijking zelf omlijnd moet worden.

Een ingekaderde vergelijking die a² = b² + c² toont

Presentation presentation = new Presentation();
try {
    ISlide slide = presentation.getSlides().get_Item(0);

    IAutoShape mathShape = slide.getShapes().addMathShape(20, 20, 700, 100);
    IMathParagraph mathParagraph = ((MathPortion) mathShape.getTextFrame().getParagraphs()
            .get_Item(0).getPortions().get_Item(0)).getMathParagraph();

    IMathBorderBox boxedEquation = new MathematicalText("a")
            .setSuperscript("2")
            .join("=")
            .join(new MathematicalText("b").setSuperscript("2"))
            .join("+")
            .join(new MathematicalText("c").setSuperscript("2"))
            .toBorderBox();

    mathParagraph.add(new MathBlock(boxedEquation));

    presentation.save("border-box.pptx", SaveFormat.Pptx);
} finally {
    presentation.dispose();
}

Termen groeperen

Gebruik group om een groeppensymbol boven of onder een expressie te plaatsen. Voeg een limiet toe om de gegroepeerde termen te labelen.

De expressie x + y gegroepeerd met het label enige tekst eronder

Presentation presentation = new Presentation();
try {
    ISlide slide = presentation.getSlides().get_Item(0);

    IAutoShape mathShape = slide.getShapes().addMathShape(20, 20, 700, 120);
    IMathParagraph mathParagraph = ((MathPortion) mathShape.getTextFrame().getParagraphs()
            .get_Item(0).getPortions().get_Item(0)).getMathParagraph();

    IMathLimit grouped = new MathematicalText("x + y")
            .group('\u23DF', MathTopBotPositions.Bottom, MathTopBotPositions.Top)
            .setLowerLimit("any text");

    mathParagraph.add(new MathBlock(grouped));

    presentation.save("grouped-terms.pptx", SaveFormat.Pptx);
} finally {
    presentation.dispose();
}

Wiskundige elementen opmaken

Gebruik opmaak‑helpers alleen wanneer ze de formule verduidelijken. Bijvoorbeeld, overbar plaatst een balk boven een wiskundig element.

Een wiskundige expressie ABC met een overbar

Presentation presentation = new Presentation();
try {
    ISlide slide = presentation.getSlides().get_Item(0);

    IAutoShape mathShape = slide.getShapes().addMathShape(20, 20, 700, 100);
    IMathParagraph mathParagraph = ((MathPortion) mathShape.getTextFrame().getParagraphs()
            .get_Item(0).getPortions().get_Item(0)).getMathParagraph();

    IMathBar overbar = new MathematicalText("ABC").overbar();

    mathParagraph.add(new MathBlock(overbar));

    presentation.save("overbar.pptx", SaveFormat.Pptx);
} finally {
    presentation.dispose();
}

Snelle referentie

Taak Hoofd‑API
Wiskundige tekst maken MathematicalText
Elementen combineren IMathElement.join
Breuken maken IMathElement.divide
Superscript of subscript toevoegen setSuperscript, setSubscript
Functies toevoegen function, asArgumentOfFunction
Wortels toevoegen IMathElement.radical
Limieten toevoegen setLowerLimit, setUpperLimit
Links‑scripts toevoegen setSubSuperscriptOnTheLeft
Sommaties en integralen toevoegen nary, integral
Matrices toevoegen MathMatrix
Vergelijkings‑arrays toevoegen toMathArray
Scheidingstekens toevoegen enclose
Balken en kaders toevoegen overbar, toBorderBox
Termen groeperen group

FAQ

Kan ik een bestaande PowerPoint‑vergelijking bewerken?

Ja. Open de presentatie, vind de vorm die een MathPortion bevat, haal de MathParagraph op en werk de wiskundige blokken in die alinea bij.

Worden vergelijkingen opgeslagen als bewerkbare PowerPoint‑wiskunde?

Ja. Wanneer je opslaat als PPTX, schrijft Aspose.Slides de vergelijking weg als bewerkbare Office‑wiskundige inhoud.

Kan ik vergelijkingen exporteren naar LaTeX?

Ja. Haal de IMathParagraph van de IMathPortion en roep IMathParagraph.toLatex aan om deze direct te exporteren. Voor een compleet voorbeeld, zie Export Math Equations from Presentations in Android via Java.