diff --git a/Mathematical-Equation/Create-Complex-Equation/.NET/Create-Complex-Equation.sln b/Mathematical-Equation/Create-Complex-Equation/.NET/Create-Complex-Equation.sln new file mode 100644 index 00000000..ba304cd4 --- /dev/null +++ b/Mathematical-Equation/Create-Complex-Equation/.NET/Create-Complex-Equation.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.14.37531.7 d17.14 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Create-Complex-Equation", "Create-Complex-Equation\Create-Complex-Equation.csproj", "{2091E74E-6598-9AFD-0545-AFFF3C4C90D2}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {2091E74E-6598-9AFD-0545-AFFF3C4C90D2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2091E74E-6598-9AFD-0545-AFFF3C4C90D2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2091E74E-6598-9AFD-0545-AFFF3C4C90D2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2091E74E-6598-9AFD-0545-AFFF3C4C90D2}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {F3B3C138-6133-4B1A-8CAC-84CD7CED6B00} + EndGlobalSection +EndGlobal diff --git a/Mathematical-Equation/Create-Complex-Equation/.NET/Create-Complex-Equation/Create-Complex-Equation.csproj b/Mathematical-Equation/Create-Complex-Equation/.NET/Create-Complex-Equation/Create-Complex-Equation.csproj new file mode 100644 index 00000000..401993e4 --- /dev/null +++ b/Mathematical-Equation/Create-Complex-Equation/.NET/Create-Complex-Equation/Create-Complex-Equation.csproj @@ -0,0 +1,19 @@ + + + + Exe + net8.0 + Create_Complex_Equation + + + + + + + + + Always + + + + diff --git a/Mathematical-Equation/Create-Complex-Equation/.NET/Create-Complex-Equation/Output/.gitkeep b/Mathematical-Equation/Create-Complex-Equation/.NET/Create-Complex-Equation/Output/.gitkeep new file mode 100644 index 00000000..5f282702 --- /dev/null +++ b/Mathematical-Equation/Create-Complex-Equation/.NET/Create-Complex-Equation/Output/.gitkeep @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Mathematical-Equation/Create-Complex-Equation/.NET/Create-Complex-Equation/Output/Output.docx b/Mathematical-Equation/Create-Complex-Equation/.NET/Create-Complex-Equation/Output/Output.docx new file mode 100644 index 00000000..0afd0a51 Binary files /dev/null and b/Mathematical-Equation/Create-Complex-Equation/.NET/Create-Complex-Equation/Output/Output.docx differ diff --git a/Mathematical-Equation/Create-Complex-Equation/.NET/Create-Complex-Equation/Program.cs b/Mathematical-Equation/Create-Complex-Equation/.NET/Create-Complex-Equation/Program.cs new file mode 100644 index 00000000..be50636b --- /dev/null +++ b/Mathematical-Equation/Create-Complex-Equation/.NET/Create-Complex-Equation/Program.cs @@ -0,0 +1,163 @@ +using Syncfusion.DocIO.DLS; +using Syncfusion.Office; +using System.IO; + +namespace Create_Complex_Equation +{ + class Program + { + static void Main(string[] args) + { + + // Create WordDocument instance + using (WordDocument document = new WordDocument()) + { + document.EnsureMinimal(); + // Add mathml equation in the word document + AddMathMLEquation(document.LastParagraph); + // Save the document to file + document.Save(Path.GetFullPath(@"Output/Output.docx")); + } + } + /// + /// Adds a math equation in the word document using MathML + /// + /// Represents a Word document paragraph to add math text + private static void AddMathMLEquation(WParagraph paragraph) + { + WordDocument document = paragraph.Document; + //Creates a new MathML element + WMath math = paragraph.AppendMath(); + IOfficeMath officeMath = math.MathParagraph.Maths.Add(); + + // Adds a Subscript equation + IOfficeMathScript mathScript = AddMathScript(officeMath, MathScriptType.Subscript); + //Adds a math text + AddMathText(document, mathScript.Equation, "L"); + AddMathText(document, mathScript.Script, "r") + ; + AddMathText(document, officeMath, "="); + + AddMathText(document, officeMath, "1.95"); + mathScript = AddMathScript(officeMath, MathScriptType.Subscript); + AddMathText(document, mathScript.Equation, "f"); + AddMathText(document, mathScript.Script, "t"); + + //Adds a math fraction + IOfficeMathFraction mathFraction = officeMath.Functions.Add(MathFunctionType.Fraction) as IOfficeMathFraction; + //Adds a numerator text + AddMathText(document, mathFraction.Numerator, "E"); + //Adds a math script + mathScript = AddMathScript(mathFraction.Denominator, MathScriptType.Subscript); + + //Adds a math text for Superscript + AddMathText(document, mathScript.Equation, "F"); + AddMathText(document, mathScript.Script, "L"); + + //Adds a radical equation + IOfficeMathRadical officeMathRadical = officeMath.Functions.Add(MathFunctionType.Radical) as IOfficeMathRadical; + //Sets false to show degree in radical + officeMathRadical.HideDegree = true; + //Adds a numerator text + AddMathText(document, officeMathRadical.Degree, ""); + + officeMath = officeMathRadical.Equation; + + mathFraction = officeMath.Functions.Add(MathFunctionType.Fraction) as IOfficeMathFraction; + //Adds a numerator text + AddMathText(document, mathFraction.Numerator, "J"); + mathScript = AddMathScript(mathFraction.Denominator, MathScriptType.Subscript); + + //Adds a math text for Superscript + AddMathText(document, mathScript.Equation, "S"); + AddMathText(document, mathScript.Script, "xc"); + mathScript = AddMathScript(mathFraction.Denominator, MathScriptType.Subscript); + + //Adds a math text for Superscript + AddMathText(document, mathScript.Equation, "h"); + AddMathText(document, mathScript.Script, "0"); + + AddMathText(document, officeMath, "+"); + + //Adds a radical equation + officeMathRadical = officeMath.Functions.Add(MathFunctionType.Radical) as IOfficeMathRadical; + //Sets false to show degree in radical + officeMathRadical.HideDegree = true; + //Adds a numerator text + AddMathText(document, officeMathRadical.Degree, ""); + + officeMath = officeMathRadical.Equation; + + //Adds a math script element + IOfficeMathScript mathScript1 = AddMathScript(officeMath, MathScriptType.Superscript); + + IOfficeMathDelimiter mathDelimiter = mathScript1.Equation.Functions.Add(MathFunctionType.Delimiter) as IOfficeMathDelimiter; + + // Adds an office math in the delimiter + officeMath = mathDelimiter.Equation.Add() as IOfficeMath; + + mathFraction = officeMath.Functions.Add(MathFunctionType.Fraction) as IOfficeMathFraction; + //Adds a numerator text + AddMathText(document, mathFraction.Numerator, "J"); + mathScript = AddMathScript(mathFraction.Denominator, MathScriptType.Subscript); + + //Adds a math text for Superscript + AddMathText(document, mathScript.Equation, "S"); + AddMathText(document, mathScript.Script, "xc"); + mathScript = AddMathScript(mathFraction.Denominator, MathScriptType.Subscript); + + //Adds a math text for Superscript + AddMathText(document, mathScript.Equation, "h"); + AddMathText(document, mathScript.Script, "0"); + //Adds a math text + AddMathText(document, mathScript1.Script, "2"); + + officeMath = officeMathRadical.Equation; + + AddMathText(document, officeMath, "+"); + AddMathText(document, officeMath, "6.76"); + + //Adds a math script element + mathScript1 = AddMathScript(officeMath, MathScriptType.Superscript); + mathDelimiter = mathScript1.Equation.Functions.Add(MathFunctionType.Delimiter) as IOfficeMathDelimiter; + // Adds an office math in the delimiter + officeMath = mathDelimiter.Equation.Add() as IOfficeMath; + //Adds a math fraction + mathFraction = officeMath.Functions.Add(MathFunctionType.Fraction) as IOfficeMathFraction; + //Adds a numerator text + AddMathText(document, mathFraction.Denominator, "E"); + //Adds a math script + mathScript = AddMathScript(mathFraction.Numerator, MathScriptType.Subscript); + //Adds a math text for Superscript + AddMathText(document, mathScript.Equation, "F"); + AddMathText(document, mathScript.Script, "L"); + //Adds a math text + AddMathText(document, mathScript1.Script, "2"); + } + /// + /// Adds a math text + /// + /// Represents a Word document to add math text + /// Represents an office math to add math text + /// Represents the text to set for math item + private static IOfficeMathRunElement AddMathText(WordDocument document, IOfficeMath officeMath, string text) + { + //Adds math text + IOfficeMathRunElement officeMathParaItem = officeMath.Functions.Add(MathFunctionType.RunElement) as IOfficeMathRunElement; + officeMathParaItem.Item = new WTextRange(document); + //Set math text value + (officeMathParaItem.Item as WTextRange).Text = text; + return officeMathParaItem; + } + /// + /// Adds a math Subscript or Superscript equation + /// + private static IOfficeMathScript AddMathScript(IOfficeMath officeMath, MathScriptType mathScriptType) + { + IOfficeMathScript mathScript = officeMath.Functions.Add(MathFunctionType.SubSuperscript) as IOfficeMathScript; + //Sets the script type as Subscript or Superscript + mathScript.ScriptType = mathScriptType; + return mathScript; + } + } +}