Skip to content

Commit 6fb95f0

Browse files
Merge pull request #186 from snehasf3509/main
Sample to insert an equation using LaTeX in a Word document
2 parents a7c0915 + 719574d commit 6fb95f0

File tree

19 files changed

+330
-1
lines changed

19 files changed

+330
-1
lines changed

Mathematical-Equation/LaTeX-equations/Create-equation-using-LaTeX/.NET Standard/Create-equation-using-LaTeX/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
//Add one section and one paragraph to the document.
99
document.EnsureMinimal();
1010

11-
//Append an accent equation using LaTeX.
11+
//Append an Fourier series equation using LaTeX.
1212
document.LastParagraph.AppendMath(@"f\left(x\right)={a}_{0}+\sum_{n=1}^{\infty}{\left({a}_{n}\cos{\frac{n\pi{x}}{L}}+{b}_{n}\sin{\frac{n\pi{x}}{L}}\right)}");
1313

1414
//Save the Word document.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.8.34322.80
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Get-LaTeX-code-for-equation", "Get-LaTeX-code-for-equation\Get-LaTeX-code-for-equation.csproj", "{C6B9981D-31EB-4763-A808-9C7360B40D2D}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{C6B9981D-31EB-4763-A808-9C7360B40D2D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{C6B9981D-31EB-4763-A808-9C7360B40D2D}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{C6B9981D-31EB-4763-A808-9C7360B40D2D}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{C6B9981D-31EB-4763-A808-9C7360B40D2D}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {4DEC13AD-D738-4D71-9512-61478E21690F}
24+
EndGlobalSection
25+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net6.0</TargetFramework>
6+
<RootNamespace>Get_LaTeX_code_for_equation</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Syncfusion.DocIO.Net.Core" Version="*" />
13+
</ItemGroup>
14+
15+
</Project>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using Syncfusion.DocIO;
2+
using Syncfusion.DocIO.DLS;
3+
4+
//Open a Word document using File stream.
5+
using (FileStream inputStream = new FileStream("../../../Input.docx", FileMode.Open, FileAccess.Read))
6+
{
7+
// OPen the existing Word document.
8+
using (WordDocument document = new WordDocument(inputStream, FormatType.Docx))
9+
{
10+
List<Entity> entities = document.FindAllItemsByProperty(EntityType.Math, null, null);
11+
12+
//Iterate through each equation in the Word document.
13+
foreach (Entity entity in entities)
14+
{
15+
WMath math = entity as WMath;
16+
//Get the laTeX code of equation.
17+
string laTeX = math.MathParagraph.LaTeX;
18+
//Print the LaTeX equation
19+
Console.WriteLine(laTeX + "\n");
20+
}
21+
}
22+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.8.34322.80
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Insert-equation-using-LaTeX", "Insert-equation-using-LaTeX\Insert-equation-using-LaTeX.csproj", "{75FB50C3-447C-4F91-96AB-C73977FDF1AE}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{75FB50C3-447C-4F91-96AB-C73977FDF1AE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{75FB50C3-447C-4F91-96AB-C73977FDF1AE}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{75FB50C3-447C-4F91-96AB-C73977FDF1AE}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{75FB50C3-447C-4F91-96AB-C73977FDF1AE}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {C7285ED4-808B-42BF-87B8-4338EBAF8572}
24+
EndGlobalSection
25+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net6.0</TargetFramework>
6+
<RootNamespace>Insert_equation_using_LaTeX</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Syncfusion.DocIO.Net.Core" Version="*" />
13+
</ItemGroup>
14+
15+
</Project>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using Syncfusion.DocIO;
2+
using Syncfusion.DocIO.DLS;
3+
4+
//Open a Word document using File stream.
5+
using (FileStream inputStream = new FileStream("../../../Input.docx", FileMode.Open, FileAccess.Read)) {
6+
// OPen the existing Word document.
7+
using (WordDocument document = new WordDocument(inputStream, FormatType.Docx))
8+
{
9+
//Create a new mathematical equation.
10+
WMath math = new WMath(document);
11+
//Set the LaTeX string to the equation .
12+
math.MathParagraph.LaTeX = @"f\left(x\right)={a}_{0}+\sum_{n=1}^{\infty}{\left({a}_{n}\cos{\frac{n\pi{x}}{L}}+{b}_{n}\sin{\frac{n\pi{x}}{L}}\right)}";
13+
//Insert the new mathematical equation to existing paragraph.
14+
document.LastSection.Paragraphs[2].ChildEntities.Insert(0, math);
15+
16+
//Save the Word document.
17+
using (FileStream outputStream = new FileStream(Path.GetFullPath(@"../../../Result.docx"), FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite))
18+
{
19+
document.Save(outputStream, FormatType.Docx);
20+
}
21+
}
22+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.8.34322.80
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LaTeX-equation-into-Image", "LaTeX-equation-into-Image\LaTeX-equation-into-Image.csproj", "{2198BE02-2850-468C-8C30-C8386D8324B4}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{2198BE02-2850-468C-8C30-C8386D8324B4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{2198BE02-2850-468C-8C30-C8386D8324B4}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{2198BE02-2850-468C-8C30-C8386D8324B4}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{2198BE02-2850-468C-8C30-C8386D8324B4}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {27F0B50D-0D1B-4928-BA46-EDEDCB1CA1B4}
24+
EndGlobalSection
25+
EndGlobal

0 commit comments

Comments
 (0)