We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Suggestion for implementing API with formulas using strings

Hello!

I noticed that it is possible to make formulas using builder->insertHtml("") using MathML tags

But firstly, not all MathML functionality is supported by rendering in Word, and secondly, it can be inconvenient - very bold lines with tags are obtained for formulas if you write them directly in the forehead.

I designed and created (completely my own development) my own “language” of formulas, which is visual, something like WYSIWYG and some of its elements correspond to hotkeys from Word when working with formulas. My parser uses antrl. it translates a string into a mathml formula with tags. Here are some examples of usage and what happens (in all these examples, an html string is generated using my parser, and this string is fed to the input of the builder->insertHtml function

    docx::Document doc("D:\\TMP\\document");

    doc.write(enter + "UnderOver formulas" + enter);

    doc.setVar("A", 1);
    doc.setVar("B", 2);
    doc.writeFormula("#over[B][∑]= B + 250");
    doc.writeFormula("#under[A][kek] = 150 + 150");
    doc.writeFormula("#underover[∑][n=1][∞][A_[n]]");

    doc.writeFormula("T_[max.зим] = [#underover[∑][(i = 1)][24][S_[i] / t_[i]]] / S_[max] * T_[зим]");

    doc.write(enter + "Enclose formulas" + enter);

    doc.writeFormula("# A = #enclose[top][B + 250]");
    doc.writeFormula("# A = #enclose[bottom][B + 250]");
    doc.writeFormula("# A = #enclose[left][B + 250]");

    doc.write(enter + "Decorative non-calculate formulas" + enter);

    doc.setVar("θ_[ННТ]", 1);
    doc.write("температуры масла в верхних слоях ($$θ_[М]$$) и температуры обмотки ($$θ_[ННТ] = {θ_[ННТ]}$$)" + enter);
    doc.writeFormula("A = 1 = 2= 3  = 4+5+1 * 2 = 1");
    doc.writeFormula("B = 1 + + + 2 * * 2 = 1");

    doc.write(enter + "Simple test" + enter);
    doc.writeFormula("# A = 2.5");
    doc.writeFormula("# B = A + 2.5");
    doc.writeFormula("# B = 2.6 - A");
    doc.writeFormula("# B = 2,7 * A");
    doc.writeFormula("# B = -1 / -5 * A");

    doc.write(enter + "Spaces symbols ignore" + enter);
    doc.writeFormula("# B    =    1");
    doc.writeFormula("# B \t= 1");
    doc.writeFormula("# B \n= 1");

    doc.write(enter + "references" + enter);

    doc.writeFormula("# B_[a] = B^[2]");
    doc.writeFormula("# B^^[b] = #sin[B_[a]] * #cos[3.14]");
    doc.writeFormula("# B_[c] = {B_[a]} + B_[a]");

    doc.write(enter + "top bottom Indexes" + enter);

    doc.writeFormula("# B^^[a]_[c] = 1 ");
    doc.writeFormula("# #subsup[B][a][b] = 55");

    doc.write(enter + "Тригонометрия" + enter);

    doc.writeFormula("# B = #tan[1] * #atan[1]");
    doc.writeFormula("# B = #tan[1] / #atan[1]");
    doc.writeFormula("# X = #sin[1]^[2] + 1");

    doc.write(enter + "Braces and square braces, which only set priority" + enter);

    doc.writeFormula("# C = A + B / X + 4");
    doc.write("$$#enter$$");
    doc.writeFormula("# C = (A + B) / C + X");
    doc.writeFormula("# C = C + (X / B) + A");
    doc.writeFormula("# C = B + A / (C + X)");
    doc.write("$$#enter$$");
    doc.writeFormula("# C = [A + B] / C + X");
    doc.writeFormula("# C = C + [X / B] + A");
    doc.writeFormula("# C = B + A / [C + X]");

    doc.write(enter + "russians symbols (actually any of Unicode are supported)" + enter);

    doc.setVar("Мама", 2);
    doc.setVar("Папа", 3);
    doc.setVar("Я", 1);
    doc.writeFormula("# СчастливаяСемья = Мама + Папа + Я");

    doc.write(enter + "Example from real life calculation" + enter);

    doc.setVar("θ_[сез]", -15);
    doc.setVar("ϑ_[м.нач]", 0);
    doc.setVar("ϑ_[м.ном]", 55);
    doc.setVar("ϑ_[ннт.м.ном]", 23);
    doc.setVar("X", 0.8);
    doc.setVar("Y", 1.6);
    doc.setVar("τ", 3);
    doc.setVar("e", 2.71828);
    doc.setVar("d^^[′′]", 2);
    doc.setVar("S_[ном]", 16);
    doc.setVar("S_[нагр]", 20);
    doc.setVar("t", 1);

    doc.writeFormula("# K = S_[нагр] / S_[ном]");
    doc.writeFormula("# ϑ_[м.уст] = ϑ_[м.ном] * ([1 + d^^[′′] * K^[2]] / [1 + d^^[′′]])^[X]");
    doc.writeFormula("# ϑ_[ннт.м.уст] = ϑ_[ннт.м.ном] * K^[Y]");
    doc.writeFormula("# ϑ_[м.t] = ϑ_[м.уст] + (ϑ_[м.нач] - ϑ_[м.уст]) * e^[-[t/τ]]");
    doc.writeFormula("# θ_[м.t] = ϑ_[м.t] + θ_[сез]");
    doc.writeFormula("# θ_[ннт.t] = θ_[м.t] + ϑ_[ннт.м.уст]");

output:
document.docx (20.8 KB)

Is Aspose interested in such technology?

@vavp Thank you for your suggestion. The code looks pretty and convenient to use. But creating formulas programmatically is not very demanded feature by our customers. During the last 10 years there were only several requests about such functionality and most of the customers are satisficed with MathML+InsertHtml method.
If you share your solution, we will consider integrating it into Aspose.Words.