Skip to content

Commit 4a62226

Browse files
author
sneha.biju
committed
Sample to modify the existing equation using LaTeX in a Word document
1 parent eaacda9 commit 4a62226

File tree

4 files changed

+69
-0
lines changed

4 files changed

+69
-0
lines changed
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}") = "Modify-equation-using-LaTeX", "Modify-equation-using-LaTeX\Modify-equation-using-LaTeX.csproj", "{BA52BFB0-4D93-403A-A91C-83DE160B6D29}"
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+
{BA52BFB0-4D93-403A-A91C-83DE160B6D29}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{BA52BFB0-4D93-403A-A91C-83DE160B6D29}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{BA52BFB0-4D93-403A-A91C-83DE160B6D29}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{BA52BFB0-4D93-403A-A91C-83DE160B6D29}.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 = {E206BA58-F65C-40BB-985F-ADF3F38061CF}
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>Modify_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: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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())
9+
{
10+
// Access the first paragraph from the last section of the document
11+
WParagraph paragraph = document.LastSection.Body.ChildEntities[2] as WParagraph;
12+
13+
// Retrieve the first math equation in the paragraph, if it exists
14+
WMath math = paragraph.ChildEntities[0] as WMath;
15+
if (math != null)
16+
{
17+
// Get the LaTeX representation of the math equation
18+
string laTeX = math.MathParagraph.LaTeX;
19+
// Replace occurrences of 'a' with 's' in the LaTeX representation
20+
laTeX = laTeX.Replace("x", "k");
21+
//Modify the LaTeX string
22+
math.MathParagraph.LaTeX = laTeX;
23+
}
24+
using (FileStream outputStream = new FileStream(@"../../../Result.docx", FileMode.Create, FileAccess.Write))
25+
{
26+
document.Save(outputStream, FormatType.Docx);
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)