เพิ่มสมการคณิตศาสตร์เข้าสู่การนำเสนอ PowerPoint บน Android

ภาพรวม

PowerPoint เก็บสมการเป็น Office Math Markup Language (OMML) โดยใช้ Aspose.Slides สำหรับ Android ผ่าน Java คุณสามารถสร้างเนื้อหาคณิตศาสตร์ประเภทเดียวกันได้โดยอัตโนมัติ: ส่วนเศษส่วน, ราก, ฟังก์ชัน, ขีดจำกัด, ตัวดำเนินการแบบ N-ary, เมทริกซ์, อาร์เรย์, และบล็อกคณิตศาสตร์ที่จัดรูปแบบ

ใน PowerPoint ผู้ใช้มักเพิ่มสมการจาก Insert > Equation:

แท็บ Insert ของ PowerPoint พร้อมคำสั่ง Equation ที่เลือก

ผลลัพธ์คือข้อความคณิตศาสตร์ที่สามารถแก้ไขได้บนสไลด์:

สไลด์ PowerPoint ที่มีสมการคณิตศาสตร์ที่แก้ไขได้

Aspose.Slides สร้างข้อความคณิตศาสตร์นั้นผ่านสามอ็อบเจกต์หลัก:

  • รูปร่างคณิตศาสตร์ที่สร้างด้วย addMathShape, คือรูปร่างที่บรรจุสมการ
  • MathPortion เก็บเนื้อหาคณิตศาสตร์ภายในเฟรมข้อความของรูปร่าง
  • MathParagraph มีหนึ่งหรือหลายอ็อบเจกต์ MathBlock

ตัวอย่างส่วนใหญ่ด้านล่างใช้ MathematicalText และเมธอดแบบ fluent จาก IMathElement เพื่อให้โค้ดสั้นและอ่านง่าย

สำหรับสถานการณ์การส่งออก MathML ดูที่ Export Math Equations from Presentations on Android

สร้างสมการ

ตัวอย่างนี้สร้างรูปร่างคณิตศาสตร์และเพิ่มทฤษฎีบทของพีทาโกรัส:

สมการ 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();
}

เพิ่มส่วนเศษส่วน

ใช้ divide เพื่อสร้างส่วนเศษส่วน. คุณสามารถเลือกสไตล์ส่วนเศษส่วนด้วย MathFractionTypes.

ส่วนเศษส่วนคณิตศาสตร์ที่เอียงแสดง 1 หาร x

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

สำหรับส่วนเศษส่วนแบบซ้อน, ใช้ MathFractionTypes.Bar:

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

เพิ่มราก

ใช้ radical เพื่อสร้างรากกำลังสอง, รากกำลังสาม หรือรากอื่น ๆ. อิลิเมนต์ปัจจุบันจะเป็นฐานและอาร์กิวเมนต์จะเป็นระดับของราก

นิพจน์ราก n-th ที่มี x อยู่ใต้สัญลักษณ์ราก

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

เพิ่มฟังก์ชันและขีดจำกัด

ใช้ asArgumentOfFunction หรือ function สำหรับฟังก์ชันเช่น sin(x), log(x), หรือชื่อฟังก์ชันที่กำหนดเอง. สำหรับขีดจำกัด, ใส่ lim ใน MathLimit หรือใช้ setLowerLimit.

ขีดจำกัดของ x เมื่อ x เข้าใกล้อนันต์

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

สำหรับชื่อฟังก์ชันที่กำหนดเอง, ทำให้ชื่อฟังก์ชันเป็นอิลิเมนต์ปัจจุบัน:

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

เพิ่มตัวดำเนินการ N-ary และอินทิกรัล

ใช้ nary สำหรับผลรวม, ยูเนียน, อินเตอร์เซกชันและตัวดำเนินการขนาดใหญ่อื่น ๆ. ใช้ integral สำหรับอินทิกรัล. ทั้งสองเมธอดให้คุณตั้งค่าขีดจำกัดล่างและบนได้

ผลรวมที่มีขีดจำกัดล่างและบน

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 ใช้สำหรับตัวดำเนินการขนาดใหญ่ที่มีขีดจำกัดเลือกได้. ตัวดำเนินการง่ายเช่น +, - และ = มักถูกเพิ่มเป็น MathematicalText แล้วรวมเข้ากับนิพจน์

สำหรับอินทิกรัล, ใช้ integral:

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

เพิ่มเมทริกซ์

ใช้ MathMatrix สำหรับแถวและคอลัมน์. เมทริกซ์โดยค่าเริ่มต้นจะไม่มีวงเล็บ, ดังนั้นให้ใส่วงเล็บ, เครื่องหมายหรือปีกกาเมื่อต้องการ

เมทริกซ์คณิตศาสตร์สองแถวที่มีช่องว่างหนึ่งช่อง

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

เพิ่มอาร์เรย์สมการ

ใช้ toMathArray เมื่อคุณต้องการสมการที่จัดแนวหรือสแต็กแนวตั้งของนิพจน์

อาร์เรย์คณิตศาสตร์แนวตั้งที่มี x อยู่เหนือ 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();
}

เพิ่มฟังก์ชันตรีโกณ

ใช้ asArgumentOfFunction เมื่ออาร์กิวเมนต์เป็นอิลิเมนต์ปัจจุบันและชื่อฟังก์ชันทราบแล้ว

ฟังก์ชันตรีโกณมิติ cos ใบ้กับ 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();
}

เพิ่มตัวห้อยและตัวบน

ใช้ตัวช่วยสำหรับตัวห้อยและตัวบนสำหรับดัชนีและกำลัง. เมื่อดัชนีต้องอยู่ด้านซ้ายของฐาน, ใช้ setSubSuperscriptOnTheLeft.

อักษร Y พิมพ์ใหญ่ที่มีตัวห้อยด้านซ้าย 1 และตัวบน 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();
}

เพิ่มตัวแบ่ง

ใช้ enclose เพื่อใส่นิพจน์ภายในตัวแบ่ง. คุณยังสามารถตั้งค่าตัวอักษรคั่นสำหรับนิพจน์ที่มีหลายอิลิเมนต์ได้

นิพจน์ตัวแบ่งที่มี x, y, และ z แยกด้วยเส้นแนวตั้ง

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

เพิ่มกล่องขอบ

ใช้ toBorderBox เมื่อสมการเองต้องการกรอบ

สมการในกล่องที่แสดง a² = b² + c²

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

จัดกลุ่มเทอม

ใช้ group เพื่อวางอักขระการจัดกลุ่มเหนือหรือใต้นิพจน์. เพิ่มขีดจำกัดเพื่อทำป้ายกำกับให้กับเทอมที่จัดกลุ่ม

นิพจน์ x + y ที่จัดกลุ่มพร้อมป้ายกำกับข้อความใด ๆ ด้านล่าง

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

จัดรูปแบบองค์ประกอบคณิตศาสตร์

ใช้ตัวช่วยจัดรูปแบบเฉพาะที่ช่วยทำให้สูตรชัดเจน. ตัวอย่างเช่น overbar จะวางเส้นเหนืออิลิเมนต์คณิตศาสตร์

นิพจน์คณิตศาสตร์ ABC ที่มีเส้นเหนือ

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

อ้างอิงอย่างรวดเร็ว

งาน API หลัก
สร้างข้อความคณิตศาสตร์ MathematicalText
รวมองค์ประกอบ IMathElement.join
สร้างส่วนเศษส่วน IMathElement.divide
เพิ่มตัวบนหรือตัวห้อย setSuperscript, setSubscript
เพิ่มฟังก์ชัน function, asArgumentOfFunction
เพิ่มราก IMathElement.radical
เพิ่มขีดจำกัด setLowerLimit, setUpperLimit
เพิ่มสคริปต์ด้านซ้าย setSubSuperscriptOnTheLeft
เพิ่มผลรวมและอินทิกรัล nary, integral
เพิ่มเมทริกซ์ MathMatrix
เพิ่มอาร์เรย์สมการ toMathArray
เพิ่มตัวแบ่ง enclose
เพิ่มแถบและขอบ overbar, toBorderBox
จัดกลุ่มเทอม group

คำถามที่พบบ่อย

ฉันสามารถแก้ไขสมการ PowerPoint ที่มีอยู่ได้หรือไม่?

ใช่. เปิดการพรีเซนเทชัน, ค้นหารูปร่างที่บรรจุ MathPortion, รับ MathParagraph ของมัน, แล้วอัปเดต MathBlock ในพารากราฟนั้น

สมการถูกบันทึกเป็นคณิตศาสตร์ PowerPoint ที่แก้ไขได้หรือไม่?

ใช่. เมื่อบันทึกเป็น PPTX, Aspose.Slides จะเขียนสมการเป็นเนื้อหา Office Math ที่แก้ไขได้

ฉันสามารถส่งออกสมการเป็น LaTeX ได้หรือไม่?

Aspose.Slides ส่งออกสมการคณิตศาสตร์เป็น MathML. หากคุณต้องการ LaTeX, ให้ส่งออกเป็น MathML ก่อนแล้วแปลง MathML ด้วยเครื่องมือที่รองรับรูปแบบ LaTeX ที่คุณต้องการ