diff --git a/File-Formats/DocIO/Working-with-LaTeX.md b/File-Formats/DocIO/Working-with-LaTeX.md index 00397d842..e5a76cd42 100644 --- a/File-Formats/DocIO/Working-with-LaTeX.md +++ b/File-Formats/DocIO/Working-with-LaTeX.md @@ -1569,3 +1569,265 @@ The following table demonstrates the LaTeX equivalent to professional format Rig {\mathbf{100}}_{\mathbf{40}}^{\mathbf{20}} + +## Format Equations + +### Apply style to characters + +Apply styles to characters, such as bold and bold-italic, for equations in a Word document using LaTeX with the .NET Word Library. Apply the following styles using LaTeX commands. + + + + + + + + + + + + + + + + +
StylesLaTeX
+Bold

+\mathbf

+BoldItalic

+\mathbit

+ +The following code example demonstrates how to apply styles to characters within equations in a Word document. + +{% tabs %} + +{% highlight c# tabtitle="C# [Cross-platform]" %} +// Create a new Word document. +using (WordDocument document = new WordDocument()) +{ + //Add one section and one paragraph to the document. + document.EnsureMinimal(); + + //Append an accent equation with bold using LaTeX. + document.LastParagraph.AppendMath(@"\dot{\mathbf{a}}"); + //Append an accent equation with bold-italic using LaTeX. + document.LastSection.AddParagraph().AppendMath(@"\dot{\mathbit{a}}"); + + //Save a Word document to the MemoryStream. + using (MemoryStream stream = new MemoryStream()) + { + document.Save(stream, FormatType.Docx); + } +} +{% endhighlight %} + +{% highlight c# tabtitle="C# [Windows-specific]" %} +// Create a new Word document. +using (WordDocument document = new WordDocument()) +{ + + //Add one section and one paragraph to the document. + document.EnsureMinimal(); + + //Append an accent equation with bold using LaTeX. + document.LastParagraph.AppendMath(@"\dot{\mathbf{a}}"); + //Append an accent equation with bold-italic using LaTeX. + document.LastSection.AddParagraph().AppendMath(@"\dot{\mathbit{a}}"); + + //Save a Word document. + document.Save("Result.docx", FormatType.Docx); +} +{% endhighlight %} + +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +' Create a new Word document. +Dim document As WordDocument = New WordDocument() + +'Add one section and one paragraph to the document. +document.EnsureMinimal() + +'Append an accent equation with Bold using LaTeX. +document.LastParagraph.AppendMath(@"\dot{\mathbf{a}}") +'Append an accent equation with Bold-Italic using LaTeX. +document. LastSection.AddParagraph().AppendMath(@"\dot{\mathbit{a}}") + +'Save the Word document. +document.Save("Result.docx", FormatType.Docx) +{% endhighlight %} + +{% endtabs %} + +### Apply scripts to the equation + +Apply scripts, such as double-struck, fraktur, and more, to equations in a Word document using LaTeX with the .NET Word Library. Apply the following scripts using LaTeX commands. + + + + + + + + + + + + + + + + + + + + + + + + +
ScriptsLaTeX
+Double-struck

+\mathbb

+Fraktur

+\mathfrak

+Sans Serif

+\mathsf

+Script

+\mathscr
\mathcal
+ +The following code examples show how to apply the scripts to equations in a Word document. + +{% tabs %} + +{% highlight c# tabtitle="C# [Cross-platform]" %} +// Create a new Word document. +using (WordDocument document = new WordDocument()) +{ + //Add one section and one paragraph to the document. + document.EnsureMinimal(); + + //Append an accent equation with Double-Struck font using LaTeX. + document.LastParagraph.AppendMath(@"\dot{\mathbb{a}}"); + //Append an accent equation with Fraktur font using LaTeX. + document.LastSection.AddParagraph().AppendMath(@"\dot{\mathfrak{a}}"); + //Append an accent equation with Sans Serif font using LaTeX. + document.LastSection.AddParagraph().AppendMath(@"\dot{\mathsf{a}}"); + //Append an accent equation with Script using LaTeX. + document.LastSection.AddParagraph().AppendMath(@"\dot{\mathcal{a}}"); + //Append an accent equation with Script using LaTeX. + document.LastSection.AddParagraph().AppendMath(@"\dot{\mathscr{a}}"); + + //Save a Word document to the MemoryStream. + using (MemoryStream stream = new MemoryStream()) + { + document.Save(stream, FormatType.Docx); + } +} +{% endhighlight %} + +{% highlight c# tabtitle="C# [Windows-specific]" %} +// Create a new Word document. +using (WordDocument document = new WordDocument()) +{ + //Add one section and one paragraph to the document. + document.EnsureMinimal(); + + //Append an accent equation with DoubleStruck font using LaTeX. + document.LastParagraph.AppendMath(@"\dot{\mathbb{a}}"); + //Append an accent equation with Fraktur font using LaTeX. + document.LastSection.AddParagraph().AppendMath(@"\dot{\mathfrak{a}}"); + //Append an accent equation with SansSerif font using LaTeX. + document.LastSection.AddParagraph().AppendMath(@"\dot{\mathsf{a}}"); + //Append an accent equation with Script using LaTeX. + document.LastSection.AddParagraph().AppendMath(@"\dot{\mathcal{a}}"); + //Append an accent equation with Script using LaTeX. + document.LastSection.AddParagraph().AppendMath(@"\dot{\mathscr{a}}"); + + //Save a Word document. + document.Save("Result.docx", FormatType.Docx); +} +{% endhighlight %} + +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +' Create a new Word document. +Dim document As WordDocument = New WordDocument() + +'Add one section and one paragraph to the document. +document.EnsureMinimal() + +'Append an accent equation with DoubleStruck font using LaTeX. +document.LastParagraph.AppendMath(@"\dot{\mathbb{a}}") +'Append an accent equation with Fraktur font using LaTeX. +document.LastSection.AddParagraph().AppendMath(@"\dot{\mathfrak{a}}") +'Append an accent equation with SansSerif font using LaTeX. +document. LastSection.AddParagraph().AppendMath(@"\dot{\mathsf{a}}") +'Append an accent equation with Script using LaTeX. +document. LastSection.AddParagraph().AppendMath(@"\dot{\mathcal{a}}") +'Append an accent equation with Script using LaTeX. +document. LastSection.AddParagraph().AppendMath(@"\dot{\mathscr{a}}") + +'Save a Word document. +document.Save("Result.docx", FormatType.Docx) +{% endhighlight %} + +{% endtabs %} + +![Apply scripts to the equation](WorkingwithMathematicalEquation_images/scripts.png) + +### Preserve as normal text + +By default, characters in equations in a Word document are in italics. However, you can also include normal text within an equation using LaTeX. + +The following code example shows how to preserve text as normal text, without any default formatting, within an equation using LaTeX. + +{% tabs %} + +{% highlight c# tabtitle="C# [Cross-platform]" %} +// Create a new Word document. +using (WordDocument document = new WordDocument()) +{ + //Add one section and one paragraph to the document. + document.EnsureMinimal(); + + //Append an accent equation as normal text using LaTeX. + document.LastParagraph.AppendMath(@"\dot{\mathrm{a}}"); + + //Save a Word document to the MemoryStream. + using (MemoryStream stream = new MemoryStream()) + { + document.Save(stream, FormatType.Docx); + } +} +{% endhighlight %} + +{% highlight c# tabtitle="C# [Windows-specific]" %} +// Create a new Word document. +using (WordDocument document = new WordDocument()) +{ + //Add one section and one paragraph to the document. + document.EnsureMinimal(); + + //Append an accent equation as normal text using LaTeX. + document.LastParagraph.AppendMath(@"\dot{\mathrm{a}}"); + + //Save a Word document. + document.Save("Result.docx", FormatType.Docx); +} +{% endhighlight %} + +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +' Create a new Word document. +Dim document As WordDocument = New WordDocument() + +'Add one section and one paragraph to the document. +document.EnsureMinimal() + +'Append an accent equation as normal text using LaTeX. +document.LastParagraph.AppendMath(@"\dot{\mathrm{a}}") + +'Save a Word document. +document.Save("Result.docx", FormatType.Docx) +{% endhighlight %} + +{% endtabs %} + +You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/DocIO-Examples/tree/main/Mathematical-Equation/LaTeX-equations/Format%20Equation). \ No newline at end of file diff --git a/File-Formats/DocIO/WorkingwithMathematicalEquation_images/scripts.png b/File-Formats/DocIO/WorkingwithMathematicalEquation_images/scripts.png new file mode 100644 index 000000000..6f58d33f5 Binary files /dev/null and b/File-Formats/DocIO/WorkingwithMathematicalEquation_images/scripts.png differ